@@ -355,7 +355,7 @@ void TableEntry::AddCompactNew(SharedPtr<SegmentEntry> segment_entry) {
355
355
}
356
356
}
357
357
358
- void TableEntry::AppendData (TransactionID txn_id, void *txn_store, TxnTimeStamp commit_ts, BufferManager *buffer_mgr) {
358
+ void TableEntry::AppendData (TransactionID txn_id, void *txn_store, TxnTimeStamp commit_ts, BufferManager *buffer_mgr, bool is_replay ) {
359
359
SizeT row_count = 0 ;
360
360
361
361
// Read-only no lock needed.
@@ -402,8 +402,11 @@ void TableEntry::AppendData(TransactionID txn_id, void *txn_store, TxnTimeStamp
402
402
row_count += actual_appended;
403
403
}
404
404
405
- // Realtime index insertion
406
- MemIndexInsert (txn, append_state_ptr->append_ranges_ );
405
+ // Needn't inserting into MemIndex since MemIndexRecover is responsible for recovering MemIndex
406
+ if (!is_replay) {
407
+ // Realtime index insertion.
408
+ MemIndexInsert (txn, append_state_ptr->append_ranges_ );
409
+ }
407
410
408
411
this ->row_count_ += row_count;
409
412
}
@@ -665,6 +668,7 @@ void TableEntry::MemIndexInsertInner(TableIndexEntry *table_index_entry, Txn *tx
665
668
if (i == dump_idx && segment_index_entry->MemIndexRowCount () >= 1000000 ) {
666
669
SharedPtr<ChunkIndexEntry> chunk_index_entry = segment_index_entry->MemIndexDump ();
667
670
if (chunk_index_entry.get () != nullptr ) {
671
+ chunk_index_entry->Commit (txn->CommitTS ());
668
672
txn_table_store->AddChunkIndexStore (table_index_entry, chunk_index_entry.get ());
669
673
670
674
if (index_base->index_type_ == IndexType::kFullText ) {
@@ -685,6 +689,7 @@ void TableEntry::MemIndexDump(Txn *txn, bool spill) {
685
689
TxnIndexStore *txn_index_store = txn_table_store->GetIndexStore (table_index_entry);
686
690
SharedPtr<ChunkIndexEntry> chunk_index_entry = table_index_entry->MemIndexDump (txn_index_store, spill);
687
691
if (chunk_index_entry.get () != nullptr ) {
692
+ chunk_index_entry->Commit (txn->CommitTS ());
688
693
txn_table_store->AddChunkIndexStore (table_index_entry, chunk_index_entry.get ());
689
694
table_index_entry->UpdateFulltextSegmentTs (txn->CommitTS ());
690
695
}
@@ -737,7 +742,12 @@ void TableEntry::MemIndexRecover(BufferManager *buffer_manager) {
737
742
append_ranges.emplace_back (segment_id, block_id, start_offset, row_count);
738
743
for (SizeT i = block_id + 1 ; i < block_entries.size (); i++) {
739
744
assert (block_entries[i - 1 ]->row_capacity () == block_capacity);
740
- assert (block_entries[i - 1 ]->GetAvailableCapacity () <= 0 );
745
+ if (block_entries[i - 1 ]->GetAvailableCapacity () > 0 ) {
746
+ LOG_ERROR (fmt::format (" MemIndexRecover got a non-full BlockEntry. block_id {}, row_count {}, block_entries {}" ,
747
+ block_entries[i - 1 ]->block_id (),
748
+ block_entries[i - 1 ]->row_count (),
749
+ block_entries.size ()));
750
+ }
741
751
append_ranges.emplace_back (segment_id, i, 0 , block_entries[i]->row_count ());
742
752
}
743
753
}
0 commit comments