Skip to content

Commit 24f1641

Browse files
committed
Moved commit "CDC Initial Scan progress" from ydb repo
1 parent 8e429b8 commit 24f1641

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

include/ydb-cpp-sdk/client/table/table.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,24 @@ class TBuildIndexOperation : public TOperation {
264264

265265
////////////////////////////////////////////////////////////////////////////////
266266

267-
//! Represents index description
267+
//! Represents changefeed description
268268
class TChangefeedDescription {
269269
friend class NYdb::TProtoAccessor;
270270

271+
public:
272+
class TInitialScanProgress {
273+
public:
274+
explicit TInitialScanProgress(uint32_t total, uint32_t completed);
275+
276+
uint32_t GetPartsTotal() const;
277+
uint32_t GetPartsCompleted() const;
278+
float GetProgress() const; // percentage
279+
280+
private:
281+
uint32_t PartsTotal;
282+
uint32_t PartsCompleted;
283+
};
284+
271285
public:
272286
TChangefeedDescription(const std::string& name, EChangefeedMode mode, EChangefeedFormat format);
273287

@@ -295,6 +309,7 @@ class TChangefeedDescription {
295309
bool GetInitialScan() const;
296310
const std::unordered_map<std::string, std::string>& GetAttributes() const;
297311
const std::string& GetAwsRegion() const;
312+
const std::optional<TInitialScanProgress>& GetInitialScanProgress() const;
298313

299314
void SerializeTo(Ydb::Table::Changefeed& proto) const;
300315
std::string ToString() const;
@@ -318,6 +333,7 @@ class TChangefeedDescription {
318333
bool InitialScan_ = false;
319334
std::unordered_map<std::string, std::string> Attributes_;
320335
std::string AwsRegion_;
336+
std::optional<TInitialScanProgress> InitialScanProgress_;
321337
};
322338

323339
bool operator==(const TChangefeedDescription& lhs, const TChangefeedDescription& rhs);

src/client/table/table.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,27 @@ TChangefeedDescription::TChangefeedDescription(const Ydb::Table::ChangefeedDescr
23982398
: TChangefeedDescription(FromProto(proto))
23992399
{}
24002400

2401+
TChangefeedDescription::TInitialScanProgress::TInitialScanProgress(uint32_t total, uint32_t completed)
2402+
: PartsTotal(total)
2403+
, PartsCompleted(completed)
2404+
{}
2405+
2406+
uint32_t TChangefeedDescription::TInitialScanProgress::GetPartsTotal() const {
2407+
return PartsTotal;
2408+
}
2409+
2410+
uint32_t TChangefeedDescription::TInitialScanProgress::GetPartsCompleted() const {
2411+
return PartsCompleted;
2412+
}
2413+
2414+
float TChangefeedDescription::TInitialScanProgress::GetProgress() const {
2415+
if (PartsTotal == 0) {
2416+
return 0;
2417+
}
2418+
2419+
return 100 * float(PartsCompleted) / float(PartsTotal);
2420+
}
2421+
24012422
TChangefeedDescription& TChangefeedDescription::WithVirtualTimestamps() {
24022423
VirtualTimestamps_ = true;
24032424
return *this;
@@ -2474,6 +2495,10 @@ const std::string& TChangefeedDescription::GetAwsRegion() const {
24742495
return AwsRegion_;
24752496
}
24762497

2498+
const std::optional<TChangefeedDescription::TInitialScanProgress>& TChangefeedDescription::GetInitialScanProgress() const {
2499+
return InitialScanProgress_;
2500+
}
2501+
24772502
template <typename TProto>
24782503
TChangefeedDescription TChangefeedDescription::FromProto(const TProto& proto) {
24792504
EChangefeedMode mode;
@@ -2541,6 +2566,13 @@ TChangefeedDescription TChangefeedDescription::FromProto(const TProto& proto) {
25412566
ret.State_ = EChangefeedState::Unknown;
25422567
break;
25432568
}
2569+
2570+
if (proto.has_initial_scan_progress()) {
2571+
ret.InitialScanProgress_ = std::make_optional<TInitialScanProgress>(
2572+
proto.initial_scan_progress().parts_total(),
2573+
proto.initial_scan_progress().parts_completed()
2574+
);
2575+
}
25442576
}
25452577

25462578
for (const auto& [key, value] : proto.attributes()) {
@@ -2628,6 +2660,10 @@ void TChangefeedDescription::Out(IOutputStream& o) const {
26282660
o << ", aws_region: " << AwsRegion_;
26292661
}
26302662

2663+
if (InitialScanProgress_) {
2664+
o << ", initial_scan_progress: " << InitialScanProgress_->GetProgress() << "%";
2665+
}
2666+
26312667
o << " }";
26322668
}
26332669

0 commit comments

Comments
 (0)