(t *testing.T)
| 505 | } |
| 506 | |
| 507 | func TestCompactionIteratesThroughTenants(t *testing.T) { |
| 508 | tempDir := t.TempDir() |
| 509 | |
| 510 | r, w, c, err := New(&Config{ |
| 511 | Backend: backend.Local, |
| 512 | Pool: &pool.Config{ |
| 513 | MaxWorkers: 10, |
| 514 | QueueDepth: 100, |
| 515 | }, |
| 516 | Local: &local.Config{ |
| 517 | Path: path.Join(tempDir, "traces"), |
| 518 | }, |
| 519 | Block: &common.BlockConfig{ |
| 520 | BloomFP: .01, |
| 521 | BloomShardSizeBytes: 100_000, |
| 522 | Version: encoding.DefaultEncoding().Version(), |
| 523 | }, |
| 524 | WAL: &wal.Config{ |
| 525 | Filepath: path.Join(tempDir, "wal"), |
| 526 | }, |
| 527 | BlocklistPoll: 0, |
| 528 | }, nil, log.NewNopLogger()) |
| 529 | assert.NoError(t, err) |
| 530 | |
| 531 | ctx := context.Background() |
| 532 | err = c.EnableCompaction(ctx, &CompactorConfig{ |
| 533 | MaxCompactionRange: 24 * time.Hour, |
| 534 | MaxCompactionObjects: 1000, |
| 535 | MaxBlockBytes: 1024 * 1024 * 1024, |
| 536 | BlockRetention: 0, |
| 537 | CompactedBlockRetention: 0, |
| 538 | }, &mockSharder{}, &mockOverrides{}) |
| 539 | require.NoError(t, err) |
| 540 | |
| 541 | r.EnablePolling(ctx, &mockJobSharder{}, true) |
| 542 | |
| 543 | // Cut blocks for multiple tenants |
| 544 | cutTestBlocks(t, w, testTenantID, 2, 2) |
| 545 | cutTestBlocks(t, w, testTenantID2, 2, 2) |
| 546 | |
| 547 | rw := r.(*readerWriter) |
| 548 | rw.pollBlocklist(ctx) |
| 549 | |
| 550 | assert.Equal(t, 2, len(rw.blocklist.Metas(testTenantID))) |
| 551 | assert.Equal(t, 2, len(rw.blocklist.Metas(testTenantID2))) |
| 552 | |
| 553 | // Verify that tenant 2 compacted, tenant 1 is not |
| 554 | // Compaction starts at index 1 for simplicity |
| 555 | rw.compactOneTenant(ctx) |
| 556 | assert.Equal(t, 2, len(rw.blocklist.Metas(testTenantID))) |
| 557 | assert.Equal(t, 1, len(rw.blocklist.Metas(testTenantID2))) |
| 558 | |
| 559 | // Verify both tenants compacted after second run |
| 560 | rw.compactOneTenant(ctx) |
| 561 | assert.Equal(t, 1, len(rw.blocklist.Metas(testTenantID))) |
| 562 | assert.Equal(t, 1, len(rw.blocklist.Metas(testTenantID2))) |
| 563 | } |
| 564 |
nothing calls this directly
no test coverage detected