@@ -151,6 +151,38 @@ func TestConfig_Validate(t *testing.T) {
151
151
}
152
152
}
153
153
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
+
154
186
func TestCompactor_ShouldDoNothingOnNoUserBlocks (t * testing.T ) {
155
187
t .Parallel ()
156
188
@@ -473,6 +505,7 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
473
505
bucketClient .MockUpload (userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/visit-mark.json" , nil )
474
506
bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
475
507
bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
508
+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
476
509
477
510
c , _ , tsdbPlannerMock , _ , registry := prepare (t , prepareConfig (), bucketClient , nil )
478
511
tsdbPlannerMock .On ("Plan" , mock .Anything , mock .Anything ).Return ([]* metadata.Meta {}, errors .New ("Failed to plan" ))
@@ -534,10 +567,14 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
534
567
bucketClient .MockGet ("user-2/01FN3V83ABR9992RF8WRJZ76ZQ/visit-mark.json" , "" , nil )
535
568
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
536
569
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 )
537
572
bucketClient .MockIter ("user-1/markers/" , nil , nil )
538
573
bucketClient .MockIter ("user-2/markers/" , nil , nil )
539
574
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
540
575
bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
576
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
577
+ bucketClient .MockUpload ("user-2/bucket-index-sync-status.json" , nil )
541
578
542
579
c , _ , tsdbPlanner , logs , registry := prepare (t , prepareConfig (), bucketClient , nil )
543
580
@@ -673,7 +710,9 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
673
710
bucketClient .MockDelete ("user-1/markers/01DTW0ZCPDDNV4BV83Q2SV4QAZ-deletion-mark.json" , nil )
674
711
bucketClient .MockDelete ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , nil )
675
712
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
713
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
676
714
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
715
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
677
716
678
717
c , _ , tsdbPlanner , logs , registry := prepare (t , cfg , bucketClient , nil )
679
718
@@ -795,10 +834,14 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
795
834
796
835
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
797
836
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 )
798
839
bucketClient .MockIter ("user-1/markers/" , nil , nil )
799
840
bucketClient .MockIter ("user-2/markers/" , nil , nil )
800
841
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
801
842
bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
843
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
844
+ bucketClient .MockUpload ("user-2/bucket-index-sync-status.json" , nil )
802
845
803
846
c , _ , tsdbPlanner , _ , registry := prepare (t , prepareConfig (), bucketClient , nil )
804
847
@@ -850,6 +893,7 @@ func TestCompactor_ShouldNotCompactBlocksForUsersMarkedForDeletion(t *testing.T)
850
893
bucketClient .MockDelete ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , nil )
851
894
bucketClient .MockDelete ("user-1/01DTVP434PA9VFXSW2JKB3392D/index" , nil )
852
895
bucketClient .MockDelete ("user-1/bucket-index.json.gz" , nil )
896
+ bucketClient .MockDelete ("user-1/bucket-index-sync-status.json" , nil )
853
897
854
898
c , _ , tsdbPlanner , logs , registry := prepare (t , cfg , bucketClient , nil )
855
899
@@ -1024,8 +1068,12 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
1024
1068
bucketClient .MockUpload ("user-2/01FN3V83ABR9992RF8WRJZ76ZQ/visit-mark.json" , nil )
1025
1069
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
1026
1070
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 )
1027
1073
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
1028
1074
bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
1075
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
1076
+ bucketClient .MockUpload ("user-2/bucket-index-sync-status.json" , nil )
1029
1077
1030
1078
ringStore , closer := consul .NewInMemoryClient (ring .GetCodec (), log .NewNopLogger (), nil )
1031
1079
t .Cleanup (func () { assert .NoError (t , closer .Close ()) })
@@ -1107,6 +1155,7 @@ func TestCompactor_ShouldCompactOnlyUsersOwnedByTheInstanceOnShardingEnabledAndM
1107
1155
bucketClient .MockUpload (userID + "/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , nil )
1108
1156
bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
1109
1157
bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
1158
+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
1110
1159
}
1111
1160
1112
1161
// Create a shared KV Store
@@ -1212,6 +1261,7 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
1212
1261
Version : VisitMarkerVersion1 ,
1213
1262
}
1214
1263
visitMarkerFileContent , _ := json .Marshal (blockVisitMarker )
1264
+ bucketClient .MockGet (userID + "/bucket-index-sync-status.json" , "" , nil )
1215
1265
bucketClient .MockGet (userID + "/" + blockID + "/meta.json" , mockBlockMetaJSONWithTime (blockID , userID , blockTimes ["startTime" ], blockTimes ["endTime" ]), nil )
1216
1266
bucketClient .MockGet (userID + "/" + blockID + "/deletion-mark.json" , "" , nil )
1217
1267
bucketClient .MockGet (userID + "/" + blockID + "/no-compact-mark.json" , "" , nil )
@@ -1230,6 +1280,7 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
1230
1280
bucketClient .MockExists (path .Join (userID , cortex_tsdb .TenantDeletionMarkPath ), false , nil )
1231
1281
bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
1232
1282
bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
1283
+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
1233
1284
}
1234
1285
1235
1286
// Create a shared KV Store
0 commit comments