mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
fix(server): Fix hset buffer bug (#994)
Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
This commit is contained in:
parent
72f67eddd8
commit
0c83b09aea
2 changed files with 13 additions and 3 deletions
|
@ -1101,15 +1101,15 @@ StringMap* HSetFamily::ConvertToStrMap(uint8_t* lp) {
|
|||
sm->Reserve(lplen / 2);
|
||||
|
||||
uint8_t* lp_elem = lpFirst(lp);
|
||||
uint8_t intbuf[LP_INTBUF_SIZE];
|
||||
uint8_t intbuf[2][LP_INTBUF_SIZE];
|
||||
|
||||
DCHECK(lp_elem); // empty containers are not allowed.
|
||||
|
||||
do {
|
||||
string_view key = LpGetView(lp_elem, intbuf);
|
||||
string_view key = LpGetView(lp_elem, intbuf[0]);
|
||||
lp_elem = lpNext(lp, lp_elem); // switch to value
|
||||
DCHECK(lp_elem);
|
||||
string_view value = LpGetView(lp_elem, intbuf);
|
||||
string_view value = LpGetView(lp_elem, intbuf[1]);
|
||||
lp_elem = lpNext(lp, lp_elem); // switch to next key
|
||||
CHECK(sm->AddOrUpdate(key, value)); // must be unique
|
||||
} while (lp_elem);
|
||||
|
|
|
@ -215,4 +215,14 @@ TEST_F(HSetFamilyTest, HSetEx) {
|
|||
EXPECT_THAT(Run({"HGET", "k", "f"}), ArgType(RespExpr::NIL));
|
||||
}
|
||||
|
||||
TEST_F(HSetFamilyTest, TriggerConvertToStrMap) {
|
||||
const int kElements = 200;
|
||||
// Enough for IsGoodForListpack to become false
|
||||
for (size_t i = 0; i < kElements; i++) {
|
||||
auto k = absl::StrCat(100500700u + i);
|
||||
Run({"HSET", "hk", k, "100500700"});
|
||||
}
|
||||
EXPECT_THAT(Run({"HLEN", "hk"}), IntArg(kElements));
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue