Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Err(CoordinatorInconsistencies { catalog_inconsistencies: CatalogInconsistencies { internal_fields: [], roles: [], comments: [], object_dependencies: [], items: [StatementParseFailure { create_sql: "CREATE SUBSOURCE #22535

Closed
def- opened this issue Oct 20, 2023 · 0 comments · Fixed by #23082
Assignees
Labels
C-bug Category: something is broken

Comments

@def-
Copy link
Contributor

def- commented Oct 20, 2023

What version of Materialize are you using?

3f50285

What is the issue?

Found using my WIP branch #22521
Testdrive reproducer:

> CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
    URL '${testdrive.schema-registry-url}'
  );

> CREATE CONNECTION kafka_conn
  TO KAFKA (BROKER '${testdrive.kafka-addr}');

$ kafka-create-topic topic=x

$ set keyschema={
    "type": "record",
    "name": "Key",
    "fields": [
        {"name": "key1", "type": "string"}
    ]
  }

$ set schema={
    "type" : "record",
    "name" : "test",
    "fields" : [
        {"name":"f1", "type":"string"}
    ]
  }

$ kafka-ingest format=avro key-format=avro topic=x key-schema=${keyschema} schema=${schema} repeat=1
{"key1": "U2${kafka-ingest.iteration}"} {"f1": "A${kafka-ingest.iteration}"}

> CREATE SOURCE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-x-${testdrive.seed}')
  FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn ENVELOPE UPSERT;
thread 'coordinator' panicked at 'assertion failed: `(left == right)`
  left: `Err(CoordinatorInconsistencies { catalog_inconsistencies: CatalogInconsistencies { internal_fields: [], roles: [], comments: [], object_dependencies: [], items: [StatementParseFailure { create_sql: "CREATE SOURCE \"materialize\".\"public\".\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" FROM KAFKA CONNECTION [u2 AS \"materialize\".\"public\".\"kafka_conn\"] (TOPIC = 'testdrive-x-748510065') FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION [u1 AS \"materialize\".\"public\".\"csr_conn\"] SEED KEY SCHEMA '{\"type\":\"record\",\"name\":\"Key\",\"fields\":[{\"name\":\"key1\",\"type\":\"string\"}]}' VALUE SCHEMA '{\"type\":\"record\",\"name\":\"test\",\"fields\":[{\"name\":\"f1\",\"type\":\"string\"}]}' ENVELOPE UPSERT EXPOSE PROGRESS AS [u3 AS \"materialize\".\"public\".\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_progress\"]", e: ParserStatementError { error: ParserError { message: "identifier length exceeds 255 bytes", pos: 736 }, statement: None } }, StatementParseFailure { create_sql: "CREATE SUBSOURCE \"materialize\".\"public\".\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_progress\" (\"partition\" [s80 AS \"pg_catalog\".\"numrange\"] NOT NULL, \"offset\" [s70 AS \"pg_catalog\".\"uint8\"]) WITH (PROGRESS = true)", e: ParserStatementError { error: ParserError { message: "identifier length exceeds 255 bytes", pos: 40 }, statement: None } }] }, read_capabilities: [] })`,
 right: `Ok(())`: coordinator inconsistency detected', /var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/ddl.rs:549:9
stack backtrace:
   0: rust_begin_unwind
             at ./rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at ./rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<core::result::Result<(), mz_adapter::coord::consistency::CoordinatorInconsistencies>, core::result::Result<(), mz_adapter::coord::consistency::CoordinatorInconsistencies>>
             at ./rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:228:5
   4: <mz_adapter::coord::Coordinator>::catalog_transact_with::<<mz_adapter::coord::Coordinator>::catalog_transact::{closure#0}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/ddl.rs:549:9
   5: <mz_adapter::coord::Coordinator>::catalog_transact_with::<<mz_adapter::coord::Coordinator>::catalog_transact::{closure#0}::{closure#0}::{closure#1}, ()>::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/ddl.rs:97:5
   6: <mz_adapter::coord::Coordinator>::catalog_transact::{closure#0}::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/ddl.rs:74:14
   7: <mz_adapter::coord::Coordinator>::catalog_transact::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/ddl.rs:67:5
   8: <mz_adapter::coord::Coordinator>::sequence_create_source::{closure#0}::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/sequencer/inner.rs:228:57
   9: <mz_adapter::coord::Coordinator>::sequence_create_source::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/sequencer/inner.rs:216:5
  10: <mz_adapter::coord::Coordinator>::sequence_plan::{closure#0}::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/sequencer.rs:140:84
  11: <mz_adapter::coord::Coordinator>::sequence_plan::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/sequencer.rs:65:5
  12: <mz_adapter::coord::Coordinator>::message_purified_statement_ready::{closure#0}::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/message_handler.rs:398:18
  13: <mz_adapter::coord::Coordinator>::message_purified_statement_ready::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/message_handler.rs:304:5
  14: <mz_adapter::coord::Coordinator>::handle_message::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord/message_handler.rs:55:62
  15: <tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::handle_message::{closure#0}> as core::future::future::Future>::poll
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.37/src/instrument.rs:272:9
  16: <mz_ore::metrics::WallTimeFuture<tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::handle_message::{closure#0}>, prometheus::histogram::Histogram> as core::future::future::Future>::poll
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/ore/src/metrics.rs:595:28
  17: <mz_adapter::coord::Coordinator>::serve::{closure#0}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord.rs:2051:18
  18: <tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::serve::{closure#0}> as core::future::future::Future>::poll
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.37/src/instrument.rs:272:9
  19: <tokio::runtime::park::CachedParkThread>::block_on::<tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::serve::{closure#0}>>::{closure#0}
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282:63
  20: tokio::runtime::coop::with_budget::<core::task::poll::Poll<()>, <tokio::runtime::park::CachedParkThread>::block_on<tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::serve::{closure#0}>>::{closure#0}>
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:107:5
  21: tokio::runtime::coop::budget::<core::task::poll::Poll<()>, <tokio::runtime::park::CachedParkThread>::block_on<tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::serve::{closure#0}>>::{closure#0}>
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:73:5
  22: <tokio::runtime::park::CachedParkThread>::block_on::<tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::serve::{closure#0}>>
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282:31
  23: <tokio::runtime::context::blocking::BlockingRegionGuard>::block_on::<tracing::instrument::Instrumented<<mz_adapter::coord::Coordinator>::serve::{closure#0}>>
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/blocking.rs:66:9
  24: <tokio::runtime::handle::Handle>::block_on::<<mz_adapter::coord::Coordinator>::serve::{closure#0}>::{closure#0}
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/handle.rs:310:13
  25: tokio::runtime::context::runtime::enter_runtime::<<tokio::runtime::handle::Handle>::block_on<<mz_adapter::coord::Coordinator>::serve::{closure#0}>::{closure#0}, ()>
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/runtime.rs:65:16
  26: <tokio::runtime::handle::Handle>::block_on::<<mz_adapter::coord::Coordinator>::serve::{closure#0}>
             at ./cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/handle.rs:309:9
  27: mz_adapter::coord::serve::{closure#0}::{closure#1}
             at ./var/lib/buildkite-agent/builds/buildkite-builders-d43b1b5-i-0c5aa06ee5de9fa45-1/materialize/tests/src/adapter/src/coord.rs:2296:17

The subsource name is too long, but we still accept the CREATE SOURCE command and then fail later. If this doesn't fall into the Surfaces area, then please assign to Storage team. I think the fix is to check how long the source+subsource combination will be and not allow creating sources which will lead to too long subsources.

@def- def- added the C-bug Category: something is broken label Oct 20, 2023
@chaas chaas assigned ParkMyCar and unassigned chaas Nov 8, 2023
ParkMyCar added a commit that referenced this issue Nov 15, 2023
This PR adds a max length to the `Ident` struct. In
#20999 we added the
concept of a "max_identifier_length" which was enforced when parsing
SQL, but it was not enforced for identifiers created internally, e.g.
when generating a name for a progress subsource by appending "_progress"
to the source name.

The largest changes in this PR are the following APIs:

* **`Ident::new(...)`** will return an `Err(IdentError)` if the provided
string is longer than our max, which is 255 bytes.
* **`ident!("some static str")`** macro, which enforces our invariants
at compile time. This prevents a pattern like `Ident::new("some static
str").expect("known correct")` from polluting the code base.
* **`Ident::new_unchecked(...)`** checks the invariants with a
`soft_assert!`. This pattern is an escape hatch for cases we know are
valid, but can't express in the type system, e.g. appending a number to
a static string.

Wherever possible I used `Ident::new(...)` or `ident!(...)`, but there
were some callsites that didn't already return an error, and didn't have
a `&'static str` as an argument. For those cases I used
`Ident::new_unchecked(...)` to prevent this PR from getting too large.
At the very least by using `new_unchecked(...)` our tests will catch
invalid `Ident`s via soft asserts.

### Motivation

Fixes #22535

But also has the goal of eliminating these kinds of bugs entirely.
Chatted about this on
[Slack](https://materializeinc.slack.com/archives/C02FWJ94HME/p1699476924158659)
and it seemed desirable.

### Checklist

- [ ] This PR has adequate test coverage / QA involvement has been duly
considered.
- [ ] This PR has an associated up-to-date [design
doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md),
is a design doc
([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)),
or is sufficiently small to not require a design.
  <!-- Reference the design in the description. -->
- [ ] If this PR evolves [an existing `$T ⇔ Proto$T`
mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md)
(possibly in a backwards-incompatible way), then it is tagged with a
`T-proto` label.
- [ ] If this PR will require changes to cloud orchestration or tests,
there is a companion cloud PR to account for those changes that is
tagged with the release-blocker label
([example](MaterializeInc/cloud#5021)).
<!-- Ask in #team-cloud on Slack if you need help preparing the cloud
PR. -->
- [x] This PR includes the following [user-facing behavior
changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note):
  - Internal only change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants