Skip to content
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

feat: Add slow flags for commands with heavy disk I/O #2494

Merged
merged 15 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/commands/cmd_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ REDIS_REGISTER_COMMANDS(Hash, MakeCmdAttr<CommandHGet>("hget", 3, "read-only", 1
MakeCmdAttr<CommandHLen>("hlen", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHMGet>("hmget", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHMSet>("hmset", -4, "write", 1, 1, 1),
MakeCmdAttr<CommandHKeys>("hkeys", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHVals>("hvals", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHGetAll>("hgetall", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHKeys>("hkeys", 2, "read-only slow", 1, 1, 1),
MakeCmdAttr<CommandHVals>("hvals", 2, "read-only slow", 1, 1, 1),
MakeCmdAttr<CommandHGetAll>("hgetall", 2, "read-only slow", 1, 1, 1),
MakeCmdAttr<CommandHScan>("hscan", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHRangeByLex>("hrangebylex", -4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHRandField>("hrandfield", -2, "read-only", 1, 1, 1), )
Expand Down
12 changes: 6 additions & 6 deletions src/commands/cmd_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ class CommandLRem : public Commander {
if (!parse_result) {
return {Status::RedisParseErr, errValueNotInteger};
}

git-hulk marked this conversation as resolved.
Show resolved Hide resolved
count_ = *parse_result;
return Commander::Parse(args);
}
Expand Down Expand Up @@ -495,6 +494,7 @@ class CommandLInsert : public Commander {
} else {
return {Status::RedisParseErr, errInvalidSyntax};
}

jonathanc-n marked this conversation as resolved.
Show resolved Hide resolved
return Commander::Parse(args);
}

Expand Down Expand Up @@ -633,7 +633,7 @@ class CommandLTrim : public Commander {

start_ = *parse_start;
stop_ = *parse_stop;

git-hulk marked this conversation as resolved.
Show resolved Hide resolved
return Commander::Parse(args);
}

Expand Down Expand Up @@ -852,18 +852,18 @@ REDIS_REGISTER_COMMANDS(List, MakeCmdAttr<CommandBLPop>("blpop", -3, "write no-s
MakeCmdAttr<CommandBRPop>("brpop", -3, "write no-script", 1, -2, 1),
MakeCmdAttr<CommandBLMPop>("blmpop", -5, "write no-script", CommandBLMPop::keyRangeGen),
MakeCmdAttr<CommandLIndex>("lindex", 3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandLInsert>("linsert", 5, "write", 1, 1, 1),
MakeCmdAttr<CommandLInsert>("linsert", 5, "write slow", 1, 1, 1),
MakeCmdAttr<CommandLLen>("llen", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandLMove>("lmove", 5, "write", 1, 2, 1),
MakeCmdAttr<CommandBLMove>("blmove", 6, "write", 1, 2, 1),
MakeCmdAttr<CommandLPop>("lpop", -2, "write", 1, 1, 1), //
MakeCmdAttr<CommandLPos>("lpos", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandLPush>("lpush", -3, "write", 1, 1, 1),
MakeCmdAttr<CommandLPushX>("lpushx", -3, "write", 1, 1, 1),
MakeCmdAttr<CommandLRange>("lrange", 4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandLRem>("lrem", 4, "write no-dbsize-check", 1, 1, 1),
MakeCmdAttr<CommandLRange>("lrange", 4, "read-only slow", 1, 1, 1),
jonathanc-n marked this conversation as resolved.
Show resolved Hide resolved
MakeCmdAttr<CommandLRem>("lrem", 4, "write no-dbsize-check slow", 1, 1, 1),
MakeCmdAttr<CommandLSet>("lset", 4, "write", 1, 1, 1),
MakeCmdAttr<CommandLTrim>("ltrim", 4, "write no-dbsize-check", 1, 1, 1),
MakeCmdAttr<CommandLTrim>("ltrim", -4, "write no-dbsize-check", 1, 1, 1),
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
MakeCmdAttr<CommandLMPop>("lmpop", -4, "write", CommandLMPop::keyRangeGen),
MakeCmdAttr<CommandRPop>("rpop", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandRPopLPUSH>("rpoplpush", 3, "write", 1, 2, 1),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ class CommandScan : public CommandScanBase {
Status Execute(Server *srv, Connection *conn, std::string *output) override {
redis::Database redis_db(srv->storage, conn->GetNamespace());
auto key_name = srv->GetKeyNameFromCursor(cursor_, CursorType::kTypeBase);

git-hulk marked this conversation as resolved.
Show resolved Hide resolved
std::vector<std::string> keys;
std::string end_key;
auto s = redis_db.Scan(key_name, limit_, prefix_, &keys, &end_key, type_);
Expand Down
16 changes: 8 additions & 8 deletions src/commands/cmd_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,19 @@ class CommandSScan : public CommandSubkeyScanBase {
REDIS_REGISTER_COMMANDS(Set, MakeCmdAttr<CommandSAdd>("sadd", -3, "write", 1, 1, 1),
MakeCmdAttr<CommandSRem>("srem", -3, "write no-dbsize-check", 1, 1, 1),
MakeCmdAttr<CommandSCard>("scard", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSMembers>("smembers", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSMembers>("smembers", 2, "read-only slow", 1, 1, 1),
MakeCmdAttr<CommandSIsMember>("sismember", 3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSMIsMember>("smismember", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSPop>("spop", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandSRandMember>("srandmember", -2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSMove>("smove", 4, "write", 1, 2, 1),
MakeCmdAttr<CommandSDiff>("sdiff", -2, "read-only", 1, -1, 1),
MakeCmdAttr<CommandSUnion>("sunion", -2, "read-only", 1, -1, 1),
MakeCmdAttr<CommandSInter>("sinter", -2, "read-only", 1, -1, 1),
MakeCmdAttr<CommandSInterCard>("sintercard", -3, "read-only", CommandSInterCard::Range),
MakeCmdAttr<CommandSDiffStore>("sdiffstore", -3, "write", 1, -1, 1),
MakeCmdAttr<CommandSUnionStore>("sunionstore", -3, "write", 1, -1, 1),
MakeCmdAttr<CommandSInterStore>("sinterstore", -3, "write", 1, -1, 1),
MakeCmdAttr<CommandSDiff>("sdiff", -2, "read-only slow", 1, -1, 1),
MakeCmdAttr<CommandSUnion>("sunion", -2, "read-only slow", 1, -1, 1),
MakeCmdAttr<CommandSInter>("sinter", -2, "read-only slow", 1, -1, 1),
MakeCmdAttr<CommandSInterCard>("sintercard", -3, "read-only slow", CommandSInterCard::Range),
MakeCmdAttr<CommandSDiffStore>("sdiffstore", -3, "write slow", 1, -1, 1),
MakeCmdAttr<CommandSUnionStore>("sunionstore", -3, "write slow", 1, -1, 1),
MakeCmdAttr<CommandSInterStore>("sinterstore", -3, "write slow", 1, -1, 1),
MakeCmdAttr<CommandSScan>("sscan", -3, "read-only", 1, 1, 1), )

} // namespace redis
14 changes: 7 additions & 7 deletions src/commands/cmd_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1516,9 +1516,9 @@ REDIS_REGISTER_COMMANDS(ZSet, MakeCmdAttr<CommandZAdd>("zadd", -4, "write", 1, 1
MakeCmdAttr<CommandZCard>("zcard", 2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZCount>("zcount", 4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZIncrBy>("zincrby", 4, "write", 1, 1, 1),
MakeCmdAttr<CommandZInterStore>("zinterstore", -4, "write", CommandZInterStore::Range),
MakeCmdAttr<CommandZInter>("zinter", -3, "read-only", CommandZInter::Range),
MakeCmdAttr<CommandZInterCard>("zintercard", -3, "read-only", CommandZInterCard::Range),
MakeCmdAttr<CommandZInterStore>("zinterstore", -4, "write slow", CommandZInterStore::Range),
MakeCmdAttr<CommandZInter>("zinter", -3, "read-only slow", CommandZInter::Range),
MakeCmdAttr<CommandZInterCard>("zintercard", -3, "read-only slow", CommandZInterCard::Range),
MakeCmdAttr<CommandZLexCount>("zlexcount", 4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZPopMax>("zpopmax", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandZPopMin>("zpopmin", -2, "write", 1, 1, 1),
Expand All @@ -1542,10 +1542,10 @@ REDIS_REGISTER_COMMANDS(ZSet, MakeCmdAttr<CommandZAdd>("zadd", -4, "write", 1, 1
MakeCmdAttr<CommandZScore>("zscore", 3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZMScore>("zmscore", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZScan>("zscan", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZUnionStore>("zunionstore", -4, "write", CommandZUnionStore::Range),
MakeCmdAttr<CommandZUnion>("zunion", -3, "read-only", CommandZUnion::Range),
MakeCmdAttr<CommandZUnionStore>("zunionstore", -4, "write slow", CommandZUnionStore::Range),
MakeCmdAttr<CommandZUnion>("zunion", -3, "read-only slow", CommandZUnion::Range),
MakeCmdAttr<CommandZRandMember>("zrandmember", -2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZDiff>("zdiff", -3, "read-only", CommandZDiff::Range),
MakeCmdAttr<CommandZDiffStore>("zdiffstore", -3, "read-only", CommandZDiffStore::Range), )
MakeCmdAttr<CommandZDiff>("zdiff", -3, "read-only slow", CommandZDiff::Range),
MakeCmdAttr<CommandZDiffStore>("zdiffstore", -3, "read-only slow", CommandZDiffStore::Range), )

} // namespace redis
3 changes: 3 additions & 0 deletions src/commands/commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum CommandFlags : uint64_t {
kCmdROScript = 1ULL << 10, // "ro-script" flag for read-only script commands
kCmdCluster = 1ULL << 11, // "cluster" flag
kCmdNoDBSizeCheck = 1ULL << 12, // "no-dbsize-check" flag
kCmdSlow = 1ULL << 13, // "slow" flag
};

enum class CommandCategory : uint8_t {
Expand Down Expand Up @@ -238,6 +239,8 @@ inline uint64_t ParseCommandFlags(const std::string &description, const std::str
flags |= kCmdCluster;
else if (flag == "no-dbsize-check")
flags |= kCmdNoDBSizeCheck;
else if (flag == "slow")
flags |= kCmdSlow;
else {
std::cout << fmt::format("Encountered non-existent flag '{}' in command {} in command attribute parsing", flag,
cmd_name)
Expand Down