Skip to content

tan: fail indexed reads that make no progress at EOF - #19

Merged
volgariver6 merged 1 commit into
matrixorigin:masterfrom
LeftHandCold:fix/tan-indexed-read-progress
Oct 16, 2026
Merged

volgariver6 merged 1 commit into
matrixorigin:masterfrom
LeftHandCold:fix/tan-indexed-read-progress

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Oct 15, 2026 •

Copy link
Copy Markdown

Problem and root cause

Addresses matrixorigin/matrixone#30219 at the Tan dependency boundary. MatrixOne must also consume the fixed dependency revision; merging this dependency PR alone must not be treated as a deployed MatrixOne fix.

When a persisted entry index points at EOF, readLog treats EOF as a successful scan. No entry callback advances passed, so getEntries reopens the same log and seeks to the same position forever. Its old EOF branch is unreachable both because EOF is normally swallowed by readLog and because non-nil errors already return above it. Raft's step worker cannot return to its stop channel while this call is spinning.

This loop was introduced in 9ef6a64061dadddfdcb9b80082fe6ae1c31421b3 (2022-11-15). The current MatrixOne pin abc3d2fce5a6 and this PR's base 18a1f46a2ea64eb42a2b330ef98d662ca68a1365 have identical trees. This identifies the origin of the non-progress loop, not the origin of missing on-disk records.

Minimal change

  • Require each unlimited indexed scan to consume at least one index entry; otherwise return an error containing shard, replica, expected index, log number and offset.
  • Preserve the earlier size-limit return: stopping within an index entry is legitimate when maxSize is reached.
  • Leave readLog EOF semantics intact because normal log rotation and index rebuild use them.
  • Do not rewrite indexes/logs, skip missing entries, alter Raft commit/snapshot state, add timeouts/background workers, or claim that missing committed records have been recovered.

The error propagates through LogDB.IterateEntries and LogReader.Entries to the existing Raft/engine storage-error path. A recovery read fails explicitly instead of busy-looping. Existing engine behavior is fail-stop; this is not a new graceful-repair mechanism.

Regression and control evidence (Linux amd64, Go 1.24.0, GOMAXPROCS=4)

TestIndexedReadWithoutProgress persists a small index, closes/reopens Tan, and checks both the public LogDB API and its LogReader consumer:

  • index exactly at EOF;
  • a valid prefix followed by the missing indexed record;
  • a state-only record at the indexed entry position;
  • healthy prefix reads still work after the error;
  • size-limited reads still stop successfully before a missing later entry;
  • Close succeeds and file/goroutine cleanup is checked.

A bounded FS-open counter makes the old version fail deterministically rather than leaving a hung test goroutine. All three bad-input cases failed before the production fix; all pass after it.

Executed successfully:

go test -mod=readonly -count=1 -timeout=300s ./internal/tan ./internal/logdb ./internal/raft ./plugin/tan
go test -mod=readonly -race -count=1 -timeout=120s -run '^TestIndexedReadWithoutProgress$' ./internal/tan
go test -mod=readonly -race -count=14 -timeout=120s -run '^TestIndexedReadWithoutProgress$' ./internal/tan
go test -mod=readonly -race -count=1 -timeout=300s ./internal/tan
go vet -mod=readonly ./internal/tan ./internal/logdb ./plugin/tan
go build -mod=readonly ./...
git diff --check

The focused race test measured 2.13 seconds; 14 repeats fit the 30-second adaptive stress budget. Existing normal tests cover log rotation, restart, entry overwrite, empty updates, max-size reads, compaction and torn-tail rebuild behavior.

Review boundaries

Contract Review
Q1 ownership No new production resources; existing file-close/read-state ownership unchanged. Regression checks closure after failure.
Q2 termination Every successful outer iteration advances passed; a no-progress iteration fails. No elapsed-time heuristic or unbounded retry.
Q3 growth No new accumulation, goroutine or persistent state. Healthy path adds only scalar bookkeeping and a comparison per scan.

No SQL BVT is added: the changed contract is below SQL, at persisted Raft-log iteration. The issue's original retained large fixtures are not reproduced by this test; the test deliberately injects the exact inconsistent-index/EOF condition. Why the original records are missing remains a separate investigation.

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.

2 participants