Skip to content

fix(frontend): keep Decimal256 primary-key pairing in DATA BRANCH - #30837

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28589-main-e02b5284
Oct 23, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28589-main-e02b5284

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

What this PR does / why we need it:

DATA BRANCH misclassifies changes on Decimal256 primary keys (DECIMAL
precision 39..76). After updating one existing row and inserting one new
row on a branch, DATA BRANCH DIFF ... OUTPUT SUMMARY reports
INSERTED 2 / DELETED 0 / UPDATED 0, so PICK and MERGE cannot apply the
update; after deleting one row, DIFF returns an empty result and the
deletion never reaches the base: on the assignment base the failing
DATA BRANCH statements (PICK, MERGE and the DELETE-case MERGE) surface
internal error 20101 carrying the vector.AppendAny conversion stack,
and on the older main snapshot from the issue comment the same
DELETE-case merge reported success while keeping the deleted row
(silent sync loss).

Root cause: the branch hashmap packs Decimal256 keys with
Packer.EncodeStringType over the raw 32 bytes, so DecodeRow returns
the tombstone key element as []byte (decimal64/128 use their typed
packer codes). findDeleteAndUpdateBat passed this raw element straight
to vector.AppendAny on the Decimal256-typed tombstone PK vector, whose
val.(types.Decimal256) assertion panics. In the async diff worker the
ants pool recovers the panic and only logs it, silently skipping the
whole tombstone-resolution step for that side; the PICK/MERGE
onlineApply path runs the same code inline and re-raises the panic to
the client.

Change: pkg/frontend/data_branch_hashdiff.go appends the decoded
tombstone key element through appendTupleValueToVector ->
normalizeTupleColumnValue, the shared normalization already used by
every other decoded-tuple consumer in the data-branch code.
Fixed-width raw payloads are converted to the typed value via
types.DecodeValue before appending; typed, varlen and packed composite
key encodings keep their existing behavior, and a malformed fixed-width
payload now returns an explicit invalid-input error instead of a
panicking type assertion.

Issue-to-test proof

  • TestHashDiff_HasLCADecimal256PKUpdateIsNotMisclassified drives the
    real hashDiff pipeline with the reported update scenario. It fails
    on the parent base 6495ce9974 (emits INSERT instead of UPDATE and
    the log shows ants: worker exits from panic: interface conversion: interface {} is []uint8, not types.Decimal256) and passes with this
    change (exact UPDATE row; it also asserts the LCA probe embeds the
    exact 40-digit Decimal256 literal with cast(... as DECIMAL(40,0))).
  • TestHashDiff_HasLCADecimal256PKDeleteIsReported drives the reported
    silent DELETE scenario. It fails on the parent base (no DELETE
    emitted) and passes with this change (the DELETE before-image is
    emitted).
  • BVT test/distributed/cases/git4data/branch/edge/branch_decimal256_pk.sql
    covers the issue's UPDATE case (diff summary/count, selected-key PICK,
    MERGE, base contents, final zero diff), the issue comment's DELETE
    case (reported deletion, survivor-row identity in the branch and the
    base, MERGE sync, final zero diff, database teardown) and a
    DECIMAL(38,0) boundary control. The result file was generated against
    the fixed binary by mo-tester, inspected against the intended
    semantics, and re-run in compare mode: 37/37 statements, 100%. After
    the run the branch_decimal256_pk database is confirmed absent from
    the instance.

Test commands

  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run 'TestHashDiff_HasLCADecimal256PK' -v ./pkg/frontend/ — new UTs red on parent, green with this change; after the review hardening they release their batch pools and leave no outstanding mpool allocations at teardown.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/frontend/databranchutils/ and ... -run 'TestHashDiff|TestHandleDelsOnLCA|TestCompare|TestFindDelete' ./pkg/frontend/ — regression sweeps green (19 matched frontend data-branch tests plus the full databranchutils package).
  • End-to-end repro on a locally built single-node cluster (isolated ports and data dir), same SQL on parent and fixed binaries: parent shows INSERTED 2/0/0, failing PICK/MERGE (ERROR 20101) and a silently unsynced DELETE; the fixed binary shows INSERTED 1/UPDATED 1, successful PICK and MERGE, final diff count 0, a synced deletion, and the unchanged DECIMAL(38,0) control.
  • gofmt -l clean, GOWORK=off go vet -mod=readonly ./pkg/frontend/ exit 0, golangci-lint run -c .golangci.yml --new-from-rev <base> ./pkg/frontend/... reports 0 issues.

