template<typename Service>
class seastar::sharded< Service >
Template helper to distribute a service across all logical cores.
The sharded
template manages a sharded service, by creating a copy of the service on each logical core, providing mechanisms to communicate with each shard's copy, and a way to stop the service.
- Template Parameters
-
Service | a class to be instantiated on each core. Must expose a stop() method that returns a future<> , to be called when the service is stopped. |
- Examples
- sharded_parameter_demo.cc.
|
| sharded () noexcept |
|
| sharded (const sharded &other)=delete |
|
sharded & | operator= (const sharded &other)=delete |
|
| sharded (sharded &&other)=delete |
|
sharded & | operator= (sharded &&other)=delete |
|
| ~sharded () |
| Destroyes a sharded object. Must not be in a started state.
|
|
template<typename... Args> |
future | start (Args &&... args) noexcept |
|
template<typename... Args> |
future | start_single (Args &&... args) noexcept |
|
future | stop () noexcept |
|
future | invoke_on_all (smp_submit_to_options options, std::function< future<>(Service &)> func) noexcept |
|
future | invoke_on_all (std::function< future<>(Service &)> func) noexcept |
|
template<typename Func , typename... Args> |
future | invoke_on_all (smp_submit_to_options options, Func func, Args... args) noexcept |
|
template<typename Func , typename... Args> |
future | invoke_on_all (Func func, Args... args) noexcept |
|
template<typename Func , typename... Args> |
future | invoke_on_others (smp_submit_to_options options, Func func, Args... args) noexcept |
|
template<typename Func , typename... Args> |
future | invoke_on_others (Func func, Args... args) noexcept |
|
template<typename Reducer , typename Func , typename... Args> |
auto | map_reduce (Reducer &&r, Func &&func, Args &&... args) -> typename reducer_traits< Reducer >::future_type |
|
template<typename Reducer , typename Func , typename... Args> |
auto | map_reduce (Reducer &&r, Func &&func, Args &&... args) const -> typename reducer_traits< Reducer >::future_type |
| The const version of map_reduce(Reducer&& r, Func&& func)
|
|
template<typename Mapper , typename Initial , typename Reduce > |
future< Initial > | map_reduce0 (Mapper map, Initial initial, Reduce reduce) |
|
template<typename Mapper , typename Initial , typename Reduce > |
future< Initial > | map_reduce0 (Mapper map, Initial initial, Reduce reduce) const |
| The const version of map_reduce0(Mapper map, Initial initial, Reduce reduce)
|
|
template<typename Mapper , typename Future = futurize_t<std::invoke_result_t<Mapper,Service&>>, typename return_type = decltype(internal::untuple(std::declval<typename Future::tuple_type>()))> |
future< std::vector< return_type > > | map (Mapper mapper) |
|
template<typename Func , typename... Args, typename Ret = futurize_t<std::invoke_result_t<Func, Service&, Args...>>> |
Ret | invoke_on (unsigned id, smp_submit_to_options options, Func &&func, Args &&... args) |
|
template<typename Func , typename... Args, typename Ret = futurize_t<std::invoke_result_t<Func, Service&, Args&&...>>> |
Ret | invoke_on (unsigned id, Func &&func, Args &&... args) |
|
const Service & | local () const noexcept |
| Gets a reference to the local instance.
|
|
Service & | local () noexcept |
| Gets a reference to the local instance.
|
|
shared_ptr< Service > | local_shared () noexcept |
| Gets a shared pointer to the local instance.
|
|
bool | local_is_initialized () const noexcept |
| Checks whether the local instance has been initialized.
|
|
template<typename Service >
template<typename Func , typename... Args>
Invoke a function on all instances of Service
. The return value becomes ready when all instances have processed the message. The function can be a member pointer to function, a free function, or a functor. The first argument of the function will be a reference to the local service on the shard.
For a non-static pointer-to-member-function, the first argument becomes this
, not the first declared parameter.
- Parameters
-
options | the options to forward to the smp::submit_to() called behind the scenes. |
func | invocable accepting a Service& as the first parameter to be invoked on all shards |
- Returns
- Future that becomes ready once all calls have completed
template<typename Service >
template<typename Mapper , typename Future = futurize_t<std::invoke_result_t<Mapper,Service&>>, typename return_type = decltype(internal::untuple(std::declval<typename Future::tuple_type>()))>
Applies a map function to all shards, and return a vector of the result.
- Parameters
-
mapper | callable with the signature Value (Service&) or future<Value> (Service&) (for some Value type). |
Each map
invocation runs on the shard associated with the service.
- Template Parameters
-
Mapper | unary function taking Service& and producing some result. |
- Returns
- Result vector of invoking
map
with each instance in parallel