Skip to content

Commit bec6a22

Browse files
authored
fix(server): keep the .rdb extension in the last-save path (#8184)
1 parent 18bab9c commit bec6a22

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/server/detail/save_stages_controller.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ SaveInfo SaveStagesController::GetSaveInfo() {
354354
fs::path resulting_path = full_path_;
355355
if (use_dfs_format_)
356356
SetExtension("summary", ".dfs", &resulting_path);
357-
else
358-
resulting_path.replace_extension(); // remove .tmp
357+
else if (!resulting_path.has_extension())
358+
resulting_path += ".rdb"; // full_path_ never carries .tmp; mirror SaveRdb's on-disk name
359359

360360
LOG(INFO) << "Saving " << resulting_path << " finished after "
361361
<< strings::HumanReadableElapsedTime(info.duration_sec);

src/server/rdb_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ABSL_DECLARE_FLAG(bool, rdb_sbf_chunked);
5050
ABSL_DECLARE_FLAG(bool, serialize_hnsw_index);
5151
ABSL_DECLARE_FLAG(bool, deserialize_hnsw_index);
5252
ABSL_DECLARE_FLAG(std::string, dbfilename);
53+
ABSL_DECLARE_FLAG(bool, df_snapshot_format);
5354
ABSL_DECLARE_FLAG(uint32_t, max_rdb_save_serialize_buffer_capacity);
5455

5556
namespace {
@@ -1006,6 +1007,21 @@ TEST_F(RdbTest, LoadSkipsEmptyKey) {
10061007
EXPECT_THAT(Run({"exists", "e"}), IntArg(0));
10071008
}
10081009

1010+
// With RDB-format snapshots the recorded last-save path must keep its .rdb extension, otherwise
1011+
// DEBUG RELOAD flushes the dataset and then fails to load it back.
1012+
TEST_F(RdbTest, DebugReloadRdbFormat) {
1013+
absl::FlagSaver fs;
1014+
ShutdownService(); // clears dbfilename; set it afterwards, as InitWithDbFilename does
1015+
absl::SetFlag(&FLAGS_df_snapshot_format, false);
1016+
absl::SetFlag(&FLAGS_dbfilename, absl::StrCat("rdbtestdump_", getpid(), ".rdb"));
1017+
ResetService();
1018+
1019+
Run({"set", "k1", "v1"});
1020+
EXPECT_EQ(Run({"debug", "reload"}), "OK");
1021+
EXPECT_THAT(service_->server_family().GetLastSaveInfo().file_name, EndsWith(".rdb"));
1022+
EXPECT_EQ(Run({"get", "k1"}), "v1");
1023+
}
1024+
10091025
// Tests loading a huge stream, where the stream is loaded in multiple partial
10101026
// reads.
10111027
TEST_F(RdbTest, LoadHugeStream) {

0 commit comments

Comments
 (0)