Skip to content

Commit 921078f

Browse files
authored
feat(function): propagate FUNCTION FLUSH/DELETE to replicas (#3121)
1 parent 173ce0c commit 921078f

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/commands/cmd_function.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ struct CommandFunction : Commander {
7474
}
7575
auto s = lua::FunctionDelete(ctx, conn, libname);
7676
if (!s) return s;
77+
s = srv->Propagate(engine::kPropagateScriptCommand, args_);
78+
if (!s) return s;
7779

7880
*output = RESP_OK;
7981
return Status::OK();
8082
} else if (parser.EatEqICase("flush")) {
8183
auto s = lua::FunctionFlush(conn, &ctx);
8284
if (!s) return s;
85+
s = srv->Propagate(engine::kPropagateScriptCommand, args_);
86+
if (!s) return s;
8387

8488
*output = RESP_OK;
8589
return Status::OK();

src/server/server.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <shared_mutex>
3939
#include <utility>
4040

41+
#include "commands/command_parser.h"
4142
#include "commands/commander.h"
4243
#include "common/string_util.h"
4344
#include "config/config.h"
@@ -1885,20 +1886,21 @@ Status Server::Propagate(const std::string &channel, const std::vector<std::stri
18851886
return storage->WriteToPropagateCF(ctx, channel, value);
18861887
}
18871888

1888-
Status Server::ExecPropagateScriptCommand(const std::vector<std::string> &tokens) {
1889-
auto subcommand = util::ToLower(tokens[1]);
1890-
if (subcommand == "flush") {
1891-
ScriptReset();
1892-
}
1893-
return Status::OK();
1894-
}
1895-
18961889
Status Server::ExecPropagatedCommand(const std::vector<std::string> &tokens) {
1897-
if (tokens.empty()) return Status::OK();
1898-
1899-
auto command = util::ToLower(tokens[0]);
1900-
if (command == "script" && tokens.size() >= 2) {
1901-
return ExecPropagateScriptCommand(tokens);
1890+
CommandParser parser(tokens);
1891+
if (parser.EatEqICase("script")) {
1892+
if (parser.EatEqICase("flush")) {
1893+
// here we must acquire the global lock to guarantee that
1894+
// no EVAL or FCALL is executing while resetting lua state.
1895+
auto guard = WorkExclusivityGuard();
1896+
ScriptReset();
1897+
}
1898+
} else if (parser.EatEqICase("function")) {
1899+
if (parser.EatEqICase("delete") || parser.EatEqICase("flush")) {
1900+
// same as above to acquire the global lock
1901+
auto guard = WorkExclusivityGuard();
1902+
ScriptReset();
1903+
}
19021904
}
19031905

19041906
return Status::OK();

src/server/server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ class Server {
318318

319319
Status Propagate(const std::string &channel, const std::vector<std::string> &tokens) const;
320320
Status ExecPropagatedCommand(const std::vector<std::string> &tokens);
321-
Status ExecPropagateScriptCommand(const std::vector<std::string> &tokens);
322321

323322
LogCollector<PerfEntry> *GetPerfLog() { return &perf_log_; }
324323
LogCollector<SlowEntry> *GetSlowLog() { return &slow_log_; }

0 commit comments

Comments
 (0)