-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: forbid DFLYCLUSTER commads set for emulated cluster mode #3307
Changes from 12 commits
8deee00
721accb
9faf6bc
6e660be
c560379
ee24076
e55573b
13aa462
56d3ed6
2a0203a
d43ddb5
44bf056
af2f8d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -369,8 +369,18 @@ void ClusterFamily::Cluster(CmdArgList args, ConnectionContext* cntx) { | |||||||||||||||
return cntx->SendError(kClusterDisabled); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (sub_cmd == "KEYSLOT") { | ||||||||||||||||
return KeySlot(args, cntx); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (args.size() > 1) { | ||||||||||||||||
return cntx->SendError(WrongNumArgsError(absl::StrCat("CLUSTER ", sub_cmd))); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (sub_cmd == "HELP") { | ||||||||||||||||
return ClusterHelp(cntx); | ||||||||||||||||
} else if (sub_cmd == "MYID") { | ||||||||||||||||
return ClusterMyId(cntx); | ||||||||||||||||
} else if (sub_cmd == "SHARDS") { | ||||||||||||||||
return ClusterShards(cntx); | ||||||||||||||||
} else if (sub_cmd == "SLOTS") { | ||||||||||||||||
|
@@ -379,8 +389,6 @@ void ClusterFamily::Cluster(CmdArgList args, ConnectionContext* cntx) { | |||||||||||||||
return ClusterNodes(cntx); | ||||||||||||||||
} else if (sub_cmd == "INFO") { | ||||||||||||||||
return ClusterInfo(cntx); | ||||||||||||||||
} else if (sub_cmd == "KEYSLOT") { | ||||||||||||||||
return KeySlot(args, cntx); | ||||||||||||||||
} else { | ||||||||||||||||
return cntx->SendError(facade::UnknownSubCmd(sub_cmd, "CLUSTER"), facade::kSyntaxErrType); | ||||||||||||||||
} | ||||||||||||||||
|
@@ -401,11 +409,15 @@ void ClusterFamily::ReadWrite(CmdArgList args, ConnectionContext* cntx) { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
void ClusterFamily::DflyCluster(CmdArgList args, ConnectionContext* cntx) { | ||||||||||||||||
if (!IsClusterEnabledOrEmulated()) { | ||||||||||||||||
return cntx->SendError(kClusterDisabled); | ||||||||||||||||
if (!(IsClusterEnabled() || (IsClusterEmulated() && cntx->journal_emulated))) { | ||||||||||||||||
return cntx->SendError("Cluster is disabled. Use --cluster_mode=yes to enable."); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
VLOG(2) << "Got DFLYCLUSTER command (" << cntx->conn()->GetClientId() << "): " << args; | ||||||||||||||||
if (cntx->conn()) { | ||||||||||||||||
VLOG(2) << "Got DFLYCLUSTER command (" << cntx->conn()->GetClientId() << "): " << args; | ||||||||||||||||
} else { | ||||||||||||||||
VLOG(2) << "Got DFLYCLUSTER command (NO_CLIENT_ID): " << args; | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+416
to
+420
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's different types. int and char[] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could return a string.. no need to duplicate code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change it next time when do some changes in this file |
||||||||||||||||
|
||||||||||||||||
ToUpper(&args[0]); | ||||||||||||||||
string_view sub_cmd = ArgS(args, 0); | ||||||||||||||||
|
@@ -414,8 +426,6 @@ void ClusterFamily::DflyCluster(CmdArgList args, ConnectionContext* cntx) { | |||||||||||||||
return DflyClusterGetSlotInfo(args, cntx); | ||||||||||||||||
} else if (sub_cmd == "CONFIG") { | ||||||||||||||||
return DflyClusterConfig(args, cntx); | ||||||||||||||||
} else if (sub_cmd == "MYID") { | ||||||||||||||||
return DflyClusterMyId(args, cntx); | ||||||||||||||||
} else if (sub_cmd == "FLUSHSLOTS") { | ||||||||||||||||
return DflyClusterFlushSlots(args, cntx); | ||||||||||||||||
} else if (sub_cmd == "SLOT-MIGRATION-STATUS") { | ||||||||||||||||
|
@@ -425,12 +435,8 @@ void ClusterFamily::DflyCluster(CmdArgList args, ConnectionContext* cntx) { | |||||||||||||||
return cntx->SendError(UnknownSubCmd(sub_cmd, "DFLYCLUSTER"), kSyntaxErrType); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
void ClusterFamily::DflyClusterMyId(CmdArgList args, ConnectionContext* cntx) { | ||||||||||||||||
if (!args.empty()) { | ||||||||||||||||
return cntx->SendError(WrongNumArgsError("DFLYCLUSTER MYID")); | ||||||||||||||||
} | ||||||||||||||||
BorysTheDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder()); | ||||||||||||||||
rb->SendBulkString(id_); | ||||||||||||||||
void ClusterFamily::ClusterMyId(ConnectionContext* cntx) { | ||||||||||||||||
cntx->SendSimpleString(id_); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
namespace { | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which flow do you get null connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is the journal emulated mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
client_info = cntx->conn()? ntx->conn()->GetClientId() : "stub";
VLOG(2) << "Got DFLYCLUSTER command (" << client_info << args;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in journal_emulated