Skip to content

Commit

Permalink
Better
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutchinson committed Dec 5, 2024
1 parent b5a681b commit 5500ecf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cmd/conformance/mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func configureTilesReadAPI(mux *http.ServeMux, storage *mysql.Storage) {
}
return
}
impliedSize := (index*256 + width) << (level * 8)
tile, err := storage.ReadTile(r.Context(), level, index, impliedSize)
inferredMinTreeSize := (index*256 + width) << (level * 8)
tile, err := storage.ReadTile(r.Context(), level, index, inferredMinTreeSize)
if err != nil {
if os.IsNotExist(err) {
w.WriteHeader(http.StatusNotFound)
Expand Down
23 changes: 10 additions & 13 deletions storage/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (s *Storage) writeTreeState(ctx context.Context, tx *sql.Tx, size uint64, r
// 3. Partial tile request with full/larger partial tile output: Return trimmed partial tile with correct tile width.
// 4. Partial tile request with partial tile (same width) output: Return partial tile.
// 5. Partial tile request with smaller partial tile output: Return error.
func (s *Storage) ReadTile(ctx context.Context, level, index, treeSize uint64) ([]byte, error) {
func (s *Storage) ReadTile(ctx context.Context, level, index, minTreeSize uint64) ([]byte, error) {
row := s.db.QueryRowContext(ctx, selectSubtreeByLevelAndIndexSQL, level, index)
if err := row.Err(); err != nil {
return nil, err
Expand All @@ -258,20 +258,17 @@ func (s *Storage) ReadTile(ctx context.Context, level, index, treeSize uint64) (

return nil, fmt.Errorf("scan tile: %v", err)
}
if false {
numEntries := uint64(len(tile) / 32)

// A tile at this height implies this many
// modulus := 1 << (level * 8)
width := treeSize % 256
if width == 0 {
width = 256
}
// Do some validation to make sure we don't return data at a tree size we haven't reached yet
// Doing so could break caching at a higher level
entriesPerLevel := 1 << level * 8
numEntries := uint64(len(tile) / 32)

if width > numEntries {
// If the user has requested more entries than we have, then return not found.
return nil, os.ErrNotExist
}
minPermanentEntries := numEntries * uint64(entriesPerLevel)

if minTreeSize > minPermanentEntries {
// If the user has requested a size larger than we have, they can't have it
return nil, os.ErrNotExist
}

return tile, nil
Expand Down

0 comments on commit 5500ecf

Please sign in to comment.