diff --git a/src/config.cc b/src/config.cc index 0ffee476541..200dc60646e 100644 --- a/src/config.cc +++ b/src/config.cc @@ -536,6 +536,11 @@ Status Config::Rewrite() { std::vector lines; std::map new_config; for (const auto &iter : fields_) { + if (iter.first == "rename-command") { + // We should NOT overwrite the rename command since it cannot be rewritten in-flight, + // so skip it here to avoid rewriting it as new item. + continue; + } new_config[iter.first] = iter.second->ToString(); } diff --git a/tests/config_test.cc b/tests/config_test.cc index f0b189057c3..e01b2135a1b 100644 --- a/tests/config_test.cc +++ b/tests/config_test.cc @@ -2,6 +2,8 @@ #include "server.h" #include #include +#include +#include #include TEST(Config, GetAndSet) { @@ -104,6 +106,28 @@ TEST(Config, GetAndSet) { } } +TEST(Config, Rewrite) { + const char *path = "test.conf"; + unlink(path); + + std::ostringstream string_stream; + string_stream << "rename-command KEYS KEYS_NEW" << "\n"; + string_stream << "rename-command GET GET_NEW" << "\n"; + string_stream << "rename-command SET SET_NEW" << "\n"; + std::ofstream output_file(path, std::ios::out); + output_file.write(string_stream.str().c_str(), string_stream.str().size()); + output_file.close(); + + Config config; + Redis::PopulateCommands(); + ASSERT_TRUE(config.Load(path).IsOK()); + ASSERT_TRUE(config.Rewrite().IsOK()); + // Need to re-populate the command table since it has renamed by the previous + Redis::PopulateCommands(); + ASSERT_TRUE(config.Load(path).IsOK()); + unlink(path); +} + TEST(Namespace, Add) { const char *path = "test.conf"; unlink(path);