diff options
-rw-r--r-- | common/index.cpp | 18 | ||||
-rw-r--r-- | common/index.h | 1 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 21 |
3 files changed, 26 insertions, 14 deletions
diff --git a/common/index.cpp b/common/index.cpp index 25dfb7c..ae56da1 100644 --- a/common/index.cpp +++ b/common/index.cpp | |||
@@ -1,15 +1,21 @@ | |||
1 | #include "index.h" | 1 | #include "index.h" |
2 | #include <QDebug> | 2 | |
3 | #include "log.h" | ||
4 | |||
5 | #undef Trace | ||
6 | #define Trace() Trace_area("index." + mName.toLatin1()) | ||
3 | 7 | ||
4 | Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode) | 8 | Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode) |
5 | : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)), | 9 | : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)), |
6 | mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Sink::Storage::Error &)>(), true)) | 10 | mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Sink::Storage::Error &)>(), true)), |
11 | mName(name) | ||
7 | { | 12 | { |
8 | 13 | ||
9 | } | 14 | } |
10 | 15 | ||
11 | Index::Index(const QByteArray &name, Sink::Storage::Transaction &transaction) | 16 | Index::Index(const QByteArray &name, Sink::Storage::Transaction &transaction) |
12 | : mDb(transaction.openDatabase(name, std::function<void(const Sink::Storage::Error &)>(), true)) | 17 | : mDb(transaction.openDatabase(name, std::function<void(const Sink::Storage::Error &)>(), true)), |
18 | mName(name) | ||
13 | { | 19 | { |
14 | 20 | ||
15 | } | 21 | } |
@@ -32,7 +38,7 @@ void Index::lookup(const QByteArray &key, const std::function<void(const QByteAr | |||
32 | return true; | 38 | return true; |
33 | }, | 39 | }, |
34 | [errorHandler](const Sink::Storage::Error &error) { | 40 | [errorHandler](const Sink::Storage::Error &error) { |
35 | qDebug() << "Error while retrieving value" << error.message; | 41 | Warning() << "Error while retrieving value" << error.message; |
36 | errorHandler(Error(error.store, error.code, error.message)); | 42 | errorHandler(Error(error.store, error.code, error.message)); |
37 | } | 43 | } |
38 | ); | 44 | ); |
@@ -45,8 +51,8 @@ QByteArray Index::lookup(const QByteArray &key) | |||
45 | [&result](const QByteArray &value) { | 51 | [&result](const QByteArray &value) { |
46 | result = value; | 52 | result = value; |
47 | }, | 53 | }, |
48 | [](const Index::Error &error) { | 54 | [this](const Index::Error &error) { |
49 | qDebug() << "Error while retrieving value" << error.message; | 55 | Trace() << "Error while retrieving value" << error.message; |
50 | }); | 56 | }); |
51 | return result; | 57 | return result; |
52 | } | 58 | } |
diff --git a/common/index.h b/common/index.h index 1a5b250..df79fc3 100644 --- a/common/index.h +++ b/common/index.h | |||
@@ -40,4 +40,5 @@ private: | |||
40 | Q_DISABLE_COPY(Index); | 40 | Q_DISABLE_COPY(Index); |
41 | Sink::Storage::Transaction mTransaction; | 41 | Sink::Storage::Transaction mTransaction; |
42 | Sink::Storage::NamedDatabase mDb; | 42 | Sink::Storage::NamedDatabase mDb; |
43 | QString mName; | ||
43 | }; | 44 | }; |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 1efffc4..f899767 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -32,9 +32,14 @@ | |||
32 | #include <QMutex> | 32 | #include <QMutex> |
33 | 33 | ||
34 | #include <lmdb.h> | 34 | #include <lmdb.h> |
35 | #include "log.h" | ||
35 | 36 | ||
36 | namespace Sink | 37 | #undef Trace |
37 | { | 38 | #define Trace() Trace_area("storage." + d->storageRoot.toLatin1() + '/' + d->name.toLatin1()) |
39 | #undef Warning | ||
40 | #define Warning() Warning_area("storage") | ||
41 | |||
42 | namespace Sink { | ||
38 | 43 | ||
39 | int getErrorCode(int e) | 44 | int getErrorCode(int e) |
40 | { | 45 | { |
@@ -328,7 +333,7 @@ qint64 Storage::NamedDatabase::getSize() | |||
328 | MDB_stat stat; | 333 | MDB_stat stat; |
329 | rc = mdb_stat(d->transaction, d->dbi, &stat); | 334 | rc = mdb_stat(d->transaction, d->dbi, &stat); |
330 | if (rc) { | 335 | if (rc) { |
331 | qWarning() << "Something went wrong " << rc; | 336 | Warning() << "Something went wrong " << rc; |
332 | } | 337 | } |
333 | // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl; | 338 | // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl; |
334 | // std::cout << "page size: " << stat.ms_psize << std::endl; | 339 | // std::cout << "page size: " << stat.ms_psize << std::endl; |
@@ -452,7 +457,7 @@ Storage::NamedDatabase Storage::Transaction::openDatabase(const QByteArray &db, | |||
452 | QList<QByteArray> Storage::Transaction::getDatabaseNames() const | 457 | QList<QByteArray> Storage::Transaction::getDatabaseNames() const |
453 | { | 458 | { |
454 | if (!d) { | 459 | if (!d) { |
455 | qWarning() << "Invalid transaction"; | 460 | Warning() << "Invalid transaction"; |
456 | return QList<QByteArray>(); | 461 | return QList<QByteArray>(); |
457 | } | 462 | } |
458 | 463 | ||
@@ -470,10 +475,10 @@ QList<QByteArray> Storage::Transaction::getDatabaseNames() const | |||
470 | list << QByteArray::fromRawData((char*)key.mv_data, key.mv_size); | 475 | list << QByteArray::fromRawData((char*)key.mv_data, key.mv_size); |
471 | } | 476 | } |
472 | } else { | 477 | } else { |
473 | qWarning() << "Failed to get a value" << rc; | 478 | Warning() << "Failed to get a value" << rc; |
474 | } | 479 | } |
475 | } else { | 480 | } else { |
476 | qWarning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); | 481 | Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); |
477 | } | 482 | } |
478 | return list; | 483 | return list; |
479 | } | 484 | } |
@@ -596,7 +601,7 @@ qint64 Storage::diskUsage() const | |||
596 | { | 601 | { |
597 | QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); | 602 | QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); |
598 | if (!info.exists()) { | 603 | if (!info.exists()) { |
599 | qWarning() << "Tried to get filesize for non-existant file: " << info.path(); | 604 | Warning() << "Tried to get filesize for non-existant file: " << info.path(); |
600 | } | 605 | } |
601 | return info.size(); | 606 | return info.size(); |
602 | } | 607 | } |
@@ -606,7 +611,7 @@ void Storage::removeFromDisk() const | |||
606 | const QString fullPath(d->storageRoot + '/' + d->name); | 611 | const QString fullPath(d->storageRoot + '/' + d->name); |
607 | QMutexLocker locker(&d->sMutex); | 612 | QMutexLocker locker(&d->sMutex); |
608 | QDir dir(fullPath); | 613 | QDir dir(fullPath); |
609 | std::cout << "Removing database from disk: " << fullPath.toStdString() << std::endl; | 614 | Trace() << "Removing database from disk: " << fullPath; |
610 | if (!dir.removeRecursively()) { | 615 | if (!dir.removeRecursively()) { |
611 | Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Failed to remove directory %1 %2").arg(d->storageRoot).arg(d->name).toLatin1()); | 616 | Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Failed to remove directory %1 %2").arg(d->storageRoot).arg(d->name).toLatin1()); |
612 | defaultErrorHandler()(error); | 617 | defaultErrorHandler()(error); |