From 52c1d1712722669fbb52434a0c4e71a93c8a6fe5 Mon Sep 17 00:00:00 2001 From: John Sully Date: Sun, 7 Feb 2021 21:41:19 +0000 Subject: [PATCH] Update test to handle forkless bgsave Former-commit-id: fc8c6de8252e6b802688413050f1a823093d0a1d --- src/debug.cpp | 6 ++++++ src/rdb.cpp | 17 +++++++++++------ tests/unit/shutdown.tcl | 7 ++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 719bc43ce..23a7c9c02 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -58,6 +58,8 @@ typedef ucontext_t sigcontext_t; int g_fInCrash = false; +void getTempFileName(char tmpfile[], int tmpfileNum); + /* ================================= Debugging ============================== */ /* Compute the sha1 of string at 's' with 'len' bytes long. @@ -825,6 +827,10 @@ NULL c->flags &= ~(CLIENT_MASTER | CLIENT_MASTER_FORCE_REPLY); } addReply(c, shared.ok); + } else if (!strcasecmp(szFromObj(c->argv[1]), "get-temp-file") && c->argc == 2) { + char tmpfile[256]; + getTempFileName(tmpfile, g_pserver->rdbThreadVars.tmpfileNum); + addReplyBulkCString(c, tmpfile); } else if (!strcasecmp(szFromObj(c->argv[1]),"truncate-repl-backlog") && c->argc == 2) { g_pserver->repl_backlog_idx = 0; g_pserver->repl_backlog_off = g_pserver->master_repl_offset+1; diff --git a/src/rdb.cpp b/src/rdb.cpp index 5a01fc2da..3dad6e989 100644 --- a/src/rdb.cpp +++ b/src/rdb.cpp @@ -1637,12 +1637,7 @@ int rdbSaveBackground(rdbSaveInfo *rsi) { return C_OK; } -/* Note that we may call this function in signal handle 'sigShutdownHandler', - * so we need guarantee all functions we call are async-signal-safe. - * If we call this function from signal handle, we won't call bg_unlik that - * is not async-signal-safe. */ -void rdbRemoveTempFile(int tmpfileNum, int from_signal) { - char tmpfile[256]; +void getTempFileName(char tmpfile[], int tmpfileNum) { char pid[32]; char tmpfileNumString[214]; @@ -1654,6 +1649,16 @@ void rdbRemoveTempFile(int tmpfileNum, int from_signal) { strcpy(tmpfile+5+pid_len, "-"); strncpy(tmpfile+5+pid_len+1, tmpfileNumString, tmpfileNum_len); strcpy(tmpfile+5+pid_len+1+tmpfileNum_len, ".rdb"); +} + +/* Note that we may call this function in signal handle 'sigShutdownHandler', + * so we need guarantee all functions we call are async-signal-safe. + * If we call this function from signal handle, we won't call bg_unlik that + * is not async-signal-safe. */ +void rdbRemoveTempFile(int tmpfileNum, int from_signal) { + char tmpfile[256]; + + getTempFileName(tmpfile, tmpfileNum); if (from_signal) { /* bg_unlink is not async-signal-safe, but in this case we don't really diff --git a/tests/unit/shutdown.tcl b/tests/unit/shutdown.tcl index f48eadc50..9e48d1c77 100644 --- a/tests/unit/shutdown.tcl +++ b/tests/unit/shutdown.tcl @@ -10,8 +10,8 @@ start_server {tags {"shutdown"}} { r bgsave after 100 set dir [lindex [r config get dir] 1] - set child_pid [get_child_pid 0] - set temp_rdb [file join [lindex [r config get dir] 1] temp-${child_pid}.rdb] + set tmpfile [r debug get-temp-file] + set temp_rdb [file join [lindex [r config get dir] 1] $tmpfile] # Temp rdb must be existed assert {[file exists $temp_rdb]} @@ -34,7 +34,8 @@ start_server {tags {"shutdown"}} { r config set rdb-key-save-delay 100000 set pid [s process_id] - set temp_rdb [file join [lindex [r config get dir] 1] temp-${pid}.rdb] + set tmpfile [r debug get-temp-file] + set temp_rdb [file join [lindex [r config get dir] 1] $tmpfile] # trigger a shutdown which will save an rdb exec kill -SIGINT $pid