@@ -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
@@ -465,6 +497,7 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
465
497
bucketClient .MockGet (userID + "/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
466
498
bucketClient .MockGet (userID + "/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
467
499
bucketClient .MockGet (userID + "/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , "" , nil )
500
+ bucketClient .MockGet (userID + "/bucket-index-sync-status.json" , "" , nil )
468
501
bucketClient .MockUpload (userID + "/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , nil )
469
502
bucketClient .MockGet (userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json" , mockBlockMetaJSON ("01FN6CDF3PNEWWRY5MPGJPE3EX" ), nil )
470
503
bucketClient .MockGet (userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/no-compact-mark.json" , "" , nil )
@@ -473,6 +506,7 @@ func TestCompactor_ShouldIncrementCompactionErrorIfFailedToCompactASingleTenant(
473
506
bucketClient .MockUpload (userID + "/01FN6CDF3PNEWWRY5MPGJPE3EX/visit-mark.json" , nil )
474
507
bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
475
508
bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
509
+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
476
510
477
511
c , _ , tsdbPlannerMock , _ , registry := prepare (t , prepareConfig (), bucketClient , nil )
478
512
tsdbPlannerMock .On ("Plan" , mock .Anything , mock .Anything ).Return ([]* metadata.Meta {}, errors .New ("Failed to plan" ))
@@ -520,6 +554,7 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
520
554
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
521
555
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
522
556
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , "" , nil )
557
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
523
558
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json" , mockBlockMetaJSON ("01FN6CDF3PNEWWRY5MPGJPE3EX" ), nil )
524
559
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/deletion-mark.json" , "" , nil )
525
560
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/no-compact-mark.json" , "" , nil )
@@ -534,10 +569,14 @@ func TestCompactor_ShouldIterateOverUsersAndRunCompaction(t *testing.T) {
534
569
bucketClient .MockGet ("user-2/01FN3V83ABR9992RF8WRJZ76ZQ/visit-mark.json" , "" , nil )
535
570
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
536
571
bucketClient .MockGet ("user-2/bucket-index.json.gz" , "" , nil )
572
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
573
+ bucketClient .MockGet ("user-2/bucket-index-sync-status.json" , "" , nil )
537
574
bucketClient .MockIter ("user-1/markers/" , nil , nil )
538
575
bucketClient .MockIter ("user-2/markers/" , nil , nil )
539
576
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
540
577
bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
578
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
579
+ bucketClient .MockUpload ("user-2/bucket-index-sync-status.json" , nil )
541
580
542
581
c , _ , tsdbPlanner , logs , registry := prepare (t , prepareConfig (), bucketClient , nil )
543
582
@@ -652,6 +691,7 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
652
691
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , mockBlockMetaJSON ("01DTVP434PA9VFXSW2JKB3392D" ), nil )
653
692
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , mockDeletionMarkJSON ("01DTVP434PA9VFXSW2JKB3392D" , time .Now ()), nil )
654
693
bucketClient .MockGet ("user-1/markers/01DTVP434PA9VFXSW2JKB3392D-deletion-mark.json" , mockDeletionMarkJSON ("01DTVP434PA9VFXSW2JKB3392D" , time .Now ()), nil )
694
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
655
695
656
696
// This block will be deleted by cleaner.
657
697
bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" , mockBlockMetaJSON ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" ), nil )
@@ -673,7 +713,9 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForDeletion(t *testing.T) {
673
713
bucketClient .MockDelete ("user-1/markers/01DTW0ZCPDDNV4BV83Q2SV4QAZ-deletion-mark.json" , nil )
674
714
bucketClient .MockDelete ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , nil )
675
715
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
716
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
676
717
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
718
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
677
719
678
720
c , _ , tsdbPlanner , logs , registry := prepare (t , cfg , bucketClient , nil )
679
721
@@ -775,6 +817,7 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
775
817
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
776
818
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , mockNoCompactBlockJSON ("01DTVP434PA9VFXSW2JKB3392D" ), nil )
777
819
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , "" , nil )
820
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
778
821
bucketClient .MockUpload ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , nil )
779
822
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json" , mockBlockMetaJSON ("01FN6CDF3PNEWWRY5MPGJPE3EX" ), nil )
780
823
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/deletion-mark.json" , "" , nil )
@@ -795,10 +838,14 @@ func TestCompactor_ShouldNotCompactBlocksMarkedForSkipCompact(t *testing.T) {
795
838
796
839
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
797
840
bucketClient .MockGet ("user-2/bucket-index.json.gz" , "" , nil )
841
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
842
+ bucketClient .MockGet ("user-2/bucket-index-sync-status.json" , "" , nil )
798
843
bucketClient .MockIter ("user-1/markers/" , nil , nil )
799
844
bucketClient .MockIter ("user-2/markers/" , nil , nil )
800
845
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
801
846
bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
847
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
848
+ bucketClient .MockUpload ("user-2/bucket-index-sync-status.json" , nil )
802
849
803
850
c , _ , tsdbPlanner , _ , registry := prepare (t , prepareConfig (), bucketClient , nil )
804
851
@@ -843,13 +890,15 @@ func TestCompactor_ShouldNotCompactBlocksForUsersMarkedForDeletion(t *testing.T)
843
890
bucketClient .MockIter ("user-1/01DTVP434PA9VFXSW2JKB3392D" , []string {"user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , "user-1/01DTVP434PA9VFXSW2JKB3392D/index" }, nil )
844
891
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , mockBlockMetaJSON ("01DTVP434PA9VFXSW2JKB3392D" ), nil )
845
892
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/index" , "some index content" , nil )
893
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
846
894
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , "" , nil )
847
895
bucketClient .MockUpload ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , nil )
848
896
bucketClient .MockExists ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , false , nil )
849
897
850
898
bucketClient .MockDelete ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , nil )
851
899
bucketClient .MockDelete ("user-1/01DTVP434PA9VFXSW2JKB3392D/index" , nil )
852
900
bucketClient .MockDelete ("user-1/bucket-index.json.gz" , nil )
901
+ bucketClient .MockDelete ("user-1/bucket-index-sync-status.json" , nil )
853
902
854
903
c , _ , tsdbPlanner , logs , registry := prepare (t , cfg , bucketClient , nil )
855
904
@@ -1006,6 +1055,7 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
1006
1055
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
1007
1056
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
1008
1057
bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , "" , nil )
1058
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
1009
1059
bucketClient .MockUpload ("user-1/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , nil )
1010
1060
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/meta.json" , mockBlockMetaJSON ("01FN6CDF3PNEWWRY5MPGJPE3EX" ), nil )
1011
1061
bucketClient .MockGet ("user-1/01FN6CDF3PNEWWRY5MPGJPE3EX/deletion-mark.json" , "" , nil )
@@ -1024,8 +1074,12 @@ func TestCompactor_ShouldCompactAllUsersOnShardingEnabledButOnlyOneInstanceRunni
1024
1074
bucketClient .MockUpload ("user-2/01FN3V83ABR9992RF8WRJZ76ZQ/visit-mark.json" , nil )
1025
1075
bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
1026
1076
bucketClient .MockGet ("user-2/bucket-index.json.gz" , "" , nil )
1077
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , "" , nil )
1078
+ bucketClient .MockGet ("user-2/bucket-index-sync-status.json" , "" , nil )
1027
1079
bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
1028
1080
bucketClient .MockUpload ("user-2/bucket-index.json.gz" , nil )
1081
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
1082
+ bucketClient .MockUpload ("user-2/bucket-index-sync-status.json" , nil )
1029
1083
1030
1084
ringStore , closer := consul .NewInMemoryClient (ring .GetCodec (), log .NewNopLogger (), nil )
1031
1085
t .Cleanup (func () { assert .NoError (t , closer .Close ()) })
@@ -1104,9 +1158,11 @@ func TestCompactor_ShouldCompactOnlyUsersOwnedByTheInstanceOnShardingEnabledAndM
1104
1158
bucketClient .MockGet (userID + "/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
1105
1159
bucketClient .MockGet (userID + "/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
1106
1160
bucketClient .MockGet (userID + "/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , "" , nil )
1161
+ bucketClient .MockGet (userID + "/bucket-index-sync-status.json" , "" , nil )
1107
1162
bucketClient .MockUpload (userID + "/01DTVP434PA9VFXSW2JKB3392D/visit-mark.json" , nil )
1108
1163
bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
1109
1164
bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
1165
+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
1110
1166
}
1111
1167
1112
1168
// Create a shared KV Store
@@ -1212,6 +1268,7 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
1212
1268
Version : VisitMarkerVersion1 ,
1213
1269
}
1214
1270
visitMarkerFileContent , _ := json .Marshal (blockVisitMarker )
1271
+ bucketClient .MockGet (userID + "/bucket-index-sync-status.json" , "" , nil )
1215
1272
bucketClient .MockGet (userID + "/" + blockID + "/meta.json" , mockBlockMetaJSONWithTime (blockID , userID , blockTimes ["startTime" ], blockTimes ["endTime" ]), nil )
1216
1273
bucketClient .MockGet (userID + "/" + blockID + "/deletion-mark.json" , "" , nil )
1217
1274
bucketClient .MockGet (userID + "/" + blockID + "/no-compact-mark.json" , "" , nil )
@@ -1230,6 +1287,7 @@ func TestCompactor_ShouldCompactOnlyShardsOwnedByTheInstanceOnShardingEnabledWit
1230
1287
bucketClient .MockExists (path .Join (userID , cortex_tsdb .TenantDeletionMarkPath ), false , nil )
1231
1288
bucketClient .MockGet (userID + "/bucket-index.json.gz" , "" , nil )
1232
1289
bucketClient .MockUpload (userID + "/bucket-index.json.gz" , nil )
1290
+ bucketClient .MockUpload (userID + "/bucket-index-sync-status.json" , nil )
1233
1291
}
1234
1292
1235
1293
// Create a shared KV Store
0 commit comments