Skip to content

Commit d0376ae

Browse files
committed
ctlog: build partial names tile from data tile instead of fetching it
1 parent c6152c7 commit d0376ae

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

internal/ctlog/ctlog.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ func LoadLog(ctx context.Context, config *Config) (*Log, error) {
263263
}
264264
edgeTiles[-1] = dataTile
265265

266-
// Verify the data tile against the level 0 tile.
266+
// Verify the data tile against the level 0 tile, and build the partial names tile.
267+
namesTile := edgeTiles[0]
268+
namesTile.L = -2
269+
namesTile.B = nil
267270
b := edgeTiles[-1].B
268271
start := sunlight.TileWidth * dataTile.N
269272
for i := start; i < start+int64(dataTile.W); i++ {
@@ -281,20 +284,17 @@ func LoadLog(ctx context.Context, config *Config) (*Log, error) {
281284
if got != exp {
282285
return nil, fmt.Errorf("tile leaf entry %d hashes to %v, level 0 hash is %v", i, got, exp)
283286
}
284-
}
285287

286-
// Fetch the right-most names tile.
287-
namesTile := edgeTiles[0]
288-
namesTile.L = -2
289-
namesTile.B, err = fetchAndDecompress(ctx, config.Backend, namesTile.Path())
290-
if err != nil {
291-
// Names tiles are a best effort, and a new feature.
292-
config.Log.ErrorContext(ctx, "couldn't fetch right edge names tile", "err", err)
293-
} else {
294-
edgeTiles[-2] = namesTile
295-
296-
// TODO: Verify the names tile against the data tile.
288+
if tl, err := e.TrimmedEntry(); err != nil {
289+
config.Log.ErrorContext(ctx, "failed to trim entry", "err", err)
290+
} else if line, err := json.Marshal(tl); err != nil {
291+
config.Log.ErrorContext(ctx, "failed to encode entry for names tile", "err", err)
292+
} else {
293+
namesTile.B = append(namesTile.B, line...)
294+
namesTile.B = append(namesTile.B, '\n')
295+
}
297296
}
297+
edgeTiles[-2] = namesTile
298298
}
299299
for _, t := range edgeTiles {
300300
config.Log.DebugContext(ctx, "edge tile", "tile", t)

0 commit comments

Comments
 (0)