summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-13 14:38:04 -0600
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-13 14:38:04 -0600
commit1e888175bbc94d0681d71feb4d12ba9354fd8224 (patch)
tree0f94955a56d914a3eb54fc67289f2e5f0c70ebf0 /sinksh/syntax_modules
parent823d4170fc884d3707425c13198c2973b049c3b3 (diff)
downloadsink-1e888175bbc94d0681d71feb4d12ba9354fd8224.tar.gz
sink-1e888175bbc94d0681d71feb4d12ba9354fd8224.zip
Inspection to validate all rids
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r--sinksh/syntax_modules/sink_inspect.cpp59
1 files changed, 58 insertions, 1 deletions
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
40bool inspect(const QStringList &args, State &state) 40bool inspect(const QStringList &args, State &state)
41{ 41{
42 if (args.isEmpty()) { 42 if (args.isEmpty()) {
43 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])"));
44 } 44 }
45 auto options = SyntaxTree::parseOptions(args); 45 auto options = SyntaxTree::parseOptions(args);
46 auto resource = options.options.value("resource").value(0); 46 auto resource = options.options.value("resource").value(0);
@@ -48,6 +48,63 @@ bool inspect(const QStringList &args, State &state)
48 Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); 48 Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly);
49 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); 49 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly);
50 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 db.scan("", [&] (const QByteArray &key, const QByteArray &data) {
89 if (!hash.remove(Sink::Storage::DataStore::uidFromKey(key))) {
90 qWarning() << "Failed to find RID for " << key;
91 }
92 return true;
93 },
94 [&](const Sink::Storage::DataStore::Error &e) {
95 state.printError(e.message);
96 },
97 false);
98
99 //If we still have items in the hash it means we have rid mappings for entities
100 //that no longer exist.
101 if (!hash.isEmpty()) {
102 qWarning() << "Have rids left: " << hash.size();
103 }
104
105 return false;
106 }
107
51 auto dbs = options.options.value("db"); 108 auto dbs = options.options.value("db");
52 auto idFilter = options.options.value("filter"); 109 auto idFilter = options.options.value("filter");
53 bool showInternal = options.options.contains("showinternal"); 110 bool showInternal = options.options.contains("showinternal");