Repository navigation
feat: datastream external table - streaming gRPC data load bridge (ENGINE = DATASTREAM) - #27469
Conversation
CREATE EXTERNAL TABLE ... ENGINE = DATASTREAM WITH ('server','port','table','recheck')
streams CSV chunks from a gRPC server (proto/datastream/v1) through the
existing external scan operator via a new DataStreamReader; predicate
conjuncts are conservatively deparsed to SQL text and pushed as a hint,
recheck=false skips local re-evaluation for exactly the pushed conjuncts.
Co-Authored-By: Claude Fable 5 <[email protected]>
- xtool/jstfu: Java gRPC reference server (Maven, shaded jar) with jdbc
(${FILTER} substitution, streaming fetch) and file (record-aligned ~1MB
chunking) datasources; make jstfu builds it
- test/datastream: self-contained e2e harness (starts the jar itself) incl.
a full MO round-trip test with pushdown, recheck, errors, ETL, parallel load
- BVT cases + fixtures + optools/jstfu_bvt.sh launcher (40/40 pass)
- plan doc updated with as-built notes
Co-Authored-By: Claude Fable 5 <[email protected]>
- datastream_load.sql: load 10000-row and 1751-record (quoted embedded newlines) CSVs through jstfu file sources and verify byte-identical results vs LOAD DATA incl. NULL columns; observable hint semantics via file-source recheck=false; jdbc AND/OR/IN/BETWEEN/NOT/LIKE/IS NULL conditions with recheck=true and recheck=false returning identical results; mixed pushable+non-pushable conjunct; filtered ETL partitions reassembling the full table - optools/jstfu_bvt.sh: file_parallel/file_rawlog/jdbc_parallel/jdbc_rawlog datasources Co-Authored-By: Claude Fable 5 <[email protected]>
- jstfu BVT config now uses chunksize 4096 (default is 1MB), so the 1.9MB and 413KB fixtures stream as ~480/~100 chunks through the whole BVT; results verified unchanged (108/108) - e2e TestJstfuMultiChunkStreaming: ~1MB generated file at 2KB chunks - hundreds of chunks, every boundary record-aligned (quote-state checked across embedded newlines), lossless reassembly - Go reader tests: 500-chunk stream; record-spanning chunks tolerated (reader treats the stream as plain bytes) Co-Authored-By: Claude Fable 5 <[email protected]>
The tester docker image (matrixorigin/tester:go1.26.4-jdk8) ships only JDK 8 and no Maven, so the jar must be Java-8-runnable: release 17 -> 8, replace arrow-switch / pattern-instanceof / text blocks / Java 11+ APIs. All deps (grpc 1.68, protobuf 3.25, jackson 2.17, mysql-connector-j 8.4) already ship Java 8 bytecode. Verified: class-file major version 52, jar smoke-tested under the actual tester image's JDK 8 (multi-chunk stream, content byte-identical), mvn tests 10/10, e2e and BVT 108/108 re-run green with the rebuilt jar. Co-Authored-By: Claude Fable 5 <[email protected]>
- optools/run_bvt.sh (standalone/launch): build jstfu.jar via the new Maven wrapper if missing and start it on :4444 before BVT; idempotent across the restart pass - etc/launch-tae-compose: jstfu-build service (maven image, shared jar volume) plus jstfu-cn0/jstfu-cn1 sidecars sharing each CN's network namespace so the BVT's 127.0.0.1:4444 resolves on whichever CN compiles the scan; jdbc datasources loop back to the CN's own 127.0.0.1:6001; resources mounted at /jstfu-test because compose CI rewrites ':/test' mounts to host workspace paths - xtool/jstfu: Maven wrapper (script-only) so runners with only JDK 8 and no Maven can build; pom compiles with source/target 1.8 on JDK 8 and --release 8 on JDK 9+ (javac 8 has no release flag); verified inside matrixorigin/tester:go1.26.4-jdk8 Co-Authored-By: Claude Fable 5 <[email protected]>
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? |
Co-Authored-By: Claude Fable 5 <[email protected]> # Conflicts: # pkg/pb/plan/plan.pb.go
The bare 'main' pattern in .gitignore (for a built binary) also matched Maven's src/main directory, so the seven jstfu implementation files were silently excluded from every commit - only the tests were tracked. A CI clone would have built a source-less jar and crash-looped the sidecars. Re-include xtool/jstfu/src/main/ and add the sources. Co-Authored-By: Claude Fable 5 <[email protected]>
aptend
left a comment
There was a problem hiding this comment.
Deep review of exact head 7ed04d196a2cee2cbd83c8c248fa74004168df86, covering the complete 64-file diff, the author self-review, MO plan/compile/remote-run/operator lifecycle, the wire contract, Java service/JDBC/CSV paths, and both launch modes. I found blocking correctness, security, bounded-streaming, and CI-closure issues.
Validation: focused CGO Go packages passed (pkg/datastream/v1, datastream config/filter, external, compile, plan, MySQL parser, features); new-path race tests passed with -race -count=20; Java tests passed under JDK 25 targeting release 8. A temporary binary counterexample reproduced corruption: input bytes ff 00 80 emerged as 5 UTF-8 bytes instead of 3; the temporary test was removed. The exact head also does not contain the launch script invoked by run_bvt.sh.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed the exact head 7ed04d196a2cee2cbd83c8c248fa74004168df86 against current main (5a1ddf0e80ae9197f2b3bc603aa5ca4930a136b1), including the complete 64-file diff, DDL/catalog/plan/compile/remote-run/external-reader call chain, protobuf contract, Java JDBC/file service, both launch paths, and tests. I am requesting changes because the following P1 blockers remain.
-
P1 correctness —
pkg/sql/compile/compile.go:2543: defaultrecheck=truestill sends every deparsed predicate to the source before local re-evaluation. Local recheck can discard over-returned rows but cannot restore rows already removed under different source semantics. For example, if the source collation treatsaandAas equal while MO distinguishes them,s <> 'a'drops both at the source and MO never sees theArow. The default mode therefore produces wrong results unless pushdown is proven superset-preserving or semantic alignment is enforced. -
P1 security —
pkg/sql/datastream/filter.go:276andxtool/jstfu/src/main/java/io/matrixone/jstfu/source/JdbcSource.java:48: MO escapes apostrophes as\', then jstfu substitutes the resulting text directly into configured SQL. A source session using the valid MySQL modeNO_BACKSLASH_ESCAPEStreats that apostrophe as a terminator, so an ordinary MO predicate containing a crafted string literal can appendUNION SELECT ...and execute it with jstfu's configured JDBC credentials. This remains exploitable even if the RPC endpoint itself is trusted; the filter needs a structured/parameterized representation or source-independent validation, with a differing-SQL-mode negative test. -
P1 security —
xtool/jstfu/src/main/java/io/matrixone/jstfu/Main.java:58,DataStreamService.java:44-52, andJdbcSource.java:48: the reference server binds on all interfaces with plaintext gRPC and performs no authentication/authorization. Any network client can select a configured datasource and supply arbitrary filter text, bypassing MO's deparser entirely and injecting it into${FILTER}. A README trust warning is not an enforcement boundary for the JDBC credentials and data exposed by the service. -
P1 lifecycle/performance —
xtool/jstfu/src/main/java/io/matrixone/jstfu/DataStreamService.java:59-66andJdbcSource.java:54-74: the producer callsonNextwithout readiness-based flow control, so a fast/large result queues unbounded output when the MO consumer is slow and can OOM jstfu. Cancellation is checked only while emitting a chunk; cancellation during blockedgetConnection,executeQuery, orrs.next()does not cancel/close the active JDBC statement and leaves the RPC executor and database resources stuck. Please make sends readiness-driven and wireonCancelto active JDBC cancellation/close, with slow-consumer and blocked-read tests. -
P1 data correctness —
xtool/jstfu/src/main/java/io/matrixone/jstfu/source/JdbcSource.java:86-90andCsvChunker.java:47:byte[]is converted through ISO-8859-1 characters and then encoded as UTF-8. The concrete input bytesff 00 80becomec3 bf 00 c2 80(3 bytes to 5), while MO appends CSV field bytes directly for BINARY/VARBINARY/BLOB. Non-ASCII binary values are therefore silently corrupted. Preserve raw bytes or define a reversible wire encoding and test a binary round trip. -
P1 CI closure —
optools/run_bvt.sh:61: the invokedoptools/jstfu_bvt.shis absent from this exact head (git ls-treereturns no entry), consistent with the repository-wide*.shignore rule. With no existing listener, every standalone launch waits 30 seconds and exits before BVT. The relevant launch checks were skipped in the current run, so the green checks do not exercise this path. Add/track the script and smoke-test the exact command.
Non-blocking findings:
- P2 compatibility —
pkg/sql/colexec/external/reader_datastream.go:72: concatenatingserver + ":" + portproduces an invalid target for a normal IPv6 literal such as::1(::1:4444). Usenet.JoinHostPort(and define whether bracketed input is accepted) with an IPv6 reader test. - P2 build/test reliability —
Makefile:373-378:make jstfuexits successfully without producing the promised jar when Maven is absent, even though the repository includesmvnw; the e2e then skips on the missing jar. Use the wrapper/fail the target so a successful build cannot silently omit all Java/product-path validation.
Validation notes: all 31 GitHub checks are complete with no failed or pending check; Java unit tests pass 10/10 on this head targeting release 8. I independently reproduced the binary charset counterexample above. The isolated host lacks the repository's native jemalloc/libmo prerequisites, so focused CGo-transitive Go tests stop at the environment header check rather than producing a code result; I did not treat that as either a pass or a PR failure.
…ing, tracked script)
MO side:
- recheck=true (default) no longer pushes any filter: a pushed predicate is
not provably superset-preserving across engines, so the server could drop a
row MO wants under different collation/tz and local recheck (which only
removes over-returned rows) cannot restore it. The safe default now returns
the full source and filters locally; recheck=false remains the opt-in that
trusts server semantics for the pushed conjuncts. (aptend P1)
jstfu server:
- consumer flow control + cancellation: the source drains on a worker thread
bounded by ServerCallStreamObserver.isReady() (slow MO consumer no longer
OOMs jstfu), and onCancel closes the source's registered JDBC connection /
file stream and interrupts the worker so a cancelled MO query releases a
blocked JDBC read instead of leaking it. (aptend P1)
- binary columns: reject BINARY/VARBINARY/BLOB with a clear error instead of
the ISO-8859-1->UTF-8 dance that silently corrupted bytes >= 0x80. (aptend P1)
- bind to 127.0.0.1 by default (configurable host) so the unauthenticated
${FILTER}-into-SQL surface is not exposed off-box out of the box. (aptend P1)
Tooling:
- track optools/jstfu_bvt.sh (the *.sh ignore rule hid it, so the launch-BVT
path run_bvt.sh invokes would fail on a clean checkout). (aptend P1)
Validated: jstfu 13 unit tests, datastream BVT 108/108 and e2e green against a
rebuilt server, deparser/compile unit tests green.
Co-Authored-By: Claude Fable 5 <[email protected]>
Closes the remaining open review thread (unauthenticated -into-SQL surface). A shared-secret API key authenticates MO->jstfu requests: - proto: ReadRequest.api_key + ErrorCode.ERROR_UNAUTHENTICATED (Go+Java regen) - jstfu: optional server 'apikey' config; when set, every Read must present a matching key (constant-time MessageDigest.isEqual) or gets an ERROR_UNAUTHENTICATED frame; empty disables the check (backward compatible) - MO: new 'apikey' WITH-option -> Config.APIKey -> url-escaped in the rel_createsql envelope -> plan.DataStreamScan.api_key -> ReadRequest; the reader surfaces auth failures with a clear 'check the apikey option' message - the key is NEVER shown by SHOW CREATE (would leak the secret; a restored table must re-supply it) and is redacted in parser Format output Tests: Go reader (correct/wrong key), config option + envelope round-trip incl. a key with envelope-breaking bytes and a legacy no-apikey envelope; Java DataStreamService auth gate (disabled/wrong/missing/correct); e2e full handshake through MO (accept/reject/no-leak); BVT option-parse + SHOW-CREATE no-leak. datastream BVT 111/111, e2e green, jstfu 17 unit tests. Co-Authored-By: Claude Fable 5 <[email protected]>
…mvnw build Addresses iamlinjunhong review (the P1s it raised on the older head were already fixed by 4f39a97/6c53e43; these are the genuinely new items): - P1 injection under NO_BACKSLASH_ESCAPES: the deparser backslash-escaped apostrophes ('\''), which a source session in NO_BACKSLASH_ESCAPES treats as a string terminator, letting a crafted predicate value break out into SQL run with jstfu's credentials. Now quote with ''-doubling only (mode independent) and refuse to push any string literal containing a backslash (no portable single-quoted form). Added a differing-sql_mode e2e negative test (jdbc source forced to NO_BACKSLASH_ESCAPES) plus deparser unit tests for the doubled/injection/refused cases. - P2 IPv6: dial target built with net.JoinHostPort (::1 -> [::1]:4444) in the reader and Config.Address(), not 'server:port' concatenation; IPv6 unit test. - P2 make jstfu: default to the committed ./mvnw wrapper and fail on error, so a missing system mvn can no longer silently skip the jar build. datastream BVT 111/111 (unchanged), e2e green incl. the NBS regression, unit + reader tests green. Co-Authored-By: Claude Fable 5 <[email protected]>
|
@iamlinjunhong thanks for the thorough pass. Your review was against head P1 injection under P1 correctness P1 security — bind-all + no auth (Main / DataStreamService) — fixed in P1 flow control + cancel (DataStreamService / JdbcSource) — fixed in P1 binary corruption (JdbcSource / CsvChunker) — fixed in P1 CI closure — P2 IPv6 target (reader_datastream.go:72) — fixed in P2 Validation on the current head: datastream BVT 111/111, e2e green (incl. the NBS regression, API-key handshake, multi-chunk), jstfu 17 unit tests, deparser/reader/compile unit tests green. All 5 inline review threads are resolved. |
Co-Authored-By: Claude Fable 5 <[email protected]>
Add a full Configuration file reference to the jstfu README: top-level field table (host/port/apikey/chunksize/datasource) and datasource field table (jdbc/file), plus a 'Setting the listen address and API key' section with a worked bind-all + apikey example and the matching MO DDL. Trim the Security section to cross-reference it. Co-Authored-By: Claude Fable 5 <[email protected]>
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 7d5c26561ce8fc0f98e4679a7a377135ba404461 against the prior reviewed head 7ed04d196a2cee2cbd83c8c248fa74004168df86. I read all historical reviews, replies, and resolved threads, checked the incremental commits plus the complete PR diff, and independently verified the earlier fixes for recheck semantics, sql_mode-safe literals, IPv6 targets, binary rejection, the tracked BVT script, and Maven invocation. Two blocking unhappy-path/security issues remain: cancellation can lose both worker and resource publication races, and the shared API key is persisted/logged in plaintext. Both were reproduced with temporary deterministic counterexample tests, which were removed after validation. Relevant Java tests, Go package tests, focused race tests, and go vet passed.
Co-Authored-By: Claude Fable 5 <[email protected]>
Addresses the two new P1 review comments (aptend): jstfu concurrency (DataStreamService): - cancellation, worker publication, and resource registration are now atomic via a synchronized Cancellation guard: cancel closes everything registered so far, registering after cancel closes the resource immediately and tells the source to stop, and the worker future is re-checked after submit so a cancel that raced submission still interrupts it - jdbc statement query timeout (querytimeoutseconds) bounds a stalled executeQuery/next even without a client cancel; connection close on cancel remains the unblock path - worker pool bounded (maxconcurrentreads, default 256) with a busy error on overflow, replacing the unbounded cached pool - unit tests for cancel-closes-registered and register-after-cancel-closes api key secret handling: - MO 'apikey' value may be an 'env:NAME' reference; the catalog/plan/logs then hold only the reference and the CN resolves the secret from its environment at scan time (ResolveAPIKey), keeping the secret out of queryable rel_createsql. Literal keys still work (documented as catalog-visible). - datastream CREATE is now redacted in statement logging (redactStatementTextForLogging), so the apikey never reaches statement_info - tests: ResolveAPIKey unit, frontend redaction unit, e2e env-ref (CN resolves from env, catalog stores only the reference, secret absent) Validated: jstfu 19 unit tests, datastream BVT 111/111, e2e green incl. env-ref, Go unit/reader/frontend tests green. Co-Authored-By: Claude Fable 5 <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #27468
What this PR does / why we need it:
Implements the datastream external table — a generic streaming data-load
bridge (
CREATE EXTERNAL TABLE ... ENGINE = DATASTREAM) that readsCSV-encoded chunks from a gRPC server, with a Java reference server
bridging the Java ecosystem (first candidate per the issue). Design spec:
docs/cn/stream_transport_fast_upload.md; implementation plan and as-builtnotes:
docs/cn/stream_transport_fast_upload_plan.md.MO side (mirrors the
ENGINE = MONGODBseams throughout):datastream_table_paramgrammar +tree.DataStreamTableParam;datastreamstays a non-reserved keyword.pkg/sql/datastreampackage validates options(
server/port/table/recheck) and stores a planner-owned/* MO_DATASTREAM: ... */envelope inrel_createsql, guarded by adurable
features.DataStreamExternalbit (envelope and bit must agree).SHOW CREATE TABLE round-trips.
ExternType_DATASTREAM_TB+plan.DataStreamScancarried onExternScan; remote-run wired throughpipeline.ExternalScan.plan.Expr→ MySQL-text deparser(comparisons, AND/OR/NOT, IN, BETWEEN, IS [NOT] NULL, LIKE over columns
and literals). The pushed text is a hint; with
recheck='true'(default)MO re-applies every filter locally.
recheck='false'skips localre-evaluation for exactly the conjuncts that were pushed, so
non-deparsable conjuncts always stay local and results can never be
wrong-by-omission.
DataStreamReader(anExternalFileReader) wraps the gRPC chunk streamas an
io.Readerfeeding the existing CSV parser and batch builder,using the INLINE virtual-single-file convention.
Wire contract:
proto/datastream/v1/datastream.proto(plain proto3,shared between the Go client and the Java server). Server-streaming
Read;chunks carry only complete CSV records; errors surface both as gRPC status
and as a terminal
Errorframe (TABLE_NOT_FOUND / DATASOURCE_ERROR).Java reference server
xtool/jstfu(Maven, shaded jar viamake jstfu,Java 8 bytecode so it runs on the CI/tester JDK 8; Maven wrapper included so
runners without Maven can build):
${FILTER}replaced by thepushed predicate text (
1=1when absent), streams rows as CSV.boundaries (quote-state aware, so quoted embedded newlines never split);
filter hint is a documented noop.
Tests
an in-process fake gRPC server (multi-chunk, error frames, cancellation,
record-spanning-chunk tolerance).
${FILTER}substitution,config validation.
test/datastream: self-contained e2e (starts the jar itself) including afull MatrixOne round-trip: file + jdbc scans, pushdown with recheck
on/off, error propagation, ETL insert, parallel load with disjoint
filters, and a 2KB-chunk multi-chunk streaming test that asserts every
chunk boundary is record-aligned.
test/distributed/cases/datastream: DDL validation, file + jdbcscans, NULL handling on a 20-column fixture with quoted embedded newlines
(byte-identical vs LOAD DATA), AND/OR/IN/BETWEEN/NOT/LIKE pushdown with
recheck=true/false equivalence, bulk ETL, and error conditions
(table-not-found, bad file, jdbc SQL error, connection refused).
CI wiring
optools/run_bvt.shbuilds the jar (Mavenwrapper) if needed and starts jstfu on
127.0.0.1:4444before BVT;idempotent across the restart pass.
jstfu-buildservice (maven image) builds the jar into ashared volume;
jstfu-cn0/jstfu-cn1sidecars share each CN's networknamespace so
127.0.0.1:4444resolves on whichever CN compiles the scan,and the jdbc datasources loop back to the CN's own
127.0.0.1:6001.Resources are mounted at
/jstfu-testso the CI:/testmount rewritecannot break the server's file paths.
docker compose up -dblocks untilthe jar build completes, so BVT cannot start before jstfu is servable.
🤖 Generated with Claude Code