Skip to main content

mz_cluster_client/
params.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//! gRPC client parameters shared by compute and storage.
11
12use serde::{Deserialize, Serialize};
13use std::time::Duration;
14
15/// gRPC client parameters.
16#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
17pub struct GrpcClientParameters {
18    /// Timeout to apply to initial connection establishment.
19    pub connect_timeout: Option<Duration>,
20    /// Time waited after the last received HTTP/2 frame before sending
21    /// a keep-alive PING to the server. Note that this is an HTTP/2
22    /// keep-alive, and is separate from TCP keep-alives.
23    pub http2_keep_alive_interval: Option<Duration>,
24    /// Time waited without response after a keep-alive PING before
25    /// terminating the connection.
26    pub http2_keep_alive_timeout: Option<Duration>,
27}
28
29impl GrpcClientParameters {
30    /// Update the parameter values with the set ones from `other`.
31    pub fn update(&mut self, other: Self) {
32        let Self {
33            connect_timeout,
34            http2_keep_alive_interval,
35            http2_keep_alive_timeout,
36        } = self;
37        let Self {
38            connect_timeout: other_connect_timeout,
39            http2_keep_alive_interval: other_http2_keep_alive_interval,
40            http2_keep_alive_timeout: other_http2_keep_alive_timeout,
41        } = other;
42
43        if let Some(v) = other_connect_timeout {
44            *connect_timeout = Some(v);
45        }
46        if let Some(v) = other_http2_keep_alive_interval {
47            *http2_keep_alive_interval = Some(v);
48        }
49        if let Some(v) = other_http2_keep_alive_timeout {
50            *http2_keep_alive_timeout = Some(v);
51        }
52    }
53
54    /// Return whether all parameters are unset.
55    pub fn all_unset(&self) -> bool {
56        *self == Self::default()
57    }
58}