armink / FlashDB

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

Linux demos 使用 C 标准文件库 tsdb 数据出错 #221

Open EthanCYQ opened 1 year ago

EthanCYQ commented 1 year ago

问题描述

Linux Demo 用 C 标准文件库代替 POSIX 文件库后,编译出来的可执行文件运行后,Log 显示插入的时间,温度和湿度数据有误:

[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:945) TSDB (log) oldest sectors is 0x00000000, current using sector is 0x00000000.
[FlashDB] FlashDB V2.0.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
[FlashDB][sample][tsdb] ==================== tsdb_sample ====================
[FlashDB][sample][tsdb] append the new status.temp (36) and status.humi (85)
[FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90)
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 0, temp: 2110953342, humi: 21989
[FlashDB][sample][tsdb] [query_by_time_cb] queried a TSL: time: 0, temp: 2110953342, humi: 21989
[FlashDB][sample][tsdb] query count is: 0
[FlashDB][sample][tsdb] set the TSL (time 0) status from 1 to 3
[FlashDB][sample][tsdb] ===========================================================

使用旧的 commit 发现没有这个问题,读出来的温湿度数据正常:

[FlashDB][tsl][log] Sector (0x00000000) header info is incorrect.
[FlashDB][tsl][log] All sector format finished.
[FlashDB][tsl][log] (../../src/fdb_tsdb.c:940) TSDB (log) oldest sectors is 0x00000000, current using sector is 0x00000000.
[FlashDB] FlashDB V1.2.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
[FlashDB][sample][tsdb] ==================== tsdb_sample ====================
[FlashDB][sample][tsdb] append the new status.temp (36) and status.humi (85)
[FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90)
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 1686572803, temp: 36, humi: 85
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 1686572803, temp: 38, humi: 90
[FlashDB][sample][tsdb] query count is: 0
[FlashDB][sample][tsdb] set the TSL (time 1686572803) status from 2 to 3
[FlashDB][sample][tsdb] set the TSL (time 1686572803) status from 2 to 3
[FlashDB][sample][tsdb] ===========================================================

复现步骤

  1. demos/linux/applications/fdb_cfg.hFDB_USING_FILE_POSIX_MODE 修改为 FDB_USING_FILE_LIBC_MODE
  2. 重新编译可执行文件并运行
  3. 即可从 log 看到错误的温湿度数据。

Reset 到一个更老的 commit a39f4e2ed6c0d68fbd35f449f01725b9795809bd 上再重新执行上述步骤就没有再复现该问题,我就没有再进一步追查这个问题了。

测试环境

armink commented 1 year ago

如果用 POSIX 库有问题吗?

EthanCYQ commented 1 year ago

如果用 POSIX 库有问题吗?

POSIX 库都没有问题