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

[CORE-60] Schema Registry: Support /mode #17952

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

BenPope
Copy link
Member

@BenPope BenPope commented Apr 18, 2024

Support /mode

TODO:

  • More Auth tests
  • Wire-up is_mutable a bit more
  • Return an error if the mode is incompatible with the operation

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.3.x
  • v23.2.x

Release Notes

Features

  • Schema Registry: Support /mode endpoints

Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
No functional changes

Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
@BenPope BenPope requested a review from a team as a code owner April 18, 2024 21:19
@BenPope BenPope self-assigned this Apr 18, 2024
@BenPope BenPope requested review from oleiman and michael-redpanda and removed request for a team and oleiman April 18, 2024 21:19
@BenPope BenPope added area/schema-registry Schema Registry service within Redpanda and removed area/redpanda labels Apr 18, 2024
@BenPope BenPope changed the title Schema Registry: Support /mode [CORE-60] Schema Registry: Support /mode Apr 18, 2024
template<>
constexpr std::optional<mode> from_string_view<mode>(std::string_view sv) {
return string_switch<std::optional<mode>>(sv)
.match(to_string_view(mode::import), mode::import)
Copy link
Member

Choose a reason for hiding this comment

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

i like how to_string_view gets reused here. nice and clena

auto sub_shard{shard_for(sub)};
co_return co_await _store.invoke_on(
sub_shard, _smp_opts, [marker, sub{std::move(sub)}, m, f](store& s) {
return s.set_mode(marker, sub, m, f).value();
Copy link
Member

Choose a reason for hiding this comment

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

i guess our default result<> configuration has a policy that throws on .value() (rather than what I always assume to be undefined behavior if no value exists) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not default; but it does throw.

@@ -325,6 +331,9 @@ constexpr std::string_view to_string_view(seq_marker_key_type v) {
case seq_marker_key_type::config:
return "config";
break;
case seq_marker_key_type::mode:
return "mode";
break;
Copy link
Member

Choose a reason for hiding this comment

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

break unused here

Copy link
Contributor

@michael-redpanda michael-redpanda left a comment

Choose a reason for hiding this comment

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

looks nice, a few questions

///\brief Get the mode for a subject, or fallback to global.
result<mode>
get_mode(const subject& sub, default_to_global fallback) const {
auto sub_it = get_subject_iter(sub, include_deleted::yes);
Copy link
Contributor

Choose a reason for hiding this comment

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

qq: Is include_deleted::yes correct?

} else if (fallback) {
return _mode;
}
return mode_not_found(sub);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be subject_not_found rather than mode_not_found? Should mode_not_found be returned if the subject exists and fallback is false?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be subject_not_found rather than mode_not_found? Should mode_not_found be returned if the subject exists and fallback is false?

The mode configuration can exist without a subject. This is required so that a subject can be placed into import without the entire registry being in import.

Comment on lines +718 to +719
result<void> check_mutable(force f) const {
if (!_mutable && !f) {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Isn't the force flag for if there are already registered schemas and the mode is going into IMPORT?

"type": "object",
"properties": {
"mode": {
"type": "string"
Copy link
Contributor

Choose a reason for hiding this comment

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

qq: can this be an enum?

Comment on lines +268 to +273
{
"name": "defaultToGlobal",
"in": "query",
"required": false,
"type": "boolean"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

question: I don't see this in the API. Is this an undocumented option?

Copy link
Member

@oleiman oleiman left a comment

Choose a reason for hiding this comment

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

lgtm. few questions mostly for my own benefit.

@@ -202,7 +202,7 @@ model::record_batch as_record_batch(Key key) {

SEASTAR_THREAD_TEST_CASE(test_consume_to_store_after_compaction) {
pps::sharded_store s;
s.start(ss::default_smp_service_group()).get();
s.start(pps::is_mutable::no, ss::default_smp_service_group()).get();
Copy link
Member

Choose a reason for hiding this comment

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

question: why sometimes is_mutable::no? branch coverage?

Comment on lines +471 to +476
auto mode = co_await ss::coroutine::as_future(
_store.get_subject_mode_written_at(sub));
if (!mode.failed()) {
rb(mode.get());
}

Copy link
Member

Choose a reason for hiding this comment

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

is it generally advisable to explicitly get_exception (or discard or whatever) on the other side of the branch here?

Copy link
Member

@dotnwat dotnwat Apr 23, 2024

Choose a reason for hiding this comment

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

is it generally advisable to explicitly get_exception (or discard or whatever) on the other side of the branch here?

Yes, you need to eat the exception out of ready future to avoid abandoned exceptional future.

same below for conf

EDIT: for conf i think I just noticed this in the PR that introduced that #17905 (review).

try {
co_await seq._store.get_mode(sub, default_to_global::no);
} catch (const exception&) {
// subject config already blank
Copy link
Member

Choose a reason for hiding this comment

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

nitpick:

Suggested change
// subject config already blank
// subject mode already blank

Comment on lines +471 to +476
auto mode = co_await ss::coroutine::as_future(
_store.get_subject_mode_written_at(sub));
if (!mode.failed()) {
rb(mode.get());
}

Copy link
Member

@dotnwat dotnwat Apr 23, 2024

Choose a reason for hiding this comment

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

is it generally advisable to explicitly get_exception (or discard or whatever) on the other side of the branch here?

Yes, you need to eat the exception out of ready future to avoid abandoned exceptional future.

same below for conf

EDIT: for conf i think I just noticed this in the PR that introduced that #17905 (review).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema-registry Schema Registry service within Redpanda
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants