Skip to content

Commit

Permalink
Generated leaves start at the size of the tree
Browse files Browse the repository at this point in the history
Without this change the generated leaves always start at size 0, which
means many writes are squashable as duplicates on the second run of the
tool. With this change, generated leaves will be unique except where the
intended duplicate generation code kicks in.
  • Loading branch information
mhutchinson committed May 21, 2024
1 parent 7754f4c commit 660ad42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hammer/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (r *LeafReader) Run(ctx context.Context) {
klog.V(2).Infof("LeafReader getting %d", i)
_, err := r.getLeaf(ctx, i, size)
if err != nil {
r.errchan <- fmt.Errorf("failed to get leaf: %v", err)
r.errchan <- fmt.Errorf("failed to get leaf %d: %v", i, err)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions hammer/hammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
MaxIdleConnsPerHost: 256,
DisableKeepAlives: false,
},
Timeout: 5 * time.Second,
}
)

Expand Down Expand Up @@ -129,7 +130,7 @@ func NewHammer(tracker *client.LogStateTracker, f client.Fetcher, addURL *url.UR
for i := 0; i < *numReadersFull; i++ {
fullReaders[i] = NewLeafReader(tracker, f, MonotonicallyIncreasingNextLeaf(), *leafBundleSize, readThrottle.tokenChan, errChan)
}
gen := newLeafGenerator()
gen := newLeafGenerator(tracker.LatestConsistent.Size)
for i := 0; i < *numWriters; i++ {
writers[i] = NewLogWriter(hc, addURL, gen, writeThrottle.tokenChan, errChan)
}
Expand Down Expand Up @@ -207,11 +208,11 @@ func (h *Hammer) Run(ctx context.Context) {
}()
}

func newLeafGenerator() func() []byte {
func newLeafGenerator(start uint64) func() []byte {
const dupChance = 0.1
var g int64
var g uint64 = start
return func() []byte {
var r int64
var r uint64
if rand.Float64() <= dupChance {
// This one will actually be unique, but the next iteration will
// duplicate it. In future, this duplication could be randomly
Expand Down

0 comments on commit 660ad42

Please sign in to comment.