system_keyspace: move initialize_virtual_tables into virtual_tables.hh
This is a readability refactoring commit without observable changes in behaviour. initialize_virtual_tables logically belongs to virtual_tables module, and it allows to make other functions in virtual_tables.cc (register_virtual_tables, install_virtual_readers) local to the module, which simplifies the matters a bit. all_virtual_tables() is not needed anymore, all the references to registered virtual tables are now local to virtual_tables module and can just use virtual_tables variable directly.
This commit is contained in:
@@ -44,7 +44,6 @@
|
||||
#include "cdc/generation.hh"
|
||||
#include "replica/tablets.hh"
|
||||
#include "replica/query.hh"
|
||||
#include "db/virtual_tables.hh"
|
||||
|
||||
using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
|
||||
@@ -1938,20 +1937,6 @@ future<> system_keyspace::make(
|
||||
}
|
||||
}
|
||||
|
||||
future<> system_keyspace::initialize_virtual_tables(
|
||||
distributed<replica::database>& dist_db, distributed<service::storage_service>& dist_ss,
|
||||
sharded<gms::gossiper>& dist_gossiper, distributed<service::raft_group_registry>& dist_raft_gr,
|
||||
db::config& cfg) {
|
||||
register_virtual_tables(dist_db, dist_ss, dist_gossiper, dist_raft_gr, cfg);
|
||||
|
||||
auto& db = dist_db.local();
|
||||
for (auto&& table: all_virtual_tables()) {
|
||||
co_await db.create_local_system_table(table, false, dist_ss.local().get_erm_factory());
|
||||
}
|
||||
|
||||
install_virtual_readers(*this, db);
|
||||
}
|
||||
|
||||
future<foreign_ptr<lw_shared_ptr<reconcilable_result>>>
|
||||
system_keyspace::query_mutations(distributed<replica::database>& db, const sstring& ks_name, const sstring& cf_name) {
|
||||
schema_ptr schema = db.local().find_schema(ks_name, cf_name);
|
||||
|
||||
@@ -286,13 +286,6 @@ public:
|
||||
replica::database&,
|
||||
system_table_load_phase phase);
|
||||
|
||||
future<> initialize_virtual_tables(
|
||||
distributed<replica::database>&,
|
||||
distributed<service::storage_service>&,
|
||||
sharded<gms::gossiper>&,
|
||||
sharded<service::raft_group_registry>&,
|
||||
db::config&);
|
||||
|
||||
|
||||
/// overloads
|
||||
|
||||
|
||||
@@ -985,17 +985,7 @@ private:
|
||||
// Map from table's schema ID to table itself. Helps avoiding accidental duplication.
|
||||
static thread_local std::map<table_id, std::unique_ptr<virtual_table>> virtual_tables;
|
||||
|
||||
// Precondition: `register_virtual_tables` has finished.
|
||||
std::vector<schema_ptr> all_virtual_tables() {
|
||||
std::vector<schema_ptr> r;
|
||||
r.reserve(virtual_tables.size());
|
||||
for (const auto& [_, v] : virtual_tables) {
|
||||
r.push_back(v->schema());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void register_virtual_tables(distributed<replica::database>& dist_db, distributed<service::storage_service>& dist_ss, sharded<gms::gossiper>& dist_gossiper, sharded<service::raft_group_registry>& dist_raft_gr, db::config& cfg) {
|
||||
static void register_virtual_tables(distributed<replica::database>& dist_db, distributed<service::storage_service>& dist_ss, sharded<gms::gossiper>& dist_gossiper, sharded<service::raft_group_registry>& dist_raft_gr, db::config& cfg) {
|
||||
auto add_table = [] (std::unique_ptr<virtual_table>&& tbl) {
|
||||
virtual_tables[tbl->schema()->id()] = std::move(tbl);
|
||||
};
|
||||
@@ -1016,7 +1006,7 @@ void register_virtual_tables(distributed<replica::database>& dist_db, distribute
|
||||
add_table(std::make_unique<raft_state_table>(dist_raft_gr));
|
||||
}
|
||||
|
||||
void install_virtual_readers(db::system_keyspace& sys_ks, replica::database& db) {
|
||||
static void install_virtual_readers_and_writers(db::system_keyspace& sys_ks, replica::database& db) {
|
||||
db.find_column_family(system_keyspace::size_estimates()).set_virtual_reader(mutation_source(db::size_estimates::virtual_reader(db, sys_ks)));
|
||||
db.find_column_family(system_keyspace::v3::views_builds_in_progress()).set_virtual_reader(mutation_source(db::view::build_progress_virtual_reader(db)));
|
||||
db.find_column_family(system_keyspace::built_indexes()).set_virtual_reader(mutation_source(db::index::built_indexes_virtual_reader(db)));
|
||||
@@ -1028,4 +1018,19 @@ void install_virtual_readers(db::system_keyspace& sys_ks, replica::database& db)
|
||||
}
|
||||
}
|
||||
|
||||
future<> initialize_virtual_tables(
|
||||
distributed<replica::database>& dist_db, distributed<service::storage_service>& dist_ss,
|
||||
sharded<gms::gossiper>& dist_gossiper, distributed<service::raft_group_registry>& dist_raft_gr,
|
||||
sharded<db::system_keyspace>& sys_ks,
|
||||
db::config& cfg) {
|
||||
register_virtual_tables(dist_db, dist_ss, dist_gossiper, dist_raft_gr, cfg);
|
||||
|
||||
auto& db = dist_db.local();
|
||||
for (auto&& [id, vt] : virtual_tables) {
|
||||
co_await db.create_local_system_table(vt->schema(), false, dist_ss.local().get_erm_factory());
|
||||
}
|
||||
|
||||
install_virtual_readers_and_writers(sys_ks.local(), db);
|
||||
}
|
||||
|
||||
} // namespace db
|
||||
|
||||
@@ -30,9 +30,12 @@ namespace db {
|
||||
class config;
|
||||
class system_keyspace;
|
||||
|
||||
void register_virtual_tables(distributed<replica::database>& dist_db, distributed<service::storage_service>& dist_ss,
|
||||
sharded<gms::gossiper>& dist_gossiper, sharded<service::raft_group_registry>& dist_raft_gr, db::config& cfg);
|
||||
void install_virtual_readers(db::system_keyspace& sys_ks, replica::database& db);
|
||||
std::vector<schema_ptr> all_virtual_tables();
|
||||
future<> initialize_virtual_tables(
|
||||
distributed<replica::database>&,
|
||||
distributed<service::storage_service>&,
|
||||
sharded<gms::gossiper>&,
|
||||
sharded<service::raft_group_registry>&,
|
||||
sharded<db::system_keyspace>& sys_ks,
|
||||
db::config&);
|
||||
|
||||
} // namespace db
|
||||
|
||||
5
main.cc
5
main.cc
@@ -95,6 +95,7 @@
|
||||
#include "lang/wasm_instance_cache.hh"
|
||||
#include "lang/wasm_alien_thread_runner.hh"
|
||||
#include "sstables/sstables_manager.hh"
|
||||
#include "db/virtual_tables.hh"
|
||||
|
||||
#include "service/raft/raft_address_map.hh"
|
||||
#include "service/raft/raft_group_registry.hh"
|
||||
@@ -1289,7 +1290,9 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl
|
||||
ss.stop().get();
|
||||
});
|
||||
supervisor::notify("initializing virtual tables");
|
||||
sys_ks.invoke_on_all(&db::system_keyspace::initialize_virtual_tables, std::ref(db), std::ref(ss), std::ref(gossiper), std::ref(raft_gr), std::ref(*cfg)).get();
|
||||
smp::invoke_on_all([&] {
|
||||
return db::initialize_virtual_tables(db, ss, gossiper, raft_gr, sys_ks, *cfg);
|
||||
}).get();
|
||||
|
||||
supervisor::notify("starting forward service");
|
||||
forward_service.start(std::ref(messaging), std::ref(proxy), std::ref(db), std::ref(token_metadata)).get();
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include "streaming/stream_manager.hh"
|
||||
#include "debug.hh"
|
||||
#include "db/schema_tables.hh"
|
||||
#include "db/virtual_tables.hh"
|
||||
#include "service/raft/raft_group0_client.hh"
|
||||
#include "service/raft/raft_group0.hh"
|
||||
#include "sstables/sstables_manager.hh"
|
||||
@@ -744,8 +745,8 @@ private:
|
||||
_ss.invoke_on_all([this] (service::storage_service& ss) {
|
||||
ss.set_query_processor(_qp.local());
|
||||
}).get();
|
||||
_sys_ks.invoke_on_all([this, &cfg] (db::system_keyspace& sys_ks) {
|
||||
return sys_ks.initialize_virtual_tables(_db, _ss, _gossiper, _group0_registry, *cfg);
|
||||
smp::invoke_on_all([&] {
|
||||
return db::initialize_virtual_tables(_db, _ss, _gossiper, _group0_registry, _sys_ks, *cfg);
|
||||
}).get();
|
||||
|
||||
replica::distributed_loader::init_non_system_keyspaces(_db, _proxy, _sys_ks).get();
|
||||
|
||||
Reference in New Issue
Block a user