schema_registry: mark global_schema_ptr move constructor noexcept

Throwing move constructors are a a pain; so we should try to make
them noexcept. Currently, global_schema_ptr's move constructor
throws an exception if used illegaly (moving from a different shard);
this patch changes it to an assert, on the grounds that this error
is impossible to recover from.

The direct motivation for the patch is the desire to store objects
containing a global_schema_ptr in a chunked_vector, to move lists
of partition keys across shards for the topppartitions functionality.
chunked_vector currently requires noexcept move constructors for its
value_type.
This commit is contained in:
Avi Kivity
2019-09-26 16:56:59 +03:00
parent 03260dd910
commit ea4976a128
2 changed files with 3 additions and 5 deletions

View File

@@ -265,11 +265,9 @@ global_schema_ptr::global_schema_ptr(const global_schema_ptr& o)
: global_schema_ptr(o.get())
{ }
global_schema_ptr::global_schema_ptr(global_schema_ptr&& o) {
global_schema_ptr::global_schema_ptr(global_schema_ptr&& o) noexcept {
auto current = engine().cpu_id();
if (o._cpu_of_origin != current) {
throw std::runtime_error("Attempted to move global_schema_ptr across shards");
}
assert(o._cpu_of_origin == current);
_ptr = std::move(o._ptr);
_cpu_of_origin = current;
}

View File

@@ -173,7 +173,7 @@ public:
// The other may come from a different shard.
global_schema_ptr(const global_schema_ptr& other);
// The other must come from current shard.
global_schema_ptr(global_schema_ptr&& other);
global_schema_ptr(global_schema_ptr&& other) noexcept;
// May be invoked across shards. Always returns an engaged pointer.
schema_ptr get() const;
operator schema_ptr() const { return get(); }