Files
scylla/db/sstables-format-selector.hh
Petr Gusev a0653590b5 sstables_format_selector: extract listener
In the following commits we want to move schema
commitlog replay earlier, but the current sstable
format should be selected before the replay.
The current sstable format is stored in system.scylla_local,
so we can't read it until system tables are loaded.
This problem is similar to the enabled_features.

To solve this we split sstables_format_selector in two
parts. The lower level part, sstables_format_selector,
knows only about database and system_keyspace. It
will be moved before system_keyspace initialization,
and the on_system_tables_loaded method will
be called on it when the system_keyspace has loaded its tables.

The higher level part, sstables_format_listener, is responsible
for subscribing to feature_services and gossipier and is started
later, at the same place as sstables_format_selector before this commit.
2023-09-13 23:04:50 +04:00

83 lines
2.1 KiB
C++

/*
* Copyright (C) 2020-present ScyllaDB
*
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <seastar/core/semaphore.hh>
#include <seastar/core/future.hh>
#include <seastar/core/gate.hh>
#include <seastar/core/sharded.hh>
#include "sstables/version.hh"
#include "gms/feature.hh"
using namespace seastar;
namespace replica {
class database;
}
namespace gms {
class gossiper;
class feature_service;
}
namespace db {
class system_keyspace;
class sstables_format_listener;
class feature_enabled_listener : public gms::feature::listener {
sstables_format_listener& _listener;
sstables::sstable_version_types _format;
public:
feature_enabled_listener(sstables_format_listener& l, sstables::sstable_version_types format)
: _listener(l)
, _format(format)
{ }
void on_enabled() override;
};
class sstables_format_selector {
sharded<replica::database>& _db;
db::system_keyspace* _sys_ks = nullptr;
sstables::sstable_version_types _selected_format = sstables::sstable_version_types::mc;
future<> select_format(sstables::sstable_version_types new_format);
future<> read_sstables_format();
public:
explicit sstables_format_selector(sharded<replica::database>& db);
future<> on_system_tables_loaded(db::system_keyspace& sys_ks);
inline sstables::sstable_version_types selected_format() const noexcept {
return _selected_format;
}
future<> update_format(sstables::sstable_version_types new_format);
};
class sstables_format_listener {
gms::gossiper& _gossiper;
sharded<gms::feature_service>& _features;
sstables_format_selector& _selector;
seastar::named_semaphore _sem = {1, named_semaphore_exception_factory{"feature listeners"}};
seastar::gate _sel;
feature_enabled_listener _md_feature_listener;
feature_enabled_listener _me_feature_listener;
public:
sstables_format_listener(gms::gossiper& g, sharded<gms::feature_service>& f, sstables_format_selector& selector);
future<> start();
future<> stop();
future<> maybe_select_format(sstables::sstable_version_types new_format);
};
} // namespace sstables