distributed<> has the connotation of being distributed across the network.
Sharded is more in line with seastar terms.
Keep the distributed<> name and header file as an alias, for
compatibility.
Otherwise tester may crash if _instances destructor is called when thread
responsible for the allocation (which tester spawned to run seastar in)
no longer running.
Sometimes remote data has to be copied to local cpu, but if data is
already local copy can be avoided. Introduce helper function that moves
or copies data depending on origin cpu.
Separating the initial value (and accumulator) from the reducer function
can result in simpler invocations.
Unfortunately, the name conflicts with another variant, so we have to name
the method map_reduce0.
distributed::stop() passes the pointer to the instance being destroyed
by reference, in an attempt to keep things clean (by nulling the pointer
after deleting it). This is illegal, however, since the lambda is moved
in the bowels of submit_to(). In release mode this is optimized away so
the code works, but in debug mode it leads to a crash.
Fix by capturing by value instead (could also have been fixed by switching
the enclosing capture to a reference).
Credit to Gleb for identifying the problem.
Makes invoking non-copyable lambdas possible:
distributed<T> t;
non_copyable_type x;
t.invoke_on(0, [x = std::move(x)] (auto& t) {});
As a side effect this could save some copyable lambdas from being
needlesly copied.
Current variants of distributed<T>::invoke_on() require member function to
invoke, which may be tedious to implement for some cases. Add a variant
that supports invoking a functor, accepting the local instance by reference.