From c00b376a3e86eea074784c199f05ab70f25b3438 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 21 Dec 2023 16:24:02 +0200 Subject: [PATCH] schema_registry, database: flush entries when no longer in use The schema registry disarms internal timers when it is destroyed. This accesses the Seastar reactor. However, after [1] we don't have ordering between the reactor destruction and the thread_local registry destruction. Fix this by flushing all entries when the database is destroyed. The database object is fundamental so it's unlikely we'll have anything using the registry after it's gone. [1] https://github.com/scylladb/seastar/commit/101b245ed709d7170f3addcb4ebdc87763d6f65b --- replica/database.cc | 1 + schema/schema_registry.cc | 4 ++++ schema/schema_registry.hh | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/replica/database.cc b/replica/database.cc index b22a8e8d26..2c01a8e69c 100644 --- a/replica/database.cc +++ b/replica/database.cc @@ -636,6 +636,7 @@ void database::set_format(sstables::sstable_version_types format) noexcept { database::~database() { _user_types->deactivate(); + local_schema_registry().clear(); } void database::update_version(const table_schema_version& version) { diff --git a/schema/schema_registry.cc b/schema/schema_registry.cc index 2fe0b1cf02..c2d462649f 100644 --- a/schema/schema_registry.cc +++ b/schema/schema_registry.cc @@ -164,6 +164,10 @@ schema_ptr schema_registry::get_or_load(table_schema_version v, const schema_loa return e.get_schema(); } +void schema_registry::clear() { + _entries.clear(); +} + schema_ptr schema_registry_entry::load(frozen_schema fs) { _frozen_schema = std::move(fs); auto s = get_schema(); diff --git a/schema/schema_registry.hh b/schema/schema_registry.hh index 8f1b95e04d..9490439021 100644 --- a/schema/schema_registry.hh +++ b/schema/schema_registry.hh @@ -150,6 +150,12 @@ public: // 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&); + + // Removes all entries from the registry. This in turn removes all dependencies + // on the Seastar reactor. + // + // Prerequisite: all futures from get_or_load() are resolved. + void clear(); }; schema_registry& local_schema_registry();