armink / FlashDB

An ultra-lightweight database that supports key-value and time series data | 一款支持 KV 数据和时序数据的超轻量级数据库
Apache License 2.0
1.7k stars 400 forks source link

linux的demo程序第一次运行都会卡住 #285

Open syan-cham opened 3 months ago

syan-cham commented 3 months ago

FlashDB-2.1.0/demos/linux$ ./out/FlashDBLinuxDemo [FlashDB][kv][env][fdb_kvdb1] (../../src/fdb_kvdb.c:1777) The oldest addr is @0x00000000 [FlashDB][kv][env][fdb_kvdb1] (../../src/fdb_kvdb.c:1793) KVDB size is 16384 bytes. [FlashDB][kv][env][fdb_kvdb1] Sector header info is incorrect. Auto format this sector (0x00000000). [FlashDB][kv][env][fdb_kvdb1] Sector header info is incorrect. Auto format this sector (0x00001000). [FlashDB][kv][env][fdb_kvdb1] Sector header info is incorrect. Auto format this sector (0x00002000). [FlashDB][kv][env][fdb_kvdb1] Sector header info is incorrect. Auto format this sector (0x00003000). [FlashDB][kv][env][fdb_kvdb1] All sector header is incorrect. Set it to default.

这个地方就一直卡住,要ctrl+c停止再运行才能往下工作。 FlashDB-2.1.0/demos/linux$ ./out/FlashDBLinuxDemo [FlashDB][kv][env][fdb_kvdb1] (../../src/fdb_kvdb.c:1777) The oldest addr is @0x00000000 [FlashDB][kv][env][fdb_kvdb1] (../../src/fdb_kvdb.c:1793) KVDB size is 16384 bytes. [FlashDB] FlashDB V2.1.0 is initialize success. [FlashDB] You can get the latest version on https://github.com/armink/FlashDB . [FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ==================== [FlashDB][sample][kvdb][basic] get the 'boot_count' failed [FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1 [FlashDB][sample][kvdb][basic] =========================================================== [FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ==================== [FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C [FlashDB][sample][kvdb][string] get the 'temp' value is: 36C [FlashDB][sample][kvdb][string] set 'temp' value to 38C [FlashDB][sample][kvdb][string] delete the 'temp' finish [FlashDB][sample][kvdb][string] =========================================================== [FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ==================== [FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36 [FlashDB][sample][kvdb][blob] get the 'temp' value is: 36 [FlashDB][sample][kvdb][blob] set 'temp' value to 38 [FlashDB][sample][kvdb][blob] delete the 'temp' finish [FlashDB][sample][kvdb][blob] =========================================================== [FlashDB][tsl][log][fdb_tsdb1] Sector (0x00000000) header info is incorrect. [FlashDB][tsl][log][fdb_tsdb1] All sector format finished. [FlashDB][tsl][log][fdb_tsdb1] (../../src/fdb_tsdb.c:978) TSDB (log) oldest sectors is 0x00000000, current using sector is 0x00000000.
[FlashDB][sample][tsdb] ==================== tsdb_sample ==================== [FlashDB][sample][tsdb] append the new status.temp (36) and status.humi (85) [FlashDB][tsl][log][fdb_tsdb1] Warning: current timestamp (1711640796) is less than or equal to the last save timestamp (1711640796). This tsl will be dropped. [FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90) [FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 1711640796, temp: 36, humi: 85 [FlashDB][sample][tsdb] query count is: 0 [FlashDB][sample][tsdb] set the TSL (time 1711640796) status from 2 to 3 [FlashDB][sample][tsdb] ===========================================================

mrchipset commented 1 month ago

今天看到这个项目想试一下也遇到这个问题。看了下发现是因为线程锁造成的阻塞。

fdb_kvdb_init这个函数里获得了线程锁,还没解锁前调用_fdb_kv_load中函数fdb_kv_set_default也想要获得线程锁就卡住了。 image

修改下代码fdb_kvdb.c文件中的fdb_kvdb_init函数可以修复

FDB_DEBUG("KVDB size is %" PRIu32 " bytes.\n", db_max_size(db));
db_unlock(db);

result = _fdb_kv_load(db);

db_lock(db);
armink commented 1 month ago

@mrchipset 多谢啦,估计是锁没有支持递归能力