Skip to content

Avoid whole-object reads for small cold extents in TP locking scans - #33438

Closed
LeftHandCold wants to merge 14 commits into
matrixorigin:mainfrom
LeftHandCold:fix/tp-lock-read-small-cold-extents
Closed

LeftHandCold wants to merge 14 commits into
matrixorigin:mainfrom
LeftHandCold:fix/tp-lock-read-small-cold-extents

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Nov 28, 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.

What this PR does / why we need it:

A cold TP locking SELECT can request 43,229 bytes starting 93,644,241 bytes into an object. Starting a whole-object disk fill at byte zero makes the foreground reader wait for the prefix. The linked incident remains open for matched 1000W/1000T validation.

Eligible single decoded extents up to 256 KiB, beginning at least 8 MiB into an object, use the existing range read path when both caches are configured. Other query and cache policies retain their current behavior.

When memory-cache admission fails, concurrent readers can reuse the raw range held by the bounded async disk writer. Each pending hit may take one temporary copy of up to 256 KiB. Opted-in followers wait within the existing foreground budget before one caller may issue a backup GET. A delete/recreate gets a distinct range generation, so new reads do not join a stalled read of the prior object version. Late publishers remain isolated in the retired generation.

Raw and decoded bytes remain separate: an eligible cold range that may be published to disk gives the converter a private input copy (up to 256 KiB). Streaming reads do not promote caller scratch buffers into raw cache entries.

Range entries use generation-qualified internal directories. A fixed-size checksummed state file occupies 36 KiB and is persisted when the effective disk-cache capacity is at least twice that size; the file is charged against cache capacity. Smaller caches keep their full configured capacity and use a process-local namespace, so range entries are cold after restart. Old generation directories age out through the existing LRU.

Before backing-object deletion, a cache with an existing persistent range namespace writes and syncs the generation file and its parent directory. If that fence cannot be recorded, deletion stops before storage mutation. A fresh cache has no earlier persistent ranges to invalidate and skips the state-file write. An in-flight fill keeps its original generation, including across first-time initialization. The delete fence stays active through cache invalidation. Waiters for the durable I/O slot can cancel; finishing an admitted delete does not wait for another writer's fsync. External object bytes and storage format are unchanged; the internal disk-cache range layout and state file have changed.

Validation

  • Real MinIO challenge on 02c6d1c2c1: overlapped first-fill and batch-delete/whole-file decode, each tested with both deletion alone and deletion/replacement, twice. Fresh default and bypass reads agreed on not-found or all 32 KiB of replacement content. Empty-cache state write fault and range directory eviction checks passed. The fileservice and s3fifo packages passed -race; targeted fileservice SCA reported zero issues.
  • The controlled local pressure probe changed from nine GETs and about 1.61 s for one leader plus eight followers to one bounded GET with the fix.
  • The fileservice package passed mo-cgo-test -race -count=1 -timeout 240s. Incremental go vet, molint, and golangci-lint passed after rebase. The targeted compile test and table-scan package compile also passed.
  • A local component microbenchmark measured about 41.3 µs per persistent delete fence versus 0.37 µs for process-local fences on this host. This is not a production storage benchmark. This cost applies when an existing persistent namespace needs a new durable fence.
  • The matched storage experiment for disjoint small reads used 16 range GETs and transferred 691,664 bytes instead of one whole-object GET transferring 96 MiB. Matched cold TPC-C runs are still needed to establish the effect on client deadlines, lock waits, and throughput.

Original review

@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 Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@XuPeng-SH

XuPeng-SH commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 47c42221b6857c87eb72febc4a313d059ac91cc9

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: 47c42221b6857c87eb72febc4a313d059ac91cc9

Assessment: request_changes

The change appropriately reuses the existing range-cache path and coalesces concurrent reads when memory admission succeeds. Its eligibility check also selects that path when memory admission fails, however, causing concurrent locking reads to retry serially while disk publication is pending.

Model: gpt-6.1-terra / max

Session: 01a2230f-39de-7f00-bf9a-e19ded95bd85 · slot 0 · generation 39

  • P2 pkg/fileservice/s3_fs.go:717: Concurrent TP locking reads request the same eligible cold extent while both caches are configured, but memory-cache capacity is reserved and the asynchronous disk-cache entry is still being finalized.
    Impact: The range leader cannot publish a reusable memory entry. Followers repeatedly wait for the pending disk entry and join successive range generations, issuing another storage read each time. This adds latency and storage requests to locking reads; the delay grows with the number of followers while those conditions persist.
    Evidence: MemCache allocation can return transient data when reservation fails, and MemCache.Update skips admission of that data. In three controlled repetitions with eight followers and a blocked disk finalizer, the candidate issued nine reads and the followers took 1.61–1.64 seconds; the unmarked full-object control issued one read and served the followers in under 1.1 ms. See pressure_probe_test.go, pressure-repeat.log, and checks/1795888937157849932-2.json. Ensure failed admission cannot leave followers serially joining generations without a reusable result, and cover this pressure case with a regression test.

