(t *testing.T, options testBlocksCleanerOptions)
| 132 | } |
| 133 | |
| 134 | func testBlocksCleanerWithOptions(t *testing.T, options testBlocksCleanerOptions) { |
| 135 | bucketClient, _ := cortex_testutil.PrepareFilesystemBucket(t) |
| 136 | |
| 137 | // If the markers migration is enabled, then we create the fixture blocks without |
| 138 | // writing the deletion marks in the global location, because they will be migrated |
| 139 | // at startup. |
| 140 | if !options.markersMigrationEnabled { |
| 141 | bucketClient = bucketindex.BucketWithGlobalMarkers(bucketClient) |
| 142 | } |
| 143 | |
| 144 | // Create blocks. |
| 145 | ctx := context.Background() |
| 146 | now := time.Now() |
| 147 | deletionDelay := 12 * time.Hour |
| 148 | block1 := createTSDBBlock(t, bucketClient, "user-1", 10, 20, nil) |
| 149 | block2 := createTSDBBlock(t, bucketClient, "user-1", 20, 30, nil) |
| 150 | block3 := createTSDBBlock(t, bucketClient, "user-1", 30, 40, nil) |
| 151 | block4 := ulid.MustNew(4, rand.Reader) |
| 152 | block5 := ulid.MustNew(5, rand.Reader) |
| 153 | block6 := createTSDBBlock(t, bucketClient, "user-1", 40, 50, nil) |
| 154 | block7 := createTSDBBlock(t, bucketClient, "user-2", 10, 20, nil) |
| 155 | block8 := createTSDBBlock(t, bucketClient, "user-2", 40, 50, nil) |
| 156 | block11 := ulid.MustNew(11, rand.Reader) |
| 157 | createDeletionMark(t, bucketClient, "user-1", block2, now.Add(-deletionDelay).Add(time.Hour)) // Block hasn't reached the deletion threshold yet. |
| 158 | createDeletionMark(t, bucketClient, "user-1", block3, now.Add(-deletionDelay).Add(-time.Hour)) // Block reached the deletion threshold. |
| 159 | createDeletionMark(t, bucketClient, "user-1", block4, now.Add(-deletionDelay).Add(time.Hour)) // Partial block hasn't reached the deletion threshold yet. |
| 160 | createDeletionMark(t, bucketClient, "user-1", block5, now.Add(-deletionDelay).Add(-time.Hour)) // Partial block reached the deletion threshold. |
| 161 | require.NoError(t, bucketClient.Delete(ctx, path.Join("user-1", block6.String(), metadata.MetaFilename))) // Partial block without deletion mark. |
| 162 | createBlockVisitMarker(t, bucketClient, "user-1", block11) // Partial block only has visit marker. |
| 163 | createDeletionMark(t, bucketClient, "user-2", block7, now.Add(-deletionDelay).Add(-time.Hour)) // Block reached the deletion threshold. |
| 164 | |
| 165 | // Blocks for user-3, tenant marked for deletion. |
| 166 | require.NoError(t, users.WriteTenantDeletionMark(context.Background(), bucketClient, "user-3", users.NewTenantDeletionMark(time.Now()))) |
| 167 | block9 := createTSDBBlock(t, bucketClient, "user-3", 10, 30, nil) |
| 168 | block10 := createTSDBBlock(t, bucketClient, "user-3", 30, 50, nil) |
| 169 | createParquetMarker(t, bucketClient, "user-3", block10) |
| 170 | |
| 171 | // User-4 with no more blocks, but couple of mark and debug files. Should be fully deleted. |
| 172 | user4Mark := users.NewTenantDeletionMark(time.Now()) |
| 173 | user4Mark.FinishedTime = time.Now().Unix() - 60 // Set to check final user cleanup. |
| 174 | require.NoError(t, users.WriteTenantDeletionMark(context.Background(), bucketClient, "user-4", user4Mark)) |
| 175 | user4DebugMetaFile := path.Join("user-4", block.DebugMetas, "meta.json") |
| 176 | require.NoError(t, bucketClient.Upload(context.Background(), user4DebugMetaFile, strings.NewReader("some random content here"))) |
| 177 | |
| 178 | // No Compact blocks marker |
| 179 | createTSDBBlock(t, bucketClient, "user-5", 10, 30, nil) |
| 180 | block12 := createTSDBBlock(t, bucketClient, "user-5", 30, 50, nil) |
| 181 | createNoCompactionMark(t, bucketClient, "user-5", block12) |
| 182 | |
| 183 | // Create Parquet marker |
| 184 | block13 := createTSDBBlock(t, bucketClient, "user-6", 30, 50, nil) |
| 185 | // This block should be converted to Parquet format so counted as remaining. |
| 186 | block14 := createTSDBBlock(t, bucketClient, "user-6", 30, 50, nil) |
| 187 | createParquetMarker(t, bucketClient, "user-6", block13) |
| 188 | |
| 189 | // The fixtures have been created. If the bucket client wasn't wrapped to write |
| 190 | // deletion marks to the global location too, then this is the right time to do it. |
| 191 | if options.markersMigrationEnabled { |
no test coverage detected