(t *testing.T)
| 368 | } |
| 369 | |
| 370 | func TestCompactionUpdatesBlocklist(t *testing.T) { |
| 371 | tempDir := t.TempDir() |
| 372 | |
| 373 | r, w, c, err := New(&Config{ |
| 374 | Backend: backend.Local, |
| 375 | Pool: &pool.Config{ |
| 376 | MaxWorkers: 10, |
| 377 | QueueDepth: 100, |
| 378 | }, |
| 379 | Local: &local.Config{ |
| 380 | Path: path.Join(tempDir, "traces"), |
| 381 | }, |
| 382 | Block: &common.BlockConfig{ |
| 383 | BloomFP: .01, |
| 384 | BloomShardSizeBytes: 100_000, |
| 385 | Version: encoding.DefaultEncoding().Version(), |
| 386 | }, |
| 387 | WAL: &wal.Config{ |
| 388 | Filepath: path.Join(tempDir, "wal"), |
| 389 | }, |
| 390 | BlocklistPoll: 0, |
| 391 | }, nil, log.NewNopLogger()) |
| 392 | require.NoError(t, err) |
| 393 | |
| 394 | ctx := context.Background() |
| 395 | err = c.EnableCompaction(ctx, &CompactorConfig{ |
| 396 | MaxCompactionRange: 24 * time.Hour, |
| 397 | BlockRetention: 0, |
| 398 | CompactedBlockRetention: 0, |
| 399 | }, &mockSharder{}, &mockOverrides{}) |
| 400 | require.NoError(t, err) |
| 401 | |
| 402 | r.EnablePolling(ctx, &mockJobSharder{}, true) |
| 403 | |
| 404 | // Cut x blocks with y records each |
| 405 | blockCount := 5 |
| 406 | recordCount := 1 |
| 407 | cutTestBlocks(t, w, testTenantID, blockCount, recordCount) |
| 408 | |
| 409 | rw := r.(*readerWriter) |
| 410 | rw.pollBlocklist(ctx) |
| 411 | |
| 412 | // compact everything |
| 413 | err = rw.compactOneJob(ctx, rw.blocklist.Metas(testTenantID), testTenantID) |
| 414 | require.NoError(t, err) |
| 415 | |
| 416 | // New blocklist contains 1 compacted block with everything |
| 417 | blocks := rw.blocklist.Metas(testTenantID) |
| 418 | require.Equal(t, 1, len(blocks)) |
| 419 | require.Equal(t, uint32(1), blocks[0].CompactionLevel) |
| 420 | require.Equal(t, int64(blockCount*recordCount), blocks[0].TotalObjects) |
| 421 | |
| 422 | // Compacted list contains all old blocks |
| 423 | require.Equal(t, blockCount, len(rw.blocklist.CompactedMetas(testTenantID))) |
| 424 | |
| 425 | // Make sure all expected traces are found. |
| 426 | for i := 0; i < blockCount; i++ { |
| 427 | for j := 0; j < recordCount; j++ { |
nothing calls this directly
no test coverage detected