@@ -48,29 +48,34 @@ class CleanupTaskTest : public BaseTest {
48
48
protected:
49
49
void WaitCleanup (Storage *storage, TxnTimeStamp last_commit_ts) {
50
50
Catalog *catalog = storage->catalog ();
51
- WalManager *wal_mgr = storage->wal_manager ();
52
51
BufferManager *buffer_mgr = storage->buffer_manager ();
53
52
54
- LOG_INFO (" Waiting cleanup" );
53
+ auto visible_ts = WaitFlushDeltaOp (storage, last_commit_ts);
54
+
55
+ auto cleanup_task = MakeShared<CleanupTask>(catalog, visible_ts, buffer_mgr);
56
+ cleanup_task->Execute ();
57
+ }
58
+
59
+ TxnTimeStamp WaitFlushDeltaOp (Storage *storage, TxnTimeStamp last_commit_ts) {
60
+ TxnManager *txn_mgr = storage->txn_manager ();
61
+
55
62
TxnTimeStamp visible_ts = 0 ;
56
63
time_t start = time (nullptr );
57
64
while (true ) {
58
- visible_ts = wal_mgr->GetLastCkpTS () + 1 ;
65
+ visible_ts = txn_mgr->GetCleanupScanTS ();
66
+ // wait for at most 10s
59
67
time_t end = time (nullptr );
60
68
if (visible_ts >= last_commit_ts) {
61
- LOG_INFO (fmt::format (" Cleanup finished after {}" , end - start));
69
+ LOG_INFO (fmt::format (" FlushDeltaOp finished after {}" , end - start));
62
70
break ;
63
71
}
64
- // wait for at most 10s
65
72
if (end - start > 10 ) {
66
- UnrecoverableError ( " WaitCleanup timeout" );
73
+ UnrecoverableException ( " WaitFlushDeltaOp timeout" );
67
74
}
68
- LOG_INFO (fmt::format (" Before usleep. Wait cleanup for {} seconds" , end - start));
75
+ LOG_INFO (fmt::format (" Before usleep. Wait flush delta op for {} seconds" , end - start));
69
76
usleep (1000 * 1000 );
70
77
}
71
-
72
- auto cleanup_task = MakeShared<CleanupTask>(catalog, visible_ts, buffer_mgr);
73
- cleanup_task->Execute ();
78
+ return visible_ts;
74
79
}
75
80
};
76
81
@@ -90,8 +95,9 @@ TEST_F(CleanupTaskTest, test_delete_db_simple) {
90
95
{
91
96
auto *txn = txn_mgr->BeginTxn (MakeUnique<String>(" create db1" ));
92
97
txn->CreateDatabase (*db_name, ConflictType::kError );
93
- txn_mgr->CommitTxn (txn);
98
+ last_commit_ts = txn_mgr->CommitTxn (txn);
94
99
}
100
+ WaitFlushDeltaOp (storage, last_commit_ts);
95
101
{
96
102
auto *txn = txn_mgr->BeginTxn (MakeUnique<String>(" drop db1" ));
97
103
Status status = txn->DropDatabase (*db_name, ConflictType::kError );
@@ -184,8 +190,9 @@ TEST_F(CleanupTaskTest, test_delete_table_simple) {
184
190
auto *txn = txn_mgr->BeginTxn (MakeUnique<String>(" create table1" ));
185
191
auto status = txn->CreateTable (*db_name, std::move (table_def), ConflictType::kIgnore );
186
192
EXPECT_TRUE (status.ok ());
187
- txn_mgr->CommitTxn (txn);
193
+ last_commit_ts = txn_mgr->CommitTxn (txn);
188
194
}
195
+ WaitFlushDeltaOp (storage, last_commit_ts);
189
196
{
190
197
auto *txn = txn_mgr->BeginTxn (MakeUnique<String>(" drop table1" ));
191
198
0 commit comments