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
impl ServerBuilder
Sourcepub fn new(pool_name: impl Into<String>) -> Self
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");Sourcepub fn from_config(cfg: &Config) -> Self
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");Sourcepub fn from_yaml_file(path: impl AsRef<Path>) -> Result<Self, EmbedError>
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");Sourcepub fn with_pool_name(self, name: impl Into<String>) -> Self
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()).
Sourcepub fn listen(self, addr: SocketAddr) -> Self
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.
Sourcepub fn dyn_listen(self, addr: SocketAddr) -> Self
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.
Sourcepub fn stats_listen(self, addr: SocketAddr) -> Self
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.
Sourcepub fn data_store(self, d: DataStore) -> Self
pub fn data_store(self, d: DataStore) -> Self
data_store: - protocol selector.
Sourcepub fn read_consistency(self, c: ConsistencyLevel) -> Self
pub fn read_consistency(self, c: ConsistencyLevel) -> Self
read_consistency: - quorum policy for reads.
Sourcepub fn write_consistency(self, c: ConsistencyLevel) -> Self
pub fn write_consistency(self, c: ConsistencyLevel) -> Self
write_consistency: - quorum policy for writes.
Sourcepub fn secure_server_option(self, opt: SecureServerOption) -> Self
pub fn secure_server_option(self, opt: SecureServerOption) -> Self
secure_server_option: - inter-node TLS mode.
Sourcepub fn pem_key_file(self, path: impl AsRef<Path>) -> Self
pub fn pem_key_file(self, path: impl AsRef<Path>) -> Self
pem_key_file: - path to the PEM private key.
Sourcepub fn servers(self, servers: Vec<ConfServer>) -> Self
pub fn servers(self, servers: Vec<ConfServer>) -> Self
servers: - the (single-element) datastore list.
Sourcepub fn dyn_seeds(self, seeds: Vec<ConfDynSeed>) -> Self
pub fn dyn_seeds(self, seeds: Vec<ConfDynSeed>) -> Self
dyn_seeds: - peer dynomite nodes.
Sourcepub fn dyn_seed_provider(self, name: impl Into<String>) -> Self
pub fn dyn_seed_provider(self, name: impl Into<String>) -> Self
dyn_seed_provider: - seeds backend selector.
Sourcepub fn auto_eject_hosts(self, on: bool) -> Self
pub fn auto_eject_hosts(self, on: bool) -> Self
auto_eject_hosts: - automatically eject failing peers.
Sourcepub fn server_failure_limit(self, n: u32) -> Self
pub fn server_failure_limit(self, n: u32) -> Self
server_failure_limit: - consecutive failures before eject.
Sourcepub fn server_retry_timeout(self, d: Duration) -> Self
pub fn server_retry_timeout(self, d: Duration) -> Self
server_retry_timeout: - retry interval for ejected servers.
Sourcepub fn gossip_interval(self, d: Duration) -> Self
pub fn gossip_interval(self, d: Duration) -> Self
gos_interval: - gossip period.
Sourcepub fn enable_gossip(self, on: bool) -> Self
pub fn enable_gossip(self, on: bool) -> Self
enable_gossip: - turn the gossip task on or off.
Sourcepub fn datacenter(self, dc: impl Into<String>) -> Self
pub fn datacenter(self, dc: impl Into<String>) -> Self
datacenter: - this node’s datacenter.
Sourcepub fn tokens_str(self, raw: impl AsRef<str>) -> Self
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.
Sourcepub fn read_repairs_enabled(self, on: bool) -> Self
pub fn read_repairs_enabled(self, on: bool) -> Self
read_repairs_enabled: - enable read-repair on quorum
mismatch.
Sourcepub fn client_connections(self, n: u32) -> Self
pub fn client_connections(self, n: u32) -> Self
client_connections: - client connection cap.
Sourcepub fn datastore_connections(self, n: u8) -> Self
pub fn datastore_connections(self, n: u8) -> Self
datastore_connections: - count of datastore-side
connections.
Sourcepub fn local_peer_connections(self, n: u8) -> Self
pub fn local_peer_connections(self, n: u8) -> Self
local_peer_connections: - count of local-DC peer
connections.
Sourcepub fn remote_peer_connections(self, n: u8) -> Self
pub fn remote_peer_connections(self, n: u8) -> Self
remote_peer_connections: - count of remote-DC peer
connections.
Sourcepub fn preconnect(self, on: bool) -> Self
pub fn preconnect(self, on: bool) -> Self
preconnect: - eagerly establish connections at startup.
Sourcepub fn stats_interval(self, d: Duration) -> Self
pub fn stats_interval(self, d: Duration) -> Self
stats_interval: - stats aggregation period.
Sourcepub fn seeds_provider(self, sp: Box<dyn SeedsProvider>) -> Self
pub fn seeds_provider(self, sp: Box<dyn SeedsProvider>) -> Self
Plug a custom SeedsProvider.
Sourcepub fn crypto_provider(self, cp: Box<dyn CryptoProvider>) -> Self
pub fn crypto_provider(self, cp: Box<dyn CryptoProvider>) -> Self
Plug a custom CryptoProvider.
Sourcepub fn metrics_sink(self, ms: Box<dyn MetricsSink>) -> Self
pub fn metrics_sink(self, ms: Box<dyn MetricsSink>) -> Self
Plug a custom MetricsSink.
Sourcepub fn with_command_extension(self, ext: Arc<dyn CommandExtension>) -> Self
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));Sourcepub fn set_command_extension(
&mut self,
ext: Arc<dyn CommandExtension>,
) -> &mut Self
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.
Sourcepub fn command_extension(&self) -> Option<&Arc<dyn CommandExtension>>
pub fn command_extension(&self) -> Option<&Arc<dyn CommandExtension>>
Borrow the configured crate::embed::CommandExtension,
if one was supplied.
Sourcepub fn build(self) -> Result<Server, EmbedError>
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.