Validation:

  • Private /tmp and loopback preflight passed: preflight.log and checks/1795888433374566264-3.json.

  • TestS3FSSmallExtentRead passed: fileservice-test.log and checks/1795888675550735520-2.json.

  • TestScopeSmallExtentReadsOnlyForTPLockingSelect passed: scope-test.log and checks/1795888787199845624-2.json.

  • An eight-follower coalescing probe passed under the race detector when memory admission was available: coalesce-race.log and checks/1795889097261811252-2.json.

Limitations:

  • The pressure comparison uses a local object backend and deliberately delayed disk finalization; its timings are not a production workload estimate.

  • The PR's full-suite, two-CN SQL, and workload measurements were reported by the author; corresponding execution artifacts were not supplied.

  • The initial local test attempt stopped before compilation because the host selected an older local Go toolchain. The retry with automatic toolchain selection passed.

@XuPeng-SH

XuPeng-SH commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 3e7b7faec3bd88f5f899c516096975b6d6c4d1d0

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: 3e7b7faec3bd88f5f899c516096975b6d6c4d1d0

Assessment: request_changes

The earlier concern about serial follower reads under memory pressure is resolved. The implementation reuses the existing range-read and asynchronous disk-cache paths, but the new pending-range publication can return incorrect data when a converter modifies its input.

Model: gpt-6.1-terra / max

Session: 01a2230f-39de-7f00-bf9a-e19ded95bd85 · slot 0 · generation 39

  • P2 pkg/fileservice/disk_cache_async.go:274: An opted-in small-extent read uses a ToCacheData converter that modifies its input during successful conversion, and a later read misses the memory cache.
    Impact: The later reader can receive incorrectly decoded data from the pending range or the published disk-cache entry. The underlying object remains unchanged, but the cached range remains wrong until it is evicted.
    Evidence: IOEntry's ToCacheData contract forbids retaining the input but does not forbid modifying it. S3FS invokes the converter before DiskCache.Update clones entry.Data, so this publication can contain converted rather than original storage bytes. A public S3FS probe with memory admission held returned 0xff for both reads on the default path; the opted-in path returned 0xff for the first read and 0x00 for subsequent reads both before and after disk publication. See inplace-published-probe.log and checks/1795914409192386967-3.json. Preserve the original range bytes for pending and disk publication before invoking the converter, and cover this case with a regression test.

Validation:

  • Private /tmp and loopback preflight passed: preflight.log and checks/1795913676472090228-3.json.

  • Focused file-service and SQL scope tests passed: focused-tests-native.log and checks/1795914167999038365-3.json.

  • The pressure and empty-generation tests passed under the race detector: race-tests.log and checks/1795914424124017077-3.json.

  • The in-place-converter probe failed on the opted-in path while its default-path control passed: inplace-published-probe.log and checks/1795914409192386967-3.json.

  • Native prerequisites were built from inputs matching the frozen source: native-provenance-check.txt.

Limitations:

  • Matched TPC-C and end-to-end SQL workload measurements were not run; the component tests do not establish the change's effect on client deadlines or total object-store traffic.

  • The initial local test attempts failed during toolchain or native setup; the focused checks passed after those prerequisites were supplied.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: cb44d74a8b8b662af7a4dfd011957138d25937be

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: cb44d74a8b8b662af7a4dfd011957138d25937be

Assessment: request_changes

The change reuses the existing caches and I/O merger, and bounded generation state avoids retaining a tombstone per object. The earlier decode-lease and hedge-generation cases are addressed by the focused tests. Two new deletion interleavings can still republish stale bytes, eviction leaves empty range directories, and persistent state can make an unused cache block backing-object deletion.

Model: gpt-6.1-terra / max

