Skip to content

Commit

Permalink
[rhythm] Fix ID generator copy bug (#4540)
Browse files Browse the repository at this point in the history
* [rhythm] Fix ID generator copy bug

* Add test
  • Loading branch information
mapno authored Jan 13, 2025
1 parent e709f8a commit b6a86e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/blockbuilder/util/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewDeterministicIDGenerator(tenantID string, seeds ...uint64) *Deterministi
func newBuf(tenantID []byte, seeds []uint64) []byte {
dl, sl := len(tenantID), len(seeds)
data := make([]byte, dl+sl*8+8) // tenantID bytes + 8 bytes per uint64 + 8 bytes for seq
copy(tenantID, data)
copy(data, tenantID)

for i, seed := range seeds {
binary.LittleEndian.PutUint64(data[dl+i*8:], seed)
Expand Down
12 changes: 12 additions & 0 deletions modules/blockbuilder/util/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func TestDeterministicIDGenerator(t *testing.T) {
}
}

func TestDeterministicIDGeneratorWithDifferentTenants(t *testing.T) {
ts := time.Now().UnixMilli()
seed := uint64(42)

gen1 := NewDeterministicIDGenerator("tenant-1", seed, uint64(ts))
gen2 := NewDeterministicIDGenerator("tenant-2", seed, uint64(ts))

for i := 0; i < 10; i++ {
assert.NotEqualf(t, gen1.NewID(), gen2.NewID(), "IDs should be different")
}
}

func FuzzDeterministicIDGenerator(f *testing.F) {
f.Skip()

Expand Down

0 comments on commit b6a86e2

Please sign in to comment.