Better log message when database can't be opened.
GitOrigin-RevId: d5aeadb0e89fb1c9391721f716801bc239b6d9b0
This commit is contained in:
parent
c63144f22f
commit
c74263ce3d
@ -283,20 +283,20 @@ Status TdDb::init_sqlite(int32 scheduler_id, const TdParameters ¶meters, DbK
|
||||
CHECK(!parameters.use_message_db || parameters.use_chat_info_db);
|
||||
CHECK(!parameters.use_chat_info_db || parameters.use_file_db);
|
||||
|
||||
const string sql_db_name = get_sqlite_path(parameters);
|
||||
const string sql_database_path = get_sqlite_path(parameters);
|
||||
|
||||
bool use_sqlite = parameters.use_file_db;
|
||||
bool use_file_db = parameters.use_file_db;
|
||||
bool use_dialog_db = parameters.use_message_db;
|
||||
bool use_message_db = parameters.use_message_db;
|
||||
if (!use_sqlite) {
|
||||
unlink(sql_db_name).ignore();
|
||||
unlink(sql_database_path).ignore();
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
sqlite_path_ = sql_db_name;
|
||||
sqlite_path_ = sql_database_path;
|
||||
TRY_STATUS(SqliteDb::change_key(sqlite_path_, key, old_key));
|
||||
sql_connection_ = std::make_shared<SqliteConnectionSafe>(sql_db_name, key);
|
||||
sql_connection_ = std::make_shared<SqliteConnectionSafe>(sql_database_path, key);
|
||||
auto &db = sql_connection_->get();
|
||||
|
||||
TRY_STATUS(init_db(db));
|
||||
|
@ -126,4 +126,5 @@ class TdDb {
|
||||
|
||||
void do_close(Promise<> on_finished, bool destroy_flag);
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -9,14 +9,20 @@
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/port/Stat.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
SqliteConnectionSafe::SqliteConnectionSafe(string name, DbKey key)
|
||||
: name_(std::move(name)), lsls_connection_([name = name_, key = std::move(key)] {
|
||||
auto r_db = SqliteDb::open_with_key(name, key);
|
||||
SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key)
|
||||
: path_(std::move(path)), lsls_connection_([path = path_, key = std::move(key)] {
|
||||
auto r_db = SqliteDb::open_with_key(path, key);
|
||||
if (r_db.is_error()) {
|
||||
LOG(FATAL) << "Can't open database " << name << ": " << r_db.error();
|
||||
auto r_stat = stat(path);
|
||||
if (r_stat.is_error()) {
|
||||
LOG(FATAL) << "Can't open database " << path << " (" << r_stat.error() << "): " << r_db.error();
|
||||
} else {
|
||||
LOG(FATAL) << "Can't open database " << path << " of size " << r_stat.ok().size_ << ": " << r_db.error();
|
||||
}
|
||||
}
|
||||
auto db = r_db.move_as_ok();
|
||||
db.exec("PRAGMA synchronous=NORMAL").ensure();
|
||||
@ -32,14 +38,14 @@ SqliteDb &SqliteConnectionSafe::get() {
|
||||
}
|
||||
|
||||
void SqliteConnectionSafe::close() {
|
||||
LOG(INFO) << "Close SQLite database " << tag("path", name_);
|
||||
LOG(INFO) << "Close SQLite database " << tag("path", path_);
|
||||
lsls_connection_.clear_values();
|
||||
}
|
||||
|
||||
void SqliteConnectionSafe::close_and_destroy() {
|
||||
close();
|
||||
LOG(INFO) << "Destroy SQLite database " << tag("path", name_);
|
||||
SqliteDb::destroy(name_).ignore();
|
||||
LOG(INFO) << "Destroy SQLite database " << tag("path", path_);
|
||||
SqliteDb::destroy(path_).ignore();
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -18,7 +18,7 @@ namespace td {
|
||||
class SqliteConnectionSafe {
|
||||
public:
|
||||
SqliteConnectionSafe() = default;
|
||||
explicit SqliteConnectionSafe(string name, DbKey key = DbKey::empty());
|
||||
explicit SqliteConnectionSafe(string path, DbKey key = DbKey::empty());
|
||||
|
||||
SqliteDb &get();
|
||||
|
||||
@ -27,7 +27,7 @@ class SqliteConnectionSafe {
|
||||
void close_and_destroy();
|
||||
|
||||
private:
|
||||
string name_;
|
||||
string path_;
|
||||
LazySchedulerLocalStorage<SqliteDb> lsls_connection_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user