Skip to content

[DO NOT MERGE] Import Spark Connect Gateway reference implementation - #1

Open
viirya wants to merge 1 commit into
apache:mainfrom
viirya:import-reference-impl
Open

[DO NOT MERGE] Import Spark Connect Gateway reference implementation#1
viirya wants to merge 1 commit into
apache:mainfrom
viirya:import-reference-impl

Conversation

@viirya

@viirya viirya commented Aug 12, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

This PR imports the full Spark Connect Gateway reference implementation as a
single squashed commit.

This PR is intentionally too large to review and is NOT meant to be merged.
It exists only as the reference / target end-state so reviewers can see the whole
picture. The implementation will be split into smaller, self-contained,
reviewable PRs that land one at a time (in dependency order, bottom-up). After
each small PR merges, this reference PR is rebased and shrinks until everything
is imported and it can be closed.

The import includes: the Cargo workspace (15 crates under crates/), the Helm
chart (deploy/helm/scg/), e2e examples (deploy/examples/), docs (docs/),
the vendored spark.connect.* protos (proto/), and the full README. Every
imported source file carries the Apache license header; the vendored protos
retain their upstream ASF headers.

Split plan

The import lands as the following small, bottom-up PRs. Each keeps main green
under the full CI matrix (cargo fmt --all --check, cargo clippy --workspace --all-targets -D warnings, cargo build --workspace, cargo test --workspace)
and appends its crate(s) to the workspace members list. This reference PR is
rebased after each one merges.

# Contents Depends on Status
1 Cargo workspace skeleton + vendored protos + genproto ✅ merged (#2)
2 routing 1 ✅ merged (#3)
3 config 1 open (#4)
4 auth 1 pending
5 observability 1 pending
6 audit + ratelimit 1 pending
7 tenant 4 pending
8 store-memory + pool-static 2 pending
9 store-redis + healthcheck 2 pending
10 pool-k8s 2 pending
11 proxy (src + tests + examples) 1,2,4,5,6,7,8,9 pending
12 gateway binary 1–11 pending
13 Dockerfile, config.example.yaml, full README, docs/, deploy/, test/ 12 pending

Dependency layers: genproto, routing, config, auth, observability,
ratelimit, audit are leaves; tenant→auth, and
store-memory/store-redis/pool-static/pool-k8s/healthcheck→routing;
proxy depends on 7 of those (and its tests/examples pull in 4 more, which is
why PRs 8–9 precede 11); gateway depends on all.

Why are the changes needed?

Implements the reference gateway from the approved SPIP (SPARK-58455), moving it
into the apache/spark-connect-gateway subproject repo.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

cargo check --workspace --all-targets and cargo fmt --check pass locally;
helm lint passes on the chart. Per-crate tests come in with the split PRs.

Was this patch authored or co-authored using generative AI tooling?

Yes, co-authored with Claude Code.

viirya added a commit that referenced this pull request Aug 14, 2026
…roto crate

### What changes were proposed in this pull request?

This is the first of a series of small, bottom-up PRs importing the Spark
Connect Gateway reference implementation (tracked in the do-not-merge reference
PR #1). It introduces the Cargo workspace:

- Root `Cargo.toml` with the full `[workspace.package]` and
  `[workspace.dependencies]` tables. `members` lists only `crates/genproto` for
  now; subsequent PRs append one or more crates.
- `Cargo.lock` (tracked — this project ships a binary), `rust-toolchain.toml`.
- The vendored `spark.connect.*` protos under `proto/spark/connect/` — a
  read-only mirror of the corresponding files in `apache/spark`.
- The `scg-genproto` crate, whose `build.rs` generates tonic bindings from the
  protos at build time via `tonic-prost-build`.

Each PR in this series keeps `main` green under the full CI matrix
(fmt / clippy --all-targets / build / test --workspace).

### Why are the changes needed?

Implements the reference gateway from the approved SPIP (SPARK-58455), imported
into the `apache/spark-connect-gateway` subproject repo one reviewable piece at
a time.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

`cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`,
`cargo build --workspace`, and `cargo test --workspace` all pass locally.

### Was this patch authored or co-authored using generative AI tooling?

Yes, co-authored with Claude Code.

Closes #2 from viirya/import-01-genproto.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <liangchi.hsieh@databricks.com>
@viirya
viirya force-pushed the import-reference-impl branch from 1062732 to ae8c73b Compare August 14, 2026 03:18
viirya added a commit that referenced this pull request Aug 19, 2026
### What changes were proposed in this pull request?

Part of importing the Spark Connect Gateway reference implementation into
`apache/spark-connect-gateway` as a series of small, bottom-up PRs (tracked in
the do-not-merge reference PR #1).

This adds the `scg-routing` crate — the routing core of the gateway. It defines
the central traits and types that the pool and store layers implement and that
the proxy routes through:

- `SessionKey` — the routing key derived from a request
- `Pool` — the backend-pool trait (implemented later by pool-static / pool-k8s)
- `AffinityStore` — the session-affinity store trait (implemented later by
  store-memory / store-redis)
- `Router` — ties them together

`scg-routing` is a leaf crate (no internal dependencies), so it compiles and
tests on its own. It is appended to the workspace `members` list. Subsequent
PRs add the crates that depend on it.

### Why are the changes needed?

Implements the reference gateway from the approved SPIP (SPARK-58455), imported
one reviewable piece at a time.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

`cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`,
`cargo build --workspace`, and `cargo test --workspace` all pass locally
(scg-routing has 15 unit tests).

### Was this patch authored or co-authored using generative AI tooling?

Yes, co-authored with Claude Code.

Closes #3 from viirya/import-02-routing.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <liangchi.hsieh@databricks.com>
Reference implementation imported from the development repo as a single
squashed commit. This is intentionally too large to review and is NOT
meant to be merged — it exists as the target end-state so reviewers can
see the whole picture. It will be split into smaller, reviewable PRs
that land one at a time; this branch is rebased and shrinks as each
split PR merges.

Every source file carries the Apache license header; the vendored
spark.connect.* protos under proto/ retain their upstream ASF headers.

Co-authored-by: Claude Code
@alexandrefimov

Copy link
Copy Markdown

The routing crate landing gives the user-aware placement piece a home, and I have it ready against main: an OwnerLabelStrategy that matches SessionKey::user_id against an owner label on BackendMember, rotates within the subset one user owns, and declines instead of placing the session when user_id is empty or no member carries a matching label. cargo test --workspace is 21/21 with clippy and fmt clean.

It fails closed rather than falling back to round-robin because a wrong placement is not an affinity miss. Spark Connect never uses user_id as the execution identity — the plan runs as the process user of the driver it lands on. On 4.0.3 with a Ranger-enabled Kyuubi engine started as testalice, a client claiming user_id=bob is denied with "user [testalice] does not have [create] privilege": the backend authorizes as its owner, whatever the client says it is.

This is the strategy half only. The other half — labels reaching the pool from discovery — has nothing to attach to yet, since scg-pool-k8s surfaces addresses only.

I can't create a SPARK sub-task myself. Could you file one under SPARK-58455 whenever it fits your import order, or point me at a better venue for the patch?

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.

2 participants