From cd3ef9a436114917d27738791c9b68b5829942d8 Mon Sep 17 00:00:00 2001 From: Shahar Mike Date: Tue, 10 Dec 2024 10:44:52 +0200 Subject: [PATCH] fix: Do not attempt to defrag `StringSet` as a `StringMap` (#4283) That'd be a total waste of time and energy, not to mention you'll crash. Fixes #4167 --- src/core/compact_object.cc | 4 ++-- src/core/compact_object_test.cc | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core/compact_object.cc b/src/core/compact_object.cc index cb884c425a86..d885b2b5e5d6 100644 --- a/src/core/compact_object.cc +++ b/src/core/compact_object.cc @@ -215,9 +215,9 @@ pair DefragSet(unsigned encoding, void* ptr, float ratio) { return DefragIntSet((intset*)ptr, ratio); } - // StringMap supports re-allocation of it's internal nodes case kEncodingStrMap2: { - return DefragStrMap2((StringMap*)ptr, ratio); + // Still not implemented + return {ptr, false}; } default: diff --git a/src/core/compact_object_test.cc b/src/core/compact_object_test.cc index bff60e3f43b9..601936dfb62b 100644 --- a/src/core/compact_object_test.cc +++ b/src/core/compact_object_test.cc @@ -16,6 +16,7 @@ #include "core/detail/bitpacking.h" #include "core/flat_set.h" #include "core/mi_memory_resource.h" +#include "core/string_set.h" extern "C" { #include "redis/intset.h" @@ -575,6 +576,14 @@ TEST_F(CompactObjectTest, DefragHash) { } } +TEST_F(CompactObjectTest, DefragSet) { + // This is still not implemented + StringSet* s = new StringSet(); + s->Add("str"); + cobj_.InitRobj(OBJ_SET, kEncodingStrMap2, s); + ASSERT_FALSE(cobj_.DefragIfNeeded(0.8)); +} + TEST_F(CompactObjectTest, RawInterface) { string str(50, 'a'), tmp, owned; cobj_.SetString(str);