Session: 01a22868-9f85-7953-8ef9-e32b1e30f8c7 · slot 2 · generation 13

  • P2 pkg/fileservice/disk_cache.go:741: The first range fill on a cache without initialized range state overlaps deletion of the same object.
    Impact: The old fill can be published under the post-delete generation, so a read after recreation can return old bytes in preference to the new full-object cache.
    Evidence: The original fence is checked before ensureRangeCacheState, then replaced with a fresh fence afterward. A delete can complete between those operations. A scheduling-hook probe returned "old" instead of "new"; see probes.log and checks/1796011869438943916-3.json. Preserve and recheck the original generation across initialization.

  • P2 pkg/fileservice/s3_fs.go:1929: A read begins after the delete fence is finished but before the old whole-file and memory caches have been cleared, then completes its conversion after deletion and recreation.
    Impact: The overlapping read can publish old whole-file bytes into memory under the new generation, causing subsequent readers to receive stale data.
    Evidence: S3FS finishes the fence before deletePathsAfterRangeRetired and MemCache.DeletePaths. A scheduling-hook S3FS probe paused at that boundary and reproduced a fresh read returning "old" instead of "new"; see delete-probes.log and checks/1796012004428985641-3.json. Keep obsolete publication fenced through cache invalidation, including failure paths; LocalFS has the same ordering.

  • P2 pkg/fileservice/disk_cache_ranges.go:289: The disk-cache device is out of space when an S3FS delete runs, including on a fresh cache that has never stored a range.
    Impact: The new state-file write fails before the backing storage delete is attempted, blocking object deletion even though no range state needed retirement.
    Evidence: beginRangeDelete unconditionally writes durable state for a nonempty delete when persistence is enabled. The S3FS /dev/full fault probe returned ENOSPC on .range-cache-state.tmp before storage deletion; see delete-probes.log and checks/1796012004428985641-3.json. Avoid requiring durable state for an unused namespace, and handle cache-space exhaustion while preserving fencing for existing ranges.

  • P2 pkg/fileservice/index_cache.go:1052: The last cached range file in a generated range directory is evicted.
    Impact: The empty directory remains until a later cleanup or restart and is outside the cache's byte accounting. A long-lived cache with continuing object churn can accumulate directories and consume disk space and inodes.
    Evidence: The cleanup guard expects the prefix plus 64 characters, but rangeDirAtEpoch adds a 32-character namespace, a 16-character epoch, separators, and the 64-character hash. The eviction probe removed the range file but found its directory still present; see probes.log and checks/1796011869438943916-3.json. Match the current directory layout when removing empty range directories.

Validation:

  • Private /tmp and loopback preflight passed: preflight.log and checks/1796011392403861666-3.json.

  • Fifteen uninstrumented focused file-service and SQL-scope tests passed under the race detector: focused-race.log and checks/1796012392934849403-3.json.

  • Four focused probes reproduced the reported failures. The concurrency probes used Go overlays containing scheduling hooks; the storage-space probe injected ENOSPC with /dev/full. Logs and matching exit-1 receipts are retained in the diagnostic directory.

  • Native prerequisites were built in the diagnostic directory from 198 inputs verified against the frozen source before and after the build. An initial verification command failed due to shell quoting; the corrected verification passed.

Limitations:

  • The probes used a local disk-backed file service and controlled scheduling; real object-store and two-CN workloads were not rerun.

  • The full test suites and matched TPC-C workload were not run. Earlier workload claims concern an older head and were not independently reproduced.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: e693f5cf203f05a8371451ae5fdf451bcd611dc0

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: e693f5cf203f05a8371451ae5fdf451bcd611dc0

Assessment: request_changes

Four actionable issues remain in the range-cache generation and cleanup paths. The first-fill, disk-full, and directory findings were raised in the prior review; the cancellation issue was identified in the earlier attempt. The separate whole-file invalidation race from the prior review also reproduces on the merge base, so it is not attributed to this PR. The design reuses the existing caches and merger, but its new persistent generation state needs correct publication, cancellation, and cleanup ownership.

Model: gpt-6.1-terra / max

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

  • P2 pkg/fileservice/disk_cache.go:741: An opted-in small-extent read begins before the range namespace is initialized, passes the original generation check, and overlaps deletion and recreation before initialization completes.
    Impact: The old fill adopts the new generation and can make later readers return deleted-object bytes instead of the replacement.
    Evidence: The original fence is checked at lines 730–733 and replaced after initialization without another check. A controlled S3FS probe returned "old" to a fresh opted-in reader while a direct storage read returned "new"; see transition-public-check.log and checks/1796029151408488981-3.json. Preserve and recheck the original generation across initialization.

  • P2 pkg/fileservice/disk_cache_ranges.go:289: The cache filesystem is full when a delete runs with range-state persistence enabled, including on a fresh cache that has never stored a range.
    Impact: The new state-file write fails before the backing-object deletion is attempted, so optional cache metadata can prevent object cleanup.
    Evidence: The /dev/full probe left the backing object present after ENOSPC, while a healthy control deleted successfully; the merge-base fileservice overlay deleted the object without the new state write. See transition-check.log and base-disk-full-check.log. Avoid requiring a durable range-state write for an unused namespace while preserving fencing when persisted ranges exist.

  • P2 pkg/fileservice/disk_cache_ranges.go:264: One delete holds rangeStateMu while its state-file or directory sync stalls, and an unrelated delete or first range initialization reaches the same mutex with a cancelled context.
    Impact: The unrelated operation cannot return on cancellation until the stalled sync releases the global mutex. A delete that has already changed backing storage can also stall in finish before cache invalidation.
    Evidence: The mutex is held across writeRangeCacheState(true), including file.Sync and dir.Sync, and acquisition does not observe context cancellation. The gated-sync probe left a cancelled bystander blocked until the first operation was released; see transition-check.log and checks/1796028880751446236-3.json. Make waiting and completion independent of an unrelated stalled sync while retaining ownership of unfinished durable fencing.

  • P2 pkg/fileservice/index_cache.go:1052: The last cached range file in a generation-qualified directory is evicted.
    Impact: The empty directory remains outside byte accounting; continued object churn can accumulate directories and consume filesystem space and inodes until later cleanup or restart.
    Evidence: The cleanup guard expects rangeDirPrefix plus 64 characters, but rangeDirAtEpoch also includes the namespace, epoch, and separators. An actual LRU eviction removed the range file and left its directory; see transition-check.log. Recognize the current directory layout when removing empty range directories.

