|
38 | 38 | #include <shared_mutex> |
39 | 39 | #include <utility> |
40 | 40 |
|
| 41 | +#include "commands/command_parser.h" |
41 | 42 | #include "commands/commander.h" |
42 | 43 | #include "common/string_util.h" |
43 | 44 | #include "config/config.h" |
@@ -1885,20 +1886,21 @@ Status Server::Propagate(const std::string &channel, const std::vector<std::stri |
1885 | 1886 | return storage->WriteToPropagateCF(ctx, channel, value); |
1886 | 1887 | } |
1887 | 1888 |
|
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 | | - |
1896 | 1889 | 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 | + } |
1902 | 1904 | } |
1903 | 1905 |
|
1904 | 1906 | return Status::OK(); |
|
0 commit comments