Skip to content

Commit 6691c9a

Browse files
committed
Use checkpoint_row_count to replace row_count
1 parent cead513 commit 6691c9a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/storage/meta/entry/segment_entry.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ SharedPtr<BlockEntry> SegmentEntry::GetBlockEntryByID(BlockID block_id) const {
409409
nlohmann::json SegmentEntry::Serialize(TxnTimeStamp max_commit_ts) {
410410
nlohmann::json json_res;
411411

412+
this->checkpoint_row_count_ = 0;
413+
412414
// const field
413415
json_res["segment_dir"] = *this->segment_dir_;
414416
json_res["row_capacity"] = this->row_capacity_;
@@ -420,7 +422,6 @@ nlohmann::json SegmentEntry::Serialize(TxnTimeStamp max_commit_ts) {
420422
json_res["min_row_ts"] = this->min_row_ts_;
421423
json_res["max_row_ts"] = std::min(this->max_row_ts_, max_commit_ts);
422424
json_res["deleted"] = this->deleted_;
423-
json_res["row_count"] = this->row_count_;
424425
json_res["actual_row_count"] = this->actual_row_count_;
425426

426427
json_res["commit_ts"] = TxnTimeStamp(this->commit_ts_);
@@ -436,8 +437,11 @@ nlohmann::json SegmentEntry::Serialize(TxnTimeStamp max_commit_ts) {
436437
if (block_entry->commit_ts_ <= max_commit_ts) {
437438
block_entry->Flush(max_commit_ts);
438439
json_res["block_entries"].emplace_back(block_entry->Serialize(max_commit_ts));
440+
this->checkpoint_row_count_ += block_entry->checkpoint_row_count();
439441
}
440442
}
443+
444+
json_res["row_count"] = this->checkpoint_row_count_;
441445
}
442446
return json_res;
443447
}
@@ -455,6 +459,7 @@ SharedPtr<SegmentEntry> SegmentEntry::Deserialize(const nlohmann::json &segment_
455459
segment_entry->max_row_ts_ = segment_entry_json["max_row_ts"];
456460
segment_entry->row_count_ = segment_entry_json["row_count"];
457461
segment_entry->actual_row_count_ = segment_entry_json["actual_row_count"];
462+
segment_entry->checkpoint_row_count_ = 0;
458463

459464
segment_entry->commit_ts_ = segment_entry_json["commit_ts"];
460465
segment_entry->begin_ts_ = segment_entry_json["begin_ts"];

src/storage/meta/entry/segment_entry.cppm

+6
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ public:
151151
return actual_row_count_;
152152
}
153153

154+
// only used in Serialize(), FullCheckpoint, and no concurrency
155+
SizeT checkpoint_row_count() const {
156+
return checkpoint_row_count_;
157+
}
158+
154159
int Room() const { return this->row_capacity_ - this->row_count(); }
155160

156161
TxnTimeStamp min_row_ts() const { return min_row_ts_; }
@@ -207,6 +212,7 @@ private:
207212

208213
SizeT row_count_{};
209214
SizeT actual_row_count_{}; // not deleted row count
215+
SizeT checkpoint_row_count_{};
210216

211217
TxnTimeStamp min_row_ts_{UNCOMMIT_TS}; // Indicate the commit_ts which create this SegmentEntry
212218
TxnTimeStamp max_row_ts_{0};

src/storage/meta/entry/table_entry.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -900,11 +900,11 @@ nlohmann::json TableEntry::Serialize(TxnTimeStamp max_commit_ts) {
900900
Vector<SegmentEntry *> segment_candidates;
901901
Vector<TableIndexMeta *> table_index_meta_candidates;
902902
Vector<String> table_index_name_candidates;
903+
SizeT checkpoint_row_count = 0;
903904
{
904905
std::shared_lock<std::shared_mutex> lck(this->rw_locker_);
905906
json_res["table_name"] = *this->GetTableName();
906907
json_res["table_entry_type"] = this->table_entry_type_;
907-
json_res["row_count"] = this->row_count_.load();
908908
json_res["begin_ts"] = this->begin_ts_;
909909
json_res["commit_ts"] = this->commit_ts_.load();
910910
json_res["txn_id"] = this->txn_id_.load();
@@ -948,7 +948,9 @@ nlohmann::json TableEntry::Serialize(TxnTimeStamp max_commit_ts) {
948948
// Serialize segments
949949
for (const auto &segment_entry : segment_candidates) {
950950
json_res["segments"].emplace_back(segment_entry->Serialize(max_commit_ts));
951+
checkpoint_row_count += segment_entry->checkpoint_row_count();
951952
}
953+
json_res["row_count"] = checkpoint_row_count;
952954
json_res["unsealed_id"] = unsealed_id_;
953955

954956
// Serialize indexes

0 commit comments

Comments
 (0)