Skip to content

Commit

Permalink
[tsdb] Fix append bug when tsdb is full. Thx @xwiron report.
Browse files Browse the repository at this point in the history
  • Loading branch information
armink committed Oct 2, 2021
1 parent cba9612 commit 8114f88
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/fdb_tsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ static fdb_err_t update_sec_status(fdb_tsdb_t db, tsdb_sec_info_t sector, fdb_bl
}
/* change current sector to full */
_FDB_WRITE_STATUS(db, cur_sec_addr, status, FDB_SECTOR_STORE_STATUS_NUM, FDB_SECTOR_STORE_FULL, true);
sector->status = FDB_SECTOR_STORE_FULL;
/* calculate next sector address */
if (sector->addr + db_sec_size(db) < db_max_size(db)) {
new_sec_addr = sector->addr + db_sec_size(db);
Expand All @@ -326,6 +327,9 @@ static fdb_err_t update_sec_status(fdb_tsdb_t db, tsdb_sec_info_t sector, fdb_bl
format_sector(db, new_sec_addr);
read_sector_info(db, new_sec_addr, &db->cur_sec, false);
}
} else if (sector->status == FDB_SECTOR_STORE_FULL) {
/* database full */
return FDB_SAVED_FULL;
}

if (sector->status == FDB_SECTOR_STORE_EMPTY) {
Expand Down Expand Up @@ -772,6 +776,8 @@ fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *path, fdb_g
latest_addr = check_sec_arg.empty_addr;
} else {
latest_addr = db->cur_sec.addr;
/* There is no empty sector. */
latest_addr = db->cur_sec.addr = db_max_size(db) - db_sec_size(db);
}
/* db->cur_sec is the latest sector, and the next is the oldest sector */
if (latest_addr + db_sec_size(db) >= db_max_size(db)) {
Expand Down

0 comments on commit 8114f88

Please sign in to comment.