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

Add a particular test case for HGETALL with async_io=true #1401

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Changes from all 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
73 changes: 61 additions & 12 deletions tests/gocase/unit/type/hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -340,12 +341,15 @@ func TestHash(t *testing.T) {
})

t.Run("HVALS - field with empty string as a value", func(t *testing.T) {
require.NoError(t, rdb.HSet(ctx, "test-hash-1", "field1", "some-value").Err())
require.NoError(t, rdb.HSet(ctx, "test-hash-1", "field2", "").Err())
testKey := "test-hash-1"
require.NoError(t, rdb.Del(ctx, testKey).Err())

require.Equal(t, []string{"some-value", ""}, rdb.HVals(ctx, "test-hash-1").Val())
require.NoError(t, rdb.HSet(ctx, testKey, "field1", "some-value").Err())
require.NoError(t, rdb.HSet(ctx, testKey, "field2", "").Err())

require.NoError(t, rdb.Del(ctx, "test-hash-1").Err())
require.Equal(t, []string{"some-value", ""}, rdb.HVals(ctx, testKey).Val())

require.NoError(t, rdb.Del(ctx, testKey).Err())
})

t.Run("HGETALL - small hash}", func(t *testing.T) {
Expand Down Expand Up @@ -375,12 +379,15 @@ func TestHash(t *testing.T) {
})

t.Run("HGETALL - field with empty string as a value", func(t *testing.T) {
require.NoError(t, rdb.HSet(ctx, "test-hash-1", "field1", "some-value").Err())
require.NoError(t, rdb.HSet(ctx, "test-hash-1", "field2", "").Err())
testKey := "test-hash-1"
require.NoError(t, rdb.Del(ctx, testKey).Err())

require.NoError(t, rdb.HSet(ctx, testKey, "field1", "some-value").Err())
require.NoError(t, rdb.HSet(ctx, testKey, "field2", "").Err())

require.Equal(t, map[string]string{"field1": "some-value", "field2": ""}, rdb.HGetAll(ctx, "test-hash-1").Val())
require.Equal(t, map[string]string{"field1": "some-value", "field2": ""}, rdb.HGetAll(ctx, testKey).Val())

require.NoError(t, rdb.Del(ctx, "test-hash-1").Err())
require.NoError(t, rdb.Del(ctx, testKey).Err())
})

t.Run("HDEL and return value", func(t *testing.T) {
Expand Down Expand Up @@ -762,12 +769,54 @@ func TestHash(t *testing.T) {
})

t.Run("HrangeByLex - field with empty string as a value", func(t *testing.T) {
require.NoError(t, rdb.HSet(ctx, "test-hash-1", "field1", "some-value").Err())
require.NoError(t, rdb.HSet(ctx, "test-hash-1", "field2", "").Err())
testKey := "test-hash-1"
require.NoError(t, rdb.Del(ctx, testKey).Err())

require.Equal(t, []interface{}{"field1", "some-value", "field2", ""}, rdb.Do(ctx, "HrangeByLex", "test-hash-1", "[a", "[z").Val())
require.NoError(t, rdb.HSet(ctx, testKey, "field1", "some-value").Err())
require.NoError(t, rdb.HSet(ctx, testKey, "field2", "").Err())

require.NoError(t, rdb.Del(ctx, "test-hash-1").Err())
require.Equal(t, []interface{}{"field1", "some-value", "field2", ""}, rdb.Do(ctx, "HrangeByLex", testKey, "[a", "[z").Val())
})
}
}

func TestHashWithAsyncIOEnabled(t *testing.T) {
srv := util.StartServer(t, map[string]string{
"rocksdb.read_options.async_io": "yes",
})
defer srv.Close()

rdb := srv.NewClient()
defer func() { require.NoError(t, rdb.Close()) }()

ctx := context.Background()

t.Run("Test bug with large value after compaction", func(t *testing.T) {
testKey := "test-hash-1"
require.NoError(t, rdb.Del(ctx, testKey).Err())

src := rand.NewSource(time.Now().UnixNano())
dd := make([]byte, 5000)
for i := 1; i <= 50; i++ {
for j := range dd {
dd[j] = byte(src.Int63())
}
key := util.RandString(10, 20, util.Alpha)
require.NoError(t, rdb.HSet(ctx, testKey, key, string(dd)).Err())
}

require.EqualValues(t, 50, rdb.HLen(ctx, testKey).Val())
require.Len(t, rdb.HGetAll(ctx, testKey).Val(), 50)
require.Len(t, rdb.HKeys(ctx, testKey).Val(), 50)
require.Len(t, rdb.HVals(ctx, testKey).Val(), 50)

require.NoError(t, rdb.Do(ctx, "COMPACT").Err())

time.Sleep(5 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to be unstable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by unstable? Since the COMPACT command is asynchronous, I add the time.Sleep call here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your explanation :)

Generally, sleep is unpredictable, so it may sleep too short and miss the correct condition. I asked here for more background. If we cannot have a determinate latch for COMPACT completion, I'm OK with current way.


require.EqualValues(t, 50, rdb.HLen(ctx, testKey).Val())
require.Len(t, rdb.HGetAll(ctx, testKey).Val(), 50)
require.Len(t, rdb.HKeys(ctx, testKey).Val(), 50)
require.Len(t, rdb.HVals(ctx, testKey).Val(), 50)
})
}