From d1838e575baeb6cd08011645609516acbdabd6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 27 Jul 2018 13:32:39 +0200 Subject: New Key API in storage layer Summary: - Use object oriented paradigm for Keys / Identifiers /Revisions - "Compress" keys by using byte representation of Uuids - Still some cleaning left to do - Also run some benchmarks - I'm questioning whether files other than entitystore (tests excluded) are allowed to access this API Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D13735 --- tests/pipelinetest.cpp | 40 ++++++++++++++++++++++++---------------- tests/storagetest.cpp | 12 ++++++++---- 2 files changed, 32 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 45e2fbb..b41a5c2 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -20,6 +20,7 @@ #include "domainadaptor.h" #include "definitions.h" #include "adaptorfactoryregistry.h" +#include "storage/key.h" static void removeFromDisk(const QString &name) { @@ -250,8 +251,8 @@ private slots: // Get uid of written entity auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto key = keys.first(); - const auto uid = Sink::Storage::DataStore::uidFromKey(key); + auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); + const auto uid = key.identifier().toDisplayByteArray(); // Execute the modification entityFbb.Clear(); @@ -260,8 +261,10 @@ private slots: pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); pipeline.commit(); + key.setRevision(2); + // Ensure we've got the new revision with the modification - auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 2)); + auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); QVERIFY(!buffer.isEmpty()); Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); @@ -296,7 +299,8 @@ private slots: // Get uid of written entity auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); + auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); + const auto uid = key.identifier().toDisplayByteArray(); // Create another operation inbetween @@ -315,8 +319,10 @@ private slots: pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); pipeline.commit(); + key.setRevision(3); + // Ensure we've got the new revision with the modification - auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); + auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); QVERIFY(!buffer.isEmpty()); Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); @@ -337,7 +343,7 @@ private slots: auto result = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(result.size(), 1); - const auto uid = Sink::Storage::DataStore::uidFromKey(result.first()); + const auto uid = Sink::Storage::Key::fromInternalByteArray(result.first()).identifier().toDisplayByteArray(); // Delete entity auto deleteCommand = deleteEntityCommand(uid, 1); @@ -372,22 +378,22 @@ private slots: pipeline.newEntity(command.constData(), command.size()); QCOMPARE(testProcessor->newUids.size(), 1); QCOMPARE(testProcessor->newRevisions.size(), 1); - // Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor->newUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->newUids.at(0))); + const auto uid = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->newUids.at(0)).toDisplayByteArray(); + QCOMPARE(testProcessor->newUids.at(0), uid); } pipeline.commit(); entityFbb.Clear(); pipeline.startTransaction(); auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); + const auto uid = Sink::Storage::Key::fromInternalByteArray(keys.first()).identifier().toDisplayByteArray(); { auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); QCOMPARE(testProcessor->modifiedUids.size(), 1); QCOMPARE(testProcessor->modifiedRevisions.size(), 1); - // Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor->modifiedUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->modifiedUids.at(0))); + const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray(); + QCOMPARE(testProcessor->modifiedUids.at(0), uid2); } pipeline.commit(); entityFbb.Clear(); @@ -398,8 +404,8 @@ private slots: QCOMPARE(testProcessor->deletedUids.size(), 1); QCOMPARE(testProcessor->deletedUids.size(), 1); QCOMPARE(testProcessor->deletedSummaries.size(), 1); - // Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor->deletedUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->deletedUids.at(0))); + const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray(); + QCOMPARE(testProcessor->deletedUids.at(0), uid2); QCOMPARE(testProcessor->deletedSummaries.at(0), QByteArray("summary2")); } } @@ -421,8 +427,8 @@ private slots: // Get uid of written entity auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto key = keys.first(); - const auto uid = Sink::Storage::DataStore::uidFromKey(key); + auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); + const auto uid = key.identifier().toDisplayByteArray(); //Simulate local modification { @@ -444,8 +450,10 @@ private slots: pipeline.commit(); } + key.setRevision(3); + // Ensure we've got the new revision with the modification - auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); + auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); QVERIFY(!buffer.isEmpty()); Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 96368a7..e165616 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -7,6 +7,7 @@ #include #include "common/storage.h" +#include "storage/key.h" /** * Test of the storage implementation to ensure it can do the low level operations as expected. @@ -499,8 +500,11 @@ private slots: auto db = transaction.openDatabase("test", nullptr, false); const auto uid = "{c5d06a9f-1534-4c52-b8ea-415db68bdadf}"; //Ensure we can sort 1 and 10 properly (by default string comparison 10 comes before 6) - db.write(Sink::Storage::DataStore::assembleKey(uid, 6), "value1"); - db.write(Sink::Storage::DataStore::assembleKey(uid, 10), "value2"); + const auto id = Sink::Storage::Identifier::fromDisplayByteArray(uid); + auto key = Sink::Storage::Key(id, 6); + db.write(key.toInternalByteArray(), "value1"); + key.setRevision(10); + db.write(key.toInternalByteArray(), "value2"); db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); QCOMPARE(result, QByteArray("value2")); } @@ -732,7 +736,7 @@ private slots: Sink::Storage::DataStore::clearEnv(); //Try to read-only dynamic opening of the db. - //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) + //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) { // Trick the db into not loading all dbs by passing in a bogus layout. Sink::Storage::DataStore store(testDataPath, {dbName, {{"bogus", 0}}}, Sink::Storage::DataStore::ReadOnly); @@ -750,7 +754,7 @@ private slots: Sink::Storage::DataStore::clearEnv(); //Try to read-write dynamic opening of the db. - //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) + //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) { // Trick the db into not loading all dbs by passing in a bogus layout. Sink::Storage::DataStore store(testDataPath, {dbName, {{"bogus", 0}}}, Sink::Storage::DataStore::ReadWrite); -- cgit v1.2.3