@@ -151,6 +151,38 @@ func TestConfig_Validate(t *testing.T) {
151151 }
152152}
153153
154+ func TestCompactor_SkipCompactionWhenCmkError (t * testing.T ) {
155+ t .Parallel ()
156+ userID := "user-1"
157+
158+ ss := bucketindex.Status {Status : bucketindex .CustomerManagedKeyError , Version : bucketindex .SyncStatusFileVersion }
159+ content , err := json .Marshal (ss )
160+ require .NoError (t , err )
161+
162+ // No user blocks stored in the bucket.
163+ bucketClient := & bucket.ClientMock {}
164+ bucketClient .MockIter ("" , []string {userID }, nil )
165+ bucketClient .MockIter (userID + "/" , []string {}, nil )
166+ bucketClient .MockIter (userID + "/markers/" , nil , nil )
167+ bucketClient .MockGet (userID + "/bucket-index-sync-status.json" , string (content ), nil )
168+ bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
169+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
170+ bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
171+ bucketClient .MockExists (path .Join (userID , cortex_tsdb .TenantDeletionMarkPath ), false , nil )
172+
173+ cfg := prepareConfig ()
174+ c , _ , _ , logs , _ := prepare (t , cfg , bucketClient , nil )
175+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), c ))
176+
177+ // Wait until a run has completed.
178+ cortex_testutil .Poll (t , time .Second , 1.0 , func () interface {} {
179+ return prom_testutil .ToFloat64 (c .compactionRunsCompleted )
180+ })
181+
182+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), c ))
183+ assert .Contains (t , strings .Split (strings .TrimSpace (logs .String ()), "\n " ), `level=info component=compactor msg="skipping compactUser due CustomerManagedKeyError" user=user-1` )
184+ }
185+
154186func TestCompactor_ShouldDoNothingOnNoUserBlocks (t * testing.T ) {
155187 t .Parallel ()
156188
@@ -535,6 +567,8 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
535567 bucketClient .MockGet ("user-2/01FN3V83ABR9992RF8WRJZ76ZQ/visit-mark.json" , "" , nil )
536568 bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
537569 bucketClient .MockGet ("user-2/bucket-index.json.gz" , "" , nil )
570+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
571+ bucketClient .MockGet ("user-2/bucket-index-sync-status.json" , "" , nil )
538572 bucketClient .MockIter ("user-1/markers/" , nil , nil )
539573 bucketClient .MockIter ("user-2/markers/" , nil , nil )
540574 bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
@@ -676,6 +710,7 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
676710 bucketClient .MockDelete ("user-1/markers/01DTW0ZCPDDNV4BV83Q2SV4QAZ-deletion-mark.json" , nil )
677711 bucketClient .MockDelete ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , nil )
678712 bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
713+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
679714 bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
680715 bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
681716
@@ -799,6 +834,8 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
799834
800835 bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
801836 bucketClient .MockGet ("user-2/bucket-index.json.gz" , "" , nil )
837+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
838+ bucketClient .MockGet ("user-2/bucket-index-sync-status.json" , "" , nil )
802839 bucketClient .MockIter ("user-1/markers/" , nil , nil )
803840 bucketClient .MockIter ("user-2/markers/" , nil , nil )
804841 bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
@@ -1031,6 +1068,8 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
10311068 bucketClient .MockUpload ("user-2/01FN3V83ABR9992RF8WRJZ76ZQ/visit-mark.json" , nil )
10321069 bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
10331070 bucketClient .MockGet ("user-2/bucket-index.json.gz" , "" , nil )
1071+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
1072+ bucketClient .MockGet ("user-2/bucket-index-sync-status.json" , "" , nil )
10341073 bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
10351074 bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
10361075 bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
0 commit comments