diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/listener.cpp | 5 | ||||
-rw-r--r-- | common/pipeline.cpp | 8 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 1 | ||||
-rw-r--r-- | common/resourceaccess.h | 2 | ||||
-rw-r--r-- | common/storage.h | 27 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 33 |
6 files changed, 50 insertions, 26 deletions
diff --git a/common/listener.cpp b/common/listener.cpp index d2fc510..32c57ac 100644 --- a/common/listener.cpp +++ b/common/listener.cpp | |||
@@ -85,6 +85,11 @@ Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArra | |||
85 | 85 | ||
86 | Listener::~Listener() | 86 | Listener::~Listener() |
87 | { | 87 | { |
88 | closeAllConnections(); | ||
89 | delete m_resource; | ||
90 | delete m_checkConnectionsTimer; | ||
91 | delete m_clientBufferProcessesTimer; | ||
92 | delete m_server; | ||
88 | } | 93 | } |
89 | 94 | ||
90 | void Listener::emergencyAbortAllConnections() | 95 | void Listener::emergencyAbortAllConnections() |
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index c6d5297..feceb77 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -79,6 +79,10 @@ Pipeline::Pipeline(const QString &resourceName, QObject *parent) : QObject(paren | |||
79 | 79 | ||
80 | Pipeline::~Pipeline() | 80 | Pipeline::~Pipeline() |
81 | { | 81 | { |
82 | d->transaction = Storage::Transaction(); | ||
83 | for (const auto &t : d->processors.keys()) { | ||
84 | qDeleteAll(d->processors.value(t)); | ||
85 | } | ||
82 | delete d; | 86 | delete d; |
83 | } | 87 | } |
84 | 88 | ||
@@ -108,9 +112,9 @@ void Pipeline::startTransaction() | |||
108 | Trace() << "Starting transaction."; | 112 | Trace() << "Starting transaction."; |
109 | d->transactionTime.start(); | 113 | d->transactionTime.start(); |
110 | d->transactionItemCount = 0; | 114 | d->transactionItemCount = 0; |
111 | d->transaction = std::move(storage().createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) { | 115 | d->transaction = storage().createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) { |
112 | Warning() << error.message; | 116 | Warning() << error.message; |
113 | })); | 117 | }); |
114 | 118 | ||
115 | //FIXME this is a temporary measure to recover from a failure to open the named databases correctly. | 119 | //FIXME this is a temporary measure to recover from a failure to open the named databases correctly. |
116 | //Once the actual problem is fixed it will be enough to simply crash if we open the wrong database (which we check in openDatabase already). | 120 | //Once the actual problem is fixed it will be enough to simply crash if we open the wrong database (which we check in openDatabase already). |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 8297fa5..93f97e8 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -643,6 +643,7 @@ Sink::ResourceAccess::Ptr ResourceAccessFactory::getAccess(const QByteArray &ins | |||
643 | } | 643 | } |
644 | if (!mTimer.contains(instanceIdentifier)) { | 644 | if (!mTimer.contains(instanceIdentifier)) { |
645 | auto timer = new QTimer; | 645 | auto timer = new QTimer; |
646 | timer->setSingleShot(true); | ||
646 | // Drop connection after 3 seconds (which is a random value) | 647 | // Drop connection after 3 seconds (which is a random value) |
647 | QObject::connect(timer, &QTimer::timeout, timer, [this, instanceIdentifier]() { mCache.remove(instanceIdentifier); }); | 648 | QObject::connect(timer, &QTimer::timeout, timer, [this, instanceIdentifier]() { mCache.remove(instanceIdentifier); }); |
648 | timer->setInterval(3000); | 649 | timer->setInterval(3000); |
diff --git a/common/resourceaccess.h b/common/resourceaccess.h index 5c65998..47b848e 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h | |||
@@ -145,7 +145,7 @@ private: | |||
145 | * | 145 | * |
146 | * This avoids constantly recreating connections, and should allow a single process to have one connection per resource. | 146 | * This avoids constantly recreating connections, and should allow a single process to have one connection per resource. |
147 | */ | 147 | */ |
148 | class ResourceAccessFactory | 148 | class SINK_EXPORT ResourceAccessFactory |
149 | { | 149 | { |
150 | public: | 150 | public: |
151 | static ResourceAccessFactory &instance(); | 151 | static ResourceAccessFactory &instance(); |
diff --git a/common/storage.h b/common/storage.h index e7b4a3e..4ef20d5 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -103,18 +103,8 @@ public: | |||
103 | */ | 103 | */ |
104 | bool contains(const QByteArray &uid); | 104 | bool contains(const QByteArray &uid); |
105 | 105 | ||
106 | NamedDatabase(NamedDatabase &&other) : d(other.d) | 106 | NamedDatabase(NamedDatabase &&other); |
107 | { | 107 | NamedDatabase &operator=(NamedDatabase &&other); |
108 | d = other.d; | ||
109 | other.d = nullptr; | ||
110 | } | ||
111 | |||
112 | NamedDatabase &operator=(NamedDatabase &&other) | ||
113 | { | ||
114 | d = other.d; | ||
115 | other.d = nullptr; | ||
116 | return *this; | ||
117 | } | ||
118 | 108 | ||
119 | operator bool() const | 109 | operator bool() const |
120 | { | 110 | { |
@@ -146,17 +136,8 @@ public: | |||
146 | NamedDatabase openDatabase(const QByteArray &name = QByteArray("default"), | 136 | NamedDatabase openDatabase(const QByteArray &name = QByteArray("default"), |
147 | const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>(), bool allowDuplicates = false) const; | 137 | const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>(), bool allowDuplicates = false) const; |
148 | 138 | ||
149 | Transaction(Transaction &&other) : d(other.d) | 139 | Transaction(Transaction &&other); |
150 | { | 140 | Transaction &operator=(Transaction &&other); |
151 | d = other.d; | ||
152 | other.d = nullptr; | ||
153 | } | ||
154 | Transaction &operator=(Transaction &&other) | ||
155 | { | ||
156 | d = other.d; | ||
157 | other.d = nullptr; | ||
158 | return *this; | ||
159 | } | ||
160 | 141 | ||
161 | operator bool() const; | 142 | operator bool() const; |
162 | 143 | ||
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 3687594..2c0240d 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -103,6 +103,21 @@ Storage::NamedDatabase::NamedDatabase(NamedDatabase::Private *prv) : d(prv) | |||
103 | { | 103 | { |
104 | } | 104 | } |
105 | 105 | ||
106 | Storage::NamedDatabase::NamedDatabase(NamedDatabase &&other) : d(nullptr) | ||
107 | { | ||
108 | *this = std::move(other); | ||
109 | } | ||
110 | |||
111 | Storage::NamedDatabase &Storage::NamedDatabase::operator=(Storage::NamedDatabase &&other) | ||
112 | { | ||
113 | if (&other != this) { | ||
114 | delete d; | ||
115 | d = other.d; | ||
116 | other.d = nullptr; | ||
117 | } | ||
118 | return *this; | ||
119 | } | ||
120 | |||
106 | Storage::NamedDatabase::~NamedDatabase() | 121 | Storage::NamedDatabase::~NamedDatabase() |
107 | { | 122 | { |
108 | delete d; | 123 | delete d; |
@@ -398,6 +413,21 @@ Storage::Transaction::Transaction(Transaction::Private *prv) : d(prv) | |||
398 | d->startTransaction(); | 413 | d->startTransaction(); |
399 | } | 414 | } |
400 | 415 | ||
416 | Storage::Transaction::Transaction(Transaction &&other) : d(nullptr) | ||
417 | { | ||
418 | *this = std::move(other); | ||
419 | } | ||
420 | |||
421 | Storage::Transaction &Storage::Transaction::operator=(Storage::Transaction &&other) | ||
422 | { | ||
423 | if (&other != this) { | ||
424 | delete d; | ||
425 | d = other.d; | ||
426 | other.d = nullptr; | ||
427 | } | ||
428 | return *this; | ||
429 | } | ||
430 | |||
401 | Storage::Transaction::~Transaction() | 431 | Storage::Transaction::~Transaction() |
402 | { | 432 | { |
403 | if (d && d->transaction) { | 433 | if (d && d->transaction) { |
@@ -532,6 +562,7 @@ QList<QByteArray> Storage::Transaction::getDatabaseNames() const | |||
532 | Warning() << "Failed to get a value" << rc; | 562 | Warning() << "Failed to get a value" << rc; |
533 | } | 563 | } |
534 | } | 564 | } |
565 | mdb_cursor_close(cursor); | ||
535 | } else { | 566 | } else { |
536 | Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); | 567 | Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); |
537 | } | 568 | } |
@@ -594,6 +625,8 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m) : st | |||
594 | } else { | 625 | } else { |
595 | // FIXME: dynamic resize | 626 | // FIXME: dynamic resize |
596 | const size_t dbSize = (size_t)10485760 * (size_t)8000; // 1MB * 8000 | 627 | const size_t dbSize = (size_t)10485760 * (size_t)8000; // 1MB * 8000 |
628 | // In order to run valgrind this size must be smaller than half your available RAM | ||
629 | // https://github.com/BVLC/caffe/issues/2404 | ||
597 | mdb_env_set_mapsize(env, dbSize); | 630 | mdb_env_set_mapsize(env, dbSize); |
598 | sEnvironments.insert(fullPath, env); | 631 | sEnvironments.insert(fullPath, env); |
599 | } | 632 | } |