Skip to content

Commit

Permalink
sumdb/tlog: make NewTiles only generate strictly necessary tiles
Browse files Browse the repository at this point in the history
Currently, NewTiles returns tiles for every partial tree size from
oldTreeSize to newTreeSize. However, if a log is only publishing
checkpoints at oldTreeSize and newTreeSize, the trees of sizes
oldTreeSize+1 to newTreeSize-1 are unverifiable, so those tiles are
unnecessary. Also, NewTiles currently returns tiles that already exists
as part of oldTreeSize, which are not new.

This has a significant performance and cost difference when uploading
tiles individually to e.g. object storage.

Change-Id: I92a5d76bc54e7022991e51997e793356ab5e7d5c
Reviewed-on: https://go-review.googlesource.com/c/mod/+/570295
Auto-Submit: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
  • Loading branch information
FiloSottile authored and gopherbot committed Mar 15, 2024
1 parent 18d3f56 commit 87140ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 4 additions & 6 deletions sumdb/tlog/tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ func NewTiles(h int, oldTreeSize, newTreeSize int64) []Tile {
for level := uint(0); newTreeSize>>(H*level) > 0; level++ {
oldN := oldTreeSize >> (H * level)
newN := newTreeSize >> (H * level)
if oldN == newN {
continue
}
for n := oldN >> H; n < newN>>H; n++ {
tiles = append(tiles, Tile{H: h, L: int(level), N: n, W: 1 << H})
}
n := newN >> H
maxW := int(newN - n<<H)
minW := 1
if oldN > n<<H {
minW = int(oldN - n<<H)
}
for w := minW; w <= maxW; w++ {
if w := int(newN - n<<H); w > 0 {
tiles = append(tiles, Tile{H: h, L: int(level), N: n, W: w})
}
}
Expand Down
26 changes: 26 additions & 0 deletions sumdb/tlog/tile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package tlog

import (
"fmt"
"testing"
)

Expand All @@ -22,3 +23,28 @@ func FuzzParseTilePath(f *testing.F) {
ParseTilePath(path)
})
}

func TestNewTilesForSize(t *testing.T) {
for _, tt := range []struct {
old, new int64
want int
}{
{1, 1, 0},
{100, 101, 1},
{1023, 1025, 3},
{1024, 1030, 1},
{1030, 2000, 1},
{1030, 10000, 10},
{49516517, 49516586, 3},
} {
t.Run(fmt.Sprintf("%d-%d", tt.old, tt.new), func(t *testing.T) {
tiles := NewTiles(10, tt.old, tt.new)
if got := len(tiles); got != tt.want {
t.Errorf("got %d, want %d", got, tt.want)
for _, tile := range tiles {
t.Logf("%+v", tile)
}
}
})
}
}

0 comments on commit 87140ec

Please sign in to comment.