flare_dht/metadata/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#[cfg(all(feature = "raft", feature = "rkyv"))]
pub mod raft;

use crate::error::FlareError;
use crate::proto::{
    ClusterMetadata, CreateCollectionRequest, CreateCollectionResponse,
    JoinRequest, JoinResponse,
};
use crate::shard::ShardMetadata;
use crate::NodeId;
use std::u32;

#[async_trait::async_trait]
pub trait MetadataManager: Send + Sync {
    async fn initialize(&mut self) -> Result<(), FlareError>;
    async fn get_shard_ids(
        &self,
        col_name: &str,
    ) -> Option<Vec<ShardGroupState>>;
    async fn get_shard_id(
        &self,
        col_name: &str,
        key: &[u8],
    ) -> Option<ShardGroupState>;
    async fn leave(&self);
    async fn other_leave(&self, node_id: NodeId) -> Result<(), FlareError>;
    async fn other_join(
        &self,
        join_request: JoinRequest,
    ) -> Result<JoinResponse, FlareError>;
    async fn get_metadata(&self) -> Result<ClusterMetadata, FlareError>;

    async fn local_shards(&self) -> Vec<ShardMetadata>;
    async fn create_collection(
        &self,
        mut request: CreateCollectionRequest,
    ) -> Result<CreateCollectionResponse, FlareError>;

    fn create_watch(&self) -> tokio::sync::watch::Receiver<u64>;
}

#[cfg_attr(
    feature = "rkyv",
    derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
    rkyv(compare(PartialEq), derive(Debug))
)]
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone)]
pub struct CollectionMetadataState {
    pub name: String,
    pub shards: Vec<ShardGroupState>,
    pub seed: u32,
    pub replication: u8,
}

#[cfg_attr(
    feature = "rkyv",
    derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
    rkyv(compare(PartialEq), derive(Debug))
)]
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone)]
pub struct ShardGroupState {
    pub shard_ids: Vec<u64>,
}