Skip to content

Commit

Permalink
Fix configuration compatibility issues
Browse files Browse the repository at this point in the history
Summary:

Making sure a single node server v1.2 can still work
with a v1.1.6 config
  • Loading branch information
muhamadazmy committed Feb 6, 2025
1 parent 7df62da commit 0ae0b07
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/local-cluster-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace-hack = { version = "0.1", path = "../../workspace-hack" }
restate-core = { workspace = true }
restate-metadata-server = { workspace = true }
# nb features here will also affect the compiled restate-server binary in integration tests
restate-types = { workspace = true, features = ["unsafe-mutable-config"] }
restate-types = { workspace = true, features = ["unsafe-mutable-config", "test-util"] }

anyhow = { workspace = true }
arc-swap = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions crates/local-cluster-runner/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ impl Node {
base_config.common.auto_provision = false;
base_config.common.log_disable_ansi_codes = true;
if !matches!(
base_config.metadata_server.kind,
base_config.metadata_server.kind(),
MetadataServerKind::Raft(_)
) {
info!("Setting the metadata server to embedded");
base_config.metadata_server.kind = MetadataServerKind::Raft(RaftOptions::default());
base_config
.metadata_server
.set_kind(MetadataServerKind::Raft(RaftOptions::default()));
}

for node_id in 1..=size {
Expand Down
2 changes: 1 addition & 1 deletion crates/metadata-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub async fn create_metadata_server(
server_builder: &mut NetworkServerBuilder,
) -> anyhow::Result<BoxedMetadataServer> {
metric_definitions::describe_metrics();
match metadata_server_options.kind {
match metadata_server_options.kind() {
MetadataServerKind::Local => LocalMetadataServer::create(
metadata_server_options,
rocksdb_options,
Expand Down
3 changes: 2 additions & 1 deletion crates/metadata-server/src/raft/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ impl Member {
connection_manager.store(Some(Arc::new(new_connection_manager)));

let_assert!(
MetadataServerKind::Raft(raft_options) = &Configuration::pinned().metadata_server.kind,
MetadataServerKind::Raft(raft_options) =
&Configuration::pinned().metadata_server.kind(),
"Expecting that the replicated/raft metadata server has been configured"
);

Expand Down
11 changes: 9 additions & 2 deletions crates/types/src/config/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ enum MetadataClientKindShadow {
#[serde(alias = "embedded")]
Native {
address: Option<AdvertisedAddress>,
#[serde(default)]
addresses: Vec<AdvertisedAddress>,
},
Etcd {
Expand Down Expand Up @@ -657,8 +658,14 @@ impl TryFrom<MetadataClientKindShadow> for MetadataClientKind {

Self::Native {
addresses: match address {
Some(address) if addresses == vec![default_address] => vec![address],
Some(_) => return Err("Conflicting configuration, embedded metadata-store-client cannot have both `address` and `addresses`"),
Some(address)
if addresses.is_empty() || addresses == vec![default_address] =>
{
vec![address]
}
Some(_) => {
return Err("Conflicting configuration, embedded metadata-store-client cannot have both `address` and `addresses`");
}
None => addresses,
},
}
Expand Down
14 changes: 12 additions & 2 deletions crates/types/src/config/metadata_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ pub struct MetadataServerOptions {
/// Type of metadata server to start
///
/// The type of metadata server to start when running the metadata store role.
// defined as Option<_> for backward compatibility with version < v1.2
#[serde(flatten)]
pub kind: MetadataServerKind,
kind: Option<MetadataServerKind>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
Expand All @@ -78,6 +79,15 @@ pub enum MetadataServerKind {
}

impl MetadataServerOptions {
pub fn kind(&self) -> MetadataServerKind {
self.kind.clone().unwrap_or_default()
}

#[cfg(any(test, feature = "test-util"))]
pub fn set_kind(&mut self, kind: MetadataServerKind) {
self.kind = Some(kind);
}

pub fn apply_common(&mut self, common: &CommonOptions) {
self.rocksdb.apply_common(&common.rocksdb);

Expand Down Expand Up @@ -126,7 +136,7 @@ impl Default for MetadataServerOptions {
rocksdb_memory_budget: None,
rocksdb_memory_ratio: 0.01,
rocksdb,
kind: MetadataServerKind::default(),
kind: Some(MetadataServerKind::default()),
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions server/tests/raft_metadata_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ async fn raft_metadata_cluster_chaos_test() -> googletest::Result<()> {
let num_nodes = 3;
let chaos_duration = Duration::from_secs(20);
let mut base_config = Configuration::default();
base_config.metadata_server.kind = MetadataServerKind::Raft(RaftOptions {
raft_election_tick: NonZeroUsize::new(5).expect("5 to be non zero"),
raft_heartbeat_tick: NonZeroUsize::new(2).expect("2 to be non zero"),
..RaftOptions::default()
});
base_config
.metadata_server
.set_kind(MetadataServerKind::Raft(RaftOptions {
raft_election_tick: NonZeroUsize::new(5).expect("5 to be non zero"),
raft_heartbeat_tick: NonZeroUsize::new(2).expect("2 to be non zero"),
..RaftOptions::default()
}));

let nodes = Node::new_test_nodes(
base_config,
Expand Down

0 comments on commit 0ae0b07

Please sign in to comment.