Skip to content

Count pipeline errors per-command, not per-window - #125

Open
fcostaoliveira wants to merge 2 commits into
masterfrom
fix/pipeline-error-count-118
Open

fcostaoliveira wants to merge 2 commits into
masterfrom
fix/pipeline-error-count-118

Conversation

@fcostaoliveira

Copy link
Copy Markdown
Contributor

Closes #118. (Supersedes #124, which auto-closed when its stacked base branch — #117/#123 — was deleted on merge. #123 is now in master, so this retargets cleanly to master and the diff is just the #118 delta.)

Problem

radix.Pipeline.Run stops decoding at the first failing command, drains the remaining replies, and returns a single aggregate error for the whole batch. flushPending then marked every command in the pipeline window as errored — so one bad reply (e.g. a WRONGTYPE) in a window of N inflated the error count by up to N.

Fix

Replace radix.Pipeline with a small custom Action (pipelineErrs) that still sends the whole batch in one buffered write (multiMarshal) but decodes every reply and records each command's own error in errs[i]. flushPending attributes hadError/isTimeout per command.

Review-gate fixes (from 15 adversarial reviews)

  • Undercount when client.Do fails before Run: radix Pool.Do calls pool.get() before Action.Run, so a connection-acquisition failure during an outage returns without ever running pipelineErrs, leaving errs all-nil → the batch was counted as fully successful. Added a ran flag; cmdErr falls back to the Do error for the whole window when !pe.ran, and keeps exact per-command attribution once the batch executed.
  • Untested transport-error tail: added pipeline_action_test.go — a fake radix.Conn drives Run deterministically through a mid-batch i/o-timeout tail, a lone RESP error, an encode failure, and the unrun state.

Validation

TestFTSBPipelineErrorCountedPerCommandNotPerWindow: one WRONGTYPE among 9 good HSETs in a pipeline of 10 → Errors == 1 (pre-fix binary: Errors == 10, verified). New unit tests + full suite green under -race.

radix.Pipeline.Run stops decoding at the first failing command, drains
(discards) the remaining replies, and returns a single aggregate error for the
whole batch. flushPending then marked EVERY command in the pipeline window as
errored, so one bad reply (e.g. a WRONGTYPE) in a window of N inflated the error
count by up to N.

Replace radix.Pipeline with a small custom Action (pipelineErrs) that still
sends the whole batch in one buffered write (via multiMarshal) but decodes every
reply and records each command's own error in errs[i]. flushPending now
attributes hadError/isTimeout per command from that slice: a RESP error fails
only its own command; a transport error (i/o timeout) fails that command and the
ones after it (the connection is broken) while the already-decoded ones stay
successful. The read cost is unchanged -- radix.Pipeline also decodes/drains all
N replies.

Regression guard: TestFTSBPipelineErrorCountedPerCommandNotPerWindow feeds one
WRONGTYPE among 9 good HSETs in a pipeline of 10 (workers=1, deterministic) and
asserts Errors==1. Verified the pre-fix binary reports Errors==10 for the same
input. Existing error/timeout integration tests still pass.
…#118)

Two adversarial-review findings on the initial #118 change:

1. Undercount when client.Do fails BEFORE pe.Run (minor): radix Pool.Do calls
   pool.get() before Action.Run, so a connection-acquisition failure during a
   server outage returns an error without ever running pipelineErrs. pe.errs
   then stayed all-nil, so every command in the window was recorded as a
   SUCCESS -- the batch's errors were undercounted to zero (pre-#118 counted the
   whole window). Add a `ran` flag set at the top of Run; flushPending's cmdErr
   falls back to the Do error for the whole window when !pe.ran, and keeps exact
   per-command attribution once the batch executed.

2. Untested transport-error tail (minor): the only multi-command test used a
   WRONGTYPE (connection stays healthy). Add pipeline_action_test.go with a fake
   radix.Conn driving Run deterministically through: a mid-batch i/o-timeout tail
   (cmd0 ok, cmd1 timeout, cmd2 on broken conn -> each recorded, none dropped or
   blamed on cmd0), a lone RESP error (only its own command fails), an encode
   failure (whole batch fails, nothing decoded), and the unrun ran=false state.

Full cmd unit suite and the #118 integration guard still pass under -race.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ftsb_redisearch: pipelined error/timeout counts are inflated by pipeline depth

1 participant