Xuanwo opened a new pull request, #8912: URL: https://github.com/apache/opendal/pull/8912
# Which issue does this PR close? No linked issue. # Rationale for this change Three correctness and concurrency bugs in the `tail-cut` layer: 1. `WindowedHistogram` read wall-clock time with `Timestamp::now()` and computed an unchecked `now - last_rotate`. A concurrent rotation or a backwards clock step underflowed, panicking in debug builds and wrapping `last_rotate` in release builds so the next slice was wiped. 2. Rotation published a slice's new `start_epoch_ms` before clearing its buckets, so a concurrent `snapshot()` could read counts from the slice's previous use as fresh data. The 12-slice ring was also one slice short: rotating at 120 s reused a slice that `snapshot()` still includes within `window_ms + SLICE_DURATION_MS`. 3. `oio::List::next`, `oio::Write::write`, and `oio::ReadStream::read` sampled every completion, including synchronous buffered ones (buffered list pages, `OneShotWriter` buffering, in-memory read chunks). Those instant 0 ms samples flood the lowest bucket, pass `min_samples` before any real I/O, and collapse the deadline toward `min_deadline`, cancelling healthy follow-up I/O. # What changes are included in this PR? - Histogram timestamps now use a monotonic `Instant` anchored at `WindowedHistogram::new()`; elapsed milliseconds start at 1 so `start_epoch_ms == 0` exclusively marks a slice hidden from snapshots. `maybe_rotate` uses `checked_sub` and leaves the ring untouched when `last_rotate` is not older than `now`. - `rotate_slice` hides the slice, clears its buckets, then publishes the new timestamp and advances `current_idx` with `Release` ordering; `record` loads `current_idx` with `Acquire`. `NUM_SLICES` is derived as `MAX_WINDOW_MS / SLICE_DURATION_MS + 1` so the recycled slice is outside the largest `window_ms + SLICE_DURATION_MS` window. - Buffered `List::next`, `Write::write`, and `ReadStream::read` now use the existing `with_buffered_io_deadline`, sampling only work that actually yields while still enforcing the deadline. - Regression tests cover the stale `last_rotate` case, the ring size, hide-before-clear ordering, and buffered list, write, and read sampling. # Are there any user-facing changes? Yes. Buffered operations no longer feed the latency estimator without yielding, so the layer activates from real async work instead of instant buffer pushes. The deadline is still enforced for buffered operations that reach async I/O. # Breaking changes # AI Usage Statement - Harness: Pi (T3 Code) - Model: DeepSeek V4.1 Flash - Effort: max - Role: Implemented the fixes and regression tests from a human-authored brief, and ran the crate's tests, clippy, rustdoc, and wasm32 check. No known unknowns affecting review. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
