Commit Graph
3 Commits
Author SHA1 Message Date
zhaiAohan 47f6805189 feat: infer remote table schema for relational external tables (#10200)
* feat: infer remote table schema for relational external tables

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: factor complex tuple into type alias to silence clippy

The 6-tuple returned by INFORMATION_SCHEMA.COLUMNS triggers
clippy::type_complexity under -D warnings. Alias it as RawColumnRow so
the driver's FromRow impl for tuples is preserved.

Signed-off-by: tian1220A <1573612521@qq.com>

* refactor: map only selected columns in declared relational external tables

Separate raw remote column metadata fetching from type mapping. The declared form maps only the columns the user lists, while the inferred form maps every remote column.

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: skip DNS resolution for unix-socket MySQL connections

fetch_mysql_columns unconditionally resolved the host via DNS and forced
resolved_ips, which is TCP-only. When the connection DSN carries an explicit
Unix socket (?socket=/path), mysql_async dials the socket path directly, so the
host is a placeholder and an unresolvable hostname should not block the DDL.
Parse the opts first and skip resolution when a socket is configured.

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: use is_none_or to silence clippy::unnecessary_map_or

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: redact relational connection DSNs in debug logs, parser errors and SHOW CREATE TABLE
Signed-off-by: tian1220A <1573612521@qq.com>

* fix: redact sqlparser debug logs leaking connection DSNs

sqlparser logs raw SQL at debug level, which carries the connection DSN
and its password. Wrap the fmt layer with a RedactingFormatter that
redacts DSNs in events whose real target is sqlparser. tracing_log
hard-codes the event target to log, so recover the real target via
NormalizeEvent::normalized_metadata.

Move redact_connection_in_text from table down to common-telemetry so the
logging layer can reuse it; table re-exports it for existing callers.

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: use explicit clone to silence clippy::implicit_clone

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: address review feedback on relational external tables

Reject MySQL TIME, accept a synthetic greptime_timestamp, unify credential redaction via REDACTED_OPTION_VALUE, and add unit tests.

Signed-off-by: tian1220A <1573612521@qq.com>

* fix(telemetry): redact DSN passwords correctly with the url crate

The hand-rolled scanner split username/password at the last colon and treated comma/semicolon/parens as DSN terminators, leaking passwords containing them (e.g. mysql://user:abc:def@host left abc visible). Extract the DSN span and parse it with the url crate, which splits userinfo at the first colon and host at the last @, then rewrite it with the password replaced.

Signed-off-by: tian1220A <1573612521@qq.com>

* refactor: drop generic DSN redaction, keep structured credential redaction

Address review feedback: check table existence before remote schema inference for IF NOT EXISTS; return Option from redact_option_value to avoid redundant allocation.

Signed-off-by: tian1220A <1573612521@qq.com>

---------

Signed-off-by: tian1220A <1573612521@qq.com>
2026-11-18 13:41:19 +00:00
jeremyhi c6962802a9 feat(meta-srv): bind candidate region leases to the migration's registration (#10440)
* feat(meta-srv): bind candidate region leases to the migration's registration

A region migration now gives its candidate region registration a random non-zero
candidate lease id. Leases granted because of that registration carry it, but only
while the table route exists, and the upgrade instruction carries the same id. The
datanode passes the id of each lease to the engine, and Mito records the lease of
the latest heartbeat per region outside the region instance, so it survives a
reopen during catchup.

The migration also drops the candidate registration before it restores the route
on rollback, and before the procedure leaves the migration tracker when it ends
without a rollback.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): record a lease only while the region stays open

Record a granted lease under the same lock that removes it after the region closes, so a lease recorded during a close does not outlive the region. The metric engine records the data region's lease when the metadata region ignores it. Remove the roles-only extraction of operating regions, and cover a present candidate lease id in the upgrade JSON.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* build: point greptime-proto at the candidate lease id change

Use the greptime-proto commit that adds GrantedRegion.candidate_lease_id (greptime-proto#357), which also brings in the RawSeriesSource Substrait payload message. Rely on the declaration order of RegionMigrationProcedure to drop the candidate registration before the tracker entry, and document it.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): drop lease records when workers stop

Remove the lease records of the regions a stopping worker closes. Check under the removal lock deterministically in tests, cover a lease that arrives after a region is removed, assert the candidate lease id on the migration's real registration and its retry, and match ids per region in a batched upgrade.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): drop a redundant helper comment

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(store-api): pin the candidate lease id wire bytes

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: document candidate registration and lease record lifecycles

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix: keep candidate lease ids through customized lease renewers

The heartbeat handler now sets the candidate lease id of each lease a
customized renewer returns from the renewed region with the same id.

The metric engine records a lease for the data region only when the
metadata region ignored it, since the data region records its own
leases. The countdown reset command carries a named struct instead of
a tuple.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(metric-engine): cover a lease the data region ignores

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor: tighten lease id lookups and lease test assertions

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor: align lease naming and share the txn-observing kv backend

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor: tidy lease naming, docs and shared test helpers

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: drop field comments that restate their names

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: drop method comments that restate their names

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: say which heartbeat a lease's send time refers to

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: drop the reset deadline field comment

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: state when an operating region's role and id reach a lease

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* chore: pin greptime-proto to the merged candidate lease id change

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test: add the candidate lease id argument to the direct demotion test

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor: order new keeper helpers after public items and test equal send times

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-16 18:37:17 +00:00
zhaiAohan 8a38b90135 feat: add relational region engine skeleton and registration (#9953)
* feat: add relational region engine skeleton and registration

Add a read-only relational RegionEngine (create/open/drop lifecycle) and register it as the 4th engine in build_store_engines alongside mito/metric/file. Add a datanode-level test asserting all 4 engines are registered.

Signed-off-by: tian1220A <1573612521@qq.com>

* feat: add relational connection and idempotent region lifecycle

Move ConnectionInfo into relational-engine (DSN parsing + redacted rendering), place the RelationalOptions/RELATIONAL_META_KEY serialization contract in table::requests, make CREATE idempotent by comparing the persisted manifest definition against the incoming request (RegionExists on mismatch), and drop the empty EngineConfig placeholder.

Signed-off-by: tian1220A <1573612521@qq.com>

* refactor: address review comments on relational region engine

- remove connection.rs (only used by its own tests); it will be
  reintroduced when connection handling is wired up
- drop RelationalOptions::version (not validated or used to select a
  deserialization format)
- validate an idempotent create against the existing region definition
  (region id / schema / primary key / options) and return Unexpected on
  mismatch, with a reason field on RegionExists
- use serde.workspace and remove the empty [features] section
- cargo fmt

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: adapt relational engine to latest main

- implement RegionEngine::set_region_role_with_lease (no-op lease, the
  engine takes no writes so no lease is needed)
- pass node_id to build_object_store_manager in the registration test
- drop stale url dependency from the relational-engine lock entry

Signed-off-by: tian1220A <1573612521@qq.com>

* ci: register relational-engine in scope rules

Signed-off-by: tian1220A <1573612521@qq.com>

* fix: remove table self-dependency from Cargo.lock

Signed-off-by: tian1220A <1573612521@qq.com>

---------

Signed-off-by: tian1220A <1573612521@qq.com>
2026-10-30 04:06:01 +00:00