Validation:

  • Private /tmp and loopback preflight passed: checks/1796028292529327161-5.json.

  • The current-head fileservice package passed under the race detector: checks/1796030114400037246-3.json and package-race-check.log. Six tests were skipped.

  • Focused fileservice tests, pressure and hedge tests, and the SQL scope-selection test passed: checks/1796028631922327072-3.json, checks/1796029203501752959-3.json, and checks/1796029330627894678-3.json.

  • Controlled transition probes reproduced the four reported failures; scheduling hooks and full output are retained in transition-check.log and transition-public-check.log. The disk-full merge-base control passed: checks/1796029444042749561-3.json.

  • The prior whole-file overlap reproduced on the merge-base fileservice overlay: checks/1796029012349592866-3.json and base-whole-file-check.log. Native build inputs were verified against the frozen head in native-provenance-check.txt.

Limitations:

  • The package race run skipped three opt-in OOM/RSS reproducers, HDFS, an obsolete restore test, and a test with no case.

  • The probes used a local disk-backed service and controlled scheduling. Matched TPC-C, multi-CN, and real object-store workloads were not rerun.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Addressed the November 30 challenge and the change request in 02c6d1c. Requesting another review; not merging or closing #33435.

Reproduction (real MinIO, same schedules) e693f5c 02c6d1c
First range fill overlaps delete; new ordinary read after Delete returns stale 32 KiB not found, same as bypass
Batch delete overlaps an old whole-file decode; same postcondition stale 32 KiB not found, same as bypass
Same two interleavings with a replacement at the same path ordinary read returned old bytes; bypass read new both returned the new object, all 32,768 bytes compared
Fresh cache with unwritable range state, backing store healthy backing deletion failed backing object removed
Evict last range from each of 128 objects 128 empty per-object directories 0

Each final variant ran twice. The local write-fault test used an unwritable temp-file target, not an actual full device. The first-fill publisher now keeps its original generation; the deletion remains active through disk and memory cache invalidation (including local FS with disk caching enabled). The whole-file timing is a pre-existing failure, not attributed to the small-extent policy. Already admitted deletes can complete and queued waiters can cancel independently of an unrelated stalled state-file write. An existing persistent namespace still fails closed if its durable fence cannot be written; skipping that fence would risk serving old bytes after restart.

Fileservice + s3fifo full package -race -count=1 passed. Targeted fileservice SCA: 0 issues. Added regression tests for the generation, cancellation, overlapping delete rollback, and eviction boundaries. This validates the file-service cases, not a production 1000W/1000T TPC-C run or a customer-visible SQL stale row.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Requesting a fresh review on 847c2b8. The linked changes request was for e693f5c; the new same-stripe failure on 02c6d1c was real and distinct.

Cause / fix: while deletion of A was still cleaning its cache, overlapping deletion of B in the same stripe did not change the persistent stripe generation. A new read of the re-created B could therefore reuse a held decoded value or wait on the old primary and backup GET. Keep the on-disk fence unchanged, but advance a process-local read identity on each deletion's admission and completion (including overlaps). Both decode entry points and the S3 GET merge keys use it. In-memory publication tracks exact canonical paths only while their deletes are in flight, with a generation check under the cache index lock. This permits reuse for B once its delete is complete without permitting publication from an obsolete reader. No persistent metadata or object format change in this revision.

