From e8298c09b1154e3eb3560352ebbea6d11d87772e Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Fri, 10 Nov 2023 18:48:41 +0000 Subject: [PATCH] internal/trace/v2: don't enforce batch order on Ms Currently the trace parser enforces that the timestamps for a series of a batches on the same M come in order. We cannot actually assume this in general because we don't trust timestamps. The source of truth on the batch order is the order in which they were emitted. If that's wrong, it should quickly become evident in the trace. For #60773. For #64061. Change-Id: I7d5a407c9568dd1ce0b79d51b2b538ed6072b26d Reviewed-on: https://go-review.googlesource.com/c/go/+/541695 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt Auto-Submit: Michael Knyszek --- src/internal/trace/v2/generation.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/internal/trace/v2/generation.go b/src/internal/trace/v2/generation.go index b430515793..4cdf76e21c 100644 --- a/src/internal/trace/v2/generation.go +++ b/src/internal/trace/v2/generation.go @@ -95,15 +95,11 @@ func readGeneration(r *bufio.Reader, spill *spilledBatch) (*generation, *spilled if g.freq == 0 { return nil, nil, fmt.Errorf("no frequency event found") } - for _, batches := range g.batches { - sorted := slices.IsSortedFunc(batches, func(a, b batch) int { - return cmp.Compare(a.time, b.time) - }) - if !sorted { - // TODO(mknyszek): Consider just sorting here. - return nil, nil, fmt.Errorf("per-M streams are out-of-order") - } - } + // N.B. Trust that the batch order is correct. We can't validate the batch order + // by timestamp because the timestamps could just be plain wrong. The source of + // truth is the order things appear in the trace and the partial order sequence + // numbers on certain events. If it turns out the batch order is actually incorrect + // we'll very likely fail to advance a partial order from the frontier. // Compactify stacks and strings for better lookup performance later. g.stacks.compactify() -- 2.44.0