From 8068e1a2ae9a42c3dd4f1d901cdc765d9d855390 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Wed, 15 Feb 2023 06:19:12 +0200 Subject: [PATCH] feat(server): save dragonfly snapshot in a new format by default (#802) Introduce a new flag `df_snapshot_format` that controls the default behavior. The flag itself is defaulted to save snapshots in a new Dragonfly specific format. BREAKING CHANGE: before that Dragonfly saved snapshots in rdb format by default. Now the flag controls which format is chosen when issuing SAVE/BGSAVE commands. In addition, "SAVE DF", "SAVE RDB" can be used to save using dragonfly/redis formats accordingly. Signed-off-by: Roman Gershman --- src/server/debugcmd.cc | 3 ++- src/server/server_family.cc | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/server/debugcmd.cc b/src/server/debugcmd.cc index edc6763fa..6b6d18bcd 100644 --- a/src/server/debugcmd.cc +++ b/src/server/debugcmd.cc @@ -27,6 +27,7 @@ using namespace std; ABSL_DECLARE_FLAG(string, dir); ABSL_DECLARE_FLAG(string, dbfilename); +ABSL_DECLARE_FLAG(bool, df_snapshot_format); namespace dfly { @@ -174,7 +175,7 @@ void DebugCmd::Reload(CmdArgList args) { trans->InitByArgs(0, {}); VLOG(1) << "Performing save"; - GenericError ec = sf_.DoSave(false, trans.get()); + GenericError ec = sf_.DoSave(absl::GetFlag(FLAGS_df_snapshot_format), trans.get()); if (ec) { return (*cntx_)->SendError(ec.Format()); } diff --git a/src/server/server_family.cc b/src/server/server_family.cc index ec00e1546..dcded575b 100644 --- a/src/server/server_family.cc +++ b/src/server/server_family.cc @@ -56,6 +56,8 @@ ABSL_FLAG(string, requirepass, "", "If empty can also be set with DFLY_PASSWORD environment variable."); ABSL_FLAG(string, save_schedule, "", "glob spec for the UTC time to save a snapshot which matches HH:MM 24h time"); +ABSL_FLAG(bool, df_snapshot_format, true, + "if true, save in dragonfly-specific snapshotting format"); ABSL_DECLARE_FLAG(uint32_t, port); ABSL_DECLARE_FLAG(bool, cache_mode); @@ -567,7 +569,7 @@ void ServerFamily::SnapshotScheduling(const SnapshotSpec& spec) { boost::intrusive_ptr trans(new Transaction{cid}); trans->InitByArgs(0, {}); - GenericError ec = DoSave(false, trans.get()); + GenericError ec = DoSave(absl::GetFlag(FLAGS_df_snapshot_format), trans.get()); if (ec) { LOG(WARNING) << "Failed to perform snapshot " << ec.Format(); } @@ -1185,7 +1187,7 @@ void ServerFamily::Memory(CmdArgList args, ConnectionContext* cntx) { void ServerFamily::Save(CmdArgList args, ConnectionContext* cntx) { string err_detail; - bool new_version = false; + bool new_version = absl::GetFlag(FLAGS_df_snapshot_format); if (args.size() > 2) { return (*cntx)->SendError(kSyntaxErr); } @@ -1195,6 +1197,8 @@ void ServerFamily::Save(CmdArgList args, ConnectionContext* cntx) { string_view sub_cmd = ArgS(args, 1); if (sub_cmd == "DF") { new_version = true; + } else if (sub_cmd == "RDB") { + new_version = false; } else { return (*cntx)->SendError(UnknownSubCmd(sub_cmd, "SAVE"), kSyntaxErrType); }