@@ -153,7 +153,7 @@ func (dc *diskCleaner) DeleteUploadedBlocks(ctx context.Context) int {
153
153
}
154
154
155
155
for _ , block := range blocks {
156
- if ! dc .isBlockDeletable (block ) {
156
+ if ! block . Uploaded || ! dc .isExpired (block ) {
157
157
continue
158
158
}
159
159
@@ -233,7 +233,7 @@ func (dc *diskCleaner) CleanupBlocksWhenHighDiskUtilization(ctx context.Context)
233
233
prevVolumeStats := & diskutil.VolumeStats {}
234
234
filesDeleted := 0
235
235
for _ , block := range blocks {
236
- if ! dc .isBlockDeletable (block ) {
236
+ if ! dc .isExpired (block ) {
237
237
continue
238
238
}
239
239
@@ -289,12 +289,12 @@ func (dc *diskCleaner) CleanupBlocksWhenHighDiskUtilization(ctx context.Context)
289
289
}
290
290
291
291
// isBlockDeletable returns true if this block can be deleted.
292
- func (dc * diskCleaner ) isBlockDeletable (block * tenantBlock ) bool {
292
+ func (dc * diskCleaner ) isExpired (block * tenantBlock ) bool {
293
293
// TODO(kolesnikovae):
294
294
// Expiry defaults to -querier.query-store-after which should be deprecated,
295
295
// blocks-storage.bucket-store.ignore-blocks-within can be used instead.
296
296
expiryTs := time .Now ().Add (- dc .policy .Expiry )
297
- return block . Uploaded && ulid .Time (block .ID .Time ()).Before (expiryTs )
297
+ return ulid .Time (block .ID .Time ()).Before (expiryTs )
298
298
}
299
299
300
300
// blocksByUploadAndAge implements sorting tenantBlock by uploaded then by age
@@ -359,6 +359,32 @@ type realFSBlockManager struct {
359
359
FS fileSystem
360
360
}
361
361
362
+ func (bm * realFSBlockManager ) getUploadedBlockIds (tenantID string ) (map [ulid.ULID ]struct {}, error ) {
363
+ localDirPath := filepath .Join (bm .Root , tenantID , phlareDBLocalPath )
364
+
365
+ shipperPath := filepath .Join (localDirPath , shipper .MetaFilename )
366
+ bytes , err := fs .ReadFile (bm .FS , shipperPath )
367
+ if err != nil {
368
+ if os .IsNotExist (err ) {
369
+ return make (map [ulid.ULID ]struct {}), nil
370
+ }
371
+ return nil , err
372
+ }
373
+
374
+ var meta shipper.Meta
375
+ err = json .Unmarshal (bytes , & meta )
376
+ if err != nil {
377
+ return nil , err
378
+ }
379
+
380
+ uploadedBlockIDs := make (map [ulid.ULID ]struct {}, len (meta .Uploaded ))
381
+ for _ , id := range meta .Uploaded {
382
+ uploadedBlockIDs [id ] = struct {}{}
383
+ }
384
+
385
+ return uploadedBlockIDs , nil
386
+ }
387
+
362
388
func (bm * realFSBlockManager ) GetTenantIDs (ctx context.Context ) ([]string , error ) {
363
389
if ctx .Err () != nil {
364
390
return nil , ctx .Err ()
@@ -391,23 +417,11 @@ func (bm *realFSBlockManager) GetBlocksForTenant(ctx context.Context, tenantID s
391
417
return nil , err
392
418
}
393
419
394
- shipperPath := filepath .Join (localDirPath , shipper .MetaFilename )
395
- bytes , err := fs .ReadFile (bm .FS , shipperPath )
420
+ uploadedBlockIDs , err := bm .getUploadedBlockIds (tenantID )
396
421
if err != nil {
397
422
return nil , err
398
423
}
399
424
400
- var meta shipper.Meta
401
- err = json .Unmarshal (bytes , & meta )
402
- if err != nil {
403
- return nil , err
404
- }
405
-
406
- uploadedBlockIDs := make (map [ulid.ULID ]struct {}, len (meta .Uploaded ))
407
- for _ , id := range meta .Uploaded {
408
- uploadedBlockIDs [id ] = struct {}{}
409
- }
410
-
411
425
// Read blocks.
412
426
blocks := make ([]* tenantBlock , 0 )
413
427
for _ , blockDir := range blockDirs {
0 commit comments