Skip to content

Commit 6a120a7

Browse files
committed
linting and fixes
1 parent 3d1c463 commit 6a120a7

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,7 @@ func (c *Cache) copyProcessMemory(
516516
return fmt.Errorf("failed to read memory: expected %d bytes, got %d", segmentSize, n)
517517
}
518518

519-
startBlock := uint(header.BlockIdx(offset, c.blockSize))
520-
endBlock := uint(header.BlockIdx(offset+segmentSize-1, c.blockSize))
521-
c.dirtyMu.Lock()
522-
for i := startBlock; i <= endBlock; i++ {
523-
c.dirty.Set(i)
524-
}
525-
c.dirtyMu.Unlock()
519+
c.setIsCached(offset, segmentSize)
526520

527521
offset += segmentSize
528522

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package block
22

33
import (
4+
"fmt"
45
"os"
56
"testing"
67

@@ -30,7 +31,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
3031
b.ReportAllocs()
3132
b.ResetTimer()
3233

33-
for i := 0; i < b.N; i++ {
34+
for i := range b.N {
3435
// Simulate marking a block as cached
3536
off := int64(i%262144) * blockSize
3637
cache.setIsCached(off, blockSize)
@@ -39,14 +40,14 @@ func BenchmarkDirtyTracking(b *testing.B) {
3940

4041
b.Run("IsCached_Hit", func(b *testing.B) {
4142
// Pre-populate some blocks as cached
42-
for i := int64(0); i < 1000; i++ {
43+
for i := range int64(1000) {
4344
cache.setIsCached(i*blockSize, blockSize)
4445
}
4546

4647
b.ReportAllocs()
4748
b.ResetTimer()
4849

49-
for i := 0; i < b.N; i++ {
50+
for i := range b.N {
5051
off := int64(i%1000) * blockSize
5152
cache.isCached(off, blockSize)
5253
}
@@ -56,7 +57,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
5657
b.ReportAllocs()
5758
b.ResetTimer()
5859

59-
for i := 0; i < b.N; i++ {
60+
for i := range b.N {
6061
// Check blocks that are definitely not cached (high offsets)
6162
off := int64(100000+i%100000) * blockSize
6263
cache.isCached(off, blockSize)
@@ -67,7 +68,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
6768
b.ReportAllocs()
6869
b.ResetTimer()
6970

70-
for i := 0; i < b.N; i++ {
71+
for i := range b.N {
7172
off := int64(i%262144) * blockSize
7273
cache.WriteAt(data, off)
7374
}
@@ -80,7 +81,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
8081
b.ReportAllocs()
8182
b.ResetTimer()
8283

83-
for i := 0; i < b.N; i++ {
84+
for i := range b.N {
8485
off := int64(i%65536) * blockSize * 4
8586
cache.WriteAt(multiBlockData, off)
8687
}
@@ -104,15 +105,15 @@ func BenchmarkDirtySortedKeys(b *testing.B) {
104105
defer cache.Close()
105106

106107
// Mark 10% of blocks as dirty (26214 blocks)
107-
for i := int64(0); i < 26214; i++ {
108+
for i := range int64(26214) {
108109
cache.setIsCached(i*blockSize, blockSize)
109110
}
110111

111112
b.Run("DirtySortedKeys_10pct", func(b *testing.B) {
112113
b.ReportAllocs()
113114
b.ResetTimer()
114115

115-
for i := 0; i < b.N; i++ {
116+
for range b.N {
116117
keys := cache.dirtySortedKeys()
117118
_ = keys
118119
}
@@ -138,7 +139,7 @@ func BenchmarkCacheCreation(b *testing.B) {
138139
b.ReportAllocs()
139140
b.ResetTimer()
140141

141-
for i := 0; i < b.N; i++ {
142+
for range b.N {
142143
tmpFile := b.TempDir() + "/bench_cache"
143144
cache, err := NewCache(size, blockSize, tmpFile, false)
144145
if err != nil {
@@ -160,10 +161,10 @@ func formatSize(bytes int64) string {
160161

161162
switch {
162163
case bytes >= GB:
163-
return string(rune('0'+bytes/GB)) + "GB"
164+
return fmt.Sprintf("%dGB", bytes/GB)
164165
case bytes >= MB:
165-
return string(rune('0'+bytes/MB)) + "MB"
166+
return fmt.Sprintf("%dMB", bytes/MB)
166167
default:
167-
return string(rune('0'+bytes/KB)) + "KB"
168+
return fmt.Sprintf("%dKB", bytes/KB)
168169
}
169170
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestSetIsCached_ZeroLengthAtNonZeroOffset(t *testing.T) {
8282
cache.setIsCached(blockSize*5, 0)
8383

8484
// No blocks should be marked as cached
85-
for i := int64(0); i < 10; i++ {
85+
for i := range int64(10) {
8686
result := cache.isCached(i*blockSize, blockSize)
8787
assert.False(t, result, "block %d should not be cached after zero-length setIsCached", i)
8888
}
@@ -126,7 +126,7 @@ func TestWriteAt_PartiallyBeyondCacheSize(t *testing.T) {
126126
assert.Equal(t, int(blockSize), n, "should only write up to cache size")
127127

128128
// Only block 9 should be marked as cached (the portion that fit)
129-
for i := int64(0); i < 10; i++ {
129+
for i := range int64(10) {
130130
if i == 9 {
131131
assert.True(t, cache.isCached(i*blockSize, blockSize), "block 9 should be cached")
132132
} else {
@@ -161,7 +161,7 @@ func TestDirtyTracking_NormalOperation(t *testing.T) {
161161
defer cache.Close()
162162

163163
// Initially nothing is cached
164-
for i := int64(0); i < 10; i++ {
164+
for i := range int64(10) {
165165
assert.False(t, cache.isCached(i*blockSize, blockSize), "block %d should not be initially cached", i)
166166
}
167167

@@ -172,7 +172,7 @@ func TestDirtyTracking_NormalOperation(t *testing.T) {
172172
assert.Equal(t, int(blockSize), n)
173173

174174
// Only block 3 should be cached
175-
for i := int64(0); i < 10; i++ {
175+
for i := range int64(10) {
176176
if i == 3 {
177177
assert.True(t, cache.isCached(i*blockSize, blockSize), "block 3 should be cached")
178178
} else {
@@ -188,7 +188,7 @@ func TestDirtyTracking_NormalOperation(t *testing.T) {
188188

189189
// Blocks 3, 5, 6, 7 should be cached
190190
expected := map[int64]bool{3: true, 5: true, 6: true, 7: true}
191-
for i := int64(0); i < 10; i++ {
191+
for i := range int64(10) {
192192
if expected[i] {
193193
assert.True(t, cache.isCached(i*blockSize, blockSize), "block %d should be cached", i)
194194
} else {

0 commit comments

Comments
 (0)