Skip to content

Commit

Permalink
crdbtest: fix MaterializeUserKey
Browse files Browse the repository at this point in the history
The KeySeeker implementation accidentally materialized four bytes of the wall
time as the logical time when encoding a MVCC timestamp with a non-zero logical
time.
  • Loading branch information
jbowens committed Oct 18, 2024
1 parent ac9b0f7 commit dff8179
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/crdbtest/crdbtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,10 @@ func (ks *cockroachKeySeeker) MaterializeUserKey(
}

// Inline binary.BigEndian.PutUint32.
*(*byte)(ptr) = byte(mvccWall >> 24)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 1)) = byte(mvccWall >> 16)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 2)) = byte(mvccWall >> 8)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 3)) = byte(mvccWall)
*(*byte)(ptr) = byte(mvccLogical >> 24)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 1)) = byte(mvccLogical >> 16)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 2)) = byte(mvccLogical >> 8)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 3)) = byte(mvccLogical)
*(*byte)(unsafe.Pointer(uintptr(ptr) + 4)) = 13
return ki.Buf[:len(ki.Buf)+14]
}
Expand Down
1 change: 1 addition & 0 deletions sstable/colblk/cockroach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestCockroachDataBlock(t *testing.T) {
serializedBlock, keys, values := generateDataBlock(rng, targetBlockSize, crdbtest.KeyConfig{
PrefixAlphabetLen: 26,
PrefixLen: 12,
PercentLogical: rng.IntN(25),
AvgKeysPerPrefix: 2,
BaseWallTime: seed,
}, valueLen)
Expand Down

0 comments on commit dff8179

Please sign in to comment.