memgraph/tests/unit/distributed_gc.cpp
Dominik Gleich d9f25cc668 Write committed/aborted op to wal
Summary:
Wal on workers didn't contain committed transactions ids, this is needed for
distributed recovery so that the master may decide which transactions are
present on all the workers.

Reviewers: buda, msantl

Reviewed By: buda

Subscribers: pullbot, msantl, buda

Differential Revision: https://phabricator.memgraph.io/D1440
2018-07-05 12:43:18 +02:00

84 lines
2.7 KiB
C++

#include <gtest/gtest.h>
#include "distributed_common.hpp"
class DistributedGcTest : public DistributedGraphDbTest {
public:
DistributedGcTest() : DistributedGraphDbTest("gc") {}
};
TEST_F(DistributedGcTest, 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(DistributedGcTest, 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();
}