1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Materialize, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

//! Configuration parameter types.

use std::sync::Arc;

use mz_dyncfg::ConfigSet;

use crate::{connections::ConnectionContext, parameters::StorageParameters};

include!(concat!(env!("OUT_DIR"), "/mz_storage_types.parameters.rs"));

/// A struct representing the _entirety_ of configuration required for interacting with storage APIs.
///
/// Portions of this struct are mutable, but it remains _clone-able_ so it can be moved between
/// tasks.
///
/// Usable within clusterd and environmentd.
#[derive(Debug, Clone)]
pub struct StorageConfiguration {
    /// Mutable, LD-controlled parameters related to upstream storage connections,
    /// persist, and rendering of dataflows.
    ///
    /// This type can be serialized and copied from environmentd to clusterd, and can
    /// be merged into a `StorageConfiguration` with `StorageConfiguration::update`.
    pub parameters: StorageParameters,

    /// Immutable, CLI-configured parameters.
    ///
    /// TODO(guswynn): `ConnectionContext` also contains some shared global state that should
    /// eventually be moved up to this struct.
    pub connection_context: ConnectionContext,

    /// A clone-able `mz_dyncfg::ConfigSet` used to access dyncfg values.
    config_set: Arc<ConfigSet>,
}

impl StorageConfiguration {
    /// Instantiate a new `StorageConfiguration` with default parameters and the given context.
    pub fn new(
        connection_context: ConnectionContext,
        config_set: ConfigSet,
    ) -> StorageConfiguration {
        StorageConfiguration {
            parameters: Default::default(),
            connection_context,
            config_set: Arc::new(config_set),
        }
    }

    /// Get a reference to the shared `ConfigSet`.
    pub fn config_set(&self) -> &ConfigSet {
        &self.config_set
    }

    pub fn update(&mut self, parameters: StorageParameters) {
        // We serialize the dyncfg updates in StorageParameters, but store the config set
        // top-level. Eventually, all of `StorageParameters` goes away.
        parameters.dyncfg_updates.apply(&self.config_set);
        self.parameters.update(parameters);
    }
}