mz_catalog/durable/upgrade/
v74_to_v75.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
10use crate::durable::traits::{UpgradeFrom, UpgradeInto};
11use crate::durable::upgrade::MigrationAction;
12use crate::durable::upgrade::wire_compatible::{WireCompatible, wire_compatible};
13use crate::durable::upgrade::{objects_v74 as v74, objects_v75 as v75};
14
15wire_compatible!(v74::ClusterReplicaKey with v75::ClusterReplicaKey);
16wire_compatible!(v74::ClusterId with v75::ClusterId);
17wire_compatible!(v74::RoleId with v75::RoleId);
18wire_compatible!(v74::ReplicaLogging with v75::ReplicaLogging);
19wire_compatible!(v74::replica_config::ManagedLocation with v75::replica_config::ManagedLocation);
20
21/// Removes some options from unmanaged (unorchestrated?) replica configs.
22pub fn upgrade(
23    snapshot: Vec<v74::StateUpdateKind>,
24) -> Vec<MigrationAction<v74::StateUpdateKind, v75::StateUpdateKind>> {
25    let mut migrations = Vec::new();
26    for update in snapshot {
27        match update.kind {
28            Some(v74::state_update_kind::Kind::ClusterReplica(old_replica)) => {
29                let new_replica =
30                    v75::state_update_kind::ClusterReplica::upgrade_from(old_replica.clone());
31                let old = v74::StateUpdateKind {
32                    kind: Some(v74::state_update_kind::Kind::ClusterReplica(old_replica)),
33                };
34                let new = v75::StateUpdateKind {
35                    kind: Some(v75::state_update_kind::Kind::ClusterReplica(new_replica)),
36                };
37
38                let migration = MigrationAction::Update(old, new);
39                migrations.push(migration);
40            }
41            _ => {}
42        }
43    }
44    migrations
45}
46
47impl UpgradeFrom<v74::state_update_kind::ClusterReplica>
48    for v75::state_update_kind::ClusterReplica
49{
50    fn upgrade_from(old: v74::state_update_kind::ClusterReplica) -> Self {
51        v75::state_update_kind::ClusterReplica {
52            key: old.key.as_ref().map(WireCompatible::convert),
53            value: old.value.map(UpgradeFrom::upgrade_from),
54        }
55    }
56}
57
58impl UpgradeFrom<v74::ClusterReplicaValue> for v75::ClusterReplicaValue {
59    fn upgrade_from(old: v74::ClusterReplicaValue) -> Self {
60        v75::ClusterReplicaValue {
61            cluster_id: old.cluster_id.as_ref().map(WireCompatible::convert),
62            name: old.name,
63            config: old.config.map(UpgradeFrom::upgrade_from),
64            owner_id: old.owner_id.as_ref().map(WireCompatible::convert),
65        }
66    }
67}
68
69impl UpgradeFrom<v74::ReplicaConfig> for v75::ReplicaConfig {
70    fn upgrade_from(old: v74::ReplicaConfig) -> Self {
71        v75::ReplicaConfig {
72            logging: old.logging.as_ref().map(WireCompatible::convert),
73            location: old.location.map(UpgradeFrom::upgrade_from),
74        }
75    }
76}
77
78impl UpgradeFrom<v74::replica_config::Location> for v75::replica_config::Location {
79    fn upgrade_from(old: v74::replica_config::Location) -> Self {
80        match old {
81            v74::replica_config::Location::Unmanaged(loc) => {
82                v75::replica_config::Location::Unmanaged(loc.upgrade_into())
83            }
84            v74::replica_config::Location::Managed(loc) => {
85                v75::replica_config::Location::Managed(WireCompatible::convert(&loc))
86            }
87        }
88    }
89}
90
91impl UpgradeFrom<v74::replica_config::UnmanagedLocation>
92    for v75::replica_config::UnmanagedLocation
93{
94    fn upgrade_from(loc: v74::replica_config::UnmanagedLocation) -> Self {
95        v75::replica_config::UnmanagedLocation {
96            storagectl_addrs: loc.storagectl_addrs,
97            computectl_addrs: loc.computectl_addrs,
98        }
99    }
100}