From b53881c6bd1aaf9841770120258a068a683b8bad Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 11 Aug 2017 20:16:38 -0600 Subject: Some metadata for inspect --- sinksh/syntax_modules/sink_inspect.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sinksh/syntax_modules/sink_inspect.cpp') diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index a8a3805..848d576 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -19,8 +19,6 @@ #include #include // tr() -#include -#include #include "common/resource.h" #include "common/storage.h" @@ -30,6 +28,7 @@ #include "common/definitions.h" #include "common/entitybuffer.h" #include "common/metadata_generated.h" +#include "common/bufferutils.h" #include "sinksh_utils.h" #include "state.h" @@ -96,7 +95,10 @@ bool inspect(const QStringList &args, State &state) state.printError("Read invalid buffer from disk: " + key); } else { const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); - state.printLine("Key: " + key + " Operation: " + QString::number(metadata->operation())); + state.printLine("Key: " + key + + " Operation: " + QString::number(metadata->operation()) + + " Replay: " + (metadata->replayToSource() ? "true" : "false") + + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" Changeset: " + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(",")) : "")); } } else { state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); -- cgit v1.2.3 From 1e888175bbc94d0681d71feb4d12ba9354fd8224 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 13 Aug 2017 14:38:04 -0600 Subject: Inspection to validate all rids --- sinksh/syntax_modules/sink_inspect.cpp | 59 +++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'sinksh/syntax_modules/sink_inspect.cpp') diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 848d576..d1f9791 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -40,7 +40,7 @@ namespace SinkInspect bool inspect(const QStringList &args, State &state) { if (args.isEmpty()) { - state.printError(QObject::tr("Options: $type [--resource $resource] [--db $db] [--filter $id] [--showinternal]")); + state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type])")); } auto options = SyntaxTree::parseOptions(args); auto resource = options.options.value("resource").value(0); @@ -48,6 +48,63 @@ bool inspect(const QStringList &args, State &state) Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); + bool validateRids = options.options.contains("validaterids"); + if (validateRids) { + if (options.options.value("validaterids").isEmpty()) { + state.printError(QObject::tr("Specify a type to validate.")); + return false; + } + auto type = options.options.value("validaterids").first().toUtf8(); + /* + * Try to find all rid's for all uid's. + * If we have entities without rid's that either means we have only created it locally or that we have a problem. + */ + Sink::Storage::DataStore syncStore(Sink::storageLocation(), resource + ".synchronization", Sink::Storage::DataStore::ReadOnly); + auto syncTransaction = syncStore.createTransaction(Sink::Storage::DataStore::ReadOnly); + + auto db = transaction.openDatabase(type + ".main", + [&] (const Sink::Storage::DataStore::Error &e) { + Q_ASSERT(false); + state.printError(e.message); + }, false); + + auto ridMap = syncTransaction.openDatabase("localid.mapping." + type, + [&] (const Sink::Storage::DataStore::Error &e) { + Q_ASSERT(false); + state.printError(e.message); + }, false); + + QHash hash; + + ridMap.scan("", [&] (const QByteArray &key, const QByteArray &data) { + hash.insert(key, data); + return true; + }, + [&](const Sink::Storage::DataStore::Error &e) { + state.printError(e.message); + }, + false); + + db.scan("", [&] (const QByteArray &key, const QByteArray &data) { + if (!hash.remove(Sink::Storage::DataStore::uidFromKey(key))) { + qWarning() << "Failed to find RID for " << key; + } + return true; + }, + [&](const Sink::Storage::DataStore::Error &e) { + state.printError(e.message); + }, + false); + + //If we still have items in the hash it means we have rid mappings for entities + //that no longer exist. + if (!hash.isEmpty()) { + qWarning() << "Have rids left: " << hash.size(); + } + + return false; + } + auto dbs = options.options.value("db"); auto idFilter = options.options.value("filter"); bool showInternal = options.options.contains("showinternal"); -- cgit v1.2.3 From bfc3abb10f8827c5753a8a90a2010f0bfd3a4f10 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 13 Aug 2017 14:38:19 -0600 Subject: More compact changeset --- sinksh/syntax_modules/sink_inspect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sinksh/syntax_modules/sink_inspect.cpp') diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index d1f9791..b271b4f 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -155,7 +155,7 @@ bool inspect(const QStringList &args, State &state) state.printLine("Key: " + key + " Operation: " + QString::number(metadata->operation()) + " Replay: " + (metadata->replayToSource() ? "true" : "false") - + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" Changeset: " + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(",")) : "")); + + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "")); } } else { state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); -- cgit v1.2.3 From b63ae293c4f93d3bea9f1a7d96baf006cc459597 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 14 Aug 2017 08:30:06 -0600 Subject: Only count every uid once. The previous code would fail on the second revision with the same uid. --- sinksh/syntax_modules/sink_inspect.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'sinksh/syntax_modules/sink_inspect.cpp') diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index b271b4f..9cc3b23 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -85,10 +85,9 @@ bool inspect(const QStringList &args, State &state) }, false); + QSet uids; db.scan("", [&] (const QByteArray &key, const QByteArray &data) { - if (!hash.remove(Sink::Storage::DataStore::uidFromKey(key))) { - qWarning() << "Failed to find RID for " << key; - } + uids.insert(Sink::Storage::DataStore::uidFromKey(key)); return true; }, [&](const Sink::Storage::DataStore::Error &e) { @@ -96,6 +95,17 @@ bool inspect(const QStringList &args, State &state) }, false); + int missing = 0; + for (const auto &uid : uids) { + if (!hash.remove(uid)) { + missing++; + qWarning() << "Failed to find RID for " << uid; + } + } + if (missing) { + qWarning() << "Found a total of " << missing << " missing rids"; + } + //If we still have items in the hash it means we have rid mappings for entities //that no longer exist. if (!hash.isEmpty()) { -- cgit v1.2.3 From c917543f0e37d423186dd10ccd7b8b80beb0cd16 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 18 Aug 2017 19:09:56 -0600 Subject: Say something if things are okay --- sinksh/syntax_modules/sink_inspect.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sinksh/syntax_modules/sink_inspect.cpp') diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 9cc3b23..da62250 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -110,6 +110,8 @@ bool inspect(const QStringList &args, State &state) //that no longer exist. if (!hash.isEmpty()) { qWarning() << "Have rids left: " << hash.size(); + } else if (!missing) { + qWarning() << "Everything is in order."; } return false; -- cgit v1.2.3