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

Use atomic operations in database to harden against failures #692

Closed
michaelsproul opened this issue Dec 10, 2019 · 1 comment · Fixed by #1285
Closed

Use atomic operations in database to harden against failures #692

michaelsproul opened this issue Dec 10, 2019 · 1 comment · Fixed by #1285
Assignees

Comments

@michaelsproul
Copy link
Member

Description

At present, each insert into the store is its own operation, but we often rely on invariants to be maintained between objects inserted at different times (e.g. if we have a block, we expect to have its state too). Through the use of transactions/atomics at the level of the KV store, we should be able to better maintain these invariants under adverse conditions (the process getting SIGKILLed, power outage, etc).

@adaszko
Copy link
Contributor

adaszko commented Mar 27, 2020

Candidates for using atomic operations:

pub fn commit<S: Store<E>>(self, store: &S) -> Result<(), Error> {
self.items.into_iter().try_for_each(|item| match item {
BatchItem::Full(state_root, state) => store.put_state(&state_root, state),
BatchItem::Summary(state_root, summary) => {
store.put_state_summary(&state_root, summary)
}
})
}

self.store.put_state(&state_root, state)?;
self.store.put_block(&block_root, signed_block)?;

for (block_hash, state_hash, slot) in abandoned_blocks.drain() {
self.store.delete_block(&block_hash.into())?;
self.store.delete_state(&state_hash.into(), slot)?;
}

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 a pull request may close this issue.

2 participants