From 189b22e0a4e0023ed61753db67d16b2e59c68c5f Mon Sep 17 00:00:00 2001 From: armink Date: Sun, 19 Nov 2023 12:32:30 +0800 Subject: [PATCH] [fdb] Improve the database lock uses in init function. --- src/fdb_kvdb.c | 12 ++++++------ src/fdb_tsdb.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/fdb_kvdb.c b/src/fdb_kvdb.c index 4978a98..2f1cc13 100644 --- a/src/fdb_kvdb.c +++ b/src/fdb_kvdb.c @@ -1754,14 +1754,14 @@ fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *path, struc /* must be aligned with write granularity */ FDB_ASSERT((FDB_STR_KV_VALUE_MAX_SIZE * 8) % FDB_WRITE_GRAN == 0); - /* lock the KVDB */ - db_lock(db); - result = _fdb_init_ex((fdb_db_t) db, name, path, FDB_DB_TYPE_KV, user_data); if (result != FDB_NO_ERR) { goto __exit; } + /* lock the KVDB */ + db_lock(db); + db->gc_request = false; db->in_recovery_check = false; if (default_kv) { @@ -1805,13 +1805,13 @@ fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *path, struc } #endif + /* unlock the KVDB */ + db_unlock(db); + __exit: _fdb_init_finish((fdb_db_t)db, result); - /* unlock the KVDB */ - db_unlock(db); - return result; } diff --git a/src/fdb_tsdb.c b/src/fdb_tsdb.c index ffe3cbb..d019476 100644 --- a/src/fdb_tsdb.c +++ b/src/fdb_tsdb.c @@ -927,14 +927,14 @@ fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *path, fdb_g FDB_ASSERT(get_time); - /* lock the TSDB */ - db_lock(db); - result = _fdb_init_ex((fdb_db_t)db, name, path, FDB_DB_TYPE_TS, user_data); if (result != FDB_NO_ERR) { goto __exit; } + /* lock the TSDB */ + db_lock(db); + db->get_time = get_time; db->max_len = max_len; /* default rollover flag is true */ @@ -995,13 +995,13 @@ fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *path, fdb_g db->last_time = sec.end_time; } + /* unlock the TSDB */ + db_unlock(db); + __exit: _fdb_init_finish((fdb_db_t)db, result); - /* unlock the TSDB */ - db_unlock(db); - return result; }