database: Implement update_keyspace
Reloads keyspace metadata and replaces in existing keyspace. Note: since keyspace metadata, and consequently, replication strategy now becomes volatile, keyspace::metadata now returns shared pointer by value (i.e. keep-alive). Replication strategy should receive the same treatment, but since it is extensively used, but never kept across a continuation, I've just added a comment for now.
This commit is contained in:
18
database.cc
18
database.cc
@@ -1473,8 +1473,17 @@ void database::add_keyspace(sstring name, keyspace k) {
|
||||
_keyspaces.emplace(std::move(name), std::move(k));
|
||||
}
|
||||
|
||||
void database::update_keyspace(const sstring& name) {
|
||||
throw std::runtime_error("update keyspace not implemented");
|
||||
future<> database::update_keyspace(const sstring& name) {
|
||||
auto& proxy = service::get_storage_proxy();
|
||||
return db::schema_tables::read_schema_partition_for_keyspace(proxy, db::schema_tables::KEYSPACES, name).then([this, name](db::schema_tables::schema_result_value_type&& v) {
|
||||
auto& ks = find_keyspace(name);
|
||||
|
||||
auto tmp_ksm = db::schema_tables::create_keyspace_from_schema_partition(v);
|
||||
auto new_ksm = ::make_lw_shared<keyspace_metadata>(tmp_ksm->name(), tmp_ksm->strategy_name(), tmp_ksm->strategy_options(), tmp_ksm->durable_writes(),
|
||||
boost::copy_range<std::vector<schema_ptr>>(ks.metadata()->cf_meta_data() | boost::adaptors::map_values), ks.metadata()->user_types());
|
||||
ks.update_from(std::move(new_ksm));
|
||||
return service::get_local_migration_manager().notify_update_keyspace(ks.metadata());
|
||||
});
|
||||
}
|
||||
|
||||
void database::drop_keyspace(const sstring& name) {
|
||||
@@ -1628,6 +1637,11 @@ keyspace::set_replication_strategy(std::unique_ptr<locator::abstract_replication
|
||||
_replication_strategy = std::move(replication_strategy);
|
||||
}
|
||||
|
||||
void keyspace::update_from(::lw_shared_ptr<keyspace_metadata> ksm) {
|
||||
_metadata = std::move(ksm);
|
||||
create_replication_strategy(_metadata->strategy_options());
|
||||
}
|
||||
|
||||
column_family::config
|
||||
keyspace::make_column_family_config(const schema& s) const {
|
||||
column_family::config cfg;
|
||||
|
||||
18
database.hh
18
database.hh
@@ -734,10 +734,24 @@ public:
|
||||
: _metadata(std::move(metadata))
|
||||
, _config(std::move(cfg))
|
||||
{}
|
||||
const lw_shared_ptr<keyspace_metadata>& metadata() const {
|
||||
|
||||
void update_from(lw_shared_ptr<keyspace_metadata>);
|
||||
|
||||
/** Note: return by shared pointer value, since the meta data is
|
||||
* semi-volatile. I.e. we could do alter keyspace at any time, and
|
||||
* boom, it is replaced.
|
||||
*/
|
||||
lw_shared_ptr<keyspace_metadata> metadata() const {
|
||||
return _metadata;
|
||||
}
|
||||
void create_replication_strategy(const std::map<sstring, sstring>& options);
|
||||
/**
|
||||
* This should not really be return by reference, since replication
|
||||
* strategy is also volatile in that it could be replaced at "any" time.
|
||||
* However, all current uses at least are "instantateous", i.e. does not
|
||||
* carry it across a continuation. So it is sort of same for now, but
|
||||
* should eventually be refactored.
|
||||
*/
|
||||
locator::abstract_replication_strategy& get_replication_strategy();
|
||||
const locator::abstract_replication_strategy& get_replication_strategy() const;
|
||||
column_family::config make_column_family_config(const schema& s) const;
|
||||
@@ -872,7 +886,7 @@ public:
|
||||
keyspace& find_keyspace(const sstring& name);
|
||||
const keyspace& find_keyspace(const sstring& name) const;
|
||||
bool has_keyspace(const sstring& name) const;
|
||||
void update_keyspace(const sstring& name);
|
||||
future<> update_keyspace(const sstring& name);
|
||||
void drop_keyspace(const sstring& name);
|
||||
const auto& keyspaces() const { return _keyspaces; }
|
||||
std::vector<sstring> get_non_system_keyspaces() const;
|
||||
|
||||
Reference in New Issue
Block a user