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: Bitmap type DUMP/RESTORE command support #2535

Merged
merged 5 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion src/storage/rdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#include "rdb_listpack.h"
#include "rdb_ziplist.h"
#include "rdb_zipmap.h"
#include "storage/redis_metadata.h"
#include "time_util.h"
#include "types/redis_bitmap.h"
#include "types/redis_bitmap_string.h"
#include "types/redis_hash.h"
#include "types/redis_list.h"
#include "types/redis_set.h"
Expand Down Expand Up @@ -718,7 +721,7 @@ Status RDB::Dump(const std::string &key, const RedisType type) {

Status RDB::SaveObjectType(const RedisType type) {
int robj_type = -1;
if (type == kRedisString) {
if (type == kRedisString || type == kRedisBitmap) {
robj_type = RDBTypeString;
} else if (type == kRedisHash) {
robj_type = RDBTypeHash;
Expand Down Expand Up @@ -781,6 +784,16 @@ Status RDB::SaveObject(const std::string &key, const RedisType type) {
}

return SaveHashObject(field_values);
} else if (type == kRedisBitmap) {
std::string value;
redis::Bitmap bitmap_db(storage_, ns_);
Config *config = storage_->GetConfig();
uint32_t max_btos_size = static_cast<uint32_t>(config->max_bitmap_to_string_mb) * MiB;
auto s = bitmap_db.GetString(ctx, key, max_btos_size, &value);
Copy link
Member

Choose a reason for hiding this comment

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

@git-hulk would this meet the same issue like lsb to msb?

if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
}
return SaveStringObject(value);
} else {
LOG(WARNING) << "Invalid or Not supported object type: " << type;
return {Status::NotOK, "Invalid or Not supported object type"};
Expand Down
18 changes: 18 additions & 0 deletions tests/gocase/unit/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ func TestDump_Set(t *testing.T) {
require.NoError(t, rdb.RestoreReplace(ctx, restoredKey, 0, serialized).Err())
require.ElementsMatch(t, members, rdb.SMembers(ctx, restoredKey).Val())
}

func TestDump_Bitset(t *testing.T) {
srv := util.StartServer(t, map[string]string{})
defer srv.Close()

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

key := "bitsetKey1"
require.NoError(t, rdb.SetBit(ctx, key, 1, 1).Err())
serialized, err := rdb.Dump(ctx, key).Result()
require.NoError(t, err)

restoredKey := fmt.Sprintf("restore_%s", key)
require.NoError(t, rdb.RestoreReplace(ctx, restoredKey, 0, serialized).Err())
require.Equal(t, rdb.Get(ctx, key).Val(), rdb.Get(ctx, restoredKey).Val())
}
Loading