schema_registry: Fix SIGSEGV in learn() when concurrent with get_or_load()

The netyr may exist, but its schema may not yet be loaded. learn()
didn't take that into account. This problem is not reachable in
production code, which currently always calls get_or_load() before
learn(), except for boot, but there's no concurrency at that point.

Exposed by unit test added later.
This commit is contained in:
Tomasz Grabiec
2023-06-06 01:17:12 +02:00
parent 053484e762
commit 84cb0f5df7

View File

@@ -60,7 +60,11 @@ schema_ptr schema_registry::learn(const schema_ptr& s) {
}
auto i = _entries.find(s->version());
if (i != _entries.end()) {
return i->second->get_schema();
schema_registry_entry& e = *i->second;
if (e._state == schema_registry_entry::state::LOADING) {
e.load(s);
}
return e.get_schema();
}
slogger.debug("Learning about version {} of {}.{}", s->version(), s->ks_name(), s->cf_name());
auto e_ptr = make_lw_shared<schema_registry_entry>(s->version(), *this);