Skip to content

fileservice: avoid whole-object fills on cold TP locking reads - #33615

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/tp-lock-cold-range-no-disk-fill
Dec 2, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/tp-lock-cold-range-no-disk-fill

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #33435. This removes one source of read amplification; it does not establish the cause of the reported 60s SQL timeouts. Narrow replacement for the closed, unmerged #33438.

What this PR does / why we need it:

A TP locking SELECT can need a single decoded column extent near the end of a large object. A cold miss can start a whole-object disk-cache fill even though the statement needs only a few KiB.

  • Carry a hint on table scans for TP locking SELECTs only. In S3FS, after cache lookups miss, reuse the existing minimal-range read for a single decoded, non-streaming extent, at most 256 KiB with offset at least 8 MiB. Restrict this to the default policy with both decoded memory and disk caches configured.
  • Keep existing cache hits and decoded-memory admission. Do not set SkipFullFilePreloads, publish raw disk ranges, change cache keys/formats, or change deletion, restart, GC, or lock behavior. Ordinary reads keep their existing path. The HDFS backend also keeps its pre-PR path even when a TP locking scan sets the hint: a seek beyond EOF there is a backend error, not an HTTP 416.
  • Trade-off: readers can issue separate range requests when they miss together or decoded memory admission rejects them. This is not a request-count optimization.

Validation

  • Compared the original main S3FS implementation at f5fcac7488 and this change using the same disk-backed object-store fixture, fresh caches, and a 96 MiB object. Read 16 nonoverlapping 43,229-byte extents starting at offset 93,644,241; verified every returned byte. Counted underlying reads and bytes consumed from their readers (not estimates from SQL metrics):

    Implementation Object reads Bytes consumed
    Main baseline 1 100,663,296
    This change 16 691,664
  • New regression test fails on the baseline: it requests from offset zero to EOF. On the candidate, forced memory rejection produces two bounded reads and no new raw disk file/range; re-enabling admission gives a decoded-memory hit. An ordinary miss still fills the whole file and a subsequent eligible lock read hits that disk file without another object read.

  • SQL scope coverage: TP locking SELECT, ordinary TP SELECT, AP, and DML, including overwriting stale scan flags. Shape guards cover explicit policies, multiple entries, early, large, unknown-length, undecoded and streaming reads.

  • Local: full pkg/fileservice with -race, full pkg/sql/compile and pkg/sql/colexec/table_scan, and selected-package static checks.

  • Independent Hadoop 3.4.1 NameNode/DataNode A/B on a 10 MiB file with fresh caches: ordinary and hinted reads crossed with EOF−16, EOF−7, EOF, and EOF+7. At 74030b9e89, 7/8 passed (hinted EOF+7 leaked a seek error). At b28e9b0a74, 8/8 passed; valid bytes matched and all short reads returned MO ErrUnexpectedEOF with zero bytes. No production or 1,000-warehouse / 1,000-terminal TPC-C result is claimed here. Before considering a 4.2 backport, compare client timeouts, lock-holder latency, throughput, and object requests/bytes under the original cold-start workload.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Dec 1, 2026
@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 6292e4d7b91083320a05c6b3c734824cbe5704ef

"interrupted"

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Fixed the EOF classification at 74030b9e89 (on top of the reviewed 416f97d566). The eligible cold locking path now classifies a 416 from opening the object range as MO ErrUnexpectedEOF, just as the previous whole-object read did. This does not translate 416 from a decoder, change the SDKs, add a HEAD/retry, or alter ordinary reads.

Verification:

  • Before the change: the new HTTP regression test failed on both AWS SDK v2 and MinIO SDK at EOF and EOF+7. After the change: all four pass. A missing key still returns MO ErrFileNotFound and an in-flight cancellation still returns context.Canceled on both SDKs.
  • Replayed the challenge length harness against a fresh, isolated real MinIO: 10 MiB object; 16-byte requests starting at EOF−7, EOF and EOF+7; ordinary/locking reads × both SDKs. 12/12 returned MO ErrUnexpectedEOF, not successful short data or raw SDK errors.
  • Local fileservice package passed with -race; package SCA reported 0 issues. GitHub CI on this new head must still pass before merge.

Scope: this is a bandwidth optimization, not a demonstrated fix for the 60s lock wait in #33435. The independent challenge's initial district object was below the 8 MiB offset threshold. Its 16 serial cold ranges at 15 ms added latency per GET were slower than a single whole-object fill; a restart need not leave a whole disk copy for an object-store outage. These trade-offs remain; no 4.2 backport or issue closure is implied.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 74030b9e891069232d40cb66aa4f44c40eedd7a8

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 74030b9e891069232d40cb66aa4f44c40eedd7a8

