Skip to main content

ServerBuilder

Struct ServerBuilder 

Source
pub struct ServerBuilder { /* private fields */ }
Expand description

Fluent builder for Server.

Every YAML-visible field on ConfPool has a setter on ServerBuilder; in addition, hook setters accept boxed trait objects to plug custom implementations.

§Examples

use dynomite::embed::ServerBuilder;
use dynomite::conf::DataStore;
let server = ServerBuilder::new("dyn_o_mite")
    .listen("127.0.0.1:18102".parse().unwrap())
    .dyn_listen("127.0.0.1:18101".parse().unwrap())
    .data_store(DataStore::Redis)
    .servers(vec![dynomite::conf::ConfServer::parse("127.0.0.1:6379:1").unwrap()])
    .tokens_str("0")
    .build()
    .unwrap();
drop(server);

Implementations§

Source§

impl ServerBuilder

Source

pub fn new(pool_name: impl Into<String>) -> Self

Build an empty ServerBuilder for a pool named pool_name.

§Examples
use dynomite::embed::ServerBuilder;
let b = ServerBuilder::new("dyn_o_mite");
assert_eq!(b.pool_name(), "dyn_o_mite");
Source

pub fn from_config(cfg: &Config) -> Self

Build from an existing parsed Config.

§Examples
use dynomite::conf::Config;
use dynomite::embed::ServerBuilder;
let yaml = "p:\n  listen: 127.0.0.1:1\n  dyn_listen: 127.0.0.1:2\n  tokens: '1'\n  servers:\n  - 127.0.0.1:3:1\n  data_store: 0\n";
let cfg = Config::parse_str(yaml).unwrap();
let b = ServerBuilder::from_config(&cfg);
assert_eq!(b.pool_name(), "p");
Source

pub fn from_yaml_file(path: impl AsRef<Path>) -> Result<Self, EmbedError>

Build by parsing a YAML file.

§Examples
use std::io::Write;
use dynomite::embed::ServerBuilder;
let mut f = tempfile::NamedTempFile::new().unwrap();
writeln!(f, "p:\n  listen: 127.0.0.1:1\n  dyn_listen: 127.0.0.1:2\n  tokens: '1'\n  servers:\n  - 127.0.0.1:3:1\n  data_store: 0").unwrap();
let b = ServerBuilder::from_yaml_file(f.path()).unwrap();
assert_eq!(b.pool_name(), "p");
Source

pub fn pool_name(&self) -> &str

Currently-configured pool name.

Source

pub fn with_pool_name(self, name: impl Into<String>) -> Self

Override the pool name supplied to Self::new.

The C reference accepts only one pool per Config, so the pool name is part of the constructor for ergonomics. This setter exists so callers that build a ServerBuilder from a default-named template ("dyn_o_mite") can rename the pool without rebuilding the chain. Recorded as Deviation in docs/parity.md (the design page sketches a no-arg Server::builder()).

Source

pub fn listen(self, addr: SocketAddr) -> Self

listen: - client-facing listener address.

Accepts port 0 (kernel-assigned ephemeral port). The post-bind address is reported via ServerHandle::listen_addr.

Source

pub fn dyn_listen(self, addr: SocketAddr) -> Self

dyn_listen: - peer-facing listener address.

Accepts port 0 (kernel-assigned ephemeral port). The post-bind address is reported via ServerHandle::dyn_listen_addr.

Source

pub fn stats_listen(self, addr: SocketAddr) -> Self

stats_listen: - HTTP stats listener address.

Accepts port 0 for ephemeral-port semantics. Note that the embedded server does not currently bind the stats listener; the dynomited binary does. Embedders that want a Prometheus-style scrape endpoint should plug a MetricsSink implementation instead.

Source

pub fn hash(self, h: HashType) -> Self

hash: - hash algorithm.

Source

pub fn data_store(self, d: DataStore) -> Self

data_store: - protocol selector.

Source

pub fn read_consistency(self, c: ConsistencyLevel) -> Self

read_consistency: - quorum policy for reads.

Source

pub fn write_consistency(self, c: ConsistencyLevel) -> Self

write_consistency: - quorum policy for writes.

Source

pub fn secure_server_option(self, opt: SecureServerOption) -> Self

secure_server_option: - inter-node TLS mode.

Source

pub fn pem_key_file(self, path: impl AsRef<Path>) -> Self

pem_key_file: - path to the PEM private key.

Source

pub fn servers(self, servers: Vec<ConfServer>) -> Self

servers: - the (single-element) datastore list.

Source

pub fn dyn_seeds(self, seeds: Vec<ConfDynSeed>) -> Self

dyn_seeds: - peer dynomite nodes.

Source

pub fn dyn_seed_provider(self, name: impl Into<String>) -> Self

dyn_seed_provider: - seeds backend selector.

Source

pub fn timeout(self, d: Duration) -> Self

timeout: - request timeout.

Source

pub fn auto_eject_hosts(self, on: bool) -> Self

