From eced652ca6449a1477652db48f194a5c95137d5b Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 30 Jul 2022 12:33:57 +0300 Subject: [PATCH] Add close state to fatal error message. --- tddb/td/db/SqliteConnectionSafe.cpp | 7 +++++-- tddb/td/db/SqliteConnectionSafe.h | 1 + tddb/td/db/SqliteDb.cpp | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tddb/td/db/SqliteConnectionSafe.cpp b/tddb/td/db/SqliteConnectionSafe.cpp index 0d63445d8..fd11d941e 100644 --- a/tddb/td/db/SqliteConnectionSafe.cpp +++ b/tddb/td/db/SqliteConnectionSafe.cpp @@ -14,10 +14,11 @@ namespace td { SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key, optional cipher_version) : path_(std::move(path)) - , lsls_connection_([path = path_, key = std::move(key), cipher_version = std::move(cipher_version)] { + , lsls_connection_([path = path_, close_state_ptr = &close_state_, key = std::move(key), + cipher_version = std::move(cipher_version)] { auto r_db = SqliteDb::open_with_key(path, false, key, cipher_version.copy()); if (r_db.is_error()) { - LOG(FATAL) << "Can't open database: " << r_db.error().message(); + LOG(FATAL) << "Can't open database in state " << *close_state_ptr << ": " << r_db.error().message(); } auto db = r_db.move_as_ok(); db.exec("PRAGMA journal_mode=WAL").ensure(); @@ -36,12 +37,14 @@ SqliteDb &SqliteConnectionSafe::get() { void SqliteConnectionSafe::close() { LOG(INFO) << "Close SQLite database " << tag("path", path_); + close_state_++; lsls_connection_.clear_values(); } void SqliteConnectionSafe::close_and_destroy() { close(); LOG(INFO) << "Destroy SQLite database " << tag("path", path_); + close_state_ += 65536; SqliteDb::destroy(path_).ignore(); } diff --git a/tddb/td/db/SqliteConnectionSafe.h b/tddb/td/db/SqliteConnectionSafe.h index a669ae3d0..8e98b54c7 100644 --- a/tddb/td/db/SqliteConnectionSafe.h +++ b/tddb/td/db/SqliteConnectionSafe.h @@ -30,6 +30,7 @@ class SqliteConnectionSafe { private: string path_; + uint32 close_state_ = 0; LazySchedulerLocalStorage lsls_connection_; }; diff --git a/tddb/td/db/SqliteDb.cpp b/tddb/td/db/SqliteDb.cpp index fe107de81..c8b5a34b4 100644 --- a/tddb/td/db/SqliteDb.cpp +++ b/tddb/td/db/SqliteDb.cpp @@ -78,7 +78,8 @@ Status SqliteDb::init(CSlice path, bool allow_creation) { if (!allow_creation) { bool was_destroyed = detail::RawSqliteDb::was_any_database_destroyed(); auto reason = was_destroyed ? Slice("was corrupted and deleted") : Slice("disappeared"); - LOG(FATAL) << "Database " << reason << " during execution and can't be recreated: " << database_stat.error(); + return Status::Error(PSLICE() << "Database " << reason + << " during execution and can't be recreated: " << database_stat.error()); } TRY_STATUS(destroy(path)); }