Skip to content

Commit

Permalink
reduce latency spike caused by rordb load by fdatasync sst files incr…
Browse files Browse the repository at this point in the history
…ementally.
  • Loading branch information
patpatbear committed Dec 31, 2024
1 parent e70e580 commit ede3307
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,6 +2893,7 @@ standardConfig configs[] = {
createBoolConfig("replica-announced", NULL, MODIFIABLE_CONFIG, server.replica_announced, 1, NULL, NULL),
createBoolConfig("slave-repl-all", NULL, MODIFIABLE_CONFIG, server.repl_slave_repl_all, 0, NULL, NULL),
createBoolConfig("swap-debug-trace-latency", NULL, MODIFIABLE_CONFIG, server.swap_debug_trace_latency, 0, NULL, NULL),
createBoolConfig("swap-rordb-load-incremental-fsync", NULL, MODIFIABLE_CONFIG, server.swap_rordb_load_incremental_fsync, 1, NULL, NULL),
createBoolConfig("swap-cuckoo-filter-enabled", NULL, MODIFIABLE_CONFIG, server.swap_cuckoo_filter_enabled, 1, NULL, updateSwapCuckooFilterEnabled),
createBoolConfig("swap-absent-cache-enabled", NULL, MODIFIABLE_CONFIG, server.swap_absent_cache_enabled, 1, NULL, updateSwapAbsentCacheEnabled),
createBoolConfig("swap-absent-cache-include-subkey", NULL, MODIFIABLE_CONFIG, server.swap_absent_cache_include_subkey, 1, NULL, NULL),
Expand Down
20 changes: 19 additions & 1 deletion src/ctrip_swap_rordb.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static int rordbLoadSSTFile(rio *rdb, char* path) {
FILE *fp = NULL;
char *filepath = NULL, *buffer = NULL;
size_t buflen = RORDB_SST_READ_BUF_LEN, readlen = 0,
filesize, toread, fplen;
filesize, toread, fplen, fsynclen = 0;

filename = rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS,NULL);
if (filename == NULL) {
Expand Down Expand Up @@ -243,6 +243,24 @@ static int rordbLoadSSTFile(rio *rdb, char* path) {
strerror(errno),errno);
goto err;
}

if (server.swap_rordb_load_incremental_fsync &&
readlen - fsynclen >= REDIS_AUTOSYNC_BYTES) {
fflush(fp);
if (redis_fsync(fileno(fp)) == -1) {
serverLog(LL_WARNING,"[rordb] fsync file failed: %s(%d)",
strerror(errno),errno);
}
fsynclen = readlen;
}
}

if (server.swap_rordb_load_incremental_fsync) {
fflush(fp);
if (redis_fsync(fileno(fp)) == -1) {
serverLog(LL_WARNING,"[rordb] fsync file failed: %s(%d)",
strerror(errno),errno);
}
}

serverLog(LL_VERBOSE, "[rordb] load sst file(%s) ok.", filepath);
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,7 @@ struct redisServer {
int swap_debug_bgsave_metalen_addition;
int swap_debug_compaction_filter_delay_micro;
int swap_debug_rdb_key_save_delay_micro;
int swap_rordb_load_incremental_fsync;

/* repl swap */
int repl_workers; /* num of repl worker clients */
Expand Down

0 comments on commit ede3307

Please sign in to comment.