auto_eject_hosts: - automatically eject failing peers.

Source

pub fn server_failure_limit(self, n: u32) -> Self

server_failure_limit: - consecutive failures before eject.

Source

pub fn server_retry_timeout(self, d: Duration) -> Self

server_retry_timeout: - retry interval for ejected servers.

Source

pub fn gossip_interval(self, d: Duration) -> Self

gos_interval: - gossip period.

Source

pub fn enable_gossip(self, on: bool) -> Self

enable_gossip: - turn the gossip task on or off.

Source

pub fn datacenter(self, dc: impl Into<String>) -> Self

datacenter: - this node’s datacenter.

Source

pub fn rack(self, rack: impl Into<String>) -> Self

rack: - this node’s rack.

Source

pub fn tokens_str(self, raw: impl AsRef<str>) -> Self

tokens: - this node’s tokens, parsed from the YAML representation.

Returns the builder unchanged when the tokens string fails to parse so callers can chain. Parse failures emit a tracing::warn! event so a typo in the token string is observable in logs even though it does not break the chain. Use ServerBuilder::tokens to set a pre-parsed TokenList when you want a hard error on bad input.

The silent-ignore-with-log behaviour is recorded as a SemVer-major candidate in docs/parity.md; v0.2 may switch to a Result-returning variant.

Source

pub fn tokens(self, tokens: TokenList) -> Self

tokens: - this node’s tokens.

Source

pub fn mbuf_size(self, n: usize) -> Self

mbuf_size: - mbuf chunk size in bytes.

Source

pub fn max_msgs(self, n: usize) -> Self

max_msgs: - maximum allocated messages.

Source

pub fn read_repairs_enabled(self, on: bool) -> Self

read_repairs_enabled: - enable read-repair on quorum mismatch.

Source

pub fn client_connections(self, n: u32) -> Self

client_connections: - client connection cap.

Source

pub fn datastore_connections(self, n: u8) -> Self

datastore_connections: - count of datastore-side connections.

Source

pub fn local_peer_connections(self, n: u8) -> Self

local_peer_connections: - count of local-DC peer connections.

Source

pub fn remote_peer_connections(self, n: u8) -> Self

remote_peer_connections: - count of remote-DC peer connections.

Source

pub fn preconnect(self, on: bool) -> Self

preconnect: - eagerly establish connections at startup.

Source

pub fn stats_interval(self, d: Duration) -> Self

stats_interval: - stats aggregation period.

Source

pub fn datastore(self, ds: Box<dyn Datastore>) -> Self

Plug a custom Datastore.

Source

pub fn seeds_provider(self, sp: Box<dyn SeedsProvider>) -> Self

Plug a custom SeedsProvider.

Source

pub fn crypto_provider(self, cp: Box<dyn CryptoProvider>) -> Self

Plug a custom CryptoProvider.

Source

pub fn metrics_sink(self, ms: Box<dyn MetricsSink>) -> Self

Plug a custom MetricsSink.

Source

pub fn with_command_extension(self, ext: Arc<dyn CommandExtension>) -> Self

Plug a crate::embed::CommandExtension.

The extension is consulted by the dispatcher in the hot path: parsed FT.* requests and HSET requests are offered to it before the routing planner runs. The trait is part of the engine; the standard RediSearch implementation lives in the dynomite-search crate. Without this setter the dispatcher’s behaviour is unchanged from the substrate’s stock behaviour.

§Examples
use std::sync::Arc;
use dynomite::embed::{CommandExtension, HsetOutcome, ServerBuilder};
use dynomite::msg::MsgType;
#[derive(Debug)]
struct NoOp;
impl CommandExtension for NoOp {
    fn handles_msg_type(&self, _: MsgType) -> bool { false }
    fn try_dispatch(&self, _: &[&[u8]]) -> Option<Vec<u8>> { None }
}
let _b = ServerBuilder::new("p").with_command_extension(Arc::new(NoOp));
Source

pub fn set_command_extension( &mut self, ext: Arc<dyn CommandExtension>, ) -> &mut Self

Mutating equivalent of Self::with_command_extension for callers (notably dynomite-search::install) that want to attach an extension to a builder they hold by &mut.

Source

pub fn command_extension(&self) -> Option<&Arc<dyn CommandExtension>>

Borrow the configured crate::embed::CommandExtension, if one was supplied.

Source

pub fn build(self) -> Result<Server, EmbedError>

Build the Server.

Applies defaults to any unset field, runs the validation pass, fills in any missing hooks with their in-crate defaults, and constructs the runtime data structures (cluster pool, dispatcher, stats, event bus). The returned Server is not running yet; call Server::start to spawn background tasks.

Trait Implementations§

Source§

impl Debug for ServerBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerBuilder

Source§

fn default() -> Self

Build a ServerBuilder for the canonical pool name "dyn_o_mite". Mirrors the design page’s sketch of a no-arg Server::builder() while keeping the typed constructor (new(pool_name)) for ergonomics; the C reference accepts only one pool per Config.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,