Implement commit log for storage v2

Reviewers: teon.banek, mferencevic

Reviewed By: teon.banek, mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2148
This commit is contained in:
Marin Tomic
2019-06-27 12:37:56 +02:00
parent 54e1e4e1ff
commit 6ce8fae54a
3 changed files with 185 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#include "storage/v2/commit_log.hpp"
#include "gtest/gtest.h"
TEST(CommitLog, Simple) {
CommitLog log;
EXPECT_EQ(log.OldestActive(), 0);
log.MarkFinished(1);
EXPECT_EQ(log.OldestActive(), 0);
log.MarkFinished(0);
EXPECT_EQ(log.OldestActive(), 2);
}
TEST(CommitLog, Fields) {
CommitLog log;
for (uint64_t i = 0; i < 64; ++i) {
log.MarkFinished(i);
EXPECT_EQ(log.OldestActive(), i + 1);
}
for (uint64_t i = 128; i < 192; ++i) {
log.MarkFinished(i);
EXPECT_EQ(log.OldestActive(), 64);
}
for (uint64_t i = 64; i < 128; ++i) {
log.MarkFinished(i);
EXPECT_EQ(log.OldestActive(), i < 127 ? i + 1 : 192);
}
}
TEST(CommitLog, Blocks) {
CommitLog log;
for (uint64_t i = 0; i < 8192 * 64; ++i) {
log.MarkFinished(i);
EXPECT_EQ(log.OldestActive(), i + 1);
}
for (uint64_t i = 8192 * 64 * 2; i < 8192 * 64 * 3; ++i) {
log.MarkFinished(i);
EXPECT_EQ(log.OldestActive(), 8192 * 64);
}
for (uint64_t i = 8192 * 64; i < 8192 * 64; ++i) {
log.MarkFinished(i);
EXPECT_EQ(log.OldestActive(), i < 8192 * 64 - 1 ? i + 1 : 8192 * 64 * 3);
}
}