Skip to content

Commit 87140ec

Browse files
FiloSottilegopherbot
authored andcommitted
sumdb/tlog: make NewTiles only generate strictly necessary tiles
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 18d3f56 commit 87140ec

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

sumdb/tlog/tile.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,14 @@ func NewTiles(h int, oldTreeSize, newTreeSize int64) []Tile {
115115
for level := uint(0); newTreeSize>>(H*level) > 0; level++ {
116116
oldN := oldTreeSize >> (H * level)
117117
newN := newTreeSize >> (H * level)
118+
if oldN == newN {
119+
continue
120+
}
118121
for n := oldN >> H; n < newN>>H; n++ {
119122
tiles = append(tiles, Tile{H: h, L: int(level), N: n, W: 1 << H})
120123
}
121124
n := newN >> H
122-
maxW := int(newN - n<<H)
123-
minW := 1
124-
if oldN > n<<H {
125-
minW = int(oldN - n<<H)
126-
}
127-
for w := minW; w <= maxW; w++ {
125+
if w := int(newN - n<<H); w > 0 {
128126
tiles = append(tiles, Tile{H: h, L: int(level), N: n, W: w})
129127
}
130128
}

sumdb/tlog/tile_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package tlog
66

77
import (
8+
"fmt"
89
"testing"
910
)
1011

@@ -22,3 +23,28 @@ func FuzzParseTilePath(f *testing.F) {
2223
ParseTilePath(path)
2324
})
2425
}
26+
27+
func TestNewTilesForSize(t *testing.T) {
28+
for _, tt := range []struct {
29+
old, new int64
30+
want int
31+
}{
32+
{1, 1, 0},
33+
{100, 101, 1},
34+
{1023, 1025, 3},
35+
{1024, 1030, 1},
36+
{1030, 2000, 1},
37+
{1030, 10000, 10},
38+
{49516517, 49516586, 3},
39+
} {
40+
t.Run(fmt.Sprintf("%d-%d", tt.old, tt.new), func(t *testing.T) {
41+
tiles := NewTiles(10, tt.old, tt.new)
42+
if got := len(tiles); got != tt.want {
43+
t.Errorf("got %d, want %d", got, tt.want)
44+
for _, tile := range tiles {
45+
t.Logf("%+v", tile)
46+
}
47+
}
48+
})
49+
}
50+
}

0 commit comments

Comments
 (0)