Fix wal retention test
Summary: Wal retention test was flaky, this kinda fixes it. It's hard to fix it completely since there are separate threads happening which are not synchronized, and forcing the synchronization from the outside would not agree to the specifications i.e. single-threadness of WAL. Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1358
This commit is contained in:
parent
92613fcab8
commit
e519a64c7c
@ -108,11 +108,14 @@ void RemoveOldWals(const fs::path &wal_dir,
|
||||
// We can remove all the WAL files that will not be used when restoring from
|
||||
// the snapshot created in the given transaction.
|
||||
auto min_trans_id = snapshot_transaction.snapshot().empty()
|
||||
? snapshot_transaction.id_
|
||||
? snapshot_transaction.id_ + 1
|
||||
: snapshot_transaction.snapshot().front();
|
||||
for (auto &wal_file : fs::directory_iterator(wal_dir)) {
|
||||
auto tx_id = TransactionIdFromWalFilename(wal_file.path().filename());
|
||||
if (tx_id && tx_id.value() < min_trans_id) fs::remove(wal_file);
|
||||
if (tx_id && tx_id.value() < min_trans_id) {
|
||||
bool result = fs::remove(wal_file);
|
||||
DCHECK(result) << "Unable to delete old wal file: " << wal_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
@ -176,7 +176,6 @@ void CompareDbs(database::GraphDb &a, database::GraphDb &b) {
|
||||
|
||||
auto is_permutation_props = [&dba_a, &dba_b](const auto &p1_id,
|
||||
const auto &p2_id) {
|
||||
|
||||
std::vector<std::pair<std::string, query::TypedValue>> p1;
|
||||
std::vector<std::pair<std::string, query::TypedValue>> p2;
|
||||
|
||||
@ -731,14 +730,19 @@ TEST_F(Durability, WalRetention) {
|
||||
MakeSnapshot(db);
|
||||
MakeDb(db, 100);
|
||||
EXPECT_EQ(DirFiles(snapshot_dir_).size(), 1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
// 1 current WAL file, plus retained ones
|
||||
EXPECT_GT(DirFiles(wal_dir_).size(), 1);
|
||||
MakeSnapshot(db);
|
||||
}
|
||||
// Flush wal with snapshot transaction tx_id
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
// only 1 current WAL file
|
||||
EXPECT_EQ(DirFiles(snapshot_dir_).size(), 2);
|
||||
EXPECT_EQ(DirFiles(wal_dir_).size(), 1);
|
||||
// There can only be one extra wal file (two total) because that file could
|
||||
// have been written after the snapshot WAL cleanup
|
||||
EXPECT_LE(DirFiles(wal_dir_).size(), 2);
|
||||
}
|
||||
|
||||
TEST_F(Durability, SnapshotOnExit) {
|
||||
|
Loading…
Reference in New Issue
Block a user