summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-06 15:10:47 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-06 15:10:47 +0100
commit279c3fd398546eb6ed8cfb950b040e47a36e6711 (patch)
tree9bda4a4162ed6719e1d3b6a4e6863938e2f4be86 /common/index.cpp
parentf03005ccc2cd0f7eea3ad8e7e1c90ed2d8ea3561 (diff)
downloadsink-279c3fd398546eb6ed8cfb950b040e47a36e6711.tar.gz
sink-279c3fd398546eb6ed8cfb950b040e47a36e6711.zip
Index debug output
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/common/index.cpp b/common/index.cpp
index f09e265..725c28b 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -2,31 +2,31 @@
2 2
3#include "log.h" 3#include "log.h"
4 4
5SINK_DEBUG_AREA("index")
6
7Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::DataStore::AccessMode mode) 5Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::DataStore::AccessMode mode)
8 : mTransaction(Sink::Storage::DataStore(storageRoot, name, mode).createTransaction(mode)), 6 : mTransaction(Sink::Storage::DataStore(storageRoot, name, mode).createTransaction(mode)),
9 mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Sink::Storage::DataStore::Error &)>(), true)), 7 mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Sink::Storage::DataStore::Error &)>(), true)),
10 mName(name) 8 mName(name),
9 mLogCtx("index." + name.toLatin1())
11{ 10{
12} 11}
13 12
14Index::Index(const QByteArray &name, Sink::Storage::DataStore::Transaction &transaction) 13Index::Index(const QByteArray &name, Sink::Storage::DataStore::Transaction &transaction)
15 : mDb(transaction.openDatabase(name, std::function<void(const Sink::Storage::DataStore::Error &)>(), true)), mName(name) 14 : mDb(transaction.openDatabase(name, std::function<void(const Sink::Storage::DataStore::Error &)>(), true)), mName(name),
15 mLogCtx("index." + name)
16{ 16{
17} 17}
18 18
19void Index::add(const QByteArray &key, const QByteArray &value) 19void Index::add(const QByteArray &key, const QByteArray &value)
20{ 20{
21 mDb.write(key, value, [&] (const Sink::Storage::DataStore::Error &error) { 21 mDb.write(key, value, [&] (const Sink::Storage::DataStore::Error &error) {
22 SinkWarning() << "Error while writing value" << error; 22 SinkWarningCtx(mLogCtx) << "Error while writing value" << error;
23 }); 23 });
24} 24}
25 25
26void Index::remove(const QByteArray &key, const QByteArray &value) 26void Index::remove(const QByteArray &key, const QByteArray &value)
27{ 27{
28 mDb.remove(key, value, [&] (const Sink::Storage::DataStore::Error &error) { 28 mDb.remove(key, value, [&] (const Sink::Storage::DataStore::Error &error) {
29 SinkWarning() << "Error while removing value: " << key << value << error << error.store; 29 SinkWarningCtx(mLogCtx) << "Error while removing value: " << key << value << error;
30 }); 30 });
31} 31}
32 32
@@ -38,7 +38,7 @@ void Index::lookup(const QByteArray &key, const std::function<void(const QByteAr
38 return true; 38 return true;
39 }, 39 },
40 [&](const Sink::Storage::DataStore::Error &error) { 40 [&](const Sink::Storage::DataStore::Error &error) {
41 SinkWarning() << "Error while retrieving value" << error.message; 41 SinkWarningCtx(mLogCtx) << "Error while retrieving value:" << error << mName;
42 errorHandler(Error(error.store, error.code, error.message)); 42 errorHandler(Error(error.store, error.code, error.message));
43 }, 43 },
44 matchSubStringKeys); 44 matchSubStringKeys);
@@ -48,6 +48,6 @@ QByteArray Index::lookup(const QByteArray &key)
48{ 48{
49 QByteArray result; 49 QByteArray result;
50 //We have to create a deep copy, otherwise the returned data may become invalid when the transaction ends. 50 //We have to create a deep copy, otherwise the returned data may become invalid when the transaction ends.
51 lookup(key, [&](const QByteArray &value) { result = QByteArray(value.constData(), value.size()); }, [this](const Index::Error &error) { SinkWarning() << "Error while retrieving value" << error.message; }); 51 lookup(key, [&](const QByteArray &value) { result = QByteArray(value.constData(), value.size()); }, [this](const Index::Error &) { });
52 return result; 52 return result;
53} 53}