-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathinternal_cluster_common.rs
More file actions
76 lines (69 loc) · 2.65 KB
/
internal_cluster_common.rs
File metadata and controls
76 lines (69 loc) · 2.65 KB
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
70
71
72
73
74
75
76
// Copyright (c) 2023 - 2026 Restate Software, Inc., Restate GmbH.
// 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.
use serde::Serialize;
use restate_types::logs::metadata::ProviderConfiguration;
use restate_types::partition_table::PartitionReplication;
use restate_types::replication::ReplicationProperty;
#[derive(Debug, Clone, Serialize)]
pub(super) struct LogsProviderView {
/// Provider kind (in-memory, local, or replicated).
pub kind: String,
/// Replication property if provider kind is replicated.
pub replication_property: Option<ReplicationProperty>,
/// Target nodeset size if provider kind is replicated.
pub target_nodeset_size: Option<u32>,
}
#[derive(Debug, Clone, Serialize)]
pub(super) struct PartitionReplicationView {
/// Replication mode.
pub mode: PartitionReplicationMode,
/// Required copies per location scope when mode is `limit`.
#[serde(skip_serializing_if = "Option::is_none")]
pub copies: Option<ReplicationProperty>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "snake_case")]
pub(super) enum PartitionReplicationMode {
Everywhere,
Limit,
}
pub(super) fn logs_provider_view(provider: ProviderConfiguration) -> LogsProviderView {
match provider {
ProviderConfiguration::InMemory => LogsProviderView {
kind: "in-memory".to_owned(),
replication_property: None,
target_nodeset_size: None,
},
ProviderConfiguration::Local => LogsProviderView {
kind: "local".to_owned(),
replication_property: None,
target_nodeset_size: None,
},
ProviderConfiguration::Replicated(config) => LogsProviderView {
kind: "replicated".to_owned(),
replication_property: Some(config.replication_property.clone()),
target_nodeset_size: Some(config.target_nodeset_size.as_u32()),
},
}
}
pub(super) fn partition_replication_view(
partition_replication: &PartitionReplication,
) -> PartitionReplicationView {
match partition_replication {
PartitionReplication::Everywhere => PartitionReplicationView {
mode: PartitionReplicationMode::Everywhere,
copies: None,
},
PartitionReplication::Limit(replication_property) => PartitionReplicationView {
mode: PartitionReplicationMode::Limit,
copies: Some(replication_property.clone()),
},
}
}