From 44a414e224e1e25a8c7fce160900555731143d5b Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 10 Sep 2021 17:20:19 +0800 Subject: [PATCH] [TSDB] Drop the append TSL when current time is less than last save time. --- src/fdb_tsdb.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/fdb_tsdb.c b/src/fdb_tsdb.c index 8ff6c69..ff80d90 100644 --- a/src/fdb_tsdb.c +++ b/src/fdb_tsdb.c @@ -347,6 +347,13 @@ static fdb_err_t tsl_append(fdb_tsdb_t db, fdb_blob_t blob) FDB_ASSERT(blob->size <= db->max_len); + /* check the current timestamp, MUST more than the last save timestamp */ + if (cur_time < db->last_time) { + FDB_INFO("Warning: current timestamp (%" PRIdMAX ") is less than the last save timestamp (%" PRIdMAX "). This tsl will be dropped.\n", + (intmax_t )cur_time, (intmax_t )(db->last_time)); + return FDB_WRITE_ERR; + } + result = update_sec_status(db, &db->cur_sec, blob, cur_time); if (result != FDB_NO_ERR) { return result; @@ -364,12 +371,7 @@ static fdb_err_t tsl_append(fdb_tsdb_t db, fdb_blob_t blob) db->cur_sec.empty_idx += LOG_IDX_DATA_SIZE; db->cur_sec.empty_data -= FDB_WG_ALIGN(blob->size); db->cur_sec.remain -= LOG_IDX_DATA_SIZE + FDB_WG_ALIGN(blob->size); - - if (cur_time >= db->last_time) { - db->last_time = cur_time; - } else { - FDB_INFO("Warning: current timestamp (%" PRIdMAX ") is less than the last save timestamp (%" PRIdMAX ")\n", (intmax_t)cur_time, (intmax_t)(db->last_time)); - } + db->last_time = cur_time; return result; }