Skip to content

Commit d8cb7f1

Browse files
authored
Cleaner would delete bucket index when there is no block in bucket store (#6577)
* Cleaner would delete bucket index and sync status file if there is no block in bucket store Signed-off-by: Alex Le <[email protected]> * fix test Signed-off-by: Alex Le <[email protected]> * updated CHANGELOG Signed-off-by: Alex Le <[email protected]> --------- Signed-off-by: Alex Le <[email protected]>
1 parent 5b53a48 commit d8cb7f1

File tree

6 files changed

+89
-26
lines changed

6 files changed

+89
-26
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* [ENHANCEMENT] Query Frontend: Add a `too_many_tenants` reason label value to `cortex_rejected_queries_total` metric to track the rejected query count due to the # of tenant limits. #6569
99
* [BUGFIX] Ingester: Avoid error or early throttling when READONLY ingesters are present in the ring #6517
1010
* [BUGFIX] Ingester: Fix labelset data race condition. #6573
11+
* [BUGFIX] Compactor: Cleaner should not put deletion marker for blocks with no-compact marker. #6576
12+
* [BUGFIX] Compactor: Cleaner would delete bucket index when there is no block in bucket store. #6577
1113

1214
## 1.19.0 in progress
1315

Diff for: pkg/compactor/blocks_cleaner.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userLogger log.Logger, us
505505
c.blocksMarkedForDeletion.WithLabelValues(userID, reasonValueRetention)
506506
startTime := time.Now()
507507

508+
bucketIndexDeleted := false
509+
508510
level.Info(userLogger).Log("msg", "started blocks cleanup and maintenance")
509511
defer func() {
510512
if returnErr != nil {
@@ -540,7 +542,14 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userLogger log.Logger, us
540542
idx, err := bucketindex.ReadIndex(ctx, c.bucketClient, userID, c.cfgProvider, c.logger)
541543

542544
defer func() {
543-
bucketindex.WriteSyncStatus(ctx, c.bucketClient, userID, idxs, userLogger)
545+
if bucketIndexDeleted {
546+
level.Info(userLogger).Log("msg", "deleting bucket index sync status since bucket index is empty")
547+
if err := bucketindex.DeleteIndexSyncStatus(ctx, c.bucketClient, userID); err != nil {
548+
level.Warn(userLogger).Log("msg", "error deleting index sync status when index is empty", "err", err)
549+
}
550+
} else {
551+
bucketindex.WriteSyncStatus(ctx, c.bucketClient, userID, idxs, userLogger)
552+
}
544553
}()
545554

546555
if errors.Is(err, bucketindex.ErrIndexCorrupted) {
@@ -628,12 +637,20 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userLogger log.Logger, us
628637
level.Info(userLogger).Log("msg", "finish cleaning partial blocks", "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())
629638
}
630639

631-
// Upload the updated index to the storage.
632-
begin = time.Now()
633-
if err := bucketindex.WriteIndex(ctx, c.bucketClient, userID, c.cfgProvider, idx); err != nil {
634-
return err
640+
if idx.IsEmpty() && len(partials) == 0 {
641+
level.Info(userLogger).Log("msg", "deleting bucket index since it is empty")
642+
if err := bucketindex.DeleteIndex(ctx, c.bucketClient, userID, c.cfgProvider); err != nil {
643+
return err
644+
}
645+
bucketIndexDeleted = true
646+
} else {
647+
// Upload the updated index to the storage.
648+
begin = time.Now()
649+
if err := bucketindex.WriteIndex(ctx, c.bucketClient, userID, c.cfgProvider, idx); err != nil {
650+
return err
651+
}
652+
level.Info(userLogger).Log("msg", "finish writing new index", "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())
635653
}
636-
level.Info(userLogger).Log("msg", "finish writing new index", "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())
637654

638655
if c.cfg.ShardingStrategy == util.ShardingStrategyShuffle && c.cfg.CompactionStrategy == util.CompactionStrategyPartitioning {
639656
begin = time.Now()

Diff for: pkg/compactor/blocks_cleaner_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func TestBlockCleaner_KeyPermissionDenied(t *testing.T) {
7373
path.Join(userID, "bucket-index.json.gz"): cortex_testutil.ErrKeyAccessDeniedError,
7474
},
7575
}
76+
createTSDBBlock(t, bkt, userID, 10, 20, nil)
7677

7778
cfg := BlocksCleanerConfig{
7879
DeletionDelay: deletionDelay,
@@ -901,6 +902,43 @@ func TestBlocksCleaner_CleanPartitionedGroupInfo(t *testing.T) {
901902

902903
}
903904

905+
func TestBlocksCleaner_DeleteEmptyBucketIndex(t *testing.T) {
906+
bucketClient, _ := cortex_testutil.PrepareFilesystemBucket(t)
907+
bucketClient = bucketindex.BucketWithGlobalMarkers(bucketClient)
908+
909+
userID := "user-1"
910+
911+
cfg := BlocksCleanerConfig{
912+
DeletionDelay: time.Hour,
913+
CleanupInterval: time.Minute,
914+
CleanupConcurrency: 1,
915+
}
916+
917+
ctx := context.Background()
918+
logger := log.NewNopLogger()
919+
reg := prometheus.NewPedanticRegistry()
920+
scanner := tsdb.NewUsersScanner(bucketClient, tsdb.AllUsers, logger)
921+
cfgProvider := newMockConfigProvider()
922+
blocksMarkedForDeletion := promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
923+
Name: blocksMarkedForDeletionName,
924+
Help: blocksMarkedForDeletionHelp,
925+
}, append(commonLabels, reasonLabelName))
926+
dummyGaugeVec := prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"test"})
927+
928+
cleaner := NewBlocksCleaner(cfg, bucketClient, scanner, 60*time.Second, cfgProvider, logger, "test-cleaner", reg, time.Minute, 30*time.Second, blocksMarkedForDeletion, dummyGaugeVec)
929+
930+
userBucket := bucket.NewUserBucketClient(userID, bucketClient, cfgProvider)
931+
932+
err := cleaner.cleanUser(ctx, logger, userBucket, userID, false)
933+
require.NoError(t, err)
934+
935+
_, err = bucketindex.ReadIndex(ctx, bucketClient, userID, cfgProvider, logger)
936+
require.ErrorIs(t, err, bucketindex.ErrIndexNotFound)
937+
938+
_, err = userBucket.WithExpectedErrs(userBucket.IsObjNotFoundErr).Get(ctx, bucketindex.SyncStatusFile)
939+
require.True(t, userBucket.IsObjNotFoundErr(err))
940+
}
941+
904942
type mockConfigProvider struct {
905943
userRetentionPeriods map[string]time.Duration
906944
}

Diff for: pkg/compactor/compactor_paritioning_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ func TestPartitionCompactor_SkipCompactionWhenCmkError(t *testing.T) {
193193
bucketClient := &bucket.ClientMock{}
194194
bucketClient.MockIter("", []string{userID}, nil)
195195
bucketClient.MockIter("__markers__", []string{}, nil)
196-
bucketClient.MockIter(userID+"/", []string{}, nil)
196+
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D"}, nil)
197+
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
197198
bucketClient.MockIter(userID+"/markers/", nil, nil)
198199
bucketClient.MockGet(userID+"/markers/cleaner-visit-marker.json", "", nil)
199200
bucketClient.MockUpload(userID+"/markers/cleaner-visit-marker.json", nil)
@@ -374,7 +375,7 @@ func TestPartitionCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASing
374375
bucketClient := &bucket.ClientMock{}
375376
bucketClient.MockIter("", []string{userID}, nil)
376377
bucketClient.MockIter("__markers__", []string{}, nil)
377-
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D/meta.json", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
378+
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX", userID + "/01DTVP434PA9VFXSW2JKB3392D/meta.json", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
378379
bucketClient.MockIter(userID+"/markers/", nil, nil)
379380
bucketClient.MockGet(userID+"/markers/cleaner-visit-marker.json", "", nil)
380381
bucketClient.MockUpload(userID+"/markers/cleaner-visit-marker.json", nil)
@@ -436,7 +437,7 @@ func TestPartitionCompactor_ShouldCompactAndRemoveUserFolder(t *testing.T) {
436437
bucketClient.MockIter("__markers__", []string{}, nil)
437438
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
438439
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
439-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
440+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
440441
bucketClient.MockIter("user-1/markers/", nil, nil)
441442
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
442443
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -493,8 +494,8 @@ func TestPartitionCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T)
493494
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
494495
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
495496
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
496-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
497-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
497+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
498+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
498499
bucketClient.MockIter("user-1/markers/", nil, nil)
499500
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
500501
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -767,8 +768,8 @@ func TestPartitionCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testin
767768
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
768769
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
769770
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
770-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
771-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
771+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
772+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
772773
bucketClient.MockIter("user-1/markers/", nil, nil)
773774
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
774775
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -1028,8 +1029,8 @@ func TestPartitionCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInst
10281029
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
10291030
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
10301031
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
1031-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
1032-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
1032+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
1033+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
10331034
bucketClient.MockIter("user-1/markers/", nil, nil)
10341035
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
10351036
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -1278,7 +1279,7 @@ func TestPartitionCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingE
12781279
bucketClient.MockGetRequireUpload(userID+"/partitioned-groups/visit-marks/"+fmt.Sprint(groupHash)+"/partition-0-visit-mark.json", string(visitMarkerFileContent), nil)
12791280
bucketClient.MockUpload(userID+"/partitioned-groups/visit-marks/"+fmt.Sprint(groupHash)+"/partition-0-visit-mark.json", nil)
12801281
// Iter with recursive so expected to get objects rather than directories.
1281-
blockFiles = append(blockFiles, path.Join(userID, blockID, block.MetaFilename))
1282+
blockFiles = append(blockFiles, path.Join(userID, blockID), path.Join(userID, blockID, block.MetaFilename))
12821283

12831284
// Get all of the unique group hashes so that they can be used to ensure all groups were compacted
12841285
groupHashes[groupHash]++

Diff for: pkg/compactor/compactor_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ func TestCompactor_SkipCompactionWhenCmkError(t *testing.T) {
171171
bucketClient := &bucket.ClientMock{}
172172
bucketClient.MockIter("", []string{userID}, nil)
173173
bucketClient.MockIter("__markers__", []string{}, nil)
174-
bucketClient.MockIter(userID+"/", []string{}, nil)
174+
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D"}, nil)
175+
bucketClient.MockGet(userID+"/01DTVP434PA9VFXSW2JKB3392D/meta.json", mockBlockMetaJSON("01DTVP434PA9VFXSW2JKB3392D"), nil)
175176
bucketClient.MockIter(userID+"/markers/", nil, nil)
176177
bucketClient.MockGet(userID+"/markers/cleaner-visit-marker.json", "", nil)
177178
bucketClient.MockUpload(userID+"/markers/cleaner-visit-marker.json", nil)
@@ -351,7 +352,7 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
351352
bucketClient := &bucket.ClientMock{}
352353
bucketClient.MockIter("", []string{userID}, nil)
353354
bucketClient.MockIter("__markers__", []string{}, nil)
354-
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D/meta.json", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
355+
bucketClient.MockIter(userID+"/", []string{userID + "/01DTVP434PA9VFXSW2JKB3392D", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX", userID + "/01DTVP434PA9VFXSW2JKB3392D/meta.json", userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
355356
bucketClient.MockIter(userID+"/markers/", nil, nil)
356357
bucketClient.MockGet(userID+"/markers/cleaner-visit-marker.json", "", nil)
357358
bucketClient.MockUpload(userID+"/markers/cleaner-visit-marker.json", nil)
@@ -409,7 +410,7 @@ func TestCompactor_ShouldCompactAndRemoveUserFolder(t *testing.T) {
409410
bucketClient.MockIter("__markers__", []string{}, nil)
410411
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-1"), false, nil)
411412
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
412-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
413+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
413414
bucketClient.MockIter("user-1/markers/", nil, nil)
414415
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
415416
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -460,8 +461,8 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
460461
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
461462
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
462463
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
463-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
464-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
464+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
465+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
465466
bucketClient.MockIter("user-1/markers/", nil, nil)
466467
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
467468
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -725,8 +726,8 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
725726
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
726727
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
727728
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
728-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
729-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
729+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
730+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
730731
bucketClient.MockIter("user-1/markers/", nil, nil)
731732
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
732733
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -973,8 +974,8 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
973974
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-1"), false, nil)
974975
bucketClient.MockExists(cortex_tsdb.GetGlobalDeletionMarkPath("user-2"), false, nil)
975976
bucketClient.MockExists(cortex_tsdb.GetLocalDeletionMarkPath("user-2"), false, nil)
976-
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
977-
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
977+
bucketClient.MockIter("user-1/", []string{"user-1/01DTVP434PA9VFXSW2JKB3392D", "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json", "user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json"}, nil)
978+
bucketClient.MockIter("user-2/", []string{"user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ", "user-2/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json", "user-2/01FN3V83ABR9992RF8WRJZ76ZQ/meta.json"}, nil)
978979
bucketClient.MockIter("user-1/markers/", nil, nil)
979980
bucketClient.MockGet("user-1/markers/cleaner-visit-marker.json", "", nil)
980981
bucketClient.MockUpload("user-1/markers/cleaner-visit-marker.json", nil)
@@ -1210,7 +1211,7 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
12101211
bucketClient.MockGetRequireUpload(userID+"/"+blockID+"/visit-mark.json", string(visitMarkerFileContent), nil)
12111212
bucketClient.MockUpload(userID+"/"+blockID+"/visit-mark.json", nil)
12121213
// Iter with recursive so expected to get objects rather than directories.
1213-
blockFiles = append(blockFiles, path.Join(userID, blockID, block.MetaFilename))
1214+
blockFiles = append(blockFiles, path.Join(userID, blockID), path.Join(userID, blockID, block.MetaFilename))
12141215

12151216
// Get all of the unique group hashes so that they can be used to ensure all groups were compacted
12161217
groupHash := hashGroup(userID, blockTimes["startTime"], blockTimes["endTime"])

Diff for: pkg/storage/tsdb/bucketindex/index.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func (idx *Index) RemoveBlock(id ulid.ULID) {
6464
}
6565
}
6666

67+
func (idx *Index) IsEmpty() bool {
68+
return len(idx.Blocks) == 0 && len(idx.BlockDeletionMarks) == 0
69+
}
70+
6771
// Block holds the information about a block in the index.
6872
type Block struct {
6973
// Block ID.

0 commit comments

Comments
 (0)