From 685a16155504831c8b5fdb9a4d0a955b21c807bf Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 2 Aug 2017 12:12:07 -0600 Subject: Info command to print some default information --- sinksh/syntax_modules/sink_info.cpp | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 sinksh/syntax_modules/sink_info.cpp (limited to 'sinksh/syntax_modules') diff --git a/sinksh/syntax_modules/sink_info.cpp b/sinksh/syntax_modules/sink_info.cpp new file mode 100644 index 0000000..5f535eb --- /dev/null +++ b/sinksh/syntax_modules/sink_info.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include // tr() + +#include "common/definitions.h" + +#include "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkInfo +{ + +bool info(const QStringList &args, State &state) +{ + state.printLine(QString("Storage location: %1").arg(Sink::storageLocation())); + state.printLine(QString("Data location: %1").arg(Sink::dataLocation())); + state.printLine(QString("Config location: %1").arg(Sink::configLocation())); + state.printLine(QString("Temporary file location: %1").arg(Sink::temporaryFileLocation())); + state.printLine(QString("Resource storage location: %1").arg(Sink::resourceStorageLocation("$RESOURCE"))); + return false; +} + +Syntax::List syntax() +{ + return Syntax::List() << Syntax{"info", QObject::tr("Shows general system info"), &SinkInfo::info, Syntax::NotInteractive}; +} + +REGISTER_SYNTAX(SinkInfo) + +} -- cgit v1.2.3 From a7c40cd33ba99658ac0c8849622a2b3f3db16de2 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 2 Aug 2017 13:04:59 -0600 Subject: Print version --- sinksh/syntax_modules/sink_info.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sinksh/syntax_modules') diff --git a/sinksh/syntax_modules/sink_info.cpp b/sinksh/syntax_modules/sink_info.cpp index 5f535eb..aa515e6 100644 --- a/sinksh/syntax_modules/sink_info.cpp +++ b/sinksh/syntax_modules/sink_info.cpp @@ -25,12 +25,14 @@ #include "sinksh_utils.h" #include "state.h" #include "syntaxtree.h" +#include "sink_version.h" namespace SinkInfo { bool info(const QStringList &args, State &state) { + state.printLine(QString("Sink version: %1").arg(sink_VERSION_STRING)); state.printLine(QString("Storage location: %1").arg(Sink::storageLocation())); state.printLine(QString("Data location: %1").arg(Sink::dataLocation())); state.printLine(QString("Config location: %1").arg(Sink::configLocation())); -- cgit v1.2.3 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') 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') 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') 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 1c455b9a0b6d5a7abb0e8e9ab68e338c62811d24 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 13 Aug 2017 14:58:34 -0600 Subject: sinksh show cleanup --- sinksh/syntax_modules/sink_show.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'sinksh/syntax_modules') diff --git a/sinksh/syntax_modules/sink_show.cpp b/sinksh/syntax_modules/sink_show.cpp index 391505a..7a4166f 100644 --- a/sinksh/syntax_modules/sink_show.cpp +++ b/sinksh/syntax_modules/sink_show.cpp @@ -18,18 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include #include #include // tr() #include #include -#include "common/resource.h" #include "common/storage.h" -#include "common/resourceconfig.h" -#include "common/log.h" -#include "common/storage.h" -#include "common/definitions.h" #include "sinksh_utils.h" #include "state.h" @@ -41,25 +35,24 @@ namespace SinkShow bool show(const QStringList &args, State &state) { if (args.isEmpty()) { - state.printError(QObject::tr("Please provide at least one type to show (e.g. resource, ..")); + state.printError(QObject::tr("Options: $type --resource $resource --id $id")); return false; } - auto argList = args; - if (argList.size() < 2 || !SinkshUtils::isValidStoreType(argList.at(0))) { + auto options = SyntaxTree::parseOptions(args); + + auto type = options.positionalArguments.isEmpty() ? QString{} : options.positionalArguments.first(); + auto resource = options.options.value("resource"); + auto id = options.options.value("id"); + + if (id.isEmpty() || resource.isEmpty() || !SinkshUtils::isValidStoreType(type)) { state.printError(QObject::tr("Invalid command syntax. Supply type and resource at least.")); return false; } - auto type = argList.takeFirst(); - auto resource = argList.takeFirst(); - bool queryForResourceOrAgent = argList.isEmpty(); Sink::Query query; - if (queryForResourceOrAgent) { - query.filter(resource.toLatin1()); - } else { - query.resourceFilter(resource.toLatin1()); - } + query.resourceFilter(resource.first().toLatin1()); + query.filter(id.first().toLatin1()); QTime time; time.start(); -- 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') 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') 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