Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/unstable' into sup_key_range
Browse files Browse the repository at this point in the history
  • Loading branch information
infdahai committed Jul 5, 2023
2 parents d9e18cf + 9a9d218 commit 6df71ac
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

<img src="https://kvrocks.apache.org/img/kvrocks-featured.png" alt="kvrocks_logo" width="350"/>

[![kvrocks ci actions](https://github.com/apache/kvrocks/actions/workflows/kvrocks.yaml/badge.svg)](https://github.com/apache/kvrocks/actions/workflows/kvrocks.yaml)
[![GitHub license](https://img.shields.io/github/license/apache/kvrocks)](https://github.com/apache/kvrocks/blob/unstable/LICENSE)
[![CI](https://github.com/apache/kvrocks/actions/workflows/kvrocks.yaml/badge.svg?branch=unstable)](https://github.com/apache/kvrocks/actions/workflows/kvrocks.yaml)
[![License](https://img.shields.io/github/license/apache/kvrocks)](https://github.com/apache/kvrocks/blob/unstable/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/apache/kvrocks)](https://github.com/apache/kvrocks/stargazers)

---
Expand Down
4 changes: 4 additions & 0 deletions cmake/rocksdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ if (DISABLE_JEMALLOC)
set(COMPILE_WITH_JEMALLOC OFF)
endif()

if (NOT PORTABLE)
set(PORTABLE 0)
endif()

include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(rocksdb
Expand Down
9 changes: 8 additions & 1 deletion src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ class CommandDisk : public Commander {

uint64_t result = 0;
s = disk_db.GetKeySize(args_[2], type, &result);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
if (!s.ok()) {
// Redis returns the Nil string when the key does not exist
if (s.IsNotFound()) {
*output = redis::NilString();
return Status::OK();
}
return {Status::RedisExecErr, s.ToString()};
}

*output = redis::Integer(result);
return Status::OK();
Expand Down
18 changes: 10 additions & 8 deletions src/commands/cmd_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ class CommandZMPop : public Commander {
}

while (parser.Good()) {
if (parser.EatEqICase("min")) {
if (flag_ == ZSET_NONE && parser.EatEqICase("min")) {
flag_ = ZSET_MIN;
} else if (parser.EatEqICase("max")) {
} else if (flag_ == ZSET_NONE && parser.EatEqICase("max")) {
flag_ = ZSET_MAX;
} else if (parser.EatEqICase("count")) {
} else if (count_ == 0 && parser.EatEqICase("count")) {
count_ = GET_OR_RET(parser.TakeInt<int>(NumericRange<int>{1, std::numeric_limits<int>::max()}));
} else {
return parser.InvalidSyntax();
Expand All @@ -483,6 +483,7 @@ class CommandZMPop : public Commander {
if (flag_ == ZSET_NONE) {
return parser.InvalidSyntax();
}
if (count_ == 0) count_ = 1;
return Commander::Parse(args);
}

Expand Down Expand Up @@ -514,7 +515,7 @@ class CommandZMPop : public Commander {
int numkeys_;
std::vector<std::string> keys_;
enum { ZSET_MIN, ZSET_MAX, ZSET_NONE } flag_ = ZSET_NONE;
int count_ = 1;
int count_ = 0;
};

class CommandBZMPop : public Commander,
Expand All @@ -535,11 +536,11 @@ class CommandBZMPop : public Commander,
}

while (parser.Good()) {
if (parser.EatEqICase("min")) {
if (flag_ == ZSET_NONE && parser.EatEqICase("min")) {
flag_ = ZSET_MIN;
} else if (parser.EatEqICase("max")) {
} else if (flag_ == ZSET_NONE && parser.EatEqICase("max")) {
flag_ = ZSET_MAX;
} else if (parser.EatEqICase("count")) {
} else if (count_ == 0 && parser.EatEqICase("count")) {
count_ = GET_OR_RET(parser.TakeInt<int>(NumericRange<int>{1, std::numeric_limits<int>::max()}));
} else {
return parser.InvalidSyntax();
Expand All @@ -549,6 +550,7 @@ class CommandBZMPop : public Commander,
if (flag_ == ZSET_NONE) {
return parser.InvalidSyntax();
}
if (count_ == 0) count_ = 1;

return Commander::Parse(args);
}
Expand Down Expand Up @@ -659,7 +661,7 @@ class CommandBZMPop : public Commander,
int num_keys_;
std::vector<std::string> keys_;
enum { ZSET_MIN, ZSET_MAX, ZSET_NONE } flag_ = ZSET_NONE;
int count_ = 1;
int count_ = 0;
Server *svr_ = nullptr;
Connection *conn_ = nullptr;
UniqueEvent timer_;
Expand Down
7 changes: 5 additions & 2 deletions tests/gocase/unit/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ func TestDisk(t *testing.T) {
})

t.Run("Disk usage nonexistent key ", func(t *testing.T) {
require.ErrorContains(t, rdb.Do(ctx, "Disk", "usage", "nonexistentkey").Err(), "Not found")
require.ErrorIs(t, rdb.Do(ctx, "Disk", "usage", "nonexistentkey").Err(), redis.Nil)
})

t.Run("Memory usage existing key - check that Kvrocks support it", func(t *testing.T) {
t.Run("Memory usage - check that Kvrocks support it", func(t *testing.T) {
key := "arbitrary-key"
require.NoError(t, rdb.Del(ctx, key).Err())

Expand All @@ -153,5 +153,8 @@ func TestDisk(t *testing.T) {
size, err := rdb.MemoryUsage(ctx, key).Result()
require.NoError(t, err)
require.Greater(t, size, int64(0))

_, err = rdb.MemoryUsage(ctx, "nonexistentkey").Result()
require.ErrorIs(t, err, redis.Nil)
})
}
27 changes: 27 additions & 0 deletions tests/gocase/unit/type/zset/zset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,19 @@ func basicTests(t *testing.T, rdb *redis.Client, ctx context.Context, encoding s
require.EqualValues(t, 0, rdb.Exists(ctx, "zseta", "zsetb").Val())
})

t.Run(fmt.Sprintf("ZMPOP error - %s", encoding), func(t *testing.T) {
rdb.Del(ctx, "zseta")
rdb.Del(ctx, "zsetb")

util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", 1, "zseta").Err(), ".*wrong number of arguments.*")
util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", "wrong_numkeys", "zseta", "zsetb").Err(), ".*not started as an integer.*")
util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", 2, "zseta", "min").Err(), ".*syntax error.*")
util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", 2, "zseta", "zsetb", "min", "min").Err(), ".*syntax error.*")
util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", 1, "zseta", "min", "max").Err(), ".*syntax error.*")
util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", 1, "zseta", "min", "count", "wrong_count").Err(), ".*not started as an integer.*")
util.ErrorRegexp(t, rdb.Do(ctx, "zmpop", 1, "zseta", "min", "count", 1, "count", 10).Err(), ".*syntax error.*")
})

t.Run(fmt.Sprintf("BZMPOP basics - %s", encoding), func(t *testing.T) {
rdb.Del(ctx, "zseta")
rdb.Del(ctx, "zsetb")
Expand Down Expand Up @@ -427,6 +440,20 @@ func basicTests(t *testing.T, rdb *redis.Client, ctx context.Context, encoding s
require.Equal(t, []redis.Z{{Score: 1, Member: "a"}, {Score: 2, Member: "b"}}, zset)
})

t.Run(fmt.Sprintf("BZMPOP error - %s", encoding), func(t *testing.T) {
rdb.Del(ctx, "zseta")
rdb.Del(ctx, "zsetb")

util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, 1, "zseta").Err(), ".*wrong number of arguments.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", "wrong_timeout", 1, "zseta", "min").Err(), ".*not started as a number.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, "wrong_numkeys", "zseta", "min").Err(), ".*not started as an integer.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, 2, "zseta", "min").Err(), ".*syntax error.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, 1, "zseta", "min", "max").Err(), ".*syntax error.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, 2, "zseta", "zsetb", "min", "min").Err(), ".*syntax error.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, 1, "zseta", "min", "count", "wrong_count").Err(), ".*not started as an integer.*")
util.ErrorRegexp(t, rdb.Do(ctx, "bzmpop", 0.1, 1, "zseta", "min", "count", 1, "count", 10).Err(), ".*syntax error.*")
})

t.Run(fmt.Sprintf("ZRANGESTORE basics - %s", encoding), func(t *testing.T) {
rdb.Del(ctx, "zsrc")
rdb.Del(ctx, "zdst")
Expand Down

0 comments on commit 6df71ac

Please sign in to comment.