mz_cluster_client/
client.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Types for commands to clusters.
11
12use std::str::FromStr;
13
14use serde::{Deserialize, Serialize};
15use uuid::Uuid;
16
17/// Configuration of the cluster we will spin up
18#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
19pub struct TimelyConfig {
20    /// Number of per-process worker threads
21    pub workers: usize,
22    /// Identity of this process
23    pub process: usize,
24    /// Addresses of all processes
25    pub addresses: Vec<String>,
26    /// Proportionality value that decides whether to exert additional arrangement merge effort.
27    ///
28    /// Specifically, additional merge effort is exerted when the size of the second-largest batch
29    /// in an arrangement is within a factor of `arrangement_exert_proportionality` of the size of
30    /// the largest batch, or when a merge is already in progress.
31    ///
32    /// The higher the proportionality value, the more eagerly arrangement batches are merged. A
33    /// value of `0` (or `1`) disables eager merging.
34    pub arrangement_exert_proportionality: u32,
35    /// Whether to use the zero copy allocator.
36    pub enable_zero_copy: bool,
37    /// Whether to use lgalloc to back the zero copy allocator.
38    pub enable_zero_copy_lgalloc: bool,
39    /// Optional limit on the number of empty buffers retained by the zero copy allocator.
40    pub zero_copy_limit: Option<usize>,
41}
42
43impl ToString for TimelyConfig {
44    fn to_string(&self) -> String {
45        serde_json::to_string(self).unwrap()
46    }
47}
48
49impl FromStr for TimelyConfig {
50    type Err = serde_json::Error;
51
52    fn from_str(s: &str) -> serde_json::Result<Self> {
53        serde_json::from_str(s)
54    }
55}
56
57/// A trait for cluster commands that provide a protocol nonce.
58pub trait TryIntoProtocolNonce {
59    /// Attempt to unpack `self` into a nonce. Otherwise, fail and return `self` back.
60    fn try_into_protocol_nonce(self) -> Result<Uuid, Self>
61    where
62        Self: Sized;
63}
64
65/// Specifies the location of a cluster replica.
66#[derive(Clone, Debug, Serialize, Deserialize)]
67pub struct ClusterReplicaLocation {
68    /// The network addresses of the cluster control endpoints for each process in
69    /// the replica. Connections from the controller to these addresses
70    /// are sent commands, and send responses back.
71    pub ctl_addrs: Vec<String>,
72}