Validation, limitations and residual risk

Validation covers the two reported failure faces, the happy paths of
DIFF/PICK/MERGE for this key type, the malformed-payload error path and
the DECIMAL(38,0) boundary control. The full git4data BVT suite remains
for CI; no multi-CN or upgrade behavior is involved in the changed code.
The normalization is shared with all existing decoded-tuple consumers, so
no other primary-key kind (integers, fake PK, varchar/binary, packed
composite) changes encoding or comparison behavior. No residual risk is
identified beyond CI coverage of the full BVT suite.

DATA BRANCH misclassifies changes on Decimal256 primary keys (DECIMAL
precision 39..76). After one UPDATE of an existing row plus one INSERT,
`DATA BRANCH DIFF ... OUTPUT SUMMARY` reports INSERTED 2 / DELETED 0 /
UPDATED 0, so PICK and MERGE cannot apply the update; after one DELETE,
DIFF returns an empty result and MERGE reports success while the base
keeps the deleted row (silent sync loss). On current main the inline
PICK/MERGE path also surfaces internal error 20101 carrying the
vector.AppendAny conversion stack.

Root cause: the branch hashmap packs Decimal256 keys with
Packer.EncodeStringType over the raw 32 bytes, so DecodeRow returns the
tombstone key element as []byte (decimal64/128 use their typed packer
codes). findDeleteAndUpdateBat passed this raw element straight to
vector.AppendAny on the Decimal256-typed tombstone PK vector, whose
val.(types.Decimal256) assertion panics. In the async diff worker the
ants pool recovers the panic and only logs it, silently skipping the
whole tombstone-resolution step for that side; the PICK/MERGE
onlineApply path runs the same code inline and re-raises the panic to
the client.

Change: append the decoded tombstone key element through
appendTupleValueToVector -> normalizeTupleColumnValue, the shared
normalization already used by every other decoded-tuple consumer in
the data-branch code. Fixed-width raw payloads are converted to the
typed value via types.DecodeValue before appending; typed, varlen and
packed composite key encodings keep their existing behavior, and a
malformed fixed-width payload now returns an explicit invalid-input
error instead of a panicking type assertion.

Tests: two focused deterministic unit tests drive the real hashDiff
pipeline with the reported update and delete scenarios (both fail on
the parent base with the production panic signature and pass with this
change), plus a BVT regression covering the issue's UPDATE case, the
issue comment's DELETE case and a DECIMAL(38,0) boundary control,
executed by mo-tester with a generated, re-compared result file.

Related to matrixorigin#28589
Address the three P3 findings from the pre-PR review:

- release the retBatchList pools in both new hashDiff tests via
  freeAllRetBatches so the session mpool no longer reports outstanding
  on-heap allocations (304 bytes / 10 objects per test) at teardown
- pin the exact surviving row in the BVT DELETE case by selecting
  d/note from both the branch and the base after the merge, so the
  case cannot pass if the wrong Decimal256 key is deleted
- drop the branch_decimal256_pk database at the end of the BVT case

The regenerated result file was re-verified in mo-tester run mode:
37/37 statements, 100%, and the database is confirmed absent after
the run.

Related to matrixorigin#28589
@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 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: eaf87f129214b9552dc3c1e4d131191bf971fed2

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

Assessment: approve

