Skip to content

Commit

Permalink
Fix import with index.
Browse files Browse the repository at this point in the history
  • Loading branch information
small-turtle-1 committed Mar 4, 2025
1 parent ed0382e commit 5004501
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/storage/new_txn/new_txn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,9 @@ Status NewTxn::PrepareCommit() {
}
case WalCommandType::DUMP_INDEX:
case WalCommandType::APPEND:
case WalCommandType::DELETE:
case WalCommandType::DELETE: {
break;
}
case WalCommandType::IMPORT: {
auto *import_cmd = static_cast<WalCmdImport *>(command.get());
Status status = CommitImport(import_cmd);
Expand Down
23 changes: 23 additions & 0 deletions src/storage/new_txn/new_txn_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Status NewTxn::Import(const String &db_name, const String &table_name, const Vec
return status;
}

SizeT segment_row_cnt = 0;
for (SizeT j = 0; j < input_blocks.size(); ++j) {
const SharedPtr<DataBlock> &input_block = input_blocks[j];
if (!input_block->Finalized()) {
Expand Down Expand Up @@ -159,6 +160,28 @@ Status NewTxn::Import(const String &db_name, const String &table_name, const Vec
if (!status.ok()) {
return status;
}
segment_row_cnt += row_cnt;
}
status = segment_meta->SetRowCnt(segment_row_cnt);
if (!status.ok()) {
return status;
}

Vector<String> *index_id_strs_ptr = nullptr;
Vector<String> *index_names_ptr = nullptr;
status = table_meta.GetIndexIDs(index_id_strs_ptr, &index_names_ptr);
if (!status.ok()) {
return status;
}
for (SizeT i = 0; i < index_id_strs_ptr->size(); ++i) {
const String &index_id_str = (*index_id_strs_ptr)[i];
const String &index_name = (*index_names_ptr)[i];
TableIndexMeeta table_index_meta(index_id_str, table_meta, table_meta.kv_instance());

status = this->PopulateIndex(db_name, table_name, index_name, table_index_meta, *segment_meta);
if (!status.ok()) {
return status;
}
}

auto import_command = MakeShared<WalCmdImport>(db_name, table_name, WalSegmentInfo(*segment_meta));
Expand Down

0 comments on commit 5004501

Please sign in to comment.