Add close state to fatal error message.
This commit is contained in:
parent
e40fbde299
commit
eced652ca6
@ -14,10 +14,11 @@ namespace td {
|
|||||||
|
|
||||||
SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key, optional<int32> cipher_version)
|
SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key, optional<int32> cipher_version)
|
||||||
: path_(std::move(path))
|
: 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());
|
auto r_db = SqliteDb::open_with_key(path, false, key, cipher_version.copy());
|
||||||
if (r_db.is_error()) {
|
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();
|
auto db = r_db.move_as_ok();
|
||||||
db.exec("PRAGMA journal_mode=WAL").ensure();
|
db.exec("PRAGMA journal_mode=WAL").ensure();
|
||||||
@ -36,12 +37,14 @@ SqliteDb &SqliteConnectionSafe::get() {
|
|||||||
|
|
||||||
void SqliteConnectionSafe::close() {
|
void SqliteConnectionSafe::close() {
|
||||||
LOG(INFO) << "Close SQLite database " << tag("path", path_);
|
LOG(INFO) << "Close SQLite database " << tag("path", path_);
|
||||||
|
close_state_++;
|
||||||
lsls_connection_.clear_values();
|
lsls_connection_.clear_values();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqliteConnectionSafe::close_and_destroy() {
|
void SqliteConnectionSafe::close_and_destroy() {
|
||||||
close();
|
close();
|
||||||
LOG(INFO) << "Destroy SQLite database " << tag("path", path_);
|
LOG(INFO) << "Destroy SQLite database " << tag("path", path_);
|
||||||
|
close_state_ += 65536;
|
||||||
SqliteDb::destroy(path_).ignore();
|
SqliteDb::destroy(path_).ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class SqliteConnectionSafe {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
string path_;
|
string path_;
|
||||||
|
uint32 close_state_ = 0;
|
||||||
LazySchedulerLocalStorage<SqliteDb> lsls_connection_;
|
LazySchedulerLocalStorage<SqliteDb> lsls_connection_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,7 +78,8 @@ Status SqliteDb::init(CSlice path, bool allow_creation) {
|
|||||||
if (!allow_creation) {
|
if (!allow_creation) {
|
||||||
bool was_destroyed = detail::RawSqliteDb::was_any_database_destroyed();
|
bool was_destroyed = detail::RawSqliteDb::was_any_database_destroyed();
|
||||||
auto reason = was_destroyed ? Slice("was corrupted and deleted") : Slice("disappeared");
|
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));
|
TRY_STATUS(destroy(path));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user