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

refuse unused WITH options in CONFLUENT SCHEMA REGISTRY #10129

Merged
merged 9 commits into from Jan 25, 2022

Conversation

guswynn
Copy link
Contributor

@guswynn guswynn commented Jan 19, 2022

Currently, if a CONFLUENT SCHEMA REGISTRY WITH option is unused, nothing happens. This leads to more complex migrations, and does not match the behavior of kafka options.

This diff validates that only accepted options are accepted, and errors otherwise. It uses a similar technique as the kafka options, passing &mut out parameters and removing options instead of get'ing them

the generate_ccsr_client_config function is used in a couple places, but we only validate no unused options in plan_create_source and plan_create_sink, to match how kafka option validation works, which is why validation happens outside that function

I am not sure where and how confluent_wire_format comes from, so where to strip that is not clear to me

Motivation

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered.
  • [N/A] This PR adds a release note for any user-facing behavior changes.

@guswynn guswynn force-pushed the ccsr_options branch 2 times, most recently from 02b4ab8 to 64d2a94 Compare January 20, 2022 18:16
@guswynn guswynn mentioned this pull request Jan 20, 2022
8 tasks
@guswynn guswynn marked this pull request as ready for review January 20, 2022 19:12
&[
Config::string("username"),
Config::string("password"),
// An old migration added this field in some avro cases, so we remove it here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this comment might be wrong, but I couldn't figure out the true reason

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely figure out the real reason before merging this. I'm happy to help. What's the test that fails without this?

@@ -1018,6 +1018,16 @@ pub fn plan_create_source(
}))
}

fn ensure_ccsr_options(ccsr_with_options: &BTreeMap<String, Value>) -> Result<(), anyhow::Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might make sense to move this function next to the with_options! macro in sql::normalize and rename it to ensure_empty_options(options: &Btreemap<String, Value>, for: &str) and then call it like ensure_empty_options(&ccsr_options, "CONFLUENT SCHEMA REGISTRY")?;.

} => {
if let Some(CsrSeedCompiledOrLegacy::Compiled(CsrSeedCompiled { key, value })) =
seed
{
let mut ccsr_with_options = normalize::options(&ccsr_options);

// We validate here instead of in purification, to match the behavior of avro
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which avro behavior exactly is this matching?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validating that there are no empty options, even though the protobuf decoder doesn't use this ccsr config

@quodlibetor
Copy link
Contributor

I do think that this deserves a release note. Users who were passing invalid options will get an error, which is user-visible.

- **Breaking change.** `CONFLUENT SCHEMA REGISTRY` sections
of `CREATE SOURCE` and `CREATE SINK` now reject unknown parameters.
(Example: [Confluent Schema Registry options](/sql/create-source/avro-kafka#confluent-schema-registry-options)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This slipped into the v0.17.0 section but needs to go in the unreleased section above!

&[
Config::string("username"),
Config::string("password"),
// An old migration added this field in some avro cases, so we remove it here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely figure out the real reason before merging this. I'm happy to help. What's the test that fails without this?

/// `WITH` options are all real, used options
pub(crate) fn ensure_empty_options<V>(
with_options: &BTreeMap<String, V>,
r#for: &str,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a raw ident is def nonstandard practice. Elsewhere in sql we call this sort of parameter name or ctx.

@guswynn
Copy link
Contributor Author

guswynn commented Jan 25, 2022

@benesch I think this update should cover all your review!

Copy link
Member

@benesch benesch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

// An old migration
// (https://github.com/MaterializeInc/materialize/blob/c402917b7078a14bc0d0d6330b9c9b177aa73e47/src/coord/src/catalog/migrate.rs#L362)
// adds this field to kafka-avro WITH options, though now in the CSR case,
// the field is unread and fixed to `true`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was just an error in the migration, no? Like this parameter has no meaning here and has never had meaning, right? Too bad. If that's true we should write another migration to fix it. Doesn't need to block this though since this is still a huge net win. Can you file a followup ticket though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it never had meaning, but yeah, now It appears to not have meaning...I will make an issue

also, I removed the username and password extraction, because I don't actually think those exist except in docs?

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.

None yet

3 participants