Reviewed the complete four-file delta and affected callers. Reusing the existing tuple normalizer fixes Decimal256 tombstone decoding for DIFF, PICK and MERGE without changing key encoding or introducing duplicate logic. Error propagation and cleanup remain intact. Added work is constant per tombstone and does not affect ordinary SQL paths. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Traced encoding, typed-vector conversion, asynchronous and inline execution, error propagation and batch ownership.

  • Reviewed both new hashDiff regressions, existing normalization/error tests, and BVT expectations for updates, deletions, selected-key PICK, MERGE, Decimal128 compatibility and cleanup.

  • Frozen exact-head CI reports successful UT, coverage, SCA, shared build and both BVT groups.

  • git diff --check and evidence audit passed; command/source/exit receipts match retained logs. Source remained unchanged. Records: /home/xupeng/.local/state/mo-bot/jobs/5414a6b25721219284a917f2/attempt-1/evidence-audit.json and review-record.json.

Limitations:

  • No local Go tests or BVT rerun; reused exact-head CI evidence. Raw author/CI logs were not supplied, so author-reported runs were not independently replayed.

  • The linked issue body was absent; review covered the concrete update/delete scenarios captured in the PR.

  • No throughput benchmark was run or performance improvement claimed.

@mergify mergify Bot added the queued label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-23 05:18 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-10-23 07:53 UTC · at e0bee4663e1f5990475adcab300d4caca72fe8eb

This pull request spent 2 hours 35 minutes 1 second in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

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

  • Requeue this pull request

@gouhongshen

gouhongshen commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Unrelated CI failure note: UT Coverage checkout timeout and downstream guards (tracked issue #28411)

The Matrixone UT Coverage execution / UT Coverage on Ubuntu/x86 job of workflow run 39914038684 (attempt 1, PR head e0bee4663e1f5990475adcab300d4caca72fe8eb) failed only inside the Checkout MatrixOne source step: the runner's git fetch of the PR head from the fork hung behind the runner proxy (proxy-service.proxy.svc.cluster.local:8001) and the step was killed by the 5-minute action timeout (full job log: job 120284004313):

##[error]The action 'Checkout MatrixOne source' has timed out after 5 minutes.

Every build, test, and coverage step was skipped, so no MatrixOne code from this PR was ever fetched, compiled, or tested on that runner. This is a transient runner/network transport failure, the same infrastructure mechanism already recorded in issue #28411; a reproduction record for this occurrence has been posted there.

Two further checks in the same run then failed purely as deterministic downstream consequences of that blocked producer, still with no MatrixOne source from this PR fetched or exercised:

  • Matrixone Coverage execution / Coverage (job 120305133384) aborted in its first step (Verify coverage prerequisites, ~8s) with prerequisites_ready: false:

    ##[error]coverage merge blocked: a required producer did not publish a complete coverage profile; no coverage verdict was calculated
    

    The producer that timed out above is the only expected coverage profile source for this merge, so no coverage verdict was ever computed from this PR's code. A reproduction record for this downstream occurrence has also been posted in issue [Bug]: UT Coverage checkout fails after repeated GnuTLS termination #28411.

  • CI Required (job 120305244018) is the aggregate required-check gate; its summary step failed with ##[error]Unhandled error: Error: matrixone-ut-coverage: failure precisely because that required producer had failed.

This PR's own diff (frontend Decimal256 pairing fix plus its UT/BVT regressions) is unrelated to all of these failures. Positive evidence in the same run on the same head: CI preflight, coverage-eligibility, shared build and pr-size-label checks all succeeded, and the full non-coverage UT Test on Ubuntu/x86 (1h0m), SCA on Linux/arm64, and both multi-CN e2e BVT suites passed.

Recovery: the run reached its terminal failed state, so the single authorized failed-jobs rerun of run 39914038684 was triggered (attempt 2) at 2026-10-23T08:35:04Z; run status queued on the same head e0bee4663e1f5990475adcab300d4caca72fe8eb. No change to this PR is needed or made for this failure.

@mergify mergify Bot added dequeued and removed queued labels Oct 23, 2026
@XuPeng-SH
XuPeng-SH merged commit e19f698 into matrixorigin:main Oct 23, 2026
27 of 31 checks passed

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

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

3 participants