schema_registry: Make learn(schema_ptr) attach entry to the target schema
System tables have static schemas and code uses those static schemas instead of looking them up in the database. We want those schemas to have a valid table() once the table is created, so we need to attach registry entry to the target schema rather than to a schema duplicate.
This commit is contained in:
@@ -64,7 +64,7 @@ schema_ptr schema_registry::learn(const schema_ptr& s) {
|
||||
}
|
||||
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);
|
||||
auto loaded_s = e_ptr->load(frozen_schema(s));
|
||||
auto loaded_s = e_ptr->load(s);
|
||||
_entries.emplace(s->version(), e_ptr);
|
||||
return loaded_s;
|
||||
}
|
||||
@@ -147,6 +147,20 @@ schema_ptr schema_registry_entry::load(frozen_schema fs) {
|
||||
return s;
|
||||
}
|
||||
|
||||
schema_ptr schema_registry_entry::load(schema_ptr s) {
|
||||
_frozen_schema = frozen_schema(s);
|
||||
_schema = &*s;
|
||||
_schema->_registry_entry = this;
|
||||
_erase_timer.cancel();
|
||||
if (_state == state::LOADING) {
|
||||
_schema_promise.set_value(s);
|
||||
_schema_promise = {};
|
||||
}
|
||||
_state = state::LOADED;
|
||||
slogger.trace("Loaded {} = {}", _version, *s);
|
||||
return s;
|
||||
}
|
||||
|
||||
future<schema_ptr> schema_registry_entry::start_loading(async_schema_loader loader) {
|
||||
_loader = std::move(loader);
|
||||
auto f = _loader(_version);
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
schema_registry_entry(const schema_registry_entry&) = delete;
|
||||
~schema_registry_entry();
|
||||
schema_ptr load(frozen_schema);
|
||||
schema_ptr load(schema_ptr);
|
||||
future<schema_ptr> start_loading(async_schema_loader);
|
||||
schema_ptr get_schema(); // call only when state >= LOADED
|
||||
// Can be called from other shards
|
||||
@@ -137,10 +138,9 @@ public:
|
||||
|
||||
// Attempts to add given schema to the registry. If the registry already
|
||||
// knows about the schema, returns existing entry, otherwise returns back
|
||||
// the schema which was passed as argument. Users should prefer to use the
|
||||
// schema_ptr returned by this method instead of the one passed to it,
|
||||
// because doing so ensures that the entry will be kept in the registry as
|
||||
// long as the schema is actively used.
|
||||
// the schema which was passed as argument.
|
||||
// The schema instance pointed to by the argument will be attached to the registry
|
||||
// entry and will keep it alive.
|
||||
schema_ptr learn(const schema_ptr&);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user