-
Notifications
You must be signed in to change notification settings - Fork 580
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
Schema Registry: GET /schemas/ids/<id>
should return references
#11216
Schema Registry: GET /schemas/ids/<id>
should return references
#11216
Conversation
This will make the next refactor slightly easier. Signed-off-by: Ben Pope <ben@redpanda.com>
This will make the next refactor slightly easier to comprehend. Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
a42bfb9
to
7a03737
Compare
7a03737
to
a408202
Compare
a408202
to
05de998
Compare
acc.insert(acc.end(), refs.begin(), refs.end()); | ||
return acc; | ||
}); | ||
absl::c_sort(references); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is htis different than std::sort used above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by using absl::btree_set
std::vector<schema_id> | ||
subject_versions_with_any_of(const std::vector<schema_id>& ids) { | ||
std::vector<schema_id> has_ids; | ||
for (const auto& s : _subjects) { | ||
for (const auto& r : s.second.versions) { | ||
if (absl::c_binary_search(ids, r.id)) { | ||
has_ids.push_back(r.id); | ||
} | ||
} | ||
} | ||
return has_ids; | ||
} | ||
|
||
bool subject_versions_has_any_of(const std::vector<schema_id>& ids) { | ||
return absl::c_any_of(_subjects, [&ids](const auto& s) { | ||
return absl::c_any_of(s.second.versions, [&ids](const auto& v) { | ||
return absl::c_binary_search(ids, v.id); | ||
}); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume these require the inputs to be sorted? probably worth a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by using absl::btree_set
This should be a pure refactoring. The store has two mappings: 1) `schema_map`: Schema ID to Schema (sharded across cores) 2) `subject_map`: Subject-Versions to Schema ID Each of these mappings are then split across shards, coordinated by sharded_store. Prior to this change, references were attached to the Subject-Versions. This is an incorrect modelling; Schema should own the references to other schema. This commit does that refactoring by moving references from `typed_schema` to `typed_schema_definition`. There are a couple of things that are not straightforward: 1) `ValidSchema` (`protobuf_schema_definition`, `avro_schema_definition`) are the respective library instantiations of the representation, and are unable to reproduce their references to form a `canonical_schema_definition`, so references are stored inside the wrappers. 2) `referenced_by` and `is_reference` now require two phases to obtain the references, due to the sharded and diconnected nature of the two mappings (schema, and subject-versions). a) Obtain a list of schema ids that reference the subject-version b) Filter that list by subject-versions that are not soft-deleted Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Ben Pope <ben@redpanda.com>
`GET /schemas/ids/<id>` now returns its references. Fixes redpanda-data#11194 Signed-off-by: Ben Pope <ben@redpanda.com>
05de998
to
9298788
Compare
Changes in force-push:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
just to confirm:
schema_id_set referenced_by(const subject& sub, schema_version ver) {
schema_id_set references;
for (const auto& s : _schemas) {
for (const auto& r : s.second.definition.refs()) {
if (r.sub == sub && r.version == ver) {
references.emplace_back(s.first);
references.insert(s.first);
}
}
}
The referenced_by
helper doesn't need to integrate the soft-delete flag?
Good question. I poked around and found no mechanism for it to be required. |
/backport v23.1.x |
/backport v22.3.x |
/backport v22.2.x |
Failed to run cherry-pick command. I executed the commands below:
|
Failed to run cherry-pick command. I executed the commands below:
|
Failed to run cherry-pick command. I executed the commands below:
|
Return
references
forGET /schemas/ids/<id>
.Fixes #11194
Notes for reviewer:
The
store
has two mappings:schema_map
: Schema ID to Schemasubject_map
: Subject-Versions to Schema IDEach of these mappings are then balanced across shards, coordinated by
sharded_store
.Prior to this change,
references
were attached to the Subject-Versions.This is an incorrect modelling; Schema should own the references to other schema. This commit does that refactoring by moving references from
typed_schema
totyped_schema_definition
.This allows returning the references when querying a schema by ID.
Additionally there is a fix to ignore references when a subject-version has been soft-deleted.
Backports Required
Release Notes
Bug Fixes
references
forGET /schemas/ids/<id>
.