Skip to content

fix(bitmap): align BITFIELD bit order with Redis#3565

Open
maoyouaa wants to merge 1 commit into
apache:unstablefrom
maoyouaa:mao/fix-bitfield-bitmap-bit-order
Open

fix(bitmap): align BITFIELD bit order with Redis#3565
maoyouaa wants to merge 1 commit into
apache:unstablefrom
maoyouaa:mao/fix-bitfield-bitmap-bit-order

Conversation

@maoyouaa

Copy link
Copy Markdown
Contributor

Summary

  • Align BITFIELD and BITFIELD_RO on bitmap keys with Redis bit ordering by reversing bits at the bitmap storage boundary.
  • Use a fixed 9-byte stack buffer for bitmap-to-bitfield conversion.
  • Add regression coverage for signed values, overflow modes, sparse bitmaps, missing data, and segment boundaries.

Root cause

Kvrocks bitmap segments store bits in LSB order, while BITFIELD interprets byte buffers in MSB order. The bitmap conversion path copied bytes directly, producing results inconsistent with Redis and with GET/GETBIT.

Compatibility

Bitmap values written by older versions through the incorrect BITFIELD path have no format marker and cannot be distinguished automatically. This change preserves the existing bitmap LSB storage format and fixes conversion at the BITFIELD boundary.

Validation

  • Docker GCC build
  • Go TestBitmap
  • Redis 7 comparison for signed values, overflow behavior, and sparse reads
  • clang-format, focused clang-tidy, and git diff --check

Closes #2500

@PragmaTwice PragmaTwice left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent behavior with Redis in BITFIELD GET command

2 participants