Trait pd_client::PdClient[][src]

pub trait PdClient: Send + Sync {
    fn get_cluster_id(&self) -> Result<u64> { ... }
fn bootstrap_cluster(
        &self,
        _stores: Store,
        _region: Region
    ) -> Result<Option<ReplicationStatus>> { ... }
fn is_cluster_bootstrapped(&self) -> Result<bool> { ... }
fn alloc_id(&self) -> Result<u64> { ... }
fn put_store(&self, _store: Store) -> Result<Option<ReplicationStatus>> { ... }
fn get_store(&self, _store_id: u64) -> Result<Store> { ... }
fn get_store_async(&self, _store_id: u64) -> PdFuture<Store> { ... }
fn get_all_stores(&self, _exclude_tombstone: bool) -> Result<Vec<Store>> { ... }
fn get_cluster_config(&self) -> Result<Cluster> { ... }
fn get_region(&self, _key: &[u8]) -> Result<Region> { ... }
fn get_region_async<'k>(
        &'k self,
        _key: &'k [u8]
    ) -> BoxFuture<'k, Result<Region>> { ... }
fn get_region_info(&self, _key: &[u8]) -> Result<RegionInfo> { ... }
fn get_region_info_async<'k>(
        &'k self,
        _key: &'k [u8]
    ) -> BoxFuture<'k, Result<RegionInfo>> { ... }
fn get_region_by_id(&self, _region_id: u64) -> PdFuture<Option<Region>> { ... }
fn get_region_leader_by_id(
        &self,
        _region_id: u64
    ) -> PdFuture<Option<(Region, Peer)>> { ... }
fn region_heartbeat(
        &self,
        _term: u64,
        _region: Region,
        _leader: Peer,
        _region_stat: RegionStat,
        _replication_status: Option<RegionReplicationStatus>
    ) -> PdFuture<()> { ... }
fn handle_region_heartbeat_response<F>(
        &self,
        _store_id: u64,
        _f: F
    ) -> PdFuture<()>
    where
        Self: Sized,
        F: Fn(RegionHeartbeatResponse) + Send + 'static
, { ... }
fn ask_split(&self, _region: Region) -> PdFuture<AskSplitResponse> { ... }
fn ask_batch_split(
        &self,
        _region: Region,
        _count: usize
    ) -> PdFuture<AskBatchSplitResponse> { ... }
fn store_heartbeat(
        &self,
        _stats: StoreStats
    ) -> PdFuture<StoreHeartbeatResponse> { ... }
fn report_batch_split(&self, _regions: Vec<Region>) -> PdFuture<()> { ... }
fn scatter_region(&self, _: RegionInfo) -> Result<()> { ... }
fn handle_reconnect<F: Fn() + Sync + Send + 'static>(&self, _: F)
    where
        Self: Sized
, { ... }
fn get_gc_safe_point(&self) -> PdFuture<u64> { ... }
fn get_store_stats_async(
        &self,
        _store_id: u64
    ) -> BoxFuture<'_, Result<StoreStats>> { ... }
fn get_operator(&self, _region_id: u64) -> Result<GetOperatorResponse> { ... }
fn get_tso(&self) -> PdFuture<TimeStamp> { ... }
fn feature_gate(&self) -> &FeatureGate { ... } }

PdClient communicates with Placement Driver (PD). Because now one PD only supports one cluster, so it is no need to pass cluster id in trait interface every time, so passing the cluster id when creating the PdClient is enough and the PdClient will use this cluster id all the time.

Provided methods

fn get_cluster_id(&self) -> Result<u64>[src]

Returns the cluster ID.

fn bootstrap_cluster(
    &self,
    _stores: Store,
    _region: Region
) -> Result<Option<ReplicationStatus>>
[src]

Creates the cluster with cluster ID, node, stores and first Region. If the cluster is already bootstrapped, return ClusterBootstrapped error. When a node starts, if it finds nothing in the node and cluster is not bootstrapped, it begins to create node, stores, first Region and then call bootstrap_cluster to let PD know it. It may happen that multi nodes start at same time to try to bootstrap, but only one can succeed, while others will fail and must remove their created local Region data themselves.

fn is_cluster_bootstrapped(&self) -> Result<bool>[src]

Returns whether the cluster is bootstrapped or not.

Cluster must be bootstrapped when we use it, so when the node starts, is_cluster_bootstrapped must be called, and panics if cluster was not bootstrapped.

