Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic migration path from local to replicated metadata server #2708

Merged

Conversation

tillrohrmann
Copy link
Contributor

This commit adds an automatic migration path from a local to a replicated metadata
server. To make use of it, users need to set

metadata-server.type = replicated
metadata-server.migrate_from_local_metadata_server = true

If the replicated metadata server hasn't provisioned before, then it will read the
key-value pairs from the local metadata store and initialize its own storage with it.
It will also run the migration logic for older NodesConfiguration versions (those
that might still have a node id of 0 configured).

crates/metadata-server/src/raft/server.rs Show resolved Hide resolved
crates/metadata-server/src/local/storage.rs Outdated Show resolved Hide resolved
crates/metadata-server/src/local/storage.rs Outdated Show resolved Hide resolved
Comment on lines 312 to 322
if raft_options.migrate_from_local_metadata_server {
info!("Trying to migrate from local metadata to replicated metadata server");

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 data from local metadata to replicated metadata server");
let member = self.become_member(my_member_id)?;
Provisioned::Member(member)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should make this migration enabled by default (or not being an option). Which one is more risky?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that making the migration explicit and requiring people to opt-in to it, it gives a bit more control over what is happening. I guess the situation it protects against is that you have a local-metadata-store directory in your node directory from which you don't want to migrate. Admittedly, it makes changing metadata-server types less convenient since it requires users to read the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I started the server and didn't actually migrate? what happens to the state of current data in loglets/partitions? I'm concerned about this leading to irreparable corrupted state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point. If the nodes start with a fresh metadata, then they will start again from lsn 0 to write to the log. I will change it to auto migrate.

crates/metadata-server/src/raft/server.rs Outdated Show resolved Hide resolved
crates/metadata-server/src/raft/server.rs Outdated Show resolved Hide resolved
crates/metadata-server/src/raft/server.rs Outdated Show resolved Hide resolved
server/src/main.rs Outdated Show resolved Hide resolved
@tillrohrmann tillrohrmann force-pushed the local-to-replicated-migration branch 3 times, most recently from 46c3319 to 8ef9255 Compare February 12, 2025 22:11
@tillrohrmann
Copy link
Contributor Author

I've changed the logic to work w/o having to set an explicit option. If the local metadata data directory exists, then the system will try to migrate from it.

Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Thanks for working on this Till.

@tillrohrmann tillrohrmann force-pushed the local-to-replicated-migration branch from 8ef9255 to 5c9e781 Compare February 13, 2025 11:51
Instead of creating a log entry with a WriteRequest, this commit changes how the
RaftMetadataServer is initialized by using a KvMemoryStorage snapshot instead.
This commit adds an automatic migraton path from a local to a replicated metadata
server. To make use of it, users need to set

metadata-server.type = replicated
metadata-server.migrate_from_local_metadata_server = true

If the replicated metadata server hasn't provisioned before, then it will read the
key-value pairs from the local metadata store and initialize its own storage with it.
It will also run the migration logic for older NodesConfiguration versions (those
that might still have a node id of 0 configured).
…g to replicated metadata server

This is a safety mechanism that should prevent accidental misconfiguration.
@tillrohrmann tillrohrmann force-pushed the local-to-replicated-migration branch from 5c9e781 to 9a1d297 Compare February 13, 2025 11:53
@tillrohrmann tillrohrmann merged commit 9a1d297 into restatedev:main Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants