Skip to content

Commit

Permalink
Fix: memory insert delete lock because reverse order of lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
small-turtle-1 committed May 8, 2024
1 parent 8763556 commit 63c46b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 9 additions & 3 deletions src/storage/meta/entry/base_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ import stl;
import txn_manager;
import txn_state;
import txn;
import infinity_exception;
import third_party;

namespace infinity {

bool BaseEntry::CheckVisible(Txn *txn) const {
TxnTimeStamp begin_ts = txn->BeginTS();
TxnManager *txn_mgr = txn->txn_mgr();
TransactionID txn_id = txn_id_.load();
if (begin_ts < commit_ts_ || txn_id_ == txn->TxnID()) {
if (begin_ts >= commit_ts_ || txn_id == txn->TxnID()) {
return true;
}
TxnManager *txn_mgr = txn->txn_mgr();
if (txn_mgr == nullptr) { // when replay
return false;
UnrecoverableError(fmt::format("Replay should not reach here. begin_ts: {}, commit_ts_: {} txn_id: {}, txn_id_: {}",
begin_ts,
commit_ts_,
txn->TxnID(),
txn_id));
}
return txn_mgr->CheckIfCommitting(txn_id, begin_ts);
}
Expand Down
22 changes: 12 additions & 10 deletions src/storage/meta/entry/segment_index_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,18 @@ void SegmentIndexEntry::MemIndexInsert(SharedPtr<BlockEntry> block_entry,
const IndexFullText *index_fulltext = static_cast<const IndexFullText *>(index_base.get());
if (memory_indexer_.get() == nullptr) {
String base_name = fmt::format("ft_{:016x}", begin_row_id.ToUint64());
std::unique_lock<std::shared_mutex> lck(rw_locker_);
memory_indexer_ = MakeUnique<MemoryIndexer>(*table_index_entry_->index_dir(),
base_name,
begin_row_id,
index_fulltext->flag_,
index_fulltext->analyzer_,
table_index_entry_->GetFulltextByteSlicePool(),
table_index_entry_->GetFulltextBufferPool(),
table_index_entry_->GetFulltextInvertingThreadPool(),
table_index_entry_->GetFulltextCommitingThreadPool());
{
std::unique_lock<std::shared_mutex> lck(rw_locker_);
memory_indexer_ = MakeUnique<MemoryIndexer>(*table_index_entry_->index_dir(),
base_name,
begin_row_id,
index_fulltext->flag_,
index_fulltext->analyzer_,
table_index_entry_->GetFulltextByteSlicePool(),
table_index_entry_->GetFulltextBufferPool(),
table_index_entry_->GetFulltextInvertingThreadPool(),
table_index_entry_->GetFulltextCommitingThreadPool());
}
table_index_entry_->UpdateFulltextSegmentTs(commit_ts);
} else {
RowID exp_begin_row_id = memory_indexer_->GetBaseRowId() + memory_indexer_->GetDocCount();
Expand Down

0 comments on commit 63c46b8

Please sign in to comment.