Matched real MinIO, unchanged challenge byte and wait oracles:

  • Reproduced all three stale-byte results on 02c6d1c. On the new code, explicit range Read, default TP locking-read policy and DecodeFromBytes all returned the entire new 32 KiB, twice each. Different-stripe, released-lease, and sharing-off controls passed.
  • With two old GETs still blocked and A still cleaning, the old head hit the 2 s deadline without starting a new range GET. The candidate issued one new GET and returned the correct bytes in 9 ms / 7 ms.
  • A synchronized burst of 32 readers of the cold replacement (memory admission available, no decode sharing): old head 32 GETs with A active versus 1 without A; candidate 1 GET in either case, twice. This is not a universal one-GET bound under memory/storage pressure.
  • Previous first-fill and batch/whole-file overlap tests passed on deletion alone and on replacement. Fresh-cache write fault still permits backing deletion; eviction left 0 empty directories for 128 objects. Package race tests cover cancellable persistence waits/retirement, overlapping aliases and publication, and primary/backup handoff. Fileservice + s3fifo under -race passed; selected fileservice SCA: 0 issues.
  • Test boundary: an undersized fixture backing store filled during one run; those results are not counted as passes. A concurrent harness invocation also hit its context deadline before the replacement oracle; the unchanged case passed twice in isolation. Incidental upload retry race tracked separately in [Bug]: Fileservice MinIO upload retry races with an in-flight request body on storage failure #33519.

No claim of SQL stale-row resurrection or matched 1000W/1000T incident resolution. Please re-review the new head; not merging or dismissing the previous review.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 999a3be5419f3108cff6470aa6cb9c4746ba8bab

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: 999a3be5419f3108cff6470aa6cb9c4746ba8bab

Assessment: request_changes

A streaming read can initialize persistent range metadata without caching a range. A later metadata write failure then prevents deletion from reaching healthy backing storage. The earlier direct empty-cache case is fixed, but this related case remains. The design otherwise reuses the existing cache and read-merger owners; generation fencing provides restart and delete/recreate isolation at the cost of persistent metadata and deletion I/O.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

  • P2 pkg/fileservice/disk_cache.go:739: With a fresh disk cache large enough to persist range state, read an object through a streaming IOEntry with SkipFullFilePreloads, then delete an object while replacement of the cache state file fails.
    Impact: The streaming read publishes no range file, but it creates the persistent namespace. Consequently, beginRangeDelete requires a state-file rewrite and S3FS.Delete returns its error before deleting from otherwise healthy backing storage.
    Evidence: updateRanges initializes the namespace before it skips WriterForRead and ReadCloserForRead entries at lines 763–769. An identical public S3FS probe passed against the merge-base overlay but failed on this head after injecting ENOSPC into the state-file write; the untouched-cache control passed on both. See stream-delete-base.log and stream-delete-current.log. Initialize persistent state only when an entry can be published as a range, while preserving the first-fill generation check and fail-closed deletion for existing persistent ranges.

Validation:

  • Private /tmp and loopback preflight passed; receipt checks/1796053037760448714-3.json.

  • The fileservice and s3fifo package suites passed normally and with -race; receipts checks/1796053435519236066-3.json and checks/1796054298636831664-3.json. Six tests were skipped.

  • Both selected SQL compile policy tests passed; the table-scan package compiled with no selected tests. Receipt checks/1796054415808345702-3.json.

  • The same streaming-read/delete probe passed on the merge-base source overlay and failed on the PR head, with the untouched-cache control passing on both. Receipts checks/1796053699577714473-3.json and checks/1796053785464144014-3.json.

Limitations:

  • The metadata failure was injected with /dev/full; a physically full cache filesystem was not used.

  • Real MinIO and matched TPC-C workload results were reported by the author and were not independently repeated. The related TPC-C issue remains open.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Addressed the streaming-read P2 in 88ffc16.

The two streaming interfaces never supply a cacheable raw range, but the previous code persisted the range namespace before testing entry eligibility. That turned an otherwise optional cache into a prerequisite for deleting from healthy backing storage. Initialization now happens only in the common synchronous/asynchronous writer after eligibility and admission. The writer carries the original read generation through initialization and checks it again before publication. No disk format or delete protocol changes.

Validation: using the same public S3FS Read → Delete test against an isolated real MinIO, I ran each subcase twice on the reviewed head and twice on the fix. Only replacement of the local metadata file was forced to fail (EISDIR; not a physically full volume). On the old head, both WriterForRead and ReadCloserForRead prevented deletion in both runs. On the fix, both deleted the backing object in both runs (verified directly via the storage API). The buffered control that actually cached a range continued to reject deletion and retain the backing object. The regression tests also cover rejected async work not creating the metadata. Local fileservice and s3fifo package suites passed under -race; targeted fileservice SCA: 0 issues. No production-scale TPC-C rerun for this change.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-reviewed 88ffc16c against merge base c22be426. Recommendation: hold merge. The TP-locking range-GET optimization is appropriately narrow and the latest fix avoids persistent state creation for streaming-only reads. The shared disk-cache change, however, has an independently reproduced regression for ordinary reads, plus a rollback compatibility hazard (inline). These tests use the actual DiskCache implementation on a local filesystem, not a hash estimate or a cluster benchmark.

