summaryrefslogtreecommitdiffstats
path: root/common/storage_lmdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r--common/storage_lmdb.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 352e250..79f4465 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -34,10 +34,8 @@
34#include <lmdb.h> 34#include <lmdb.h>
35#include "log.h" 35#include "log.h"
36 36
37#undef Trace 37SINK_DEBUG_AREA("storage")
38#define Trace() Trace_area("storage." + d->storageRoot.toLatin1() + '/' + d->name.toLatin1()) 38// SINK_DEBUG_COMPONENT(d->storageRoot.toLatin1() + '/' + d->name.toLatin1())
39#undef Warning
40#define Warning() Warning_area("storage")
41 39
42namespace Sink { 40namespace Sink {
43 41
@@ -354,7 +352,7 @@ qint64 Storage::NamedDatabase::getSize()
354 MDB_stat stat; 352 MDB_stat stat;
355 rc = mdb_stat(d->transaction, d->dbi, &stat); 353 rc = mdb_stat(d->transaction, d->dbi, &stat);
356 if (rc) { 354 if (rc) {
357 Warning() << "Something went wrong " << QByteArray(mdb_strerror(rc)); 355 SinkWarning() << "Something went wrong " << QByteArray(mdb_strerror(rc));
358 } 356 }
359 // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl; 357 // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl;
360 // std::cout << "page size: " << stat.ms_psize << std::endl; 358 // std::cout << "page size: " << stat.ms_psize << std::endl;
@@ -482,7 +480,7 @@ static bool ensureCorrectDb(Storage::NamedDatabase &database, const QByteArray &
482 bool openedTheWrongDatabase = false; 480 bool openedTheWrongDatabase = false;
483 auto count = database.scan("__internal_dbname", [db, &openedTheWrongDatabase](const QByteArray &key, const QByteArray &value) ->bool { 481 auto count = database.scan("__internal_dbname", [db, &openedTheWrongDatabase](const QByteArray &key, const QByteArray &value) ->bool {
484 if (value != db) { 482 if (value != db) {
485 Warning() << "Opened the wrong database, got " << value << " instead of " << db; 483 SinkWarning() << "Opened the wrong database, got " << value << " instead of " << db;
486 openedTheWrongDatabase = true; 484 openedTheWrongDatabase = true;
487 } 485 }
488 return false; 486 return false;
@@ -505,7 +503,7 @@ bool Storage::Transaction::validateNamedDatabases()
505 for (const auto &dbName : databases) { 503 for (const auto &dbName : databases) {
506 auto db = openDatabase(dbName); 504 auto db = openDatabase(dbName);
507 if (!db) { 505 if (!db) {
508 Warning() << "Failed to open the database: " << dbName; 506 SinkWarning() << "Failed to open the database: " << dbName;
509 return false; 507 return false;
510 } 508 }
511 } 509 }
@@ -527,7 +525,7 @@ Storage::NamedDatabase Storage::Transaction::openDatabase(const QByteArray &db,
527 } 525 }
528 auto database = Storage::NamedDatabase(p); 526 auto database = Storage::NamedDatabase(p);
529 if (!ensureCorrectDb(database, db, d->requestedRead)) { 527 if (!ensureCorrectDb(database, db, d->requestedRead)) {
530 Warning() << "Failed to open the database" << db; 528 SinkWarning() << "Failed to open the database" << db;
531 return Storage::NamedDatabase(); 529 return Storage::NamedDatabase();
532 } 530 }
533 return database; 531 return database;
@@ -536,7 +534,7 @@ Storage::NamedDatabase Storage::Transaction::openDatabase(const QByteArray &db,
536QList<QByteArray> Storage::Transaction::getDatabaseNames() const 534QList<QByteArray> Storage::Transaction::getDatabaseNames() const
537{ 535{
538 if (!d) { 536 if (!d) {
539 Warning() << "Invalid transaction"; 537 SinkWarning() << "Invalid transaction";
540 return QList<QByteArray>(); 538 return QList<QByteArray>();
541 } 539 }
542 540
@@ -559,12 +557,12 @@ QList<QByteArray> Storage::Transaction::getDatabaseNames() const
559 rc = 0; 557 rc = 0;
560 } 558 }
561 if (rc) { 559 if (rc) {
562 Warning() << "Failed to get a value" << rc; 560 SinkWarning() << "Failed to get a value" << rc;
563 } 561 }
564 } 562 }
565 mdb_cursor_close(cursor); 563 mdb_cursor_close(cursor);
566 } else { 564 } else {
567 Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); 565 SinkWarning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc));
568 } 566 }
569 return list; 567 return list;
570} 568}
@@ -611,7 +609,7 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m) : st
611 int rc = 0; 609 int rc = 0;
612 if ((rc = mdb_env_create(&env))) { 610 if ((rc = mdb_env_create(&env))) {
613 // TODO: handle error 611 // TODO: handle error
614 Warning() << "mdb_env_create: " << rc << " " << mdb_strerror(rc); 612 SinkWarning() << "mdb_env_create: " << rc << " " << mdb_strerror(rc);
615 } else { 613 } else {
616 mdb_env_set_maxdbs(env, 50); 614 mdb_env_set_maxdbs(env, 50);
617 unsigned int flags = MDB_NOTLS; 615 unsigned int flags = MDB_NOTLS;
@@ -619,7 +617,7 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m) : st
619 flags |= MDB_RDONLY; 617 flags |= MDB_RDONLY;
620 } 618 }
621 if ((rc = mdb_env_open(env, fullPath.toStdString().data(), flags, 0664))) { 619 if ((rc = mdb_env_open(env, fullPath.toStdString().data(), flags, 0664))) {
622 Warning() << "mdb_env_open: " << rc << " " << mdb_strerror(rc); 620 SinkWarning() << "mdb_env_open: " << rc << " " << mdb_strerror(rc);
623 mdb_env_close(env); 621 mdb_env_close(env);
624 env = 0; 622 env = 0;
625 } else { 623 } else {
@@ -681,7 +679,7 @@ qint64 Storage::diskUsage() const
681{ 679{
682 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); 680 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb");
683 if (!info.exists()) { 681 if (!info.exists()) {
684 Warning() << "Tried to get filesize for non-existant file: " << info.path(); 682 SinkWarning() << "Tried to get filesize for non-existant file: " << info.path();
685 } 683 }
686 return info.size(); 684 return info.size();
687} 685}
@@ -691,7 +689,7 @@ void Storage::removeFromDisk() const
691 const QString fullPath(d->storageRoot + '/' + d->name); 689 const QString fullPath(d->storageRoot + '/' + d->name);
692 QMutexLocker locker(&d->sMutex); 690 QMutexLocker locker(&d->sMutex);
693 QDir dir(fullPath); 691 QDir dir(fullPath);
694 Trace() << "Removing database from disk: " << fullPath; 692 SinkTrace() << "Removing database from disk: " << fullPath;
695 if (!dir.removeRecursively()) { 693 if (!dir.removeRecursively()) {
696 Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Failed to remove directory %1 %2").arg(d->storageRoot).arg(d->name).toLatin1()); 694 Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Failed to remove directory %1 %2").arg(d->storageRoot).arg(d->name).toLatin1());
697 defaultErrorHandler()(error); 695 defaultErrorHandler()(error);