garnet icon indicating copy to clipboard operation
garnet copied to clipboard

Bug title: BITPOS failing at bit 0

Open hamdaankhalid opened this issue 1 year ago • 2 comments

Describe the bug

The command BITPOS for check for the first bit being 0 when the bits are all zeroe'd out is returning -1.

Steps to reproduce the bug

Result and response in Garnet with Redis CLI

172.18.224.1:6379> BITPOS mybitmap 0 0
(integer) 0
172.18.224.1:6379> SETBIT mybitmap 63 0
(integer) 0
172.18.224.1:6379> BITPOS mybitmap 0 1
(integer) -1
172.18.224.1:6379> BITPOS mybitmap 0 0
(integer) -1

Expected behavior

Result and response with Redis Server and Redis CLI

not connected> SETBIT mybitmap 0 0
(integer) 0
127.0.0.1:6379> SETBIT mybitmap 63 0
(integer) 0
127.0.0.1:6379> BITPOS mybitmap 0 1
(integer) 8
127.0.0.1:6379> BITPOS mybitmap 0 0
(integer) 0

Screenshots

No response

Release version

No response

IDE

No response

OS version

No response

Additional context

No response

hamdaankhalid avatar Oct 11 '24 02:10 hamdaankhalid

Error is coming from https://github.com/microsoft/garnet/blob/e3c8a2064852d733285886252f450faa6a1e3d28/libs/server/Resp/Bitmap/BitmapManagerBitPos.cs#L185

hamdaankhalid avatar Oct 11 '24 03:10 hamdaankhalid

In the case where i am looking for the first 0 in all 0's this flips it and exits, which is not the expected behavior here.

hamdaankhalid avatar Oct 11 '24 03:10 hamdaankhalid

Fixed with #724

vazois avatar Oct 16 '24 17:10 vazois