Repository navigation
[4.2-dev] fix(frontend): preserve string literals in merged role rules - #32891
Conversation
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 5d7201fefc7d570c62748616c8022de7a3597301
Assessment: request_changes
The mode-aware merge preserves literal identity and reuses the existing session cache with one memoized result. The earlier rollback and secondary-role recovery findings are resolved. A rule-merge error can still prevent an explicit COMMIT from reaching the transaction handler.
Model: gpt-6.2-sol / xhigh
Session: 01a1ee7f-fdcb-7b83-ad57-3b17a0e9d494 · slot 1 · generation 1
- P2
pkg/frontend/rewrite_rule.go:286: A session issues COMMIT after its role-rule cache is refreshed with competing rules that cannot merge under its current SQL mode. A transactional DROP TABLE can invalidate the cache while the transaction stays open.
Impact: The client receives a rule-merge error and cannot explicitly commit pending work. COMMIT finalizes the transaction through the existing handler and requires no row-rule rewrite.
Evidence: TestRewritePolicyAllowsRoleRuleRecovery explicitly expects COMMIT to fail at pkg/frontend/rewrite_rule_test.go:1495. The refresh path follows pkg/frontend/status_stmt.go:159 and pkg/frontend/session.go:1144. The merge base parses competing rules in the default mode, and the hint consumer skips COMMIT at pkg/sql/parsers/sqlparse.go:516. Allow a parsed standalone COMMIT to reach the existing handler at pkg/frontend/mysql_cmd_executor.go:4170 while preserving fail-closed handling for protected statements.
Validation:
-
Focused frontend race tests passed for rule merging, cache concurrency, role switching, and recovery. See frontend-race.log and checks/1795015071108022877-2.json.
-
Frontend SQL-mode staging and prepared-statement race tests passed. See frontend-staging-race.log and checks/1795015387036546350-2.json.
-
Parser, tree, and MySQL dialect race suites passed. See parser-race.log and checks/1795015301351677001-2.json.
-
Frozen-head diff and isolation preflight checks passed. See diff-check.log, preflight.log, and checks/1795014830525057165-2.json and checks/1795014830525154147-2.json.
Limitations:
-
The active-transaction COMMIT path was traced in source. Local execution covered the rewrite rejection at the policy layer.
-
The distributed fixture checks that ROLLBACK is accepted. Its preceding SET sql_mode implicitly commits the open transaction. The author reports 330 of 330 checks passed for the role-rule case, with no raw run log supplied.
|
mo-bot review · Commit: Review discussion changed before publication; a fresh contextual review is queued. |
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed a496024e82dfff6cd9cd3f12b3b571c696d95438 against 4.2-dev at 54956dc8e9e1315e38956b0ba3662e3f8a51b6c4.
- [P2]
test/distributed/cases/zz_accesscontrol/role_rule.sql:366. The recovery fixture switches SQL mode in an autocommit session and then issuesCOMMITandROLLBACKwith no pending work. Its success responses cover statement acceptance. Add separate cases that cause a role-rule merge error while a transaction has pending work, then verify from another connection that the committed change persists and the rolled-back change disappears. A mode change afterBEGINwould implicitly commit, so induce the error through a rule-cache refresh while the transaction is open.
The current recovery guard addresses both previous findings. It admits standalone ROLLBACK and SET SECONDARY ROLE NONE, and this head also admits standalone COMMIT. The captured threads and conversation contain no explicit author replies to either review. Rollback and role recovery review · Commit recovery review
CI reports 14 successful, 13 skipped and 2 neutral checks out of 29, with zero failures. CI Required passed.
Local validation passed for the parser, MySQL dialect and tree suites, plus seven parser-level recovery guard cases. The focused frontend suite could not build because the local native headers for usearch, xxHash and CRoaring were missing. Distributed transaction behavior was checked by tracing the code and fixture.
| select count(*) from db1.t_dup; | ||
| set sql_mode = 'NO_BACKSLASH_ESCAPES'; | ||
| select count(*) from db1.t_dup; | ||
| commit; |
There was a problem hiding this comment.
[P2] Cover recovery with pending transactional writes. This session is in autocommit mode and has no pending work when COMMIT and ROLLBACK run, so both can return success without exercising transaction finalization. In separate cases, trigger the merge error through a role-rule cache refresh while a transaction is open, then verify from another connection that COMMIT persists the change and ROLLBACK discards it. Changing sql_mode after BEGIN would implicitly commit.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: a496024e82dfff6cd9cd3f12b3b571c696d95438
Assessment: request_changes
The prior binary-literal finding still reproduces. The checked-in SQL case covers COMMIT and ROLLBACK acceptance, and a fresh embedded SQL probe verified their effects on pending writes after a role-rule cache refresh.
Model: gpt-6.2-sol / xhigh
Session: 01a1eecd-3287-70c0-bb93-ab923faf5f3f · slot 0 · generation 2
- P2
pkg/frontend/rewrite_rule.go:934: Compatible role rules merge a SELECT containing a quoted binary literal with bytes that are invalid UTF-8.
Impact: The rewrite can silently change a projected binary value or the bytes compared by a row predicate.
Evidence: The formatter emits raw binary bytes at pkg/sql/parsers/tree/format.go:209. The JSON hint encoder at pkg/frontend/rewrite_rule.go:190 replaces invalid UTF-8 before the rule is reparsed. The frontend probe reproduced the byte change through the actual merge and hint path. Printable and hexadecimal controls passed. Reuse the existing hexadecimal binary representation before JSON encoding and cover the decoded bytes in a hint round-trip test.
Validation:
-
The frontend probe reproduced the binary defect. The committed string-literal and recovery tests passed in the same run. See frontend-binary-rewrite.jsonl and receipt 1795021762628742098-3.
-
The embedded SQL probe held pending writes across a cache refresh and a protected-read error. A second connection saw the committed row and verified that the rolled-back row stayed absent. See live-role-recovery-verified.jsonl and receipt 1795021965879429346-3.
-
Verified the frozen patch, native input ledger, and all 10 discussion entries. Frozen CI records successful unit tests, static analysis, both multi-CN BVT jobs, and CI Required. See validation-reconciliation.json and receipt 1795022015119170657-4.
Limitations:
-
The earlier attempt's raw artifacts were unavailable. The findings rely on fresh focused checks. The first two embedded runs stopped during fixture setup because of a long Unix socket path and an insufficient test grant. The corrected run passed.
-
The embedded probe used one CN. Individual distributed case logs and the referenced PR discussions were unavailable.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: afefd5685ecfb9fbfd3e46367696788de57f0a59
Assessment: approve
The 4.2-dev fix preserves string and binary literals through role-rule merging and hint parsing. It keeps the existing role priority and caches one merged result per catalog generation. The prior binary transport and transaction recovery findings are resolved.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
Validation:
-
Verified the frozen head, merge base, patch, clean checkout, formatting, and isolation preflight.
-
Focused frontend tests and the full frontend, parser, MySQL dialect, and tree suites passed. The full race suites passed in separate runs after the combined run timed out. See receipts 1795044932396727428-3, 1795045277601939547-3, 1795045504958054398-3, and 1795045606970033937-3.
-
The authenticated MySQL probe confirmed that protected reads failed after a rule refresh, the committed row persisted, and the rolled-back row stayed absent. Single-role and merged-role reads returned the original binary bytes. See embedded-role-probe.log and receipt 1795045006488020899-5.
-
All 12 discussion entries are reconciled in discussion-assessment.json.
Limitations:
- The authenticated probe used one CN. The author reports 353 of 353 distributed role-rule checks passed. The frozen evidence contains no raw BVT logs.
What type of PR is this?
Which issue(s) this PR fixes:
Related to matrixorigin/matrixflow#22006;
4.2-devcounterpart of #32890.What this PR does / why we need it:
Compatible rules from active roles are merged as an OR over base rows. The merged SELECT must keep string type and value when the rewrite hint is serialized and reparsed. The frontend preserves literal bytes, quoted identifiers, grammar keywords, and projection identity, including ENUM and SET member case. It keeps the existing priority fallback and memoizes the last result by parser mode within the catalog generation.
For binary literals, keep the original bytes during intermediate merges. After rule selection, use the existing hexadecimal binary representation for bytes JSON would otherwise replace. This covers single rules, repeated merges, and fallback winners. Ordinary UTF-8-valid rules keep their spelling. Unrepresentable non-binary text returns an error.
Standalone transaction finalization, role deactivation, and literal or DEFAULT session SQL-mode changes remain available when a rule cannot be merged. The SQL regression opens two transactions with pending writes, verifies that a policy refresh rejects protected reads, then observes that only the committed write survives. This covers the prior recovery and binary-transport findings. Transaction coverage · Binary round trip
Local validation on Go 1.26.4 (darwin/arm64): frontend and parser race suites, scoped go vet and golangci-lint, role-rule SQL BVT (353/353), and an authenticated MySQL check of projected and predicate binary bytes with one and two active roles.