Skip to content

Commit 44a414e

Browse files
committed
[TSDB] Drop the append TSL when current time is less than last save time.
1 parent cea7a06 commit 44a414e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/fdb_tsdb.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ static fdb_err_t tsl_append(fdb_tsdb_t db, fdb_blob_t blob)
347347

348348
FDB_ASSERT(blob->size <= db->max_len);
349349

350+
/* check the current timestamp, MUST more than the last save timestamp */
351+
if (cur_time < db->last_time) {
352+
FDB_INFO("Warning: current timestamp (%" PRIdMAX ") is less than the last save timestamp (%" PRIdMAX "). This tsl will be dropped.\n",
353+
(intmax_t )cur_time, (intmax_t )(db->last_time));
354+
return FDB_WRITE_ERR;
355+
}
356+
350357
result = update_sec_status(db, &db->cur_sec, blob, cur_time);
351358
if (result != FDB_NO_ERR) {
352359
return result;
@@ -364,12 +371,7 @@ static fdb_err_t tsl_append(fdb_tsdb_t db, fdb_blob_t blob)
364371
db->cur_sec.empty_idx += LOG_IDX_DATA_SIZE;
365372
db->cur_sec.empty_data -= FDB_WG_ALIGN(blob->size);
366373
db->cur_sec.remain -= LOG_IDX_DATA_SIZE + FDB_WG_ALIGN(blob->size);
367-
368-
if (cur_time >= db->last_time) {
369-
db->last_time = cur_time;
370-
} else {
371-
FDB_INFO("Warning: current timestamp (%" PRIdMAX ") is less than the last save timestamp (%" PRIdMAX ")\n", (intmax_t)cur_time, (intmax_t)(db->last_time));
372-
}
374+
db->last_time = cur_time;
373375

374376
return result;
375377
}

0 commit comments

Comments
 (0)