summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_inspect.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-13 12:42:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-13 12:42:31 +0200
commitc12a9a09da59b9e418316dba02e6215cb55e47ee (patch)
tree05498d9a42e399bcca787f40c1fc473fb09e680e /sinksh/syntax_modules/sink_inspect.cpp
parent55fe06979ceebe67553135b43aa47e70d931304b (diff)
parentebdb89b8bb482bbb5ecd544c3d38bef35fc7d820 (diff)
downloadsink-2cbc37da82bb06757c38f891c465a24219268d3b.tar.gz
sink-2cbc37da82bb06757c38f891c465a24219268d3b.zip
Merge commit 'ebdb89b8bb482bbb5ecd544c3d38bef35fc7d820'v0.4.0
Diffstat (limited to 'sinksh/syntax_modules/sink_inspect.cpp')
-rw-r--r--sinksh/syntax_modules/sink_inspect.cpp79
1 files changed, 75 insertions, 4 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp
index a8a3805..da62250 100644
--- a/sinksh/syntax_modules/sink_inspect.cpp
+++ b/sinksh/syntax_modules/sink_inspect.cpp
@@ -19,8 +19,6 @@
19 19
20#include <QDebug> 20#include <QDebug>
21#include <QObject> // tr() 21#include <QObject> // tr()
22#include <QTimer>
23#include <QDir>
24 22
25#include "common/resource.h" 23#include "common/resource.h"
26#include "common/storage.h" 24#include "common/storage.h"
@@ -30,6 +28,7 @@
30#include "common/definitions.h" 28#include "common/definitions.h"
31#include "common/entitybuffer.h" 29#include "common/entitybuffer.h"
32#include "common/metadata_generated.h" 30#include "common/metadata_generated.h"
31#include "common/bufferutils.h"
33 32
34#include "sinksh_utils.h" 33#include "sinksh_utils.h"
35#include "state.h" 34#include "state.h"
@@ -41,7 +40,7 @@ namespace SinkInspect
41bool inspect(const QStringList &args, State &state) 40bool inspect(const QStringList &args, State &state)
42{ 41{
43 if (args.isEmpty()) { 42 if (args.isEmpty()) {
44 state.printError(QObject::tr("Options: $type [--resource $resource] [--db $db] [--filter $id] [--showinternal]")); 43 state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type])"));
45 } 44 }
46 auto options = SyntaxTree::parseOptions(args); 45 auto options = SyntaxTree::parseOptions(args);
47 auto resource = options.options.value("resource").value(0); 46 auto resource = options.options.value("resource").value(0);
@@ -49,6 +48,75 @@ bool inspect(const QStringList &args, State &state)
49 Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); 48 Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly);
50 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); 49 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly);
51 50
51 bool validateRids = options.options.contains("validaterids");
52 if (validateRids) {
53 if (options.options.value("validaterids").isEmpty()) {
54 state.printError(QObject::tr("Specify a type to validate."));
55 return false;
56 }
57 auto type = options.options.value("validaterids").first().toUtf8();
58 /*
59 * Try to find all rid's for all uid's.
60 * If we have entities without rid's that either means we have only created it locally or that we have a problem.
61 */
62 Sink::Storage::DataStore syncStore(Sink::storageLocation(), resource + ".synchronization", Sink::Storage::DataStore::ReadOnly);
63 auto syncTransaction = syncStore.createTransaction(Sink::Storage::DataStore::ReadOnly);
64
65 auto db = transaction.openDatabase(type + ".main",
66 [&] (const Sink::Storage::DataStore::Error &e) {
67 Q_ASSERT(false);
68 state.printError(e.message);
69 }, false);
70
71 auto ridMap = syncTransaction.openDatabase("localid.mapping." + type,
72 [&] (const Sink::Storage::DataStore::Error &e) {
73 Q_ASSERT(false);
74 state.printError(e.message);
75 }, false);
76
77 QHash<QByteArray, QByteArray> hash;
78
79 ridMap.scan("", [&] (const QByteArray &key, const QByteArray &data) {
80 hash.insert(key, data);
81 return true;
82 },
83 [&](const Sink::Storage::DataStore::Error &e) {
84 state.printError(e.message);
85 },
86 false);
87
88 QSet<QByteArray> uids;
89 db.scan("", [&] (const QByteArray &key, const QByteArray &data) {
90 uids.insert(Sink::Storage::DataStore::uidFromKey(key));
91 return true;
92 },
93 [&](const Sink::Storage::DataStore::Error &e) {
94 state.printError(e.message);
95 },
96 false);
97
98 int missing = 0;
99 for (const auto &uid : uids) {
100 if (!hash.remove(uid)) {
101 missing++;
102 qWarning() << "Failed to find RID for " << uid;
103 }
104 }
105 if (missing) {
106 qWarning() << "Found a total of " << missing << " missing rids";
107 }
108
109 //If we still have items in the hash it means we have rid mappings for entities
110 //that no longer exist.
111 if (!hash.isEmpty()) {
112 qWarning() << "Have rids left: " << hash.size();
113 } else if (!missing) {
114 qWarning() << "Everything is in order.";
115 }
116
117 return false;
118 }
119
52 auto dbs = options.options.value("db"); 120 auto dbs = options.options.value("db");
53 auto idFilter = options.options.value("filter"); 121 auto idFilter = options.options.value("filter");
54 bool showInternal = options.options.contains("showinternal"); 122 bool showInternal = options.options.contains("showinternal");
@@ -96,7 +164,10 @@ bool inspect(const QStringList &args, State &state)
96 state.printError("Read invalid buffer from disk: " + key); 164 state.printError("Read invalid buffer from disk: " + key);
97 } else { 165 } else {
98 const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); 166 const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer());
99 state.printLine("Key: " + key + " Operation: " + QString::number(metadata->operation())); 167 state.printLine("Key: " + key
168 + " Operation: " + QString::number(metadata->operation())
169 + " Replay: " + (metadata->replayToSource() ? "true" : "false")
170 + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": ""));
100 } 171 }
101 } else { 172 } else {
102 state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); 173 state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data));