Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
small-turtle-1 committed Jan 7, 2025
1 parent 8dd53dd commit 0c76f40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/storage/compaction_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ void CompactionProcessor::DoDumpByline(DumpIndexBylineTask *dump_task) {
RecoverableError(Status::TxnRollback(txn->TxnID(), fmt::format("Dumped chunk {} is deleted.", dumped_chunk->encode())));
}

SharedPtr<SegmentIndexEntry> segment_index_entry;
bool created = table_index_entry->GetOrCreateSegment(dump_task->segment_id_, txn, segment_index_entry);
if (created) {
UnrecoverableError(fmt::format("DumpByline: Cannot find segment index entry with id: {}", dump_task->segment_id_));
SharedPtr<SegmentIndexEntry> segment_index_entry = table_index_entry->GetSegment(dump_task->segment_id_, txn);
if (!segment_index_entry) {
RecoverableError(Status::TxnRollback(txn->TxnID(), fmt::format("Cannot find segment index entry with id: {}", dump_task->segment_id_)));
}
segment_index_entry->AddWalIndexDump(dumped_chunk, txn);

Expand Down
11 changes: 10 additions & 1 deletion src/storage/meta/entry/table_index_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,20 @@ String TableIndexEntry::GetPathNameTail() const {
return index_dir_->substr(delimiter_i + 1);
}

SharedPtr<SegmentIndexEntry> TableIndexEntry::GetSegment(SegmentID segment_id, Txn *txn) {
std::unique_lock w_lock(rw_locker_);
auto iter = index_by_segment_.find(segment_id);
if (iter == index_by_segment_.end() || !iter->second->CheckDeprecate(txn->BeginTS())) {
return nullptr;
}
return iter->second;
}

bool TableIndexEntry::GetOrCreateSegment(SegmentID segment_id, Txn *txn, SharedPtr<SegmentIndexEntry> &segment_index_entry) {
bool created = false;
std::unique_lock w_lock(rw_locker_);
auto iter = index_by_segment_.find(segment_id);
if (iter == index_by_segment_.end()) {
if (iter == index_by_segment_.end() && !iter->second->CheckDeprecate(txn->BeginTS())) {
segment_index_entry = SegmentIndexEntry::NewIndexEntry(this, segment_id, txn);
index_by_segment_.emplace(segment_id, segment_index_entry);
created = true;
Expand Down
2 changes: 2 additions & 0 deletions src/storage/meta/entry/table_index_entry.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public:
Map<SegmentID, SharedPtr<SegmentIndexEntry>> GetIndexBySegmentSnapshot(const TableEntry *table_entry, Txn *txn);
const SharedPtr<String> &index_dir() const { return index_dir_; }
String GetPathNameTail() const;

SharedPtr<SegmentIndexEntry> GetSegment(SegmentID segment_id, Txn *txn);
bool GetOrCreateSegment(SegmentID segment_id, Txn *txn, SharedPtr<SegmentIndexEntry> &segment_index_entry);

// MemIndexCommit is non-blocking.
Expand Down

0 comments on commit 0c76f40

Please sign in to comment.