Skip to content

Commit

Permalink
Enable automatic migration from local metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tillrohrmann committed Feb 13, 2025
1 parent f179a7c commit 9a1d297
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion crates/metadata-server/src/local/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl RocksDbStorage {
})
}

pub(super) fn data_dir() -> PathBuf {
pub fn data_dir() -> PathBuf {
data_dir(DATA_DIR)
}

Expand Down
35 changes: 13 additions & 22 deletions crates/metadata-server/src/raft/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ use slog::o;
use std::collections::{HashMap, VecDeque};
use std::sync::Arc;
use std::time::Duration;
use thiserror::__private::AsDisplay;
use tokio::sync::{mpsc, oneshot, watch};
use tokio::time;
use tokio::time::{Interval, MissedTickBehavior};
use tonic::codec::CompressionEncoding;
use tracing::{debug, info, instrument, trace, warn, Span};
use tracing::{debug, error, info, instrument, trace, warn, Span};
use tracing_slog::TracingSlogDrain;
use ulid::Ulid;

Expand Down Expand Up @@ -109,7 +110,7 @@ pub enum Error {
RestoreSnapshot(#[from] RestoreSnapshotError),
#[error("failed creating snapshot: {0}")]
CreateSnapshot(#[from] CreateSnapshotError),
#[error("failed provisioning from local metadata server: {0}")]
#[error("failed provisioning from local metadata: {0}")]
ProvisionFromLocal(GenericError),
#[error(transparent)]
Shutdown(#[from] ShutdownError),
Expand Down Expand Up @@ -301,20 +302,20 @@ impl RaftMetadataServer {
async fn provision(&mut self) -> Result<(), Error> {
let _ = self.status_tx.send(MetadataServerSummary::Provisioning);

let_assert!(
MetadataServerKind::Raft(raft_options) = Configuration::pinned().metadata_server.kind(),
"Replicated metadata server must have been configured"
);

if raft_options.migrate_local_metadata {
info!("Trying to migrate from local to replicated metadata");
if local::storage::RocksDbStorage::data_dir_exists() {
info!("Trying to migrate local to replicated metadata");

let my_member_id = self
.initialize_storage_from_local_metadata_server()
.await
.map_err(|err| Error::ProvisionFromLocal(err.into()))?;

info!(member_id = %my_member_id, "Successfully migrated all local to replicated metadata");
.map_err(|err| {
error!(%err, "Failed to migrate local to replicated metadata. Please make sure \
that {} exists and has not been corrupted. If the directory does not contain \
local metadata you want to migrate from, then please remove it", local::storage::RocksDbStorage::data_dir().as_display());
Error::ProvisionFromLocal(err.into())
})?;

info!(member_id = %my_member_id, "Successfully migrated local to replicated metadata");
} else {
self.await_provisioning_signal().await?
}
Expand Down Expand Up @@ -422,16 +423,6 @@ impl RaftMetadataServer {
) -> anyhow::Result<KvMemoryStorage> {
let local_metadata_server_options = MetadataServerOptions::default();

// check whether local metadata server data exists to avoid wrong intentions and possible
// misconfigurations
if !local::storage::RocksDbStorage::data_dir_exists() {
anyhow::bail!(
"Trying to migrate from local metadata server but couldn't find any data. \
Please make sure that this node has been run with the local metadata server before or \
unset the metadata-server.migrate-local-metadata option."
);
}

let mut local_storage = local::storage::RocksDbStorage::create(
&local_metadata_server_options,
Constant::new(RocksDbOptions::default()).boxed(),
Expand Down
6 changes: 1 addition & 5 deletions crates/metadata-server/src/raft/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ use std::collections::HashMap;
#[test_log::test(restate_core::test)]
async fn migration_local_to_replicated() -> googletest::Result<()> {
let mut configuration = Configuration::default();
let raft_options = RaftOptions {
// enable migration from local metadata
migrate_local_metadata: true,
..Default::default()
};
let raft_options = RaftOptions::default();

configuration
.metadata_server
Expand Down
6 changes: 0 additions & 6 deletions crates/types/src/config/metadata_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ pub struct RaftOptions {
#[serde_as(as = "serde_with::DisplayFromStr")]
#[cfg_attr(feature = "schemars", schemars(with = "String"))]
pub status_update_interval: humantime::Duration,
/// # Migrate local to replicated metadata
///
/// If true, then this node will try to provision itself from data of the local metadata server.
/// This can only work if the node has been run before with the local metadata server.
pub migrate_local_metadata: bool,
}

impl Default for RaftOptions {
Expand All @@ -182,7 +177,6 @@ impl Default for RaftOptions {
raft_heartbeat_tick: NonZeroUsize::new(2).expect("2 to be non zero"),
raft_tick_interval: Duration::from_millis(100).into(),
status_update_interval: Duration::from_secs(5).into(),
migrate_local_metadata: false,
}
}
}

0 comments on commit 9a1d297

Please sign in to comment.