From 29f80e6e4d698217933b7bd2df90c08162416d3f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 26 Mar 2018 13:33:17 +0200 Subject: Don't just set the db version, only when we create the db first. --- common/pipeline.cpp | 4 +--- common/storage/entitystore.cpp | 9 +++++++++ common/storage/entitystore.h | 2 ++ common/storage_lmdb.cpp | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 434f732..ee9d3af 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -63,9 +63,7 @@ public: Pipeline::Pipeline(const ResourceContext &context, const Sink::Log::Context &ctx) : QObject(nullptr), d(new Private(context, ctx)) { //Create main store immediately on first start - auto store = Sink::Storage::DataStore(Sink::storageLocation(), context.instanceId(), Sink::Storage::DataStore::ReadWrite); - auto t = store.createTransaction(Storage::DataStore::ReadWrite); - Storage::DataStore::setDatabaseVersion(t, Sink::latestDatabaseVersion()); + d->entityStore.createIfMissing(); } Pipeline::~Pipeline() diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 7da7efa..6021344 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -158,6 +158,15 @@ EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx } +void EntityStore::createIfMissing() +{ + if (!d->exists()) { + startTransaction(Sink::Storage::DataStore::ReadWrite); + Storage::DataStore::setDatabaseVersion(d->transaction, Sink::latestDatabaseVersion()); + commitTransaction(); + } +} + void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) { SinkTraceCtx(d->logCtx) << "Starting transaction: " << accessMode; diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index 3eb0b7b..985e7f9 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h @@ -39,6 +39,8 @@ public: EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &); ~EntityStore() = default; + void createIfMissing(); + //Only the pipeline may call the following functions outside of tests bool add(const QByteArray &type, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource); diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 4e7f322..9d0bd6b 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -918,7 +918,8 @@ DataStore::~DataStore() bool DataStore::exists() const { - return (d->env != 0); + QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); + return (d->env != 0) && info.exists(); } DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function &errorHandlerArg) -- cgit v1.2.3