Skip to content

Commit

Permalink
oh my, what am i doing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutchinson committed Dec 5, 2024
1 parent 5500ecf commit 5f73ad1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions storage/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,16 @@ func (s *Storage) ReadTile(ctx context.Context, level, index, minTreeSize uint64

// 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
startOfTileSize := (1 << ((1 + level) * 8)) * index // Size of perfect tree if this tile had 0 entries in it

numEntries := uint64(len(tile) / 32)
entriesPerPerfectSubtree := uint64(1 << (level * 8)) // Each leaf at this level implies this many permanent entries in the tree

minPermanentEntries := numEntries * uint64(entriesPerLevel)
minPermanentEntries := startOfTileSize + numEntries*uint64(entriesPerPerfectSubtree)

if minTreeSize > minPermanentEntries {
// If the user has requested a size larger than we have, they can't have it
return nil, os.ErrNotExist
return nil, fmt.Errorf("Requested tree size %d but tree size is %d: %w", minTreeSize, minPermanentEntries, os.ErrNotExist)
}

return tile, nil
Expand Down

0 comments on commit 5f73ad1

Please sign in to comment.