Repository navigation
feat(sql): add durable cluster-scoped UUID_SHORT() - #29805
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Independent final QA: PASSModel explicitly selected: Kernel: matrixone#29805. Docs: matrixone-doc#374; merge docs after its kernel dependency. Complete independent QA recordIndependent review — remaining UUID deliveryStatus: overall PASS. Kernel Reviewed design: revision 2, SHA-256 Scope and change mapRead-only review against explicit bases: kernel
All changed hunks have been read. Correctness, contract, state, control, lifecycle, boundedness, compatibility, performance, delivery and test architecture lenses apply to the closures above. Auth/privilege changes, new background owners, new wire/disk fields, operator Reset/Call transitions, index-format/migration work, GPU/build-tag selection and independent algorithm dispatch are N/A because no corresponding owner or artifact changes. Existing UINT64 protocol paths were traced through column extraction, unsigned MySQL column metadata and text/binary encoders. Ownership, wait and bound closure
No namespace collision was found: existing consumers use Resource/test economy: no new fixture, background goroutine, function cache, counter, tombstone or durable request identity was added. Production work is constant-time range validation plus one existing allocator call and fixed-width append per selected row. No throughput/zero-allocation claim is made. Findings and correctionsNo open confirmed production finding.
Evidence auditEvidence is reused from the implementation owner after inspecting the listed artifacts and receiving explicit terminal-status/mode/source-freshness handoff. No duplicate test processes were started by this reviewer.
Delivery artifact gateThe complete exact design revision 2 is included in the published kernel PR body, with a clearly marked Delivery remains through non-default feature branches and review PRs. No remote mutation was performed by this reviewer. Issue closure must preserve the design's finite boundaries: #29803 canonical docs; #28382 accepted native contract decision; only UUID_SHORT for #25107; #27800 conditional P1 is not activated. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Code review for cff322740e48605b5853b6e5fd776d292a4aa359: no blocking correctness, design, or performance findings; I recommend approval.
The earlier reservation-granularity performance finding is addressed by reserving 8,192 IDs for the fixed SQL namespace through the existing managed HAKeeper client. The durable allocator remains the authority for ranges and exhaustion; the client remains the owner of cache refill and waiter release. The fixed batch and its gap/exhaustion tradeoffs are documented. Paired local SQL measurements show the 10,000-ID query improving from about 420 ms cold / 397 ms warm to 24–28 ms cold / 4.8–5.5 ms warm. These are local measurements, not a cluster throughput guarantee.
One non-blocking cleanup: pkg/hakeeper/rsm.go:515's assignIDByKey has no production callers after this change; only TestAllocateIDByKeyCmd still calls it. Please consider making those two single-ID test reservations through Update(GetAllocateIDCmd(...)), preserving the existing expected IDs, and deleting the obsolete helper. This is P3 maintenance cleanup; I found no reachable production failure from it.
The final-source normal/race tests, two-CN public QA, and incremental static checks were reviewed and their source/diff fingerprints match this head. CI status is tracked separately from this code review.
What type of PR is this?
Which issue(s) this PR fixes:
Implements only the
UUID_SHORT()item in #25107; its other functions and syntax remain separate work. Follows the native UUID contract accepted in #29800. Companion bilingual documentation: https://github.com/matrixorigin/matrixone-doc/pull/374, tracking #29803.What this PR does / why we need it:
Add volatile
UUID_SHORT()returningBIGINT UNSIGNED, backed by the existing durable HAKeeper allocator. Reserve 8,192 IDs per refill for its fixed SQL namespace. This avoids inheriting the metadata allocation default of 100, which needed about 100 synchronous HAKeeper reservations to generate 10,000 SQL values.Design and behavior
objectio.BlockMaxRows(8,192) through existingAllocateIDByKeyWithBatch. This is a fixed SQL policy, independent ofAllocateIDBatch; other consumers retain their configured reservation sizes. Scalar statements reuse the same client cache, and sparse evaluations consume IDs only for selected rows.Successful values are unique within one preserved cluster allocation history. Gaps and out-of-order observation are allowed. Rollback, cancellation, lost replies and CN restart consume or abandon reserved IDs. A client can leave up to 8,191 unused IDs from its current successful reservation; repeated failures/restarts have no lifetime gap guarantee. A refill errors when the remaining durable range cannot fit the complete 8,192 batch, leaving the counter unchanged. Independent clusters, cloned allocator state and rewound snapshots can repeat values; this differs from MySQL's server/startup bit layout. Values are not secrets.
Upgrade CNs and all HAKeeper replicas before relying on the function and reservation guards. Preserve allocator state on rollback. The existing native UUIDv7 functions retain their accepted contract.
Performance evidence
Paired local SQL measurements use the same embedded two-CN topology, queries and data, with a one-call-site old-API overlay as the baseline. Query:
Persistent prepared scalar calls and ordinary UPDATE controls were also exercised. Cold samples include first-query/CN initialization; timings vary on this shared host. These are local diagnostic results, not a cluster throughput or SLA claim. No wall-clock threshold is added to unit tests. The optimization itself adds 4 production lines and removes 3 test lines net; the complete feature is production +58 / tests +334.
Validation
Base / merge base:
8f48d6fac04bf612be65ed1b44477ef9b32cb88f. Final source:cff322740e48605b5853b6e5fd776d292a4aa359. Go 1.27.1, Linux/amd64 CPU, matching native libraries throughmo-cgo-test, disk TMPDIR, GOMAXPROCS=4, package parallelism=2.-racePASS 11.616s.-race: logservice PASS 1.914s, including explicit batch overriding configured batch and first three IDs sharing one RPC / fourth ID causing the second.-race: DML PASS 11.941s. Retain two-CN, repeated/prepared expressions, rollback gaps, invalid-arity connection recovery, unsigned CTAS and text/prepared MaxUint64 controls.go vetPASS; configured golangci-lint 2.14.0 reports 0 issues; matching-Go molint has 0 new diagnostics. Its two existing unsafe-import diagnostics are byte-identical to base sources and separately recorded.CI will run on the updated source; no pending CI result is counted as passed.
Reviewed design and QA
Design model:
gpt-6.1-sol, reasoningxhigh, session01a12212-268c-7693-a7de-2fa7a67020aa; design amendment SHA25602fa7c9b27c83e5b85f30722685c945b5fbb520339cbec2fca5659f24f4457ad. Runtime model/effort selection was verified from the CLI session. The preserved allocator-history contract and existing owner guards follow the accepted base design; the complete approved SQL batch amendment is below.Final independent overall review:
gpt-6.1-sol/xhigh, session01a12225-0a88-7392-bd26-6540a72565f3, PASS for the complete PR atcff322740e48605b5853b6e5fd776d292a4aa359, no unresolved material blocker. Review artifact SHA256c8629b1e4d00f53c8d7bfee0204d65576dee2c8b345c53e5009f89210c8eb913. The original reservation-granularity P2 is closed; unchanged allocator evidence was checked against source hashes, and revised function/client/public tests have fresh evidence..Approved SQL reservation design amendment
Design decision: PASS for a fixed SQL reservation of 8,192 IDs through the existing
AllocateIDByKeyWithBatchAPI. Implement this on the samefeat/uuid-shortbranch and PR #29805. This design supplements head1e41c466aaa4d6f6ece9cb8ad12d507222374a99, based on8f48d6fac04bf612be65ed1b44477ef9b32cb88f.This phase read source and the supplied artifacts. It made no edits, ran no tests, and performed no remote mutations.
Root cause and invariant. The confirmed review evidence (recorded artifact) establishes that the executor’s per-row
AllocateIDByKeycall inherits the metadata allocation default of 100. Generating 10,000 IDs therefore requires approximately 100 synchronous HAKeeper reservations. The measured original → batch-10,000 overlay → original comparison was 405–428 ms → 4.9–5.8 ms → 426–428 ms, with correct results throughout. The separate counter namespace still shares HAKeeper RPC and Raft capacity.The correction must amortize reservation work across ordinary SQL batches while retaining these invariants:
uint64ID; ignored rows and empty evaluations consume none.__mo_sql_uuid_short, retains uniqueness within preserved allocator history.These retain the ownership and compatibility decisions in the accepted design (recorded artifact).
Exact correction. In func_builtin.go, add a named SQL policy constant beside the allocation key:
Replace only the allocation call:
Use
objectio.BlockMaxRowsdirectly: it is 8,192.options.DefaultBlockMaxRowsaliases it, andgenerate_seriesalso emits 8,192-row batches. This makes one ordinary block the justified SQL reservation lower bound and the fixed refill size. Do not grow it with evaluation length.SQL owns this policy; managedHAKeeperClient remains the sole mechanism owner. Its cache is keyed by namespace, so cached ranges remain usable regardless of the batch argument that originally reserved them.
Policy challenge and accepted costs. A fixed 8,192 reservation is not a claim of universal optimality. It is the smallest direct policy aligned with the established execution unit and an explicit waste bound.
Using evaluation length alone would leave scalar calls making frequent reservations. Using
max(8192, length)would allow unusually large or sparse vectors to reserve much larger ranges. Counting selected rows first adds work without improving cache reuse across evaluations. Larger fixed multiples need evidence beyond this finding.The selected policy behaves as follows:
Ncalls requireceil(N / 8192)refills. A 10,000-call workload requires two rather than 100.Memory remains constant per existing keyed cache entry: reserving 8,192 IDs does not materialize an 8,192-element buffer.
The explicit API overrides
AllocateIDBatchfor this SQL namespace, whether that configuration is smaller or larger than 8,192. Other consumers retain their configured behavior. This is a deliberate SQL policy change and should appear in the implementation description.Gaps, exhaustion, and compatibility. After a successful refill consumes its first ID, at most 8,191 unused IDs remain cached per client. Restart or client replacement can abandon that remainder. Lost replies can abandon a complete 8,192-ID reservation per successful-but-unobserved proposal; retries and repeated restarts have no cumulative lifetime gap bound. Rollback and failed result publication add their existing consumed-ID gaps.
Preserve full-batch, fail-closed exhaustion. When fewer than 8,192 unreserved values remain, a refill errors even for a scalar request, leaving the durable counter unchanged. Accept the resulting unused tail of at most 8,191 values. Existing cached IDs may still be consumed, and a legal range ending at
MaxUint64remains valid. There is no smaller-batch fallback.HAKeeper’s range guards and
NextIDByKeypersistence remain unchanged. The existing error convention and client publication guard remain unchanged. Old and new CNs reserving different positive batch sizes remain disjoint under the guarded owner. Existing rollout requirements for those guards still apply. Rollback must retain the advanced namespace. Native UUIDv7 is outside this correction.Minimum regression architecture.
Migrate the existing function mock. In uuid_short_test.go, implement
AllocateIDByKeyWithBatchand give its callback the batch argument. Assert the namespace and exact named SQL batch size on every allocation. Retain the existing empty, mask, deadline, child-cancel, parent-cancel, nil-client, zero-result, injected-error, and full-uint64oracles.Prove refill counts through the real managed client. Extend the existing batch-consumption suite in hakeeper_client_test.go with a named explicit-batch case: configure batch 1, request batch 3 through
WithBatch, and allocate four IDs. Assert IDs 1–3 require exactly one RPC and ID 4 causes exactly the second RPC; assert both RPC batch arguments equal 3. ReusesendCNAllocateIDFunc, restore it immediately through cleanup, and keep the case serialized. This independently proves explicit configuration override and full-range consumption; the function mock proves SQL supplies 8,192. Four allocations suffice.Add one bounded public workload. Extend TestUUIDShortSQL in its existing fixture with:
Assert both results are 8,193. This is one reservation quantum plus one, aggregated server-side, without a Go uniqueness loop. The client UT owns the exact refill-count oracle; the SQL assertion must not infer RPC counts or require contiguity. Retain the existing two-CN, prepared execution, rollback, connection reuse, unsigned protocol, and CTAS checks.
Previous DEFAULT, INSERT SELECT, UPDATE, generated-column, and concurrent correctness probes inform coverage. Their old executions do not certify the changed executor.
Risk-to-validation map.
TestUUIDShort; fresh full function normal/race evidence.TestUUIDShortSQLnormal/race, including the aggregate above; applicable owning DML normal evidence for the final inputs.Use the established CGo setup for later validation. Relevant function and DML evidence becomes stale when their source or tests change; unchanged owner evidence does not.
For performance acceptance, record a bounded paired comparison of the original head and the final 8,192 policy using the same 10,000-row SQL query, topology, and build mode. Record cold-client and warm-cache conditions, correctness, and ordinary UUID controls. Include repeated scalar SELECT/prepared calls on a persistent connection, a few separate sessions, and a modest real-table
UPDATE ... SET id = uuid_short()with affected-row and distinct-count checks. Investigate any unexplained scalar/update regression. The diagnostic 10,000 overlay is causal evidence, not final-policy validation.Acceptance requires the deterministic API/refill oracles, fresh affected checks, zero new static findings, and a reproducible material SQL latency reduction consistent with fewer reservations. Neither 4.9–5.8 ms nor UUID control latency becomes a promised target. Ordinary tests receive no timing thresholds.
Blockers and suggestions. No unresolved design blocker remains. PR acceptance still requires the correction and final validation above; the confirmed performance finding remains open until then. Constant naming, comment wording, and broader cluster throughput characterization are subjective suggestions, not additional blockers. Changes to allocator ownership, reservation fallback, or the selected bound require a new design decision.