| 584 | } |
| 585 | |
| 586 | func (c *LeveledCompactor) Write(dest string, b BlockReader, mint, maxt int64, base *BlockMeta) ([]ulid.ULID, error) { |
| 587 | start := time.Now() |
| 588 | |
| 589 | uid := ulid.MustNew(ulid.Now(), rand.Reader) |
| 590 | c.logger.Info("write block started", "mint", mint, "maxt", maxt, "ulid", uid) |
| 591 | |
| 592 | meta := &BlockMeta{ |
| 593 | ULID: uid, |
| 594 | MinTime: mint, |
| 595 | MaxTime: maxt, |
| 596 | } |
| 597 | meta.Compaction.Level = 1 |
| 598 | meta.Compaction.Sources = []ulid.ULID{uid} |
| 599 | |
| 600 | if base != nil { |
| 601 | meta.Compaction.Parents = []BlockDesc{ |
| 602 | {ULID: base.ULID, MinTime: base.MinTime, MaxTime: base.MaxTime}, |
| 603 | } |
| 604 | if base.Compaction.FromOutOfOrder() { |
| 605 | meta.Compaction.SetOutOfOrder() |
| 606 | } |
| 607 | if base.Compaction.FromStaleSeries() { |
| 608 | meta.Compaction.SetStaleSeries() |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | err := c.write(dest, meta, DefaultBlockPopulator{}, b) |
| 613 | if err != nil { |
| 614 | return nil, err |
| 615 | } |
| 616 | |
| 617 | if meta.Stats.NumSamples == 0 { |
| 618 | c.logger.Info( |
| 619 | "write block resulted in empty block", |
| 620 | "mint", meta.MinTime, |
| 621 | "maxt", meta.MaxTime, |
| 622 | "duration", time.Since(start), |
| 623 | ) |
| 624 | return nil, nil |
| 625 | } |
| 626 | |
| 627 | c.logger.Info( |
| 628 | "write block completed", |
| 629 | "mint", meta.MinTime, |
| 630 | "maxt", meta.MaxTime, |
| 631 | "ulid", meta.ULID, |
| 632 | "duration", time.Since(start), |
| 633 | "ooo", meta.Compaction.FromOutOfOrder(), |
| 634 | ) |
| 635 | return []ulid.ULID{uid}, nil |
| 636 | } |
| 637 | |
| 638 | // instrumentedChunkWriter is used for level 1 compactions to record statistics |
| 639 | // about compacted chunks. |