diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-26 15:05:41 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-26 15:05:41 +0200 |
commit | 80afd7070f2d8e57cab2fe55fef611623fdb75f0 (patch) | |
tree | 5ec29f1bfece2b4344d040db232f7c4c0f746b73 /common/storage/entitystore.cpp | |
parent | b334872e612433aee1284561fa247127bcdeeaf8 (diff) | |
download | sink-80afd7070f2d8e57cab2fe55fef611623fdb75f0.tar.gz sink-80afd7070f2d8e57cab2fe55fef611623fdb75f0.zip |
Make sure we initialize the environment correctly and only set the db version when creating it
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 6021344..d5a7c5f 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -158,13 +158,23 @@ EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx | |||
158 | 158 | ||
159 | } | 159 | } |
160 | 160 | ||
161 | void EntityStore::createIfMissing() | 161 | void EntityStore::initialize() |
162 | { | 162 | { |
163 | if (!d->exists()) { | 163 | //This function is only called in the resource code where we want to be able to write to the databse. |
164 | |||
165 | //Check for the existience of the db without creating it or the envrionment. | ||
166 | //This is required to be able to set the database version only in the case where we create a new database. | ||
167 | if (!Storage::DataStore::exists(Sink::storageLocation(), d->resourceContext.instanceId())) { | ||
168 | //The first time we open the environment we always want it to be read/write. Otherwise subsequent tries to open a write transaction will fail. | ||
164 | startTransaction(Sink::Storage::DataStore::ReadWrite); | 169 | startTransaction(Sink::Storage::DataStore::ReadWrite); |
170 | //Create the database with the correct version if it wasn't existing before | ||
171 | SinkLogCtx(d->logCtx) << "Creating resource database."; | ||
165 | Storage::DataStore::setDatabaseVersion(d->transaction, Sink::latestDatabaseVersion()); | 172 | Storage::DataStore::setDatabaseVersion(d->transaction, Sink::latestDatabaseVersion()); |
166 | commitTransaction(); | 173 | } else { |
174 | //The first time we open the environment we always want it to be read/write. Otherwise subsequent tries to open a write transaction will fail. | ||
175 | startTransaction(Sink::Storage::DataStore::ReadWrite); | ||
167 | } | 176 | } |
177 | commitTransaction(); | ||
168 | } | 178 | } |
169 | 179 | ||
170 | void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) | 180 | void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) |
@@ -383,9 +393,11 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) | |||
383 | 393 | ||
384 | bool EntityStore::cleanupRevisions(qint64 revision) | 394 | bool EntityStore::cleanupRevisions(qint64 revision) |
385 | { | 395 | { |
396 | Q_ASSERT(d->exists()); | ||
386 | bool implicitTransaction = false; | 397 | bool implicitTransaction = false; |
387 | if (!d->transaction) { | 398 | if (!d->transaction) { |
388 | startTransaction(Sink::Storage::DataStore::ReadWrite); | 399 | startTransaction(Sink::Storage::DataStore::ReadWrite); |
400 | Q_ASSERT(d->transaction); | ||
389 | implicitTransaction = true; | 401 | implicitTransaction = true; |
390 | } | 402 | } |
391 | const auto lastCleanRevision = DataStore::cleanedUpRevision(d->transaction); | 403 | const auto lastCleanRevision = DataStore::cleanedUpRevision(d->transaction); |