One further performance check for the design: range-file eviction now tries to remove its parent under the cache-wide directory write lock (index_cache.go:1057); unrelated whole-file fills take the same lock for reading when creating temp files. Also, once durable range state exists, a fresh delete fence syncs both file and directory before backing storage deletion. I did not measure production P99 for either. Please compare ordinary warm reads + GC and sustained eviction/fills on the same FS alongside the planned cold TPC-C run; measure absolute GETs/bytes, read P99, delete latency and throughput. A short design/rollout note recording invalidation scope, disk-failure and rollback behavior would be useful. The matched 1000W/1000T incident result is still separate from this component evidence.

Comment thread pkg/fileservice/disk_cache_ranges.go Resolved
Comment thread pkg/fileservice/disk_cache.go Outdated
}

func (d *DiskCache) pathForIOEntryAtEpoch(path string, entry IOEntry, epoch uint64) string {
return rangeFilePath(d.rangeDirAtEpoch(path, epoch), entry)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[P2, rollback correctness] The new epoch-qualified path prevents the upgraded reader from using a legacy range, but does not retire the old filename for the previous reader. Verified across three independent processes sharing one cache directory: (1) base c22be426 cached OLD; (2) head opened that directory, called DeletePaths on the same key, cached the replacement and read NEW; (3) base reopened the directory and reported a cache hit returning OLD. No object-store corruption is implied. This specifically requires a legacy warm range, delete/reuse of the path, and rollback onto the same cache volume. Please either invalidate legacy ranges in a bounded way, or document/enforce a cold, disposable FileService disk-cache directory on downgrade and add the cross-version case to the rollout checks. Do not rely on LRU eviction as a rollback guarantee.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed the operational option in d4ec7cb: docs/guides/fileservice-range-cache-rollback.md requires an empty local FileService disk cache per downgraded instance, including reattached volumes, and includes the old/new/old three-key rollout check. The archived two trials failed with the reused volume and passed with a fresh cache. This is an operator preflight, not automatic enforcement by an old binary. Do not clear backing storage, WAL or checkpoints.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: ed81395b9bdeb19b602cf7c011344dae9b2bd4d0

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: ed81395b9bdeb19b602cf7c011344dae9b2bd4d0

Assessment: request_changes

The change reuses the existing range cache and I/O merger, and the earlier disjoint-GC and streaming-initialization concerns are addressed. The new generation and retirement coordination still has a stale-publication race and a cancellation failure. Reopening a persistent cache at a small capacity also disables its usable disk-cache capacity.

Model: gpt-6.1-terra / max

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

  • P2 pkg/fileservice/disk_cache_ranges.go:61: A decode using old bytes starts while deletion of the same path is active, and deletion finishes between the separate state and readEpoch loads.
    Impact: The fence can classify the deleted path as an unrelated path in the new read epoch. The old decode can then be admitted to memory or shared with new readers, so a read after delete and recreation can receive deleted-object bytes.
    Evidence: rangeFence reads state and readEpoch separately; readFence subsequently checks deletingPaths under another lock. If finish removes the path and advances readEpoch between those reads, otherPath becomes true and memoryCurrent accepts the mixed snapshot. DecodeFromBytes uses that epoch for shared decoding and memory publication. This is an uncovered form of the earlier stale-decode concern, established by source analysis rather than an executed interleaving probe. Capture a coherent fence and retain the generation associated with the source bytes through decoding and publication.

  • P2 pkg/fileservice/disk_cache_ranges.go:409: A delete retires a range while an unrelated cache write is stalled in temporary-file creation with directoryMu held for reading.
    Impact: The delete remains blocked after its context is cancelled. It also holds the range-state I/O slot, delaying other deletes and first range initialization until the unrelated filesystem operation returns.
    Evidence: retireRangeDirs checks the context before taking the uninterruptible directoryMu lock; createCacheTempFile holds the corresponding read lock across filesystem operations. The reviewer-local race probe held the existing temporary-file creation barrier and observed the cancelled delete remain blocked; attempt-2/checks/1796129653503592139-3.json and directory-wait.log record the failure. Make the wait cancellable without losing the exclusion between directory retirement and temporary-file creation.

  • P2 pkg/fileservice/disk_cache_ranges.go:116: A cache that previously persisted range state is reopened with a configured disk-cache capacity below twice the state-file size.
    Impact: Loading the old state forces persistence back on and subtracts the 36 KiB state file from the new capacity. A 32 KiB cache consequently has zero usable data capacity, evicting cached data and preventing useful disk caching despite the stated small-cache behavior.
    Evidence: loadRangeCacheState unconditionally enables persistence for a valid state file, and disk_cache.go:197 subtracts its size from capacity. The exact-head probe reopened a 1 MiB cache at 32 KiB and reported capacity 0; the fresh 32 KiB control passed. See attempt-2/checks/1796129256744465909-3.json and capacity-control.log. Safely retire the old persistent namespace when entering small-cache mode so the configured capacity remains usable without allowing old ranges to reappear.

Validation:

  • The prior attempt's focused fileservice race selection passed on this head, including disjoint GC, streaming, delete and decode tests; attempt-1/checks/1796128491576137115-4.json and fileservice-race.log.

  • The attempt-2 isolation preflight, scan-policy tests, focused LocalFS/FIFO race tests, and git diff --check passed; receipts are in attempt-2/checks.

  • The reviewer-local capacity and cancelled-directory-wait probes failed as described above; their source, logs and exit receipts are retained in attempt-2.

  • All 33 discussion items are accounted for in attempt-2/discussion-assessment.json.

Limitations:

  • The generation-snapshot interleaving is supported by source reasoning; the earlier prepared scheduling probe has no terminal result and is not counted as executed.

  • Real MinIO and matched 1000W/1000T workload measurements were not independently rerun. The related workload incident remains open.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-reviewed this head against main. Changes needed before merge. The earlier disjoint-GC collateral eviction and streaming initialization findings are closed: the new deletion path retires object-specific directories. I would not hold the PR on those old findings.

I traced the three issues in the existing review of this SHA and agree with them. In particular: (1) the stripe state, read epoch and deleting-path lookup do not constitute one observation. A decode holding old bytes can observe the old active state and the new epoch after deletion finishes, be classified as an unrelated-path read and become admissible to the memory cache after recreation (source interleaving, not a new runtime reproduction); (2) retirement holds the cache-wide range-state I/O slot while waiting for directoryMu, whose read side spans file creation. An unrelated slow filesystem operation can keep an already-cancelled delete and later deletes waiting. This has an exact-head barrier reproduction. Fixing (1) should preserve concurrency for unrelated paths; fixing (2) must still exclude retirement racing temporary-file creation. (3) lowering a previously persistent cache to 32 KiB can leave zero usable data capacity; the same setting on a fresh cache works. This is a configuration-transition bug, not a claim that normal-size caches are unusable.

The bounded-read byte savings are real. For the performance follow-up I would specifically measure restarted warm cache + batched GC + concurrent foreground reads: reopening conservatively marks all stripes, and retirement can sync an existing shard directory even if the object's directory wasn't found. This is a risk to measure, not an observed TPS regression. I did not rerun the heavy benchmark.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: ed81395b9bdeb19b602cf7c011344dae9b2bd4d0

New discussion was assessed; the previous review remains unchanged.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Addressed both reviews (6131724889, 6131882202) in 328a2c0. They describe the same three findings. Independent checks against ed81395:

  • Mixed decode generation: a scheduling-only overlay paused the real read of the generation fields; DecodeFromBytes entered with actual old bytes while same-path deletion was in flight. After delete and recreate, ReadCache had been repopulated and a new public S3FS.Read returned old, not new. Fixed: pin the entry epoch; snapshot stripe and exact-path membership under the transition lock. A crossing read cannot publish or join the next epoch. The fixed overlay returned new; a stable neighbor on the stripe remains eligible. This is a FileService result, not a SQL wrong-row reproduction; caller-supplied bytes are still subject to DecodeFromBytes' immutable-range contract.
  • Cancelled GC: with a real unrelated fill stopped in temp-file creation, the old S3FS.Delete stayed blocked past the 5s test guard even after cancellation. Now it returns context.Canceled before the unrelated fill resumes; the backing object remains present and retry deletes only the target. Retirement, directory creation and final range rename still exclude one another as required. This bounds queue waits, not an OS syscall already in progress. The actual TAE GC caller is Deleter.deleteBatch (default 1000 paths, 10-minute context).
  • Reopen after capacity reduction: after 1 MiB -> 32 KiB the old data capacity was 0 (fresh 32 KiB control worked). The fix durably retires the old namespace. A real 16 KiB range is now admitted and read; growing back to 1 MiB doesn't resurrect removed/replaced data. Failure to retire the old namespace stops initialization. This narrow configuration transition isn't evidence of ordinary large CN caches becoming unusable.

Restarted cache + concurrent GC: 3 local trials, S3FS with a disk object backend, no memory cache, 4 readers of 256 live keys, 1000 disjoint backing objects deleted. All live reads hit and matched their bytes. Median batch time on main base c22be42 vs fix: dead keys cold 70 vs 81 ms; dead keys also warm 60 vs 345 ms. Importantly, with warm dead keys the base still returned deleted bytes on a normal range read (backing/bypass not found); the fix returned not-found. The extra GC work is real; the two implementations do not deliver equivalent invalidation. This is not a MinIO, SQL TPS or 1000W/1000T result.

Validation: full pkg/fileservice and pkg/fileservice/s3fifo under -race, the two transition concurrency tests 100 repetitions each under -race, objectio Top-N reuse check, and fileservice SCA (0 issues). New-head CI and matched incident-scale acceptance are separate. Requesting re-review; not marking the incident resolved.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Recommendation: changes needed; do the bounded-read optimization, but don't merge this whole cache design as the incident fix yet. I rechecked the updated head and the old/new receipts. The previous three counterexamples (mixed decode epoch, cancellation of a GC retirement waiter, persistent → small → persistent capacity) are addressed. I am not carrying them forward. I reproduced a distinct, narrower synchronous cancellation failure on this exact SHA (inline).

Why the investment is not yet justified for #33435: a 43,229-byte cold locking read at offset 93,644,241 is a good reason not to start a full-object fill from zero. In the 16-disjoint-range component comparison bytes fell from 96 MiB to 691,664, but requests went from 1 GET to 16. The separate 9→1 repeated-reader result fixes the first range-publishing candidate under memory pressure; its original full-file control already did 1 GET. Neither establishes a reduction in live-holder SQL latency or the 60-s client failures on the 4.2 workload.

Costs outside opt-in TP reads: S3FS.Read and LocalFS.Read take the cache-wide read-side fence even before memory hits when disk cache exists; GC takes its write side to update batch metadata. The new reopened-cache experiment is useful: 1,000 cold targets 70→81 ms; 1,000 warm targets 60→345 ms. On warm targets the old implementation could still serve deleted bytes and the new one didn't. The four concurrent disk-hit readers didn't show a corresponding P99 regression in those three local trials; the test disabled MemCache, so this is not normal memory-hit TPS evidence. Once a persistent namespace exists, a local retirement/sync failure can prevent the backing delete; binary rollback requires fresh local cache directories. These are real operator contracts even if no client enables this SQL optimization.

Decision I would take: First compare (A) main base, (B) after existing cache lookups, force the existing minimal-range read only on the same eligible TP miss, without turning on raw range writes for that request, and (C) this head. B must preserve applicable normal cache hits and measure repeated GETs under rejected memory admission; simply setting SkipFullFilePreloads is not B because policy.CacheIOEntry also becomes true. Match cold 1000W/1000T and record client timeouts, holder SQL P99, throughput, GETs and bytes; include warm ordinary memory hits during batched GC. If B delivers the benefit, merge the small change and handle the independently demonstrated general range-cache invalidation defect separately. If C delivers meaningful extra benefit, link an approved, versioned cache design covering retirement and rollback before landing it. The current rollout guide explains how to downgrade, but isn't approval of that design. The incident is on 4.2-dev; a main-branch microbenchmark is not incident closure.

if writeErr != nil {
// Temp creation may have succeeded before cancellation. Finish the
// same empty-directory cleanup as an ordinary failed publication.
d.removeEmptyDirectory(context.WithoutCancel(ctx), filepath.Dir(diskPath))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

P2 — reproduced on 328a2c0, distinct from the now-fixed Delete waiter. In a focused external Go test against the real DiskCache.Update(ctx, vec, false), pause writer A in the existing beforeCacheTempFileCreate barrier (it owns the path and one directory permit). Start writer B for the same range and observe it blocked in startUpdateWithCleanupContext/Cond.Wait. Cancel B. It wakes before ever owning the path or a temp file, but writeEntry handles all errors by calling removeEmptyDirectory(context.WithoutCancel(ctx), …). Its stack is now in removeEmptyDirectory → Weighted.Acquire(all permits); B only returns context.Canceled when A is released. One selected test, exit 1, test body 0.05 s; this was an observed wait edge, not a deadline guess. Base writeEntry returned the write error here. Avoid synchronous exclusive cleanup when the writer never created anything; for paths that actually own temp state, preserve exact cleanup without making a cancelled request wait unboundedly for another creator. Please add the same-path cancellation control. This demonstrates the synchronous API path, not a cluster-wide SQL stall or a regression in the default async read path.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Closing without merging; retaining this branch and its evidence as the full-cache comparison. The replacement will target only cold TP locking-read amplification, without changing disk-cache publication, deletion or restart. #33435 remains open; I will link the smaller PR here.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

The narrow main replacement is #33615. It keeps existing cache hits and uses bounded reads on eligible TP locking misses without publishing new disk ranges or changing GC/delete/restart. The 96 MiB component comparison and the increased request count are documented there. #33435 remains open for workload-level validation.

This branch was previously deployed

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

Labels

kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants