mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
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:
parent
15c856726a
commit
8068e1a2ae
2 changed files with 8 additions and 3 deletions
|
@ -27,6 +27,7 @@ using namespace std;
|
||||||
|
|
||||||
ABSL_DECLARE_FLAG(string, dir);
|
ABSL_DECLARE_FLAG(string, dir);
|
||||||
ABSL_DECLARE_FLAG(string, dbfilename);
|
ABSL_DECLARE_FLAG(string, dbfilename);
|
||||||
|
ABSL_DECLARE_FLAG(bool, df_snapshot_format);
|
||||||
|
|
||||||
namespace dfly {
|
namespace dfly {
|
||||||
|
|
||||||
|
@ -174,7 +175,7 @@ void DebugCmd::Reload(CmdArgList args) {
|
||||||
trans->InitByArgs(0, {});
|
trans->InitByArgs(0, {});
|
||||||
VLOG(1) << "Performing save";
|
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) {
|
if (ec) {
|
||||||
return (*cntx_)->SendError(ec.Format());
|
return (*cntx_)->SendError(ec.Format());
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,8 @@ ABSL_FLAG(string, requirepass, "",
|
||||||
"If empty can also be set with DFLY_PASSWORD environment variable.");
|
"If empty can also be set with DFLY_PASSWORD environment variable.");
|
||||||
ABSL_FLAG(string, save_schedule, "",
|
ABSL_FLAG(string, save_schedule, "",
|
||||||
"glob spec for the UTC time to save a snapshot which matches HH:MM 24h time");
|
"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(uint32_t, port);
|
||||||
ABSL_DECLARE_FLAG(bool, cache_mode);
|
ABSL_DECLARE_FLAG(bool, cache_mode);
|
||||||
|
@ -567,7 +569,7 @@ void ServerFamily::SnapshotScheduling(const SnapshotSpec& spec) {
|
||||||
boost::intrusive_ptr<Transaction> trans(new Transaction{cid});
|
boost::intrusive_ptr<Transaction> trans(new Transaction{cid});
|
||||||
trans->InitByArgs(0, {});
|
trans->InitByArgs(0, {});
|
||||||
|
|
||||||
GenericError ec = DoSave(false, trans.get());
|
GenericError ec = DoSave(absl::GetFlag(FLAGS_df_snapshot_format), trans.get());
|
||||||
if (ec) {
|
if (ec) {
|
||||||
LOG(WARNING) << "Failed to perform snapshot " << ec.Format();
|
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) {
|
void ServerFamily::Save(CmdArgList args, ConnectionContext* cntx) {
|
||||||
string err_detail;
|
string err_detail;
|
||||||
bool new_version = false;
|
bool new_version = absl::GetFlag(FLAGS_df_snapshot_format);
|
||||||
if (args.size() > 2) {
|
if (args.size() > 2) {
|
||||||
return (*cntx)->SendError(kSyntaxErr);
|
return (*cntx)->SendError(kSyntaxErr);
|
||||||
}
|
}
|
||||||
|
@ -1195,6 +1197,8 @@ void ServerFamily::Save(CmdArgList args, ConnectionContext* cntx) {
|
||||||
string_view sub_cmd = ArgS(args, 1);
|
string_view sub_cmd = ArgS(args, 1);
|
||||||
if (sub_cmd == "DF") {
|
if (sub_cmd == "DF") {
|
||||||
new_version = true;
|
new_version = true;
|
||||||
|
} else if (sub_cmd == "RDB") {
|
||||||
|
new_version = false;
|
||||||
} else {
|
} else {
|
||||||
return (*cntx)->SendError(UnknownSubCmd(sub_cmd, "SAVE"), kSyntaxErrType);
|
return (*cntx)->SendError(UnknownSubCmd(sub_cmd, "SAVE"), kSyntaxErrType);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue