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