Skip to content

Commit 7fc43fc

Browse files
committed
PR feedback: i->blockIdx, restore comments
1 parent 6b71c54 commit 7fc43fc

File tree

1 file changed

+7
-3
lines changed
  • packages/orchestrator/pkg/sandbox/block

1 file changed

+7
-3
lines changed

packages/orchestrator/pkg/sandbox/block/cache.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,21 @@ func (c *Cache) Slice(off, length int64) ([]byte, error) {
248248
return nil, BytesNotAvailableError{}
249249
}
250250

251-
func (c *Cache) isBlockCached(i int64) bool {
252-
if i < 0 || i >= int64(len(c.dirty))*64 {
251+
func (c *Cache) isBlockCached(blockIdx int64) bool {
252+
if blockIdx < 0 || blockIdx >= int64(len(c.dirty))*64 {
253253
return false
254254
}
255255

256-
return c.dirty[i/64].Load()&(1<<uint(i%64)) != 0
256+
return c.dirty[blockIdx/64].Load()&(1<<uint(blockIdx%64)) != 0
257257
}
258258

259259
func (c *Cache) isCached(off, length int64) bool {
260+
// Make sure the offset is within the cache size
260261
if off >= c.size {
261262
return false
262263
}
263264

265+
// Cap if the length goes beyond the cache size, so we don't check for blocks that are out of bounds.
264266
end := min(off+length, c.size)
265267
start := off / c.blockSize
266268
n := (end + c.blockSize - 1) / c.blockSize
@@ -327,6 +329,8 @@ func (c *Cache) WriteAtWithoutLock(b []byte, off int64) (int, error) {
327329
return n, nil
328330
}
329331

332+
// dirtySortedKeys returns a sorted list of dirty keys.
333+
// Key represents a block offset.
330334
func (c *Cache) dirtySortedKeys() []int64 {
331335
var keys []int64
332336

0 commit comments

Comments
 (0)