Assessment: request_changes

The narrow range-read design reuses the existing cache and storage paths, and the HTTP 416 handling passes the focused AWS and MinIO SDK tests. The change needs one correction for HDFS: an eligible past-end read no longer returns the file service’s required unexpected-EOF error.

Model: gpt-6.1-terra / max

Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39

  • P2 pkg/fileservice/s3_fs.go:946: An HDFS-backed TP locking scan with both caches enabled requests an eligible small extent whose offset is beyond the end of the object.
    Impact: The hinted read returns a generic invalid-offset error instead of ErrUnexpectedEOF, so callers cannot identify the truncated object using the documented FileService error contract.
    Evidence: The new eligibility check includes HDFS, but HDFS.Read passes seek errors from readObjectRange through, and the HDFS client rejects seeks beyond the file size. The new normalization handles HTTP 416 only. The retained hdfs-short-read-probe.log uses an HDFS seek-behavior double: the ordinary control returned ErrUnexpectedEOF, while the hinted read returned 'invalid resulting offset'. Exclude this backend from the optimization or preserve the short-read error classification for its range reads, and cover the boundary in a regression test.

Validation:

  • Private /tmp and loopback preflight passed.

  • Four focused pkg/fileservice tests passed, covering eligibility, cache behavior, the ordinary full-object control, and mocked AWS and MinIO error paths.

  • TestScopeSmallExtentReadsOnlyForTPLockingSelect passed for TP and AP, locking and plain SELECT, DML, and stale-flag controls.

  • The simulated HDFS short-read probe reproduced the error-classification difference; it was an observational test, not a real HDFS service test.

  • git diff --check passed. Check receipts, source fingerprints, and retained logs are mapped in validation-audit.json.

Limitations:

  • A real HDFS service, end-to-end SQL workload, performance benchmark, and race run were not independently exercised.

  • The first Go test invocation did not run because the inherited toolchain setting selected Go 1.26.6; the focused tests passed after enabling the required toolchain.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Addressed the HDFS review at b28e9b0a74. A range starting beyond EOF is rejected by HDFS FileReader.Seek before MO sees any bytes. It is not an HTTP 416, so the S3 classification fix cannot apply. The optimization now leaves HDFS on the pre-PR path. No string matching, extra Stat, HDFS adapter change, or change to ordinary/S3 reads.

I independently replayed the original public NewS3FS fixture against a real Hadoop 3.4.1 NameNode/DataNode, using a 10 MiB object, fresh caches and the same 16-byte read at EOF-16, EOF-7, EOF and EOF+7, with and without the hint. On 74030b9 only hinted EOF+7 leaked “invalid resulting offset: 10485767” (7/8). At b28e9b0 both valid reads returned the expected bytes, all six short reads returned MO ErrUnexpectedEOF and zero bytes (8/8). The new deterministic regression test is red on the parent and green here; retained S3 range/416 tests, full fileservice -race and package static checks passed locally.

This is a real file-service error-contract regression, not evidence of wrong SQL rows or of regular SQL generating out-of-bounds offsets. #33435 remains open; please wait for required CI and re-review.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: b28e9b0a74645167883f410811e9371184ecd6bf

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: b28e9b0a74645167883f410811e9371184ecd6bf

Assessment: approve

The narrow range-read optimization reuses the existing scan, cache and storage paths. The prior HDFS short-read finding is resolved, and no actionable defects remain. The accepted trade-off is that eligible cold reads may issue more range requests and leave no whole-object disk copy; this change does not establish a fix for the linked timeout incident.

Model: gpt-6.1-terra / max

Session: 01a23504-137d-7f93-9b91-fd29f7f60fa2 · slot 1 · generation 42

Validation:

  • Private-runtime preflight passed, and native prerequisites built outside the checkout matched the frozen source inputs.

  • Focused normal and race-enabled tests passed for cache behavior, scan routing, AWS and MinIO error handling, and the HDFS short-read control.

  • A diagnostic scope-to-S3FS probe verified the requested bytes and cache behavior for TP locking, plain TP and AP controls.

  • The frozen diff passed whitespace validation. The review plan and discussion assessment were saved and verified, covering all eight discussion keys.

Limitations:

  • The integrated probe used a test reader and disk-backed object storage; it was not a production SQL or object-store workload.

  • The author's reported real-Hadoop and larger component comparisons were not independently repeated. No TPC-C result is claimed, and the linked incident remains open.

@mergify mergify Bot added the queued label Dec 2, 2026
@mergify

mergify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request merged manually

1 h 8 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 2 Dec, 12:01 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 13:09 · 4c78e1b

Reason

Pull request #33615 has been merged manually at 5496ca7

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

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

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants