meta_srv/
flow_meta_alloc.rs1use std::collections::HashSet;
16
17use common_error::ext::BoxedError;
18use common_meta::ddl::flow_meta::PartitionPeerAllocator;
19use common_meta::peer::Peer;
20use snafu::ResultExt;
21
22use crate::metasrv::{SelectorContext, SelectorRef};
23use crate::selector::SelectorOptions;
24
25pub struct FlowPeerAllocator {
26 ctx: SelectorContext,
27 selector: SelectorRef,
28}
29
30impl FlowPeerAllocator {
31 pub fn new(ctx: SelectorContext, selector: SelectorRef) -> Self {
32 Self { ctx, selector }
33 }
34}
35
36#[async_trait::async_trait]
37impl PartitionPeerAllocator for FlowPeerAllocator {
38 async fn alloc(&self, partitions: usize) -> common_meta::error::Result<Vec<Peer>> {
39 self.selector
40 .select(
41 &self.ctx,
42 SelectorOptions {
43 min_required_items: partitions,
44 allow_duplication: true,
45 exclude_peer_ids: HashSet::new(),
46 },
47 )
48 .await
49 .map_err(BoxedError::new)
50 .context(common_meta::error::ExternalSnafu)
51 }
52}