diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-23 19:07:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-23 19:07:21 +0200 |
commit | ae0255bf8eb913004082278af27d69047503ea71 (patch) | |
tree | fbe5f2a8a22776c8eec5c51df1da3727b24f9ede /common/storage_lmdb.cpp | |
parent | 91cb5bf93c7eb1caad910b693927d80e552239b1 (diff) | |
download | sink-ae0255bf8eb913004082278af27d69047503ea71.tar.gz sink-ae0255bf8eb913004082278af27d69047503ea71.zip |
Storage cleanup
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 3c153fc..7fed830 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -233,10 +233,9 @@ int Storage::NamedDatabase::scan(const QByteArray &k, | |||
233 | class Storage::Transaction::Private | 233 | class Storage::Transaction::Private |
234 | { | 234 | { |
235 | public: | 235 | public: |
236 | Private(bool _requestRead, bool _allowDuplicates, const std::function<void(const Storage::Error &error)> &_defaultErrorHandler, const QString &_name, MDB_env *_env) | 236 | Private(bool _requestRead, const std::function<void(const Storage::Error &error)> &_defaultErrorHandler, const QString &_name, MDB_env *_env) |
237 | : env(_env), | 237 | : env(_env), |
238 | requestedRead(_requestRead), | 238 | requestedRead(_requestRead), |
239 | allowDuplicates(_allowDuplicates), | ||
240 | defaultErrorHandler(_defaultErrorHandler), | 239 | defaultErrorHandler(_defaultErrorHandler), |
241 | name(_name), | 240 | name(_name), |
242 | implicitCommit(false), | 241 | implicitCommit(false), |
@@ -254,7 +253,6 @@ public: | |||
254 | MDB_txn *transaction; | 253 | MDB_txn *transaction; |
255 | MDB_dbi dbi; | 254 | MDB_dbi dbi; |
256 | bool requestedRead; | 255 | bool requestedRead; |
257 | bool allowDuplicates; | ||
258 | std::function<void(const Storage::Error &error)> defaultErrorHandler; | 256 | std::function<void(const Storage::Error &error)> defaultErrorHandler; |
259 | QString name; | 257 | QString name; |
260 | bool implicitCommit; | 258 | bool implicitCommit; |
@@ -345,7 +343,7 @@ bool Storage::Transaction::write(const QByteArray &key, const QByteArray &value, | |||
345 | d->error = true; | 343 | d->error = true; |
346 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); | 344 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); |
347 | }; | 345 | }; |
348 | openDatabase("default", eHandler, d->allowDuplicates).write(key, value, eHandler); | 346 | openDatabase("default", eHandler).write(key, value, eHandler); |
349 | d->implicitCommit = true; | 347 | d->implicitCommit = true; |
350 | 348 | ||
351 | return !d->error; | 349 | return !d->error; |
@@ -358,7 +356,7 @@ void Storage::Transaction::remove(const QByteArray &k, | |||
358 | d->error = true; | 356 | d->error = true; |
359 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); | 357 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); |
360 | }; | 358 | }; |
361 | openDatabase("default", eHandler, d->allowDuplicates).remove(k, eHandler); | 359 | openDatabase("default", eHandler).remove(k, eHandler); |
362 | d->implicitCommit = true; | 360 | d->implicitCommit = true; |
363 | } | 361 | } |
364 | 362 | ||
@@ -366,7 +364,7 @@ int Storage::Transaction::scan(const QByteArray &k, | |||
366 | const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, | 364 | const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, |
367 | const std::function<void(const Storage::Error &error)> &errorHandler) const | 365 | const std::function<void(const Storage::Error &error)> &errorHandler) const |
368 | { | 366 | { |
369 | auto db = openDatabase("default", std::function<void(const Storage::Error &error)>(), d->allowDuplicates); | 367 | auto db = openDatabase("default", std::function<void(const Storage::Error &error)>()); |
370 | if (db) { | 368 | if (db) { |
371 | return db.scan(k, resultHandler, errorHandler); | 369 | return db.scan(k, resultHandler, errorHandler); |
372 | } | 370 | } |
@@ -384,7 +382,7 @@ int Storage::Transaction::scan(const QByteArray &k, | |||
384 | class Storage::Private | 382 | class Storage::Private |
385 | { | 383 | { |
386 | public: | 384 | public: |
387 | Private(const QString &s, const QString &n, AccessMode m, bool duplicates); | 385 | Private(const QString &s, const QString &n, AccessMode m); |
388 | ~Private(); | 386 | ~Private(); |
389 | 387 | ||
390 | QString storageRoot; | 388 | QString storageRoot; |
@@ -392,9 +390,6 @@ public: | |||
392 | 390 | ||
393 | MDB_env *env; | 391 | MDB_env *env; |
394 | AccessMode mode; | 392 | AccessMode mode; |
395 | bool readTransaction; | ||
396 | bool firstOpen; | ||
397 | bool allowDuplicates; | ||
398 | static QMutex sMutex; | 393 | static QMutex sMutex; |
399 | static QHash<QString, MDB_env*> sEnvironments; | 394 | static QHash<QString, MDB_env*> sEnvironments; |
400 | }; | 395 | }; |
@@ -402,14 +397,11 @@ public: | |||
402 | QMutex Storage::Private::sMutex; | 397 | QMutex Storage::Private::sMutex; |
403 | QHash<QString, MDB_env*> Storage::Private::sEnvironments; | 398 | QHash<QString, MDB_env*> Storage::Private::sEnvironments; |
404 | 399 | ||
405 | Storage::Private::Private(const QString &s, const QString &n, AccessMode m, bool duplicates) | 400 | Storage::Private::Private(const QString &s, const QString &n, AccessMode m) |
406 | : storageRoot(s), | 401 | : storageRoot(s), |
407 | name(n), | 402 | name(n), |
408 | env(0), | 403 | env(0), |
409 | mode(m), | 404 | mode(m) |
410 | readTransaction(false), | ||
411 | firstOpen(true), | ||
412 | allowDuplicates(duplicates) | ||
413 | { | 405 | { |
414 | const QString fullPath(storageRoot + '/' + name); | 406 | const QString fullPath(storageRoot + '/' + name); |
415 | QFileInfo dirInfo(fullPath); | 407 | QFileInfo dirInfo(fullPath); |
@@ -464,8 +456,8 @@ Storage::Private::~Private() | |||
464 | // } | 456 | // } |
465 | } | 457 | } |
466 | 458 | ||
467 | Storage::Storage(const QString &storageRoot, const QString &name, AccessMode mode, bool allowDuplicates) | 459 | Storage::Storage(const QString &storageRoot, const QString &name, AccessMode mode) |
468 | : d(new Private(storageRoot, name, mode, allowDuplicates)) | 460 | : d(new Private(storageRoot, name, mode)) |
469 | { | 461 | { |
470 | } | 462 | } |
471 | 463 | ||
@@ -494,7 +486,7 @@ Storage::Transaction Storage::createTransaction(AccessMode type, const std::func | |||
494 | return Transaction(); | 486 | return Transaction(); |
495 | } | 487 | } |
496 | 488 | ||
497 | return Transaction(new Transaction::Private(requestedRead, d->allowDuplicates, defaultErrorHandler(), d->name, d->env)); | 489 | return Transaction(new Transaction::Private(requestedRead, defaultErrorHandler(), d->name, d->env)); |
498 | } | 490 | } |
499 | 491 | ||
500 | qint64 Storage::diskUsage() const | 492 | qint64 Storage::diskUsage() const |