Skip to content

Commit cffa73b

Browse files
committed
Fix Redis cache index accounting bugs
- Evict: Skip decrementing build counters when size is 0 to avoid corrupting per-build aggregates when cleaning ghost entries - cleanFromBucket: Call index.Evict for bucket-driven deletes to keep Redis synchronized with GCS state
1 parent 585d7e8 commit cffa73b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/orchestrator/cmd/clean-rapid-cache/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func clean(ctx context.Context, bucket string, prefix string, cutoff time.Time,
7979
return nil
8080
}
8181

82-
return cleanFromBucket(ctx, client, bucket, prefix, cutoff, maxDeletions, dryRun)
82+
return cleanFromBucket(ctx, client, bucket, prefix, cutoff, maxDeletions, dryRun, index)
8383
}
8484

8585
func cleanFromIndex(ctx context.Context, client *gcs.Client, bucket string, cutoff time.Time, maxDeletions int, dryRun bool, index storage.RapidCacheIndex) (int, error) {
@@ -117,7 +117,7 @@ func cleanFromIndex(ctx context.Context, client *gcs.Client, bucket string, cuto
117117
return deleted, nil
118118
}
119119

120-
func cleanFromBucket(ctx context.Context, client *gcs.Client, bucket string, prefix string, cutoff time.Time, maxDeletions int, dryRun bool) error {
120+
func cleanFromBucket(ctx context.Context, client *gcs.Client, bucket string, prefix string, cutoff time.Time, maxDeletions int, dryRun bool, index storage.RapidCacheIndex) error {
121121
var scanned, matched, deleted int
122122
objects := client.Bucket(bucket).Objects(ctx, &gcs.Query{Prefix: prefix})
123123
for {
@@ -145,6 +145,7 @@ func cleanFromBucket(ctx context.Context, client *gcs.Client, bucket string, pre
145145
if err := client.Bucket(bucket).Object(attrs.Name).Delete(ctx); err != nil {
146146
return fmt.Errorf("delete cache object: %w", err)
147147
}
148+
_ = index.Evict(ctx, attrs.Name, attrs.Size)
148149
deleted++
149150
}
150151

packages/shared/pkg/storage/storage_cache_rapid_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (i *redisRapidCacheIndex) Evict(ctx context.Context, path string, size int6
9292
buildID := rapidCacheBuildID(path)
9393
pipe := i.redis.Pipeline()
9494
pipe.ZRem(ctx, i.keys.chunks, path)
95-
if buildID != "" {
95+
if buildID != "" && size > 0 {
9696
pipe.HIncrBy(ctx, i.keys.buildBytes, buildID, -size)
9797
pipe.HIncrBy(ctx, i.keys.buildChunks, buildID, -1)
9898
}

0 commit comments

Comments
 (0)