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 | |
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')
-rw-r--r-- | common/storage/entitystore.cpp | 18 | ||||
-rw-r--r-- | common/storage/entitystore.h | 2 |
2 files changed, 16 insertions, 4 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); |
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index 985e7f9..003a2ca 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h | |||
@@ -39,7 +39,7 @@ public: | |||
39 | EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &); | 39 | EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &); |
40 | ~EntityStore() = default; | 40 | ~EntityStore() = default; |
41 | 41 | ||
42 | void createIfMissing(); | 42 | void initialize(); |
43 | 43 | ||
44 | //Only the pipeline may call the following functions outside of tests | 44 | //Only the pipeline may call the following functions outside of tests |
45 | bool add(const QByteArray &type, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); | 45 | bool add(const QByteArray &type, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); |