This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new bf5ba41d Fix write flag for FUNCTION and SCRIPT commands (#2219)
bf5ba41d is described below
commit bf5ba41dcdaba15c975ef204acef706db0bac37e
Author: Twice <[email protected]>
AuthorDate: Thu Apr 4 19:55:41 2024 +0900
Fix write flag for FUNCTION and SCRIPT commands (#2219)
---
src/commands/cmd_cluster.cc | 6 +++---
src/commands/cmd_function.cc | 11 ++++++++++-
src/commands/cmd_script.cc | 8 ++++++++
src/commands/cmd_server.cc | 10 ++++------
src/commands/commander.h | 4 ++--
5 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/commands/cmd_cluster.cc b/src/commands/cmd_cluster.cc
index 9567dcd5..5831fa50 100644
--- a/src/commands/cmd_cluster.cc
+++ b/src/commands/cmd_cluster.cc
@@ -295,12 +295,12 @@ class CommandClusterX : public Commander {
std::unique_ptr<SyncMigrateContext> sync_migrate_ctx_ = nullptr;
};
-static uint64_t GenerateClusterFlag(const std::vector<std::string> &args) {
+static uint64_t GenerateClusterFlag(uint64_t flags, const
std::vector<std::string> &args) {
if (args.size() >= 2 && Cluster::SubCommandIsExecExclusive(args[1])) {
- return kCmdExclusive;
+ return flags | kCmdExclusive;
}
- return 0;
+ return flags;
}
class CommandReadOnly : public Commander {
diff --git a/src/commands/cmd_function.cc b/src/commands/cmd_function.cc
index 2d7ce193..1afab33d 100644
--- a/src/commands/cmd_function.cc
+++ b/src/commands/cmd_function.cc
@@ -99,7 +99,16 @@ struct CommandFCall : Commander {
CommandKeyRange GetScriptEvalKeyRange(const std::vector<std::string> &args);
-REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandFunction>("function", -2,
"exclusive no-script", 0, 0, 0),
+uint64_t GenerateFunctionFlags(uint64_t flags, const std::vector<std::string>
&args) {
+ if (util::EqualICase(args[1], "load") || util::EqualICase(args[1],
"delete")) {
+ return flags | kCmdWrite;
+ }
+
+ return flags;
+}
+
+REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandFunction>("function", -2,
"exclusive no-script", 0, 0, 0,
+ GenerateFunctionFlags),
MakeCmdAttr<CommandFCall<>>("fcall", -3, "exclusive
write no-script", GetScriptEvalKeyRange),
MakeCmdAttr<CommandFCall<true>>("fcall_ro", -3,
"read-only ro-script no-script",
GetScriptEvalKeyRange));
diff --git a/src/commands/cmd_script.cc b/src/commands/cmd_script.cc
index c7576a6a..34a71837 100644
--- a/src/commands/cmd_script.cc
+++ b/src/commands/cmd_script.cc
@@ -116,6 +116,14 @@ CommandKeyRange GetScriptEvalKeyRange(const
std::vector<std::string> &args) {
return {3, 2 + numkeys, 1};
}
+uint64_t GenerateScriptFlags(uint64_t flags, const std::vector<std::string>
&args) {
+ if (util::EqualICase(args[1], "load") || util::EqualICase(args[1], "flush"))
{
+ return flags | kCmdWrite;
+ }
+
+ return flags;
+}
+
REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandEval>("eval", -3, "exclusive write
no-script", GetScriptEvalKeyRange),
MakeCmdAttr<CommandEvalSHA>("evalsha", -3, "exclusive
write no-script", GetScriptEvalKeyRange),
MakeCmdAttr<CommandEvalRO>("eval_ro", -3, "read-only
no-script ro-script",
diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc
index 481f3f59..c1bdd96a 100644
--- a/src/commands/cmd_server.cc
+++ b/src/commands/cmd_server.cc
@@ -1066,12 +1066,12 @@ class CommandStats : public Commander {
}
};
-static uint64_t GenerateConfigFlag(const std::vector<std::string> &args) {
+static uint64_t GenerateConfigFlag(uint64_t flags, const
std::vector<std::string> &args) {
if (args.size() >= 2 && util::EqualICase(args[1], "set")) {
- return kCmdExclusive;
+ return flags | kCmdExclusive;
}
- return 0;
+ return flags;
}
class CommandLastSave : public Commander {
@@ -1228,9 +1228,7 @@ class CommandAnalyze : public Commander {
cmd->SetAttributes(redis_cmd);
cmd->SetArgs(command_args_);
- int arity = cmd->GetAttributes()->arity;
- if ((arity > 0 && static_cast<int>(command_args_.size()) != arity) ||
- (arity < 0 && static_cast<int>(command_args_.size()) < -arity)) {
+ if
(!cmd->GetAttributes()->CheckArity(static_cast<int>(command_args_.size()))) {
*output = redis::Error("ERR wrong number of arguments");
return {Status::RedisExecErr, errWrongNumOfArguments};
}
diff --git a/src/commands/commander.h b/src/commands/commander.h
index d759bd20..1982d897 100644
--- a/src/commands/commander.h
+++ b/src/commands/commander.h
@@ -112,7 +112,7 @@ using CommandKeyRangeGen =
std::function<CommandKeyRange(const std::vector<std::
using CommandKeyRangeVecGen = std::function<std::vector<CommandKeyRange>(const
std::vector<std::string> &)>;
-using AdditionalFlagGen = std::function<uint64_t(const
std::vector<std::string> &)>;
+using AdditionalFlagGen = std::function<uint64_t(uint64_t, const
std::vector<std::string> &)>;
struct CommandAttributes {
// command name
@@ -146,7 +146,7 @@ struct CommandAttributes {
auto GenerateFlags(const std::vector<std::string> &args) const {
uint64_t res = flags;
- if (flag_gen) res |= flag_gen(args);
+ if (flag_gen) res = flag_gen(res, args);
return res;
}