Skip to content

Commit

Permalink
chore(config): enable the RESP3 potocol by default (#2746)
Browse files Browse the repository at this point in the history
Co-authored-by: Twice <[email protected]>
  • Loading branch information
git-hulk and PragmaTwice authored Jan 29, 2025
1 parent 06fa457 commit 88f1f3e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 47 deletions.
5 changes: 2 additions & 3 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,9 @@ max-bitmap-to-string-mb 16
redis-cursor-compatible yes

# Whether to enable the RESP3 protocol.
# NOTICE: RESP3 is still under development, don't enable it in production environment.
#
# Default: no
# resp3-enabled no
# Default: yes
# resp3-enabled yes

# Maximum nesting depth allowed when parsing and serializing
# JSON documents while using JSON commands like JSON.SET.
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Config::Config() {
{"log-retention-days", false, new IntField(&log_retention_days, -1, -1, INT_MAX)},
{"persist-cluster-nodes-enabled", false, new YesNoField(&persist_cluster_nodes_enabled, true)},
{"redis-cursor-compatible", false, new YesNoField(&redis_cursor_compatible, true)},
{"resp3-enabled", false, new YesNoField(&resp3_enabled, false)},
{"resp3-enabled", false, new YesNoField(&resp3_enabled, true)},
{"repl-namespace-enabled", false, new YesNoField(&repl_namespace_enabled, false)},
{"proto-max-bulk-len", false,
new IntWithUnitField<uint64_t>(&proto_max_bulk_len, std::to_string(512 * MiB), 1 * MiB, UINT64_MAX)},
Expand Down
18 changes: 7 additions & 11 deletions tests/gocase/unit/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

func TestRenameCommand(t *testing.T) {
srv := util.StartServer(t, map[string]string{
"resp3-enabled": "no",
"rename-command KEYS": "KEYSNEW",
"rename-command GET": "GETNEW",
"rename-command SET": "SETNEW",
Expand Down Expand Up @@ -71,10 +72,8 @@ func TestSetConfigBackupDir(t *testing.T) {

originBackupDir := filepath.Join(configs["dir"], "backup")

r := rdb.Do(ctx, "CONFIG", "GET", "backup-dir")
rList := r.Val().([]interface{})
require.EqualValues(t, rList[0], "backup-dir")
require.EqualValues(t, rList[1], originBackupDir)
r := rdb.ConfigGet(ctx, "backup-dir").Val()
require.EqualValues(t, r["backup-dir"], originBackupDir)

hasCompactionFiles := func(dir string) bool {
if _, err := os.Stat(dir); os.IsNotExist(err) {
Expand All @@ -98,14 +97,11 @@ func TestSetConfigBackupDir(t *testing.T) {

require.False(t, hasCompactionFiles(newBackupDir))

require.NoError(t, rdb.Do(ctx, "CONFIG", "SET", "backup-dir", newBackupDir).Err())
require.NoError(t, rdb.ConfigSet(ctx, "backup-dir", newBackupDir).Err())
r = rdb.ConfigGet(ctx, "backup-dir").Val()
require.EqualValues(t, r["backup-dir"], newBackupDir)

r = rdb.Do(ctx, "CONFIG", "GET", "backup-dir")
rList = r.Val().([]interface{})
require.EqualValues(t, rList[0], "backup-dir")
require.EqualValues(t, rList[1], newBackupDir)

require.NoError(t, rdb.Do(ctx, "bgsave").Err())
require.NoError(t, rdb.BgSave(ctx).Err())
time.Sleep(2000 * time.Millisecond)

require.True(t, hasCompactionFiles(newBackupDir))
Expand Down
2 changes: 1 addition & 1 deletion tests/gocase/unit/hello/hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestHello(t *testing.T) {
srv := util.StartServer(t, map[string]string{})
srv := util.StartServer(t, map[string]string{"resp3-enabled": "no"})
defer srv.Close()

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion tests/gocase/unit/scripting/scripting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

func TestScripting(t *testing.T) {
srv := util.StartServer(t, map[string]string{})
srv := util.StartServer(t, map[string]string{"resp3-enabled": "no"})
defer srv.Close()

ctx := context.Background()
Expand Down
4 changes: 2 additions & 2 deletions tests/gocase/unit/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func TestSearch(t *testing.T) {
require.Equal(t, "index_definition", idxInfo[2])
require.Equal(t, []interface{}{"key_type", "ReJSON-RL", "prefixes", []interface{}{"test1:"}}, idxInfo[3])
require.Equal(t, "fields", idxInfo[4])
require.Equal(t, []interface{}{"identifier", "a", "type", "tag", "properties", []interface{}{"separator", ",", "case_sensitive", int64(0)}}, idxInfo[5].([]interface{})[0])
require.Equal(t, []interface{}{"identifier", "a", "type", "tag", "properties", []interface{}{"separator", ",", "case_sensitive", false}}, idxInfo[5].([]interface{})[0])
require.Equal(t, []interface{}{"identifier", "b", "type", "numeric", "properties", []interface{}{}}, idxInfo[5].([]interface{})[1])
require.Equal(t, []interface{}{"identifier", "c", "type", "vector", "properties", []interface{}{"algorithm", "HNSW", "vector_type", "FLOAT64", "dim", int64(3), "distance_metric", "L2", "m", int64(16), "ef_construction", int64(200), "ef_runtime", int64(10), "epsilon", "0.01"}}, idxInfo[5].([]interface{})[2])
require.Equal(t, []interface{}{"identifier", "c", "type", "vector", "properties", []interface{}{"algorithm", "HNSW", "vector_type", "FLOAT64", "dim", int64(3), "distance_metric", "L2", "m", int64(16), "ef_construction", int64(200), "ef_runtime", int64(10), "epsilon", 0.01}}, idxInfo[5].([]interface{})[2])
}
verify(t)

Expand Down
57 changes: 29 additions & 28 deletions tests/gocase/unit/server/poll_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ func parseRESPCommands(t *testing.T, values []any) []any {
return updates
}

func parsePollUpdatesResult(t *testing.T, slice []any, isRESP bool) *PollUpdatesResult {
itemCount := 6
require.Len(t, slice, itemCount)
func parsePollUpdatesResult(t *testing.T, m map[any]any, isRESP bool) *PollUpdatesResult {
itemCount := 3
require.Len(t, m, itemCount)
var latestSeq, nextSeq int64

updates := make([]any, 0)
for i := 0; i < itemCount; i += 2 {
key := slice[i].(string)
for k, v := range m {
key := k.(string)
switch key {
case "latest_sequence":
latestSeq = slice[i+1].(int64)
latestSeq = v.(int64)
case "next_sequence":
nextSeq = slice[i+1].(int64)
nextSeq = v.(int64)
case "updates":
fields := slice[i+1].([]interface{})
fields := v.([]interface{})
if isRESP {
updates = parseRESPCommands(t, fields)
} else {
Expand Down Expand Up @@ -127,17 +127,18 @@ func TestPollUpdates_Basic(t *testing.T) {
}

updates := make([]any, 0)
slice, err := rdb0.Do(ctx, "POLLUPDATES", 0, "MAX", 6).Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", 0, "MAX", 6).Result()
require.NoError(t, err)
pollUpdates := parsePollUpdatesResult(t, slice, false)
pollUpdates := parsePollUpdatesResult(t, result.(map[interface{}]interface{}), false)
require.EqualValues(t, 10, pollUpdates.LatestSeq)
require.EqualValues(t, 6, pollUpdates.NextSeq)
require.Len(t, pollUpdates.Updates, 6)
updates = append(updates, pollUpdates.Updates...)

slice, err = rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 6).Slice()
result, err = rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 6).Result()
require.NoError(t, err)
pollUpdates = parsePollUpdatesResult(t, slice, false)

pollUpdates = parsePollUpdatesResult(t, result.(map[interface{}]interface{}), false)
require.EqualValues(t, 10, pollUpdates.LatestSeq)
require.EqualValues(t, 10, pollUpdates.NextSeq)
require.Len(t, pollUpdates.Updates, 4)
Expand Down Expand Up @@ -179,10 +180,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
require.NoError(t, rdb0.Set(ctx, "k0", "v0", 0).Err())
require.NoError(t, rdb0.Set(ctx, "k1", "v1", 0).Err())
require.NoError(t, rdb0.Del(ctx, "k1").Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", 0, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", 0, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.EqualValues(t, 3, pollUpdates.LatestSeq)
require.EqualValues(t, 3, pollUpdates.NextSeq)
require.Len(t, pollUpdates.Updates, 1)
Expand All @@ -199,10 +200,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
t.Run("Hash type", func(t *testing.T) {
require.NoError(t, rdb0.HSet(ctx, "h0", "f0", "v0", "f1", "v1").Err())
require.NoError(t, rdb0.HDel(ctx, "h0", "f1").Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.Len(t, pollUpdates.Updates, 1)
require.EqualValues(t, []any{RESPFormat{
Namespace: "default",
Expand All @@ -217,10 +218,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
t.Run("List type", func(t *testing.T) {
require.NoError(t, rdb0.LPush(ctx, "l0", "v0", "v1").Err())
require.NoError(t, rdb0.LSet(ctx, "l0", 1, "v2").Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.Len(t, pollUpdates.Updates, 1)
require.EqualValues(t, []any{RESPFormat{
Namespace: "default",
Expand All @@ -235,10 +236,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
t.Run("Set type", func(t *testing.T) {
require.NoError(t, rdb0.SAdd(ctx, "s0", "v0", "v1").Err())
require.NoError(t, rdb0.SRem(ctx, "s0", "v1").Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.Len(t, pollUpdates.Updates, 1)
require.EqualValues(t, []any{RESPFormat{
Namespace: "default",
Expand All @@ -254,10 +255,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
require.NoError(t, rdb0.ZAdd(ctx, "z0", redis.Z{Member: "v0", Score: 1.2}).Err())
require.NoError(t, rdb0.ZAdd(ctx, "z0", redis.Z{Member: "v1", Score: 1.2}).Err())
require.NoError(t, rdb0.ZRem(ctx, "z0", "v1").Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.Len(t, pollUpdates.Updates, 1)
require.EqualValues(t, []any{RESPFormat{
Namespace: "default",
Expand All @@ -276,10 +277,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
}).Result()
require.NoError(t, err)
require.NoError(t, rdb0.XDel(ctx, "stream", id).Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.Len(t, pollUpdates.Updates, 1)
require.EqualValues(t, []any{RESPFormat{
Commands: [][]string{
Expand All @@ -292,10 +293,10 @@ func TestPollUpdates_WithRESPFormat(t *testing.T) {
t.Run("JSON type", func(t *testing.T) {
require.NoError(t, rdb0.JSONSet(ctx, "json", "$", `{"field": "value"}`).Err())
require.NoError(t, rdb0.JSONDel(ctx, "json", "$.field").Err())
slice, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", pollUpdates.NextSeq, "MAX", 10, "FORMAT", "RESP").Result()
require.NoError(t, err)

pollUpdates = parsePollUpdatesResult(t, slice, true)
pollUpdates = parsePollUpdatesResult(t, result.(map[any]any), true)
require.Len(t, pollUpdates.Updates, 1)
require.EqualValues(t, []any{RESPFormat{
Namespace: "default",
Expand Down Expand Up @@ -332,9 +333,9 @@ func TestPollUpdates_WithStrict(t *testing.T) {
// Works well if the sequence number is mismatched but not in strict mode
require.NoError(t, rdb0.Do(ctx, "POLLUPDATES", 1, "MAX", 1).Err())

slice, err := rdb0.Do(ctx, "POLLUPDATES", 0, "MAX", 10, "STRICT").Slice()
result, err := rdb0.Do(ctx, "POLLUPDATES", 0, "MAX", 10, "STRICT").Result()
require.NoError(t, err)
pollUpdates := parsePollUpdatesResult(t, slice, false)
pollUpdates := parsePollUpdatesResult(t, result.(map[any]any), false)
require.EqualValues(t, 3, pollUpdates.LatestSeq)
require.EqualValues(t, 3, pollUpdates.NextSeq)
require.Len(t, pollUpdates.Updates, 2)
Expand Down

0 comments on commit 88f1f3e

Please sign in to comment.