Skip to content

fix(fileservice): preserve errors and cache merge ordering - #25659

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-fileservice-error-paths
Jul 14, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-fileservice-error-paths

Conversation

@LeftHandCold

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:

issue #25550
issue #25602
issue #25603

What this PR does / why we need it:

This change closes three related fileservice error-path gaps:

  • delay the S3 I/O-merger completion signal until deferred cache updates finish, so waiters observe the leader's cached data instead of issuing duplicate object reads;
  • return non-ENOENT errors from LocalFS.StatFile instead of dereferencing a nil FileInfo after os.Stat fails;
  • close and remove .mofstemp files on every failed disk-object write, propagate cleanup failures, and report real delete failures while keeping missing-object deletes idempotent.

The merger regression test now uses a blocked leader and an observed waiter handshake, making the original ordering race deterministic. Disk and local filesystem tests cover copy failure, size mismatch, delete failure, and ENOTDIR.

Tested with:

go test -count=1 ./pkg/fileservice

go test -race -count=20 ./pkg/fileservice -run '^(TestLocalFSStatFileReturnsNonNotExistError|TestDiskObjectStorageWriteFailureRemovesTempFile|TestDiskObjectStorageSizeMismatchRemovesTempFile|TestDiskObjectStorageDeleteReturnsRemovalError|TestS3FSIOMerger)$'

go vet ./pkg/fileservice

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Jul 13, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 13, 2026
@LeftHandCold
LeftHandCold marked this pull request as ready for review July 13, 2026 14:16
@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 →

@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.

The production fixes look sound, but the S3 merger regression test does not make the old ordering race deterministic as claimed. The waiter handshake only proves that the second read has entered ioMerger.Merge; after done() closes the channel, the waiter is merely runnable, and the leader can still execute the cache-update defers before the scheduler runs it. I kept the new test unchanged, reverted only finishMerge back to the old defer done(), and the test still passed 100/100 times with GOMAXPROCS=1 and 100/100 times with GOMAXPROCS=8. Therefore this test is green on the buggy ordering and does not protect the fix. Please add a controlled barrier/hook around cache update versus merger completion (or an equivalent deterministic mechanism), and verify that the test is reliably red with the old ordering and green with the new ordering. The disk-object and LocalFS error-path changes and tests otherwise look good.

@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.

Approved. The previous review blocker is resolved.

The rewritten S3 merger regression is now deterministic: on the current head it passed 20/20 under the race detector; after temporarily restoring only the old defer done() ordering, it failed 20/20 at the IsMerging assertion while the cache update was blocked. Restoring the PR implementation returned it to green. The production defer order keeps the merge active through synchronous cache updates and releases waiters on every return/error path.

The LocalFS non-ENOENT handling is correct. Disk-object writes now close and remove the temp file across copy, size, sync, close, mkdir, and rename failures while preserving cleanup errors; Delete remains idempotent for missing keys and aggregates real removal failures.

Verified locally: full pkg/fileservice tests, targeted race tests with -count=20, go build, go vet, and git diff --check. All GitHub CI checks are green.

@mergify mergify Bot added the queued label Jul 14, 2026
@mergify

mergify Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-14 15:20 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-14 15:28 UTC · at 69e00e7f2bcf997de5dda6480832894ae705ada6

This pull request spent 7 minutes 38 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 0c21589 into matrixorigin:main Jul 14, 2026
23 of 24 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 14, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#25659)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#25550
issue matrixorigin#25602
issue matrixorigin#25603

## What this PR does / why we need it:

This change closes three related fileservice error-path gaps:

- delay the S3 I/O-merger completion signal until deferred cache updates
finish, so waiters observe the leader's cached data instead of issuing
duplicate object reads;
- return non-`ENOENT` errors from `LocalFS.StatFile` instead of
dereferencing a nil `FileInfo` after `os.Stat` fails;
- close and remove `.mofstemp` files on every failed disk-object write,
propagate cleanup failures, and report real delete failures while
keeping missing-object deletes idempotent.

The merger regression test now uses a blocked leader and an observed
waiter handshake, making the original ordering race deterministic. Disk
and local filesystem tests cover copy failure, size mismatch, delete
failure, and `ENOTDIR`.

Tested with:

`go test -count=1 ./pkg/fileservice`

`go test -race -count=20 ./pkg/fileservice -run
'^(TestLocalFSStatFileReturnsNonNotExistError|TestDiskObjectStorageWriteFailureRemovesTempFile|TestDiskObjectStorageSizeMismatchRemovesTempFile|TestDiskObjectStorageDeleteReturnsRemovalError|TestS3FSIOMerger)$'`

`go vet ./pkg/fileservice`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#25659)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#25550
issue matrixorigin#25602
issue matrixorigin#25603

## What this PR does / why we need it:

This change closes three related fileservice error-path gaps:

- delay the S3 I/O-merger completion signal until deferred cache updates
finish, so waiters observe the leader's cached data instead of issuing
duplicate object reads;
- return non-`ENOENT` errors from `LocalFS.StatFile` instead of
dereferencing a nil `FileInfo` after `os.Stat` fails;
- close and remove `.mofstemp` files on every failed disk-object write,
propagate cleanup failures, and report real delete failures while
keeping missing-object deletes idempotent.

The merger regression test now uses a blocked leader and an observed
waiter handshake, making the original ordering race deterministic. Disk
and local filesystem tests cover copy failure, size mismatch, delete
failure, and `ENOTDIR`.

Tested with:

`go test -count=1 ./pkg/fileservice`

`go test -race -count=20 ./pkg/fileservice -run
'^(TestLocalFSStatFileReturnsNonNotExistError|TestDiskObjectStorageWriteFailureRemovesTempFile|TestDiskObjectStorageSizeMismatchRemovesTempFile|TestDiskObjectStorageDeleteReturnsRemovalError|TestS3FSIOMerger)$'`

`go vet ./pkg/fileservice`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#25659)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#25550
issue matrixorigin#25602
issue matrixorigin#25603

## What this PR does / why we need it:

This change closes three related fileservice error-path gaps:

- delay the S3 I/O-merger completion signal until deferred cache updates
finish, so waiters observe the leader's cached data instead of issuing
duplicate object reads;
- return non-`ENOENT` errors from `LocalFS.StatFile` instead of
dereferencing a nil `FileInfo` after `os.Stat` fails;
- close and remove `.mofstemp` files on every failed disk-object write,
propagate cleanup failures, and report real delete failures while
keeping missing-object deletes idempotent.

The merger regression test now uses a blocked leader and an observed
waiter handshake, making the original ordering race deterministic. Disk
and local filesystem tests cover copy failure, size mismatch, delete
failure, and `ENOTDIR`.

Tested with:

`go test -count=1 ./pkg/fileservice`

`go test -race -count=20 ./pkg/fileservice -run
'^(TestLocalFSStatFileReturnsNonNotExistError|TestDiskObjectStorageWriteFailureRemovesTempFile|TestDiskObjectStorageSizeMismatchRemovesTempFile|TestDiskObjectStorageDeleteReturnsRemovalError|TestS3FSIOMerger)$'`

`go vet ./pkg/fileservice`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants