Commit b405ced
committed
tbV2: fix write_wrap_count under-counting natural wraps
write_wrap_count was only being incremented on the "panic wrap" path
(when the incoming chunk is too big for the remaining tail space and
unread chunks must be evicted to make room). The "natural wrap" path
where wr_ reaches size_ exactly and silently resets to 0 was not
counted. Consequently traces could legitimately show bytes_written
much greater than buffer_size with write_wrap_count = 0, making the
stat unreliable for ring-buffer-pressure diagnostics. V1 counts both
paths; V2 had regressed this.
Fix: introduce a local |wrapped| flag in CopyChunkUntrusted, set it
in both wrap branches, and increment write_wrap_count once at the
end if wrapped is true.
Why a flag instead of incrementing in both places directly: when the
incoming chunk is exactly the buffer size, the panic-wrap path resets
wr_ to 0, the chunk is then written, wr_ advances back to size_, and
the natural-wrap branch fires too. With direct increments in both
places this single CopyChunkUntrusted call would double-count one
logical wrap. The flag collapses both branches into a single
increment per call, matching the proto contract:
// Num. times the ring buffer wrapped around.
Adds a regression test that exercises both wrap paths and asserts the
counter increments correctly.1 parent 31d39b6 commit b405ced
2 files changed
Lines changed: 44 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
777 | 777 | | |
778 | 778 | | |
779 | 779 | | |
| 780 | + | |
780 | 781 | | |
781 | 782 | | |
782 | 783 | | |
| |||
785 | 786 | | |
786 | 787 | | |
787 | 788 | | |
788 | | - | |
| 789 | + | |
789 | 790 | | |
790 | 791 | | |
791 | 792 | | |
| |||
880 | 881 | | |
881 | 882 | | |
882 | 883 | | |
883 | | - | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
884 | 888 | | |
885 | 889 | | |
886 | 890 | | |
| 891 | + | |
| 892 | + | |
887 | 893 | | |
888 | 894 | | |
889 | 895 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2092 | 2092 | | |
2093 | 2093 | | |
2094 | 2094 | | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
2095 | 2131 | | |
2096 | 2132 | | |
2097 | 2133 | | |
| |||
0 commit comments