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

Fix race condition between provision step and BifrostService::start #2533

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

muhamadazmy
Copy link
Contributor

@muhamadazmy muhamadazmy commented Jan 22, 2025

Fix race condition between provision step and BifrostService::start

Summary:
During initialization of metadata. Try to resolve conflict with bifrost initialization
by recreating the logs iff it still at MIN version and has an empty chains

Fixes #2486


Stack created with Sapling. Best reviewed with ReviewStack.

@muhamadazmy
Copy link
Contributor Author

@tillrohrmann I still need to check why the CI is failing while things seems to be working locally, meanwhile you already can take a look if I overlooked something else in this approach.

@muhamadazmy muhamadazmy force-pushed the pr2533 branch 2 times, most recently from 02ea5fa to f4e6ed6 Compare January 23, 2025 15:33
Comment on lines 682 to 701
let value = metadata_store_client
.read_modify_write(key, |current| match current {
None => Ok(initial_value.clone()),
Some(logs) => {
if logs.version() == Version::MIN && logs.num_logs() == 0 {
let builder = initial_value.clone().into_builder();
// make sure version is incremented to MIN + 1
Ok(builder.build())
} else {
Err(ReadModifyWriteError::FailedOperation(AlreadyInitialized))
}
}
})
.await;
Copy link
Contributor

Choose a reason for hiding this comment

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

The check for num_logs() is a bit extra but in general it looks correct. I would suggest to improve this a bit by checking if the current_value == the initial_value in case we were trying to overwrite our own previous write. In that case we can just return success instead of bumping up the version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but because Logs does not implement PartitalEq, I compared the config instead since this is what we care about. Instead of adding PartialEq everywhere.

Copy link
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this race condition @muhamadazmy. LGTM. +1 for merging.

crates/node/src/lib.rs Show resolved Hide resolved
Summary:
During initialization of metadata. Try to resolve conflict with bifrost initialization
by recreating the logs iff it still at MIN version and has an empty chains

Fixes restatedev#2486
@muhamadazmy muhamadazmy merged commit e4cf04f into restatedev:main Jan 24, 2025
23 of 24 checks passed
@muhamadazmy muhamadazmy deleted the pr2533 branch January 24, 2025 09:26
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.

Race condition between provision step and BifrostService::start to initialize Logs configuration
3 participants