Skip to content

Split the largest functions; one replication builder - #137

Open
austin-barrington wants to merge 4 commits into
refactor/adapter-inversionsfrom
refactor/split-large-functions
Open

austin-barrington wants to merge 4 commits into
refactor/adapter-inversionsfrom
refactor/split-large-functions

Conversation

@austin-barrington

Copy link
Copy Markdown
Member

Stacked on #136. Plan: docs/superpowers/plans/2026-11-03-split-large-functions.md.

This splits the three largest functions without changing behaviour:

  • Golden test (tests/compat/cluster_replication_tests.rs with testdata/replicated_mutations.json). It records what each non-Raft cluster statement replicates and each statement's result. It covers all 19 replicating statement kinds, a cross-database CREATE RETENTION POLICY, and an invalid SET, and checks that users carry an argon2 hash, never the password. The test was committed before the refactor and passes unchanged after it.
  • PeerQueryService::execute_query, 578 → 84 lines. The 19 inline replicate arms are now one path over mutation_request_from_statement. Retention-policy statements still run locally against their own ON <db>. CQ, MV and password build failures are still reported on the statement.
  • execute_statement, 1,228 → 182 lines. 31 arms moved verbatim into query_service/statements/{show_schema,show_catalog,ddl,delete,users,select}.rs.
  • apply_shard_map_op, 426 → 85 lines. One function per op is now in domain/sharding/ops/apply.rs. The map_version bump stays in the dispatcher; refused_op_still_bumps_version covers it.

One narrow change the review found: a CREATE MATERIALIZED VIEW whose source-metadata read fails after the local create now reports a statement error instead of failing the whole request.

Gate: fmt, clippy -D warnings, unit, integration 376 and CLI 54 tests all pass.

The 19 inline replicate arms in PeerQueryService::execute_query become one
path over mutation_request_from_statement. The golden test passed unchanged:
the builder already matched every arm. Retention policy statements still run
locally against their own ON <db>, and a CQ/MV/password build failure is
still reported on the statement.
@cursor

cursor Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches cluster mutation replication and query statement dispatch across many paths; behavior is mostly a move, but MV replication/metadata errors and peer batch error semantics changed slightly.

Overview
Refactors three oversized code paths into smaller modules without changing replication payloads (locked by a new golden test), plus one targeted error-handling fix for materialized views.

Cluster peer execution (PeerQueryService) replaces ~19 duplicated “execute locally then replicate” match arms with a single cluster-mutation path that always builds mutations via mutation_request_from_statement, runs locally against local_db for retention-policy ON <db> statements, and turns CQ/MV/password build failures into per-statement errors via build_error_is_statement_error instead of aborting the whole batch. Other mutation build failures still fail the request.

Query execution moves the bulk of execute_statement into query_service/statements/{ddl,delete,select,show_catalog,show_schema,users}.rs, leaving a thin dispatcher in mod.rs (behavior moved verbatim).

Sharding splits apply_shard_map_op into per-op helpers in domain/sharding/ops/apply.rs and adds refused_op_still_bumps_version to document that map_version increments even when an op is rejected.

Testing adds cluster_replication_tests.rs and testdata/replicated_mutations.json to record non-Raft mutation replication and statement outcomes across all cluster statement kinds (with masked password hashes).

Reviewed by Cursor Bugbot for commit ed5c601. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant