memgraph/tests/unit/distributed_gc.cpp
Dominik Gleich eb30ecb6a0 Commit log gc
Summary: Adds a commit log garbage collector, which clears old transactions from the commit log

Reviewers: florijan

Reviewed By: florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1310
2018-04-04 10:25:25 +02:00

79 lines
2.6 KiB
C++

#include <gtest/gtest.h>
#include "distributed_common.hpp"
TEST_F(DistributedGraphDbTest, GarbageCollect) {
database::GraphDbAccessor dba{master()};
auto tx = dba.transaction_id();
dba.Commit();
// Create multiple transactions so that the commit log can be cleared
for (int i = 0; i < tx::CommitLog::kBitsetBlockSize; ++i) {
database::GraphDbAccessor dba{master()};
}
master().CollectGarbage();
worker(1).CollectGarbage();
worker(2).CollectGarbage();
EXPECT_EQ(master().tx_engine().Info(tx).is_committed(), true);
database::GraphDbAccessor dba2{master()};
auto tx_last = dba2.transaction_id();
dba2.Commit();
worker(1).CollectGarbage();
worker(2).CollectGarbage();
master().CollectGarbage();
EXPECT_DEATH(master().tx_engine().Info(tx), "chunk is nullptr");
EXPECT_DEATH(worker(1).tx_engine().Info(tx), "chunk is nullptr");
EXPECT_DEATH(worker(2).tx_engine().Info(tx), "chunk is nullptr");
EXPECT_EQ(master().tx_engine().Info(tx_last).is_committed(), true);
EXPECT_EQ(worker(1).tx_engine().Info(tx_last).is_committed(), true);
EXPECT_EQ(worker(2).tx_engine().Info(tx_last).is_committed(), true);
}
TEST_F(DistributedGraphDbTest, GarbageCollectBlocked) {
database::GraphDbAccessor dba{master()};
auto tx = dba.transaction_id();
dba.Commit();
// Block garbage collection because this is a still alive transaction on the
// worker
database::GraphDbAccessor dba3{worker(1)};
// Create multiple transactions so that the commit log can be cleared
for (int i = 0; i < tx::CommitLog::kBitsetBlockSize; ++i) {
database::GraphDbAccessor dba{master()};
}
// Query for a large id so that the commit log new block is created
master().tx_engine().Info(tx::CommitLog::kBitsetBlockSize);
master().CollectGarbage();
worker(1).CollectGarbage();
worker(2).CollectGarbage();
EXPECT_EQ(master().tx_engine().Info(tx).is_committed(), true);
database::GraphDbAccessor dba2{master()};
auto tx_last = dba2.transaction_id();
dba2.Commit();
worker(1).CollectGarbage();
worker(2).CollectGarbage();
master().CollectGarbage();
EXPECT_EQ(master().tx_engine().Info(tx).is_committed(), true);
EXPECT_EQ(worker(1).tx_engine().Info(tx).is_committed(), true);
EXPECT_EQ(worker(2).tx_engine().Info(tx).is_committed(), true);
EXPECT_EQ(master().tx_engine().Info(tx_last).is_committed(), true);
EXPECT_EQ(worker(1).tx_engine().Info(tx_last).is_committed(), true);
EXPECT_EQ(worker(2).tx_engine().Info(tx_last).is_committed(), true);
}
int main(int argc, char **argv) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}