fn alloc_id(&self) -> Result<u64>[src]

Allocates a unique positive id.

fn put_store(&self, _store: Store) -> Result<Option<ReplicationStatus>>[src]

Informs PD when the store starts or some store information changes.

fn get_store(&self, _store_id: u64) -> Result<Store>[src]

We don’t need to support Region and Peer put/delete, because PD knows all Region and Peers itself:

  • For bootstrapping, PD knows first Region with bootstrap_cluster.
  • For changing Peer, PD determines where to add a new Peer in some store for this Region.
  • For Region splitting, PD determines the new Region id and Peer id for the split Region.
  • For Region merging, PD knows which two Regions will be merged and which Region and Peers will be removed.
  • For auto-balance, PD determines how to move the Region from one store to another. Gets store information if it is not a tombstone store.

fn get_store_async(&self, _store_id: u64) -> PdFuture<Store>[src]

Gets store information if it is not a tombstone store asynchronously

fn get_all_stores(&self, _exclude_tombstone: bool) -> Result<Vec<Store>>[src]

Gets all stores information.

fn get_cluster_config(&self) -> Result<Cluster>[src]

Gets cluster meta information.

fn get_region(&self, _key: &[u8]) -> Result<Region>[src]

For route. Gets Region which the key belongs to.

fn get_region_async<'k>(
    &'k self,
    _key: &'k [u8]
) -> BoxFuture<'k, Result<Region>>
[src]

Gets Region which the key belongs to asynchronously.

fn get_region_info(&self, _key: &[u8]) -> Result<RegionInfo>[src]

Gets Region info which the key belongs to.

fn get_region_info_async<'k>(
    &'k self,
    _key: &'k [u8]
) -> BoxFuture<'k, Result<RegionInfo>>
[src]

Gets Region info which the key belongs to asynchronously.

fn get_region_by_id(&self, _region_id: u64) -> PdFuture<Option<Region>>[src]

Gets Region by Region id.

fn get_region_leader_by_id(
    &self,
    _region_id: u64
) -> PdFuture<Option<(Region, Peer)>>
[src]

Gets Region and its leader by Region id.

fn region_heartbeat(
    &self,
    _term: u64,
    _region: Region,
    _leader: Peer,
    _region_stat: RegionStat,
    _replication_status: Option<RegionReplicationStatus>
) -> PdFuture<()>
[src]

Region’s Leader uses this to heartbeat PD.

fn handle_region_heartbeat_response<F>(
    &self,
    _store_id: u64,
    _f: F
) -> PdFuture<()> where
    Self: Sized,
    F: Fn(RegionHeartbeatResponse) + Send + 'static, 
[src]

Gets a stream of Region heartbeat response.

Please note that this method should only be called once.

fn ask_split(&self, _region: Region) -> PdFuture<AskSplitResponse>[src]

Asks PD for split. PD returns the newly split Region id.

fn ask_batch_split(
    &self,
    _region: Region,
    _count: usize
) -> PdFuture<AskBatchSplitResponse>
[src]

Asks PD for batch split. PD returns the newly split Region ids.

fn store_heartbeat(
    &self,
    _stats: StoreStats
) -> PdFuture<StoreHeartbeatResponse>
[src]

Sends store statistics regularly.

fn report_batch_split(&self, _regions: Vec<Region>) -> PdFuture<()>[src]

Reports PD the split Region.

fn scatter_region(&self, _: RegionInfo) -> Result<()>[src]

Scatters the Region across the cluster.

fn handle_reconnect<F: Fn() + Sync + Send + 'static>(&self, _: F) where
    Self: Sized
[src]

Registers a handler to the client, which will be invoked after reconnecting to PD.

Please note that this method should only be called once.

fn get_gc_safe_point(&self) -> PdFuture<u64>[src]

fn get_store_stats_async(
    &self,
    _store_id: u64
) -> BoxFuture<'_, Result<StoreStats>>
[src]

Gets store state if it is not a tombstone store asynchronously.

fn get_operator(&self, _region_id: u64) -> Result<GetOperatorResponse>[src]

Gets current operator of the region

fn get_tso(&self) -> PdFuture<TimeStamp>[src]

Gets a timestamp from PD.

fn feature_gate(&self) -> &FeatureGate[src]

Gets the internal FeatureGate.

Loading content...

Implementors

impl PdClient for DummyPdClient[src]

impl PdClient for RpcClient[src]

Loading content...