Skip to content

Commit

Permalink
Fix: unittest.
Browse files Browse the repository at this point in the history
  • Loading branch information
small-turtle-1 committed May 9, 2024
1 parent 621990b commit f121b11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
28 changes: 17 additions & 11 deletions src/unit_test/storage/buffer/buffer_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,34 @@ class BufferObjTest : public BaseTest {

void WaitCleanup(Storage *storage, TxnTimeStamp last_commit_ts) {
Catalog *catalog = storage->catalog();
TxnManager *txn_mgr = storage->txn_manager();
BufferManager *buffer_mgr = storage->buffer_manager();

LOG_INFO("Waiting cleanup");
auto visible_ts = WaitFlushDeltaOp(storage, last_commit_ts);

auto cleanup_task = MakeShared<CleanupTask>(catalog, visible_ts, buffer_mgr);
cleanup_task->Execute();
}

TxnTimeStamp WaitFlushDeltaOp(Storage *storage, TxnTimeStamp last_commit_ts) {
TxnManager *txn_mgr = storage->txn_manager();

TxnTimeStamp visible_ts = 0;
time_t start = time(nullptr);
while (true) {
visible_ts = txn_mgr->GetCleanupScanTS();
// wait for at most 10s
time_t end = time(nullptr);
if (visible_ts >= last_commit_ts) {
LOG_INFO(fmt::format("Cleanup finished after {}", end - start));
LOG_INFO(fmt::format("FlushDeltaOp finished after {}", end - start));
break;
}
// wait for at most 10s
if (end - start > 10) {
UnrecoverableError("WaitCleanup timeout");
if (end - start > 5) {
UnrecoverableError("WaitFlushDeltaOp timeout");
}
LOG_INFO(fmt::format("Before usleep. Wait cleanup for {} seconds", end - start));
LOG_INFO(fmt::format("Before usleep. Wait flush delta op for {} seconds", end - start));
usleep(1000 * 1000);
}

auto cleanup_task = MakeShared<CleanupTask>(catalog, visible_ts, buffer_mgr);
cleanup_task->Execute();
return visible_ts;
}
};

Expand Down Expand Up @@ -602,9 +607,10 @@ TEST_F(BufferObjTest, test_hnsw_index_buffer_obj_shutdown) {
auto append_status = txn->Append(table_entry, data_block);
ASSERT_TRUE(append_status.ok());

txn_mgr->CommitTxn(txn);
last_commit_ts = txn_mgr->CommitTxn(txn);
}
}
WaitFlushDeltaOp(storage, last_commit_ts);
// Get Index
{
auto *txn = txn_mgr->BeginTxn();
Expand Down
5 changes: 4 additions & 1 deletion test/data/config/test_buffer_obj.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ version = "0.1.0"
timezone = "utc-8"

[storage]
cleanup_interval = 1
# close auto cleanup task
cleanup_interval = 0
# close auto compaction
compaction_interval = 0

[wal]
#short checkpoint interval to allow quick cleanup
Expand Down

0 comments on commit f121b11

Please sign in to comment.