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 <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2023-02-15 06:19:12 +02:00 committed by GitHub
parent 15c856726a
commit 8068e1a2ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -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());
}

View file

@ -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<Transaction> 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);
}