Skip to content

Commit

Permalink
[tsdb] Improve exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
armink committed Dec 26, 2021
1 parent 83f1669 commit 9107213
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/fdb_tsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static fdb_err_t read_tsl(fdb_tsdb_t db, fdb_tsl_t tsl)
/* 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);
if (tsl->status == FDB_TSL_PRE_WRITE) {
if ((tsl->status == FDB_TSL_PRE_WRITE) || (tsl->status == FDB_TSL_UNUSED)) {
tsl->log_len = db->max_len;
tsl->addr.log = FDB_DATA_UNUSED;
tsl->time = 0;
Expand Down Expand Up @@ -510,13 +510,15 @@ void fdb_tsl_iter_by_time(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl
/* search all TSL */
do {
read_tsl(db, &tsl);
if (tsl.time >= from && tsl.time <= to) {
/* iterator is interrupted when callback return true */
if (cb(&tsl, cb_arg)) {
if (tsl.status != FDB_TSL_UNUSED) {
if (tsl.time >= from && tsl.time <= to) {
/* iterator is interrupted when callback return true */
if (cb(&tsl, cb_arg)) {
return;
}
} else {
return;
}
} else {
return;
}
} while ((tsl.addr.index = get_next_tsl_addr(&sector, &tsl)) != FAILED_ADDR);
}
Expand Down
8 changes: 6 additions & 2 deletions src/fdb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ size_t fdb_blob_read(fdb_db_t db, fdb_blob_t blob)
if (read_len > blob->saved.len) {
read_len = blob->saved.len;
}
_fdb_flash_read(db, blob->saved.addr, blob->buf, read_len);
if (_fdb_flash_read(db, blob->saved.addr, blob->buf, read_len) != FDB_NO_ERR) {
read_len = 0;
}

return read_len;
}
Expand All @@ -253,7 +255,9 @@ fdb_err_t _fdb_flash_read(fdb_db_t db, uint32_t addr, void *buf, size_t size)
#endif
} else {
#ifdef FDB_USING_FAL_MODE
fal_partition_read(db->storage.part, addr, (uint8_t *) buf, size);
if (fal_partition_read(db->storage.part, addr, (uint8_t *) buf, size) < 0) {
result = FDB_READ_ERR;
}
#endif
}

Expand Down

0 comments on commit 9107213

Please sign in to comment.