-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBG-3909: use deltas for pv and mv when persisting to the bucket #7096
Changes from all commits
4489b79
1d2adc1
f3c6a7d
f784390
75e9574
0e5f537
3d10502
ac139eb
7af5e2b
857ab82
665b76d
da52e6a
547c706
b94c4c8
902462f
addb767
3d3c510
a0a346a
2b63f97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1735,3 +1735,40 @@ func TestCASToLittleEndianHex(t *testing.T) { | |
littleEndianHex := Uint64CASToLittleEndianHex(casValue) | ||
require.Equal(t, expHexValue, string(littleEndianHex)) | ||
} | ||
|
||
func TestUint64CASToLittleEndianHexAndStripZeros(t *testing.T) { | ||
hexLE := "0x0000000000000000" | ||
u64 := HexCasToUint64(hexLE) | ||
hexLEStripped := Uint64ToLittleEndianHexAndStripZeros(u64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running this test locally, the value of hexLEStripped is "000". Is this what we intend? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good spot, fixed this so now that delta is just 0, also added new test case for this |
||
u64Stripped, err := HexCasToUint64ForDelta([]byte(hexLEStripped)) | ||
require.NoError(t, err) | ||
assert.Equal(t, u64, u64Stripped) | ||
|
||
hexLE = "0xffffffffffffffff" | ||
u64 = HexCasToUint64(hexLE) | ||
hexLEStripped = Uint64ToLittleEndianHexAndStripZeros(u64) | ||
u64Stripped, err = HexCasToUint64ForDelta([]byte(hexLEStripped)) | ||
require.NoError(t, err) | ||
assert.Equal(t, u64, u64Stripped) | ||
|
||
hexLE = "0xd123456e789a0bcf" | ||
u64 = HexCasToUint64(hexLE) | ||
hexLEStripped = Uint64ToLittleEndianHexAndStripZeros(u64) | ||
u64Stripped, err = HexCasToUint64ForDelta([]byte(hexLEStripped)) | ||
require.NoError(t, err) | ||
assert.Equal(t, u64, u64Stripped) | ||
|
||
hexLE = "0xd123456e78000000" | ||
u64 = HexCasToUint64(hexLE) | ||
hexLEStripped = Uint64ToLittleEndianHexAndStripZeros(u64) | ||
u64Stripped, err = HexCasToUint64ForDelta([]byte(hexLEStripped)) | ||
require.NoError(t, err) | ||
assert.Equal(t, u64, u64Stripped) | ||
|
||
hexLE = "0xa500000000000000" | ||
u64 = HexCasToUint64(hexLE) | ||
hexLEStripped = Uint64ToLittleEndianHexAndStripZeros(u64) | ||
u64Stripped, err = HexCasToUint64ForDelta([]byte(hexLEStripped)) | ||
require.NoError(t, err) | ||
assert.Equal(t, u64, u64Stripped) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't binary.LittleEndian.Uint64 expect a length 8 []byte as input? Here it looks like we're setting decoded to MaxDecodedLength (18) - can you help me understand the case where casByte[2:] is longer than 8 bytes but we need to support this and are intentionally ignoring trailing bytes?
I thought this was just handling the case where it's less than 8 bytes because we've trimmed trailing zeros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I don't think the max decoded length line is needed, I have removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, hex.Decode is going to panic if casByte[2:] overflows decoded, so it's possible the previous code was defensive. https://go.dev/play/p/_LEScaOT1FG
Our HexCasToUint64 has an explicit length check to protect against this. Possibly we just want to do the same (but also supporting the case here that the length can be less than 8): doing something like return error
if len(casByte) > 10
at the top of the function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some safety checks around this area, let me know what you think