memgraph/tests/unit/mvcc.cpp

75 lines
1.9 KiB
C++
Raw Normal View History

2017-05-05 17:05:56 +08:00
#include <vector>
#include "gtest/gtest.h"
#include "mvcc/record.hpp"
2017-05-05 17:05:56 +08:00
#include "mvcc/version.hpp"
#include "mvcc/version_list.hpp"
2017-05-05 17:05:56 +08:00
#include "threading/sync/lock_timeout_exception.hpp"
#include "transactions/engine.hpp"
2017-05-05 17:05:56 +08:00
#include "transactions/transaction.cpp"
#include "mvcc_gc_common.hpp"
2017-05-05 17:05:56 +08:00
TEST(MVCC, Deadlock) {
tx::Engine engine;
auto t0 = engine.Begin();
Write-ahead log Summary: My dear fellow Memgraphians. It's friday afternoon, and I am as ready to pop as WAL is to get reviewed... What's done: - Vertices and Edges have global IDs, stored in `VersionList`. Main storage is now a concurrent map ID->vlist_ptr. - WriteAheadLog class added. It's based around buffering WAL::Op objects (elementraly DB changes) and periodically serializing and flusing them to disk. - Snapshot recovery refactored, WAL recovery added. Snapshot format changed again to include necessary info. - Durability testing completely reworked. What's not done (and should be when we decide how): - Old WAL file purging. - Config refactor (naming and organization). Will do when we discuss what we want. - Changelog and new feature documentation (both depending on the point above). - Better error handling and recovery feedback. Currently it's all returning bools, which is not fine-grained enough (neither for errors nor partial successes, also EOF is reported as a failure at the moment). - Moving the implementation of WAL stuff to .cpp where possible. - Not sure if there are transactions being created outside of `GraphDbAccessor` and it's `BuildIndex`. Need to look into. - True write-ahead logic (flag controlled): not committing a DB transaction if the WAL has not flushed it's data. We can discuss the gain/effort ratio for this feature. Reviewers: buda, mislav.bradac, teon.banek, dgleich Reviewed By: dgleich Subscribers: mtomic, pullbot Differential Revision: https://phabricator.memgraph.io/D958
2017-11-13 16:50:49 +08:00
mvcc::VersionList<Prop> version_list1(*t0, 0);
mvcc::VersionList<Prop> version_list2(*t0, 1);
t0->Commit();
auto t1 = engine.Begin();
auto t2 = engine.Begin();
2017-05-05 17:05:56 +08:00
version_list1.update(*t1);
version_list2.update(*t2);
EXPECT_THROW(version_list1.update(*t2), LockTimeoutException);
}
2017-05-05 17:05:56 +08:00
// TODO Gleich: move this test to mvcc_gc???
// check that we don't delete records when we re-link
TEST(MVCC, UpdateDontDelete) {
std::atomic<int> count{0};
{
tx::Engine engine;
auto t1 = engine.Begin();
Write-ahead log Summary: My dear fellow Memgraphians. It's friday afternoon, and I am as ready to pop as WAL is to get reviewed... What's done: - Vertices and Edges have global IDs, stored in `VersionList`. Main storage is now a concurrent map ID->vlist_ptr. - WriteAheadLog class added. It's based around buffering WAL::Op objects (elementraly DB changes) and periodically serializing and flusing them to disk. - Snapshot recovery refactored, WAL recovery added. Snapshot format changed again to include necessary info. - Durability testing completely reworked. What's not done (and should be when we decide how): - Old WAL file purging. - Config refactor (naming and organization). Will do when we discuss what we want. - Changelog and new feature documentation (both depending on the point above). - Better error handling and recovery feedback. Currently it's all returning bools, which is not fine-grained enough (neither for errors nor partial successes, also EOF is reported as a failure at the moment). - Moving the implementation of WAL stuff to .cpp where possible. - Not sure if there are transactions being created outside of `GraphDbAccessor` and it's `BuildIndex`. Need to look into. - True write-ahead logic (flag controlled): not committing a DB transaction if the WAL has not flushed it's data. We can discuss the gain/effort ratio for this feature. Reviewers: buda, mislav.bradac, teon.banek, dgleich Reviewed By: dgleich Subscribers: mtomic, pullbot Differential Revision: https://phabricator.memgraph.io/D958
2017-11-13 16:50:49 +08:00
mvcc::VersionList<DestrCountRec> version_list(*t1, 0, count);
t1->Commit();
auto t2 = engine.Begin();
version_list.update(*t2);
t2->Abort();
EXPECT_EQ(count, 0);
auto t3 = engine.Begin();
// Update re-links the node and shouldn't clear it yet.
version_list.update(*t3);
EXPECT_EQ(count, 0);
2017-05-05 17:05:56 +08:00
// TODO Gleich: why don't we also test that remove doesn't delete?
t3->Commit();
}
EXPECT_EQ(count, 3);
}
// Check that we get the oldest record.
TEST(MVCC, Oldest) {
tx::Engine engine;
auto t1 = engine.Begin();
Write-ahead log Summary: My dear fellow Memgraphians. It's friday afternoon, and I am as ready to pop as WAL is to get reviewed... What's done: - Vertices and Edges have global IDs, stored in `VersionList`. Main storage is now a concurrent map ID->vlist_ptr. - WriteAheadLog class added. It's based around buffering WAL::Op objects (elementraly DB changes) and periodically serializing and flusing them to disk. - Snapshot recovery refactored, WAL recovery added. Snapshot format changed again to include necessary info. - Durability testing completely reworked. What's not done (and should be when we decide how): - Old WAL file purging. - Config refactor (naming and organization). Will do when we discuss what we want. - Changelog and new feature documentation (both depending on the point above). - Better error handling and recovery feedback. Currently it's all returning bools, which is not fine-grained enough (neither for errors nor partial successes, also EOF is reported as a failure at the moment). - Moving the implementation of WAL stuff to .cpp where possible. - Not sure if there are transactions being created outside of `GraphDbAccessor` and it's `BuildIndex`. Need to look into. - True write-ahead logic (flag controlled): not committing a DB transaction if the WAL has not flushed it's data. We can discuss the gain/effort ratio for this feature. Reviewers: buda, mislav.bradac, teon.banek, dgleich Reviewed By: dgleich Subscribers: mtomic, pullbot Differential Revision: https://phabricator.memgraph.io/D958
2017-11-13 16:50:49 +08:00
mvcc::VersionList<Prop> version_list(*t1, 0);
auto first = version_list.Oldest();
EXPECT_NE(first, nullptr);
2017-05-05 17:05:56 +08:00
// TODO Gleich: no need to do 10 checks of the same thing
for (int i = 0; i < 10; ++i) {
engine.Advance(t1->id_);
version_list.update(*t1);
EXPECT_EQ(version_list.Oldest(), first);
}
2017-05-05 17:05:56 +08:00
// TODO Gleich: what about remove?
// TODO Gleich: here it might make sense to write a concurrent test
// since these ops rely heavily on linkage atomicity?
}
2017-05-05 17:05:56 +08:00
// TODO Gleich: perhaps some concurrent VersionList::find tests?