From 6a541571bc6aa1f7777e2d679e1770094596525c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 23 Feb 2017 12:57:56 +0100 Subject: Bring the application down in a controlled fashion if we experience a critical error. --- common/storage_common.cpp | 6 +++++- common/storage_lmdb.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 3951a81..27139ee 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -40,7 +40,11 @@ static const int s_internalPrefixSize = strlen(s_internalPrefix); void errorHandler(const DataStore::Error &error) { - SinkWarning() << "Database error in " << error.store << ", code " << error.code << ", message: " << error.message; + if (error.code == DataStore::TransactionError) { + SinkError() << "Database error in " << error.store << ", code " << error.code << ", message: " << error.message; + } else { + SinkWarning() << "Database error in " << error.store << ", code " << error.code << ", message: " << error.message; + } } std::function DataStore::basicErrorHandler() diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index b389e58..cebd3f0 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -468,8 +468,10 @@ bool DataStore::Transaction::commit(const std::functiontransaction); if (rc) { abort(); - Error error(d->name.toLatin1(), ErrorCodes::GenericError, "Error during transaction commit: " + QByteArray(mdb_strerror(rc))); + Error error(d->name.toLatin1(), ErrorCodes::TransactionError, "Error during transaction commit: " + QByteArray(mdb_strerror(rc))); errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); + //If transactions start failing we're in an unrecoverable situation (i.e. out of diskspace). So throw an exception that will terminate the application. + throw std::runtime_error("Fatal error while committing transaction."); } d->transaction = nullptr; -- cgit v1.2.3