(t *testing.T, appendSample func(app storage.Appender, l labels.Labels, mins int64) (storage.SeriesRef, error), expectedOOORecords []any, expectedInORecords []any, )
| 4615 | } |
| 4616 | |
| 4617 | func testOOOWALWrite(t *testing.T, |
| 4618 | appendSample func(app storage.Appender, l labels.Labels, mins int64) (storage.SeriesRef, error), |
| 4619 | expectedOOORecords []any, |
| 4620 | expectedInORecords []any, |
| 4621 | ) { |
| 4622 | opts := DefaultOptions() |
| 4623 | opts.OutOfOrderCapMax = 2 |
| 4624 | opts.OutOfOrderTimeWindow = 30 * time.Minute.Milliseconds() |
| 4625 | db := newTestDB(t, withOpts(opts)) |
| 4626 | |
| 4627 | s1, s2 := labels.FromStrings("l", "v1"), labels.FromStrings("l", "v2") |
| 4628 | |
| 4629 | // Ingest sample at 1h. |
| 4630 | app := db.Appender(context.Background()) |
| 4631 | appendSample(app, s1, 60) |
| 4632 | appendSample(app, s2, 60) |
| 4633 | require.NoError(t, app.Commit()) |
| 4634 | |
| 4635 | // OOO for s1. |
| 4636 | app = db.Appender(context.Background()) |
| 4637 | appendSample(app, s1, 40) |
| 4638 | require.NoError(t, app.Commit()) |
| 4639 | |
| 4640 | // OOO for s2. |
| 4641 | app = db.Appender(context.Background()) |
| 4642 | appendSample(app, s2, 42) |
| 4643 | require.NoError(t, app.Commit()) |
| 4644 | |
| 4645 | // OOO for both s1 and s2 in the same commit. |
| 4646 | app = db.Appender(context.Background()) |
| 4647 | appendSample(app, s2, 45) |
| 4648 | appendSample(app, s1, 35) |
| 4649 | appendSample(app, s1, 36) // m-maps. |
| 4650 | appendSample(app, s1, 37) |
| 4651 | require.NoError(t, app.Commit()) |
| 4652 | |
| 4653 | // OOO for s1 but not for s2 in the same commit. |
| 4654 | app = db.Appender(context.Background()) |
| 4655 | appendSample(app, s1, 50) // m-maps. |
| 4656 | appendSample(app, s2, 65) |
| 4657 | require.NoError(t, app.Commit()) |
| 4658 | |
| 4659 | // Single commit has 2 times m-mapping and more samples after m-map. |
| 4660 | app = db.Appender(context.Background()) |
| 4661 | appendSample(app, s2, 50) // m-maps. |
| 4662 | appendSample(app, s2, 51) |
| 4663 | appendSample(app, s2, 52) // m-maps. |
| 4664 | appendSample(app, s2, 53) |
| 4665 | require.NoError(t, app.Commit()) |
| 4666 | |
| 4667 | getRecords := func(walDir string) []any { |
| 4668 | sr, err := wlog.NewSegmentsReader(walDir) |
| 4669 | require.NoError(t, err) |
| 4670 | r := wlog.NewReader(sr) |
| 4671 | defer func() { |
| 4672 | require.NoError(t, sr.Close()) |
| 4673 | }() |
| 4674 |
no test coverage detected
searching dependent graphs…