schema: provide method to get sharder, iff it is static
The current get_sharder() method only allows getting a static sharder (since a dynamic sharder needs additional protection). However, it chooses to abort if someone attempt to get a dynamic sharder. In one case, it's useful to get a sharder only if it's static, so provide a method to do that. This is for providing sstable sharding metadata, which isn't useful with tablets.
This commit is contained in:
@@ -151,13 +151,22 @@ const dht::i_partitioner& schema::get_partitioner() const {
|
||||
return _raw._partitioner.get();
|
||||
}
|
||||
|
||||
const dht::sharder& schema::get_sharder() const {
|
||||
const dht::sharder* schema::try_get_static_sharder() const {
|
||||
auto t = maybe_table();
|
||||
if (t && !t->uses_static_sharding()) {
|
||||
// Use table()->get_effective_replication_map()->get_sharder() instead.
|
||||
return nullptr;
|
||||
}
|
||||
return &_raw._sharder.get();
|
||||
}
|
||||
|
||||
const dht::sharder& schema::get_sharder() const {
|
||||
auto* s = try_get_static_sharder();
|
||||
if (!s) {
|
||||
// Use table()->get_effective_replication_map()->get_sharder() instead.
|
||||
on_internal_error(dblog, format("Attempted to obtain static sharder for table {}.{}", ks_name(), cf_name()));
|
||||
}
|
||||
return _raw._sharder.get();
|
||||
return *s;
|
||||
}
|
||||
|
||||
replica::table* schema::maybe_table() const {
|
||||
|
||||
@@ -821,6 +821,10 @@ public:
|
||||
// To obtain a sharder which is valid for all kinds of tables, use table::get_effective_replication_map()->get_sharder()
|
||||
const dht::sharder& get_sharder() const;
|
||||
|
||||
// Returns a sharder for this table, but only if it is a static sharder (token->shard mappings
|
||||
// don't change while the node is up)
|
||||
const dht::sharder* try_get_static_sharder() const;
|
||||
|
||||
// Returns a pointer to the table if the local database has a table which this object references by id().
|
||||
// The table pointer is not guaranteed to be stable, schema_ptr doesn't keep the table alive.
|
||||
replica::table* maybe_table() const;
|
||||
|
||||
Reference in New Issue
Block a user