Skip to content

fix(backup): select file indexes by numeric timestamp - #25970

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25937-file-index-order
Jul 21, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25937-file-index-order

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 #25937

What this PR does / why we need it:

LoadGlobalFileIndex selected the greatest timestamp substring with ordinary
string comparison. MatrixOne timestamp components are unpadded decimal values,
so both 1-9 > 1-10 and 9-0 > 10-0 are wrong lexicographically. The stale
index then makes incremental backup recopy objects that are present only in the
newer index.

Parse the physical component as int64 and the logical component as uint32,
build a types.TS, and compare timestamps numerically. Malformed or legacy
filenames are ignored rather than panicking or masking a valid index.

Tests cover width changes in both components, malformed and overflowing names,
and a mixed directory where a lexicographically larger malformed name must not
hide a valid index. The confirmed impact is redundant backup I/O/space; this PR
does not claim data loss.

Validation:

  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s ./pkg/backup
  • go build ./pkg/backup (repository CGo environment)
  • go vet ./pkg/backup (repository CGo environment)

@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 added the kind/bug Something isn't working label Jul 21, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 21, 2026

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

Codex automated review

No findings. The numeric parser matches types.TS physical/logical ordering and the regression tests cover both width-change failures and malformed names. Existing PR reviews/inline threads are empty; linked issue context was assessed. Local package testing was blocked by the missing CGo libmo prerequisite; all PR CI checks succeeded.

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

No blocking findings after tracing the filename contract through listing, numeric parsing, types.TS ordering, index selection, CSV loading, and backup consumption. The implementation correctly handles physical/logical decimal-width changes, zero timestamps, overflow, negative physical values, malformed component counts, and invalid names without allowing them to hide a valid index.

Validation:

  • full pkg/backup test suite passed locally with the deterministic MatrixOne CGo wrapper;
  • the new selection and malformed-name tests passed 20x after a clean merge with the latest main;
  • git diff --check passed and the latest main merges without conflicts;
  • all required PR CI checks are green.

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

mergify Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-21 11:09 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-21 14:18 UTC · at efa992389d8962306ec7395df12bab2e5b452a6f

This pull request spent 3 hours 8 minutes 40 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 eb161ff into matrixorigin:main Jul 21, 2026
23 of 24 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 21, 2026
XuPeng-SH pushed a commit that referenced this pull request Jul 22, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue #26006

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

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to #25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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
…5970)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25937

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

`LoadGlobalFileIndex` selected the greatest timestamp substring with
ordinary
string comparison. MatrixOne timestamp components are unpadded decimal
values,
so both `1-9 > 1-10` and `9-0 > 10-0` are wrong lexicographically. The
stale
index then makes incremental backup recopy objects that are present only
in the
newer index.

Parse the physical component as `int64` and the logical component as
`uint32`,
build a `types.TS`, and compare timestamps numerically. Malformed or
legacy
filenames are ignored rather than panicking or masking a valid index.

Tests cover width changes in both components, malformed and overflowing
names,
and a mixed directory where a lexicographically larger malformed name
must not
hide a valid index. The confirmed impact is redundant backup I/O/space;
this PR
does not claim data loss.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s
./pkg/backup`
- `go build ./pkg/backup` (repository CGo environment)
- `go vet ./pkg/backup` (repository CGo environment)

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
…ixorigin#26009)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26006

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

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to matrixorigin#25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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
…5970)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25937

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

`LoadGlobalFileIndex` selected the greatest timestamp substring with
ordinary
string comparison. MatrixOne timestamp components are unpadded decimal
values,
so both `1-9 > 1-10` and `9-0 > 10-0` are wrong lexicographically. The
stale
index then makes incremental backup recopy objects that are present only
in the
newer index.

Parse the physical component as `int64` and the logical component as
`uint32`,
build a `types.TS`, and compare timestamps numerically. Malformed or
legacy
filenames are ignored rather than panicking or masking a valid index.

Tests cover width changes in both components, malformed and overflowing
names,
and a mixed directory where a lexicographically larger malformed name
must not
hide a valid index. The confirmed impact is redundant backup I/O/space;
this PR
does not claim data loss.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s
./pkg/backup`
- `go build ./pkg/backup` (repository CGo environment)
- `go vet ./pkg/backup` (repository CGo environment)

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
…ixorigin#26009)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26006

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

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to matrixorigin#25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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
…5970)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25937

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

`LoadGlobalFileIndex` selected the greatest timestamp substring with
ordinary
string comparison. MatrixOne timestamp components are unpadded decimal
values,
so both `1-9 > 1-10` and `9-0 > 10-0` are wrong lexicographically. The
stale
index then makes incremental backup recopy objects that are present only
in the
newer index.

Parse the physical component as `int64` and the logical component as
`uint32`,
build a `types.TS`, and compare timestamps numerically. Malformed or
legacy
filenames are ignored rather than panicking or masking a valid index.

Tests cover width changes in both components, malformed and overflowing
names,
and a mixed directory where a lexicographically larger malformed name
must not
hide a valid index. The confirmed impact is redundant backup I/O/space;
this PR
does not claim data loss.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s
./pkg/backup`
- `go build ./pkg/backup` (repository CGo environment)
- `go vet ./pkg/backup` (repository CGo environment)

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
…ixorigin#26009)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26006

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

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to matrixorigin#25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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