From 016fea734d09df707be9a16a4ad6a1107f41549f Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 27 Jun 2018 11:12:38 +0200 Subject: Fix pipelinetest + remove useless commented lines --- common/changereplay.cpp | 1 - common/storage.h | 4 ---- common/storage/entitystore.cpp | 16 ++++++---------- common/storage_common.cpp | 24 ------------------------ common/synchronizer.cpp | 2 +- common/utils.cpp | 1 - sinksh/syntax_modules/sink_inspect.cpp | 1 - tests/pipelinetest.cpp | 13 ++++++------- tests/storagetest.cpp | 9 +++++---- 9 files changed, 18 insertions(+), 53 deletions(-) diff --git a/common/changereplay.cpp b/common/changereplay.cpp index e94ed80..5817e8d 100644 --- a/common/changereplay.cpp +++ b/common/changereplay.cpp @@ -114,7 +114,6 @@ KAsync::Job ChangeReplay::replayNextRevision() if (uid.isEmpty() || type.isEmpty()) { SinkErrorCtx(mLogCtx) << "Failed to read uid or type for revison: " << revision << uid << type; } else { - //const auto key = DataStore::assembleKey(uid, revision); // TODO: should not use internal representations const auto key = Storage::Key(Storage::Identifier::fromDisplayByteArray(uid), revision).toInternalByteArray(); QByteArray entityBuffer; diff --git a/common/storage.h b/common/storage.h index 25d0fa6..8904148 100644 --- a/common/storage.h +++ b/common/storage.h @@ -239,10 +239,6 @@ public: static bool isInternalKey(void *key, int keySize); static bool isInternalKey(const QByteArray &key); - //static QByteArray assembleKey(const QByteArray &key, qint64 revision); - //static Identifier uidFromKey(const QByteArray &key); - //static qint64 revisionFromKey(const QByteArray &key); - static NamedDatabase mainDatabase(const Transaction &, const QByteArray &type); static QByteArray generateUid(); diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index efafe8a..d3420e4 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -371,8 +371,9 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) return; } SinkTraceCtx(d->logCtx) << "Cleaning up revision " << revision << uid << bufferType; + const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); DataStore::mainDatabase(d->transaction, bufferType) - .scan(uid, + .scan(internalUid, [&](const QByteArray &key, const QByteArray &data) -> bool { EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { @@ -530,7 +531,6 @@ ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArra return dt; } -// TODO: check every usage void EntityStore::readEntity(const QByteArray &type, const QByteArray &displayKey, const std::function callback) { const auto key = Key::fromDisplayByteArray(displayKey); @@ -598,7 +598,6 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); db.scan(internalUid, [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { - //const auto foundRevision = DataStore::revisionFromKey(key); const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); if (foundRevision < revision && foundRevision > latestRevision) { latestRevision = foundRevision; @@ -633,11 +632,7 @@ void EntityStore::readAllUids(const QByteArray &type, const std::functiongetTransaction(), type).contains(internalUid); } @@ -675,10 +670,11 @@ void EntityStore::readRevisions(const QByteArray &type, const QByteArray &uid, q { Q_ASSERT(d); Q_ASSERT(!uid.isEmpty()); + const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); DataStore::mainDatabase(d->transaction, type) - .scan(uid, + .scan(internalUid, [&](const QByteArray &key, const QByteArray &value) -> bool { - const auto parsedKey = Key::fromDisplayByteArray(key); + const auto parsedKey = Key::fromInternalByteArray(key); const auto revision = parsedKey.revision().toQint64(); if (revision >= startingRevision) { callback(parsedKey.identifier().toDisplayByteArray(), revision, Sink::EntityBuffer(value.data(), value.size())); diff --git a/common/storage_common.cpp b/common/storage_common.cpp index c922d9d..f96097a 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -24,8 +24,6 @@ #include "log.h" #include "utils.h" -#include - QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) { dbg << error.message << "Code: " << error.code << "Db: " << error.store; @@ -38,8 +36,6 @@ namespace Storage { static const char *s_internalPrefix = "__internal"; static const int s_internalPrefixSize = strlen(s_internalPrefix); static const int s_lengthOfUid = 38; -// RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes -//static const int s_lengthOfUid = 16; DbLayout::DbLayout() { @@ -198,26 +194,6 @@ bool DataStore::isInternalKey(const QByteArray &key) return key.startsWith(s_internalPrefix); } -/* -QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision) -{ - Q_ASSERT(revision <= 9223372036854775807); - Q_ASSERT(key.size() == s_lengthOfUid); - return key + QByteArray::number(revision).rightJustified(19, '0', false); -} - -//QByteArray DataStore::uidFromKey(const QByteArray &key) -Identifier DataStore::uidFromKey(const QByteArray &key) -{ - return Identifier::fromByteArray(key.mid(0, s_lengthOfUid)); -} - -qint64 DataStore::revisionFromKey(const QByteArray &key) -{ - return key.mid(s_lengthOfUid + 1).toLongLong(); -} -*/ - QByteArray DataStore::generateUid() { return createUuid(); diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index f19c08a..ffc7020 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -616,7 +616,7 @@ KAsync::Job Synchronizer::replay(const QByteArray &type, const QByteArray Q_ASSERT(mEntityStore->hasTransaction()); const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; - //const auto uid = Sink::Storage::DataStore::uidFromKey(key); + // TODO: should not use internal representations const auto uid = Sink::Storage::Key::fromDisplayByteArray(key).identifier().toDisplayByteArray(); const auto modifiedProperties = metadataBuffer->modifiedProperties() ? BufferUtils::fromVector(*metadataBuffer->modifiedProperties()) : QByteArrayList(); QByteArray oldRemoteId; diff --git a/common/utils.cpp b/common/utils.cpp index e98365c..3c54db4 100644 --- a/common/utils.cpp +++ b/common/utils.cpp @@ -22,5 +22,4 @@ QByteArray Sink::createUuid() { return QUuid::createUuid().toByteArray(); - //return QUuid::createUuid().toRfc4122(); } diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 019ef31..1b3d77c 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -92,7 +92,6 @@ bool inspect(const QStringList &args, State &state) QSet uids; db.scan("", [&] (const QByteArray &key, const QByteArray &data) { - //uids.insert(Sink::Storage::DataStore::uidFromKey(key)); uids.insert(Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); return true; }, diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 5165d35..2610305 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -22,6 +22,8 @@ #include "adaptorfactoryregistry.h" #include "storage/key.h" +// TODO: fix test + static void removeFromDisk(const QString &name) { Sink::Storage::DataStore store(Sink::Store::storageLocation(), name, Sink::Storage::DataStore::ReadWrite); @@ -379,8 +381,7 @@ 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 - const auto uid = Sink::Storage::Key::fromDisplayByteArray(testProcessor->newUids.at(0)).identifier().toDisplayByteArray(); + const auto uid = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->newUids.at(0)).toDisplayByteArray(); QCOMPARE(testProcessor->newUids.at(0), uid); } pipeline.commit(); @@ -388,14 +389,13 @@ private slots: pipeline.startTransaction(); auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Sink::Storage::Key::fromDisplayByteArray(keys.first()).identifier().toDisplayByteArray(); + 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 - const auto uid2 = Sink::Storage::Key::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).identifier().toDisplayByteArray(); + const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray(); QCOMPARE(testProcessor->modifiedUids.at(0), uid2); } pipeline.commit(); @@ -407,8 +407,7 @@ 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 - const auto uid2 = Sink::Storage::Key::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).identifier().toDisplayByteArray(); + 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")); } diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index d3f180a..2ddbebf 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -457,10 +457,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) - const auto key1 = Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(uid), 6); - db.write(key1.toInternalByteArray(), "value1"); - const auto key2 = Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(uid), 10); - db.write(key2.toInternalByteArray(), "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")); } -- cgit v1.2.3