diff --git a/db/schema_tables.cc b/db/schema_tables.cc index b5c1033fa9..7384c30aba 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -115,7 +115,6 @@ schema_ctxt::schema_ctxt(const db::config& cfg, std::shared_ptr _user_types; }; diff --git a/replica/database.cc b/replica/database.cc index 78d6fb0530..6be9a2298a 100644 --- a/replica/database.cc +++ b/replica/database.cc @@ -483,7 +483,7 @@ database::database(const db::config& cfg, database_config dbcfg, service::migrat { SCYLLA_ASSERT(dbcfg.available_memory != 0); // Detect misconfigured unit tests, see #7544 - local_schema_registry().init(*this); // TODO: we're never unbound. + local_schema_registry().init(*this, std::chrono::seconds(get_config().schema_registry_grace_period())); // TODO: we're never unbound. setup_metrics(); _row_cache_tracker.set_compaction_scheduling_group(dbcfg.memory_compaction_scheduling_group); diff --git a/schema/schema_registry.cc b/schema/schema_registry.cc index 179d481eb8..e4fb6cc285 100644 --- a/schema/schema_registry.cc +++ b/schema/schema_registry.cc @@ -54,8 +54,9 @@ schema_registry_entry::schema_registry_entry(table_schema_version v, schema_regi schema_registry::~schema_registry() = default; -void schema_registry::init(const db::schema_ctxt& ctxt) { +void schema_registry::init(const db::schema_ctxt& ctxt, schema_registry_entry::erase_clock::duration grace_period) { _ctxt = std::make_unique(ctxt); + _grace_period = grace_period; } void schema_registry::attach_table(schema_registry_entry& e) noexcept { @@ -121,10 +122,6 @@ schema_registry_entry& schema_registry::get_entry(table_schema_version v) const return e; } -schema_registry_entry::erase_clock::duration schema_registry::grace_period() const { - return std::chrono::seconds(_ctxt->schema_registry_grace_period()); -} - schema_ptr schema_registry::get(table_schema_version v) const { return get_entry(v).get_schema(); } diff --git a/schema/schema_registry.hh b/schema/schema_registry.hh index d6e8188322..88fbf2e3c3 100644 --- a/schema/schema_registry.hh +++ b/schema/schema_registry.hh @@ -112,18 +112,17 @@ public: class schema_registry { std::unordered_map> _entries; std::unique_ptr _ctxt; + schema_registry_entry::erase_clock::duration _grace_period{std::chrono::seconds(1)}; friend class schema_registry_entry; schema_registry_entry& get_entry(table_schema_version) const; - // Duration for which unused entries are kept alive to avoid - // too frequent re-requests and syncs. Default is 1 second. - schema_registry_entry::erase_clock::duration grace_period() const; + schema_registry_entry::erase_clock::duration grace_period() const { return _grace_period; } private: void attach_table(schema_registry_entry&) noexcept; public: ~schema_registry(); // workaround to this object being magically appearing from nowhere. - void init(const db::schema_ctxt&); + void init(const db::schema_ctxt&, schema_registry_entry::erase_clock::duration grace_period); // Looks up schema by version or loads it using supplied loader. // If the schema refers to a view, the loader must return both view and base schemas. diff --git a/test/boost/schema_registry_test.cc b/test/boost/schema_registry_test.cc index 2b7118d2be..5916f900cc 100644 --- a/test/boost/schema_registry_test.cc +++ b/test/boost/schema_registry_test.cc @@ -45,12 +45,11 @@ static schema_ptr random_schema() { struct dummy_init { std::unique_ptr config; gms::feature_service fs; - seastar::lowres_clock::duration grace_period; dummy_init() : config(std::make_unique()) - , fs({get_disabled_features_from_db_config(*config)}) - , grace_period(std::chrono::seconds(config->schema_registry_grace_period())) { - local_schema_registry().init(db::schema_ctxt(*config, std::make_shared(), fs)); + , fs({get_disabled_features_from_db_config(*config)}) { + local_schema_registry().init(db::schema_ctxt(*config, std::make_shared(), fs), + std::chrono::seconds(config->schema_registry_grace_period())); } };