summaryrefslogtreecommitdiffstats
path: root/tests/pipelinetest.cpp
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-08-22 14:16:59 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-22 14:28:51 +0200
commit46313049ac01a3007ef60bdc937442945355a38d (patch)
tree56ce0cd679367a60ba3a706ac4d207bc9cc82230 /tests/pipelinetest.cpp
parentaf91a18748b91f4a4fc0d83247561371d376bec5 (diff)
downloadsink-46313049ac01a3007ef60bdc937442945355a38d.tar.gz
sink-46313049ac01a3007ef60bdc937442945355a38d.zip
Separate UIDs and Revisions in main databases
Summary: - Change revision type from `qint64` to `size_t` for LMDB in a couple of places (LMDB supports `unsigned int` or `size_t` which are `long unsigned int` on my machine) - Better support for database flags (duplicate, integer keys, integer values for now but is extensible) - Main databases' keys are now revisions - Some databases switched to integer keys databases: - Main databases - the revision to uid mapping database - the revision to entity type mapping database - Refactor the entity type's `typeDatabases` method (if in the future we need to change the main databases' flags again) - New uid to revision mapping database (`uidsToRevisions`): - Stores all revisions (not uid to latest revision) because we need it for cleaning old revisions - Flags are: duplicates + integer values (so findLatest finds the latest revision for the given uid) ~~Problems to fix before merging:~~ All Fixed! - ~~Sometimes Sink can't read what has just been written to the database (maybe because of transactions race conditions)~~ - ~~Most of the times, this results in Sink not able to find the uid for a given revision by reading the `revisions` database~~ - ~~`pipelinetest`'s `testModifyWithConflict` fails because the local changes are overridden~~ ~~The first problem prevents me from running benchmarks~~ Reviewers: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D14974
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r--tests/pipelinetest.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index b41a5c2..801a9e0 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -28,26 +28,29 @@ static void removeFromDisk(const QString &name)
28 store.removeFromDisk(); 28 store.removeFromDisk();
29} 29}
30 30
31static QList<QByteArray> getKeys(const QByteArray &dbEnv, const QByteArray &name) 31static QList<Sink::Storage::Key> getKeys(const QByteArray &dbEnv, const QByteArray &name)
32{ 32{
33 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly); 33 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly);
34 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); 34 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
35 auto db = transaction.openDatabase(name, nullptr, false); 35 auto db = transaction.openDatabase(name, nullptr, Sink::Storage::IntegerKeys);
36 QList<QByteArray> result; 36 QList<Sink::Storage::Key> result;
37 db.scan("", [&](const QByteArray &key, const QByteArray &value) { 37 db.scan("", [&](const QByteArray &key, const QByteArray &value) {
38 result << key; 38 size_t revision = Sink::byteArrayToSizeT(key);
39 result << Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(
40 Sink::Storage::DataStore::getUidFromRevision(transaction, revision)),
41 revision);
39 return true; 42 return true;
40 }); 43 });
41 return result; 44 return result;
42} 45}
43 46
44static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, const QByteArray &uid) 47static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, const Sink::Storage::Key &key)
45{ 48{
46 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly); 49 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly);
47 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); 50 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
48 auto db = transaction.openDatabase(name, nullptr, false); 51 auto db = transaction.openDatabase(name, nullptr, Sink::Storage::IntegerKeys);
49 QByteArray result; 52 QByteArray result;
50 db.scan(uid, [&](const QByteArray &key, const QByteArray &value) { 53 db.scan(key.revision().toSizeT(), [&](size_t rev, const QByteArray &value) {
51 result = value; 54 result = value;
52 return true; 55 return true;
53 }); 56 });
@@ -251,7 +254,7 @@ private slots:
251 // Get uid of written entity 254 // Get uid of written entity
252 auto keys = getKeys(instanceIdentifier(), "event.main"); 255 auto keys = getKeys(instanceIdentifier(), "event.main");
253 QCOMPARE(keys.size(), 1); 256 QCOMPARE(keys.size(), 1);
254 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); 257 auto key = keys.first();
255 const auto uid = key.identifier().toDisplayByteArray(); 258 const auto uid = key.identifier().toDisplayByteArray();
256 259
257 // Execute the modification 260 // Execute the modification
@@ -264,7 +267,7 @@ private slots:
264 key.setRevision(2); 267 key.setRevision(2);
265 268
266 // Ensure we've got the new revision with the modification 269 // Ensure we've got the new revision with the modification
267 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); 270 auto buffer = getEntity(instanceIdentifier(), "event.main", key);
268 QVERIFY(!buffer.isEmpty()); 271 QVERIFY(!buffer.isEmpty());
269 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 272 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
270 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 273 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
@@ -299,7 +302,7 @@ private slots:
299 // Get uid of written entity 302 // Get uid of written entity
300 auto keys = getKeys(instanceIdentifier(), "event.main"); 303 auto keys = getKeys(instanceIdentifier(), "event.main");
301 QCOMPARE(keys.size(), 1); 304 QCOMPARE(keys.size(), 1);
302 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); 305 auto key = keys.first();
303 const auto uid = key.identifier().toDisplayByteArray(); 306 const auto uid = key.identifier().toDisplayByteArray();
304 307
305 308
@@ -322,7 +325,7 @@ private slots:
322 key.setRevision(3); 325 key.setRevision(3);
323 326
324 // Ensure we've got the new revision with the modification 327 // Ensure we've got the new revision with the modification
325 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); 328 auto buffer = getEntity(instanceIdentifier(), "event.main", key);
326 QVERIFY(!buffer.isEmpty()); 329 QVERIFY(!buffer.isEmpty());
327 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 330 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
328 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 331 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
@@ -343,7 +346,7 @@ private slots:
343 auto result = getKeys(instanceIdentifier(), "event.main"); 346 auto result = getKeys(instanceIdentifier(), "event.main");
344 QCOMPARE(result.size(), 1); 347 QCOMPARE(result.size(), 1);
345 348
346 const auto uid = Sink::Storage::Key::fromInternalByteArray(result.first()).identifier().toDisplayByteArray(); 349 const auto uid = result.first().identifier().toDisplayByteArray();
347 350
348 // Delete entity 351 // Delete entity
349 auto deleteCommand = deleteEntityCommand(uid, 1); 352 auto deleteCommand = deleteEntityCommand(uid, 1);
@@ -386,7 +389,7 @@ private slots:
386 pipeline.startTransaction(); 389 pipeline.startTransaction();
387 auto keys = getKeys(instanceIdentifier(), "event.main"); 390 auto keys = getKeys(instanceIdentifier(), "event.main");
388 QCOMPARE(keys.size(), 1); 391 QCOMPARE(keys.size(), 1);
389 const auto uid = Sink::Storage::Key::fromInternalByteArray(keys.first()).identifier().toDisplayByteArray(); 392 const auto uid = keys.first().identifier().toDisplayByteArray();
390 { 393 {
391 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); 394 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
392 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 395 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
@@ -427,7 +430,7 @@ private slots:
427 // Get uid of written entity 430 // Get uid of written entity
428 auto keys = getKeys(instanceIdentifier(), "event.main"); 431 auto keys = getKeys(instanceIdentifier(), "event.main");
429 QCOMPARE(keys.size(), 1); 432 QCOMPARE(keys.size(), 1);
430 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); 433 auto key = keys.first();
431 const auto uid = key.identifier().toDisplayByteArray(); 434 const auto uid = key.identifier().toDisplayByteArray();
432 435
433 //Simulate local modification 436 //Simulate local modification
@@ -453,7 +456,7 @@ private slots:
453 key.setRevision(3); 456 key.setRevision(3);
454 457
455 // Ensure we've got the new revision with the modification 458 // Ensure we've got the new revision with the modification
456 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); 459 auto buffer = getEntity(instanceIdentifier(), "event.main", key);
457 QVERIFY(!buffer.isEmpty()); 460 QVERIFY(!buffer.isEmpty());
458 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 461 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
459 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 462 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());