-
Notifications
You must be signed in to change notification settings - Fork 521
TSDB feature: Added FDB_TSDB_FIXED_BLOB_SIZE compile-time option to reduce flash usage in fixed-size blob scenarios. #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0fb447a
a32bcba
b2bd249
0d3899a
6dcd4ad
dc35884
cf3275c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -94,8 +94,10 @@ typedef struct sector_hdr_data *sector_hdr_data_t; | |||||||||||||
| struct log_idx_data { | ||||||||||||||
| uint8_t status_table[TSL_STATUS_TABLE_SIZE]; /**< node status, @see fdb_tsl_status_t */ | ||||||||||||||
| fdb_time_t time; /**< node timestamp */ | ||||||||||||||
| #ifndef FDB_TSDB_FIXED_BLOB_SIZE | ||||||||||||||
| uint32_t log_len; /**< node total length (header + name + value), must align by FDB_WRITE_GRAN */ | ||||||||||||||
| uint32_t log_addr; /**< node address */ | ||||||||||||||
| #endif | ||||||||||||||
| }; | ||||||||||||||
| typedef struct log_idx_data *log_idx_data_t; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -114,6 +116,7 @@ struct check_sec_hdr_cb_args { | |||||||||||||
| static fdb_err_t read_tsl(fdb_tsdb_t db, fdb_tsl_t tsl) | ||||||||||||||
| { | ||||||||||||||
| struct log_idx_data idx; | ||||||||||||||
|
|
||||||||||||||
| /* read TSL index raw data */ | ||||||||||||||
| _fdb_flash_read((fdb_db_t)db, tsl->addr.index, (uint32_t *) &idx, sizeof(struct log_idx_data)); | ||||||||||||||
| tsl->status = (fdb_tsl_status_t) _fdb_get_status(idx.status_table, FDB_TSL_STATUS_NUM); | ||||||||||||||
|
|
@@ -122,9 +125,19 @@ static fdb_err_t read_tsl(fdb_tsdb_t db, fdb_tsl_t tsl) | |||||||||||||
| tsl->addr.log = FDB_DATA_UNUSED; | ||||||||||||||
| tsl->time = 0; | ||||||||||||||
| } else { | ||||||||||||||
| #ifdef FDB_TSDB_FIXED_BLOB_SIZE | ||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code can move to here uint32_t tsl_index_in_sector;
uint32_t sector_addr;
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||||
| uint32_t tsl_index_in_sector; | ||||||||||||||
| uint32_t sector_addr; | ||||||||||||||
| tsl->log_len = FDB_TSDB_FIXED_BLOB_SIZE; | ||||||||||||||
| sector_addr = FDB_ALIGN_DOWN(tsl->addr.index, db_sec_size(db)); | ||||||||||||||
| tsl_index_in_sector = (tsl->addr.index - sector_addr - SECTOR_HDR_DATA_SIZE) / LOG_IDX_DATA_SIZE; | ||||||||||||||
| tsl->addr.log = sector_addr + db_sec_size(db) - (tsl_index_in_sector + 1) * FDB_WG_ALIGN(FDB_TSDB_FIXED_BLOB_SIZE); | ||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Is there a way to simplify the logic here? |
||||||||||||||
| tsl->time = idx.time; | ||||||||||||||
| #else | ||||||||||||||
| tsl->log_len = idx.log_len; | ||||||||||||||
| tsl->addr.log = idx.log_addr; | ||||||||||||||
| tsl->time = idx.time; | ||||||||||||||
| #endif | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return FDB_NO_ERR; | ||||||||||||||
|
|
@@ -306,16 +319,21 @@ static fdb_err_t write_tsl(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t time) | |||||||||||||
| fdb_err_t result = FDB_NO_ERR; | ||||||||||||||
| struct log_idx_data idx; | ||||||||||||||
| uint32_t idx_addr = db->cur_sec.empty_idx; | ||||||||||||||
| uint32_t log_addr = db->cur_sec.empty_data - FDB_WG_ALIGN(blob->size); | ||||||||||||||
|
|
||||||||||||||
| #ifndef FDB_TSDB_FIXED_BLOB_SIZE | ||||||||||||||
| // variable-size blobs must store address and size in flash | ||||||||||||||
| idx.log_addr = log_addr; | ||||||||||||||
| idx.log_len = blob->size; | ||||||||||||||
| #endif | ||||||||||||||
| idx.time = time; | ||||||||||||||
| idx.log_addr = db->cur_sec.empty_data - FDB_WG_ALIGN(idx.log_len); | ||||||||||||||
|
|
||||||||||||||
| /* write the status will by write granularity */ | ||||||||||||||
| _FDB_WRITE_STATUS(db, idx_addr, idx.status_table, FDB_TSL_STATUS_NUM, FDB_TSL_PRE_WRITE, false); | ||||||||||||||
| /* write other index info */ | ||||||||||||||
| FLASH_WRITE(db, idx_addr + LOG_IDX_TS_OFFSET, &idx.time, sizeof(struct log_idx_data) - LOG_IDX_TS_OFFSET, false); | ||||||||||||||
|
||||||||||||||
| FLASH_WRITE(db, idx_addr + LOG_IDX_TS_OFFSET, &idx.time, sizeof(struct log_idx_data) - LOG_IDX_TS_OFFSET, false); | |
| #ifdef FDB_TSDB_FIXED_BLOB_SIZE | |
| FLASH_WRITE(db, idx_addr + LOG_IDX_TS_OFFSET, &idx.time, sizeof(idx.time), false); | |
| #else | |
| FLASH_WRITE(db, idx_addr + LOG_IDX_TS_OFFSET, &idx.time, sizeof(struct log_idx_data) - LOG_IDX_TS_OFFSET, false); | |
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This AI comments can be ignored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical design issue: LOG_IDX_DATA_SIZE is defined as FDB_WG_ALIGN(sizeof(struct log_idx_data)) and is used throughout the codebase for sector layout calculations, address computations, and space accounting. When FDB_TSDB_FIXED_BLOB_SIZE is enabled, the struct size changes (removing 8 bytes), which changes LOG_IDX_DATA_SIZE. This creates an incompatible on-flash format - databases created with this feature enabled cannot be read by code compiled without it, and vice versa. This breaks the entire storage layout and makes the feature fundamentally incompatible with existing data. Consider using a separate macro or ensuring the struct size remains constant to maintain format compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the AI's comment for now, enabling this macro will indeed cause incompatibility in the data format stored in Flash. Just specify this when configuring the macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated see link