Skip to main content

CoordinatorService

Trait CoordinatorService 

Source
pub trait CoordinatorService: Sized {
    // Required methods
    async fn register(
        self,
        context: Context,
        info: ShardInfo,
    ) -> RpcResult<ShardId>;
    async fn unregister(
        self,
        context: Context,
        shard_id: ShardId,
    ) -> RpcResult<()>;
    async fn phase_complete(
        self,
        context: Context,
        shard_id: ShardId,
        phase: TickPhase,
        tick: u64,
    ) -> RpcResult<()>;
    async fn route_document(
        self,
        context: Context,
        doc_id: DocumentId,
    ) -> ShardId;
    async fn route_node(self, context: Context, node_id: NodeId) -> ShardId;
    async fn get_global_df(
        self,
        context: Context,
        terms: Vec<String>,
    ) -> RpcResult<HashMap<String, u64>>;
    async fn barrier_ready(
        self,
        context: Context,
        shard_id: ShardId,
        phase: TickPhase,
        tick: u64,
    ) -> RpcResult<bool>;
    async fn current_tick(self, context: Context) -> u64;
    async fn list_shards(self, context: Context) -> Vec<ShardInfo>;
    async fn start_tick(self, context: Context) -> RpcResult<u64>;
    async fn tick_status(self, context: Context) -> RpcResult<TickStatus>;

    // Provided method
    fn serve(self) -> ServeCoordinatorService<Self> { ... }
}
Expand description

Service provided by the coordinator.

The coordinator manages shard registration, tick synchronization, query distribution, and global state aggregation.

Required Methods§

Source

async fn register(self, context: Context, info: ShardInfo) -> RpcResult<ShardId>

Register a new shard with the coordinator.

Returns the assigned shard ID. The coordinator will include this shard in subsequent tick coordination.

Source

async fn unregister(self, context: Context, shard_id: ShardId) -> RpcResult<()>

Unregister a shard from the coordinator.

Should be called during graceful shutdown. The coordinator will stop routing requests to this shard.

Source

async fn phase_complete( self, context: Context, shard_id: ShardId, phase: TickPhase, tick: u64, ) -> RpcResult<()>

Report that a shard has completed a tick phase.

Used for barrier synchronization. The coordinator tracks completion across all shards before advancing to the next phase.

Source

async fn route_document(self, context: Context, doc_id: DocumentId) -> ShardId

Get the shard responsible for a document.

Uses consistent hashing to determine which shard owns a document.

Source

async fn route_node(self, context: Context, node_id: NodeId) -> ShardId

Get the shard responsible for a node.

Uses consistent hashing based on node ID.

Source

async fn get_global_df( self, context: Context, terms: Vec<String>, ) -> RpcResult<HashMap<String, u64>>

Get global document frequencies for TF-IDF.

Returns aggregated term frequencies across all shards.

Source

async fn barrier_ready( self, context: Context, shard_id: ShardId, phase: TickPhase, tick: u64, ) -> RpcResult<bool>

Signal ready for next phase (barrier).

Returns true when all shards are ready and the phase can proceed.

Source

async fn current_tick(self, context: Context) -> u64

Get current tick number.

Returns the global tick counter maintained by the coordinator.

Source

async fn list_shards(self, context: Context) -> Vec<ShardInfo>

Get all registered shards.

Returns information about all shards in the cluster.

Source

async fn start_tick(self, context: Context) -> RpcResult<u64>

Request to start a new tick.

Only succeeds if no tick is currently in progress.

Source

async fn tick_status(self, context: Context) -> RpcResult<TickStatus>

Get the status of the current tick.

Returns the current phase and which shards have completed it.

Provided Methods§

Source

fn serve(self) -> ServeCoordinatorService<Self>

Returns a serving function to use with InFlightRequest::execute.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§