https://github.com/redis/redis/blob/unstable/src/ziplist.c#L1111
target = __ziplistCascadeUpdate(target, target+first_offset);
Is there something wrong (a bug) about the first_offset is used here?
I think the order of the two string first and second should be consider.
When the second string is stored before the first in target, the second_offset should be used, not the first_offset.
The right code may be
size_t cascade_offset = append? first_offset : second_offset;
target = __ziplistCascadeUpdate(target, target+ cascade_offset);
Is that right?
Comment From: oranagra
I don't think so (the current code looks ok).
first_offset is the tail offset (ZIPLIST_TAIL_OFFSET) of the first ziplist, i.e. the byte offset of the last record in the ziplist (the one that went first into the target).
so that's where we should start the search for the cascade effect (to update prevlen).
it doesn't matter which one of them got reallocated, and if was memmoveed or memcpied, all it matters is to find the last record of the one that comes first in the target.
If you feel i may be wrong, it's probably not too hard to write a test for it (at the bottom of ziplist.c), so i invite you to add it (and i'll merge it either way, even without a bug fix)
Comment From: BottomCoder-Ander
it doesn't matter which one of them got reallocated, and if was
memmoveed ormemcpied, all it matters is to find the last record of the one that comes first in the target.If you feel i may be wrong, it's probably not too hard to write a test for it (at the bottom of ziplist.c), so i invite you to add it (and i'll merge it either way, even without a bug fix)
I have misunderstand. Thank you for your reply.