| 319 | } |
| 320 | |
| 321 | func (p *Poller) pollTenantBlocks( |
| 322 | ctx context.Context, |
| 323 | tenantID string, |
| 324 | previous *List, |
| 325 | ) ([]*backend.BlockMeta, []*backend.CompactedBlockMeta, error) { |
| 326 | derivedCtx, span := tracer.Start(ctx, "Poller.pollTenantBlocks") |
| 327 | defer span.End() |
| 328 | |
| 329 | currentBlockIDs, currentCompactedBlockIDs, err := p.reader.Blocks(derivedCtx, tenantID) |
| 330 | if err != nil { |
| 331 | return nil, nil, fmt.Errorf("failed listing tenant blocks: %w", err) |
| 332 | } |
| 333 | |
| 334 | var ( |
| 335 | metas = previous.Metas(tenantID) |
| 336 | compactedMetas = previous.CompactedMetas(tenantID) |
| 337 | mm = make(map[backend.UUID]*backend.BlockMeta, len(metas)) |
| 338 | cm = make(map[backend.UUID]*backend.CompactedBlockMeta, len(compactedMetas)) |
| 339 | newBlockList = make([]*backend.BlockMeta, 0, len(currentBlockIDs)) |
| 340 | newCompactedBlocklist = make([]*backend.CompactedBlockMeta, 0, len(currentCompactedBlockIDs)) |
| 341 | unknownBlockIDs = make(map[uuid.UUID]bool, 1000) |
| 342 | ) |
| 343 | |
| 344 | span.SetAttributes(attribute.Int("metas", len(metas))) |
| 345 | span.SetAttributes(attribute.Int("compactedMetas", len(compactedMetas))) |
| 346 | |
| 347 | for _, i := range metas { |
| 348 | mm[i.BlockID] = i |
| 349 | } |
| 350 | |
| 351 | for _, i := range compactedMetas { |
| 352 | cm[i.BlockID] = i |
| 353 | } |
| 354 | |
| 355 | // The boolean here to track if we know the block has been compacted |
| 356 | for _, blockID := range currentBlockIDs { |
| 357 | // if we already have this block id in our previous list, use the existing data. |
| 358 | if v, ok := mm[backend.UUID(blockID)]; ok { |
| 359 | newBlockList = append(newBlockList, v) |
| 360 | continue |
| 361 | } |
| 362 | unknownBlockIDs[blockID] = false |
| 363 | |
| 364 | } |
| 365 | |
| 366 | for _, blockID := range currentCompactedBlockIDs { |
| 367 | // if we already have this block id in our previous list, use the existing data. |
| 368 | if v, ok := cm[backend.UUID(blockID)]; ok { |
| 369 | newCompactedBlocklist = append(newCompactedBlocklist, v) |
| 370 | continue |
| 371 | } |
| 372 | |
| 373 | // TODO: Review the ability to avoid polling for compacted blocks that we |
| 374 | // know about. We need to know the compacted time, but perhaps there is |
| 375 | // another way to get that, like the object creation time. |
| 376 | |
| 377 | unknownBlockIDs[blockID] = true |
| 378 | |