mz_storage_types/
configuration.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//! Configuration parameter types.
11
12use std::sync::Arc;
13
14use mz_dyncfg::ConfigSet;
15
16use crate::{connections::ConnectionContext, parameters::StorageParameters};
17
18include!(concat!(env!("OUT_DIR"), "/mz_storage_types.parameters.rs"));
19
20/// A struct representing the _entirety_ of configuration required for interacting with storage APIs.
21///
22/// Portions of this struct are mutable, but it remains _clone-able_ so it can be moved between
23/// tasks.
24///
25/// Usable within clusterd and environmentd.
26#[derive(Debug, Clone)]
27pub struct StorageConfiguration {
28    /// Mutable, LD-controlled parameters related to upstream storage connections,
29    /// persist, and rendering of dataflows.
30    ///
31    /// This type can be serialized and copied from environmentd to clusterd, and can
32    /// be merged into a `StorageConfiguration` with `StorageConfiguration::update`.
33    pub parameters: StorageParameters,
34
35    /// Immutable, CLI-configured parameters.
36    ///
37    /// TODO(guswynn): `ConnectionContext` also contains some shared global state that should
38    /// eventually be moved up to this struct.
39    pub connection_context: ConnectionContext,
40
41    /// A clone-able `mz_dyncfg::ConfigSet` used to access dyncfg values.
42    config_set: Arc<ConfigSet>,
43}
44
45impl StorageConfiguration {
46    /// Instantiate a new `StorageConfiguration` with default parameters and the given context.
47    pub fn new(
48        connection_context: ConnectionContext,
49        config_set: ConfigSet,
50    ) -> StorageConfiguration {
51        StorageConfiguration {
52            parameters: Default::default(),
53            connection_context,
54            config_set: Arc::new(config_set),
55        }
56    }
57
58    /// Get a reference to the shared `ConfigSet`.
59    pub fn config_set(&self) -> &Arc<ConfigSet> {
60        &self.config_set
61    }
62
63    pub fn update(&mut self, parameters: StorageParameters) {
64        // We serialize the dyncfg updates in StorageParameters, but store the config set
65        // top-level. Eventually, all of `StorageParameters` goes away.
66        parameters.dyncfg_updates.apply(&self.config_set);
67        self.parameters.update(parameters);
68    }
69}