Skip to content

Commit

Permalink
Fix lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
small-turtle-1 committed Dec 17, 2024
1 parent a94a50b commit a62f973
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/storage/meta/entry/table_index_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,25 @@ Vector<String> TableIndexEntry::GetFilePath(TransactionID txn_id, TxnTimeStamp b

void TableIndexEntry::PickCleanup(CleanupScanner *scanner) {
TxnTimeStamp visible_ts = scanner->visible_ts();
std::shared_lock r_lock(rw_locker_);
for (auto iter = index_by_segment_.begin(); iter != index_by_segment_.end();) {
auto &[segment_id, segment_index_entry] = *iter;
if (segment_index_entry->CheckDeprecate(visible_ts)) {
scanner->AddEntry(std::move(segment_index_entry));
iter = index_by_segment_.erase(iter);
} else {
segment_index_entry->PickCleanup(scanner);
++iter;
Vector<SegmentID> segment_ids;
{
std::shared_lock r_lock(rw_locker_);
for (auto iter = index_by_segment_.begin(); iter != index_by_segment_.end();) {
auto &[segment_id, segment_index_entry] = *iter;
if (segment_index_entry->CheckDeprecate(visible_ts)) {
scanner->AddEntry(std::move(segment_index_entry));
segment_ids.push_back(segment_id);
++iter;
} else {
segment_index_entry->PickCleanup(scanner);
++iter;
}
}
}
if (!segment_ids.empty()) {
std::unique_lock w_lock(rw_locker_);
for (auto segment_id : segment_ids) {
index_by_segment_.erase(segment_id);
}
}
}
Expand Down

0 comments on commit a62f973

Please sign in to comment.