-
Notifications
You must be signed in to change notification settings - Fork 12
Create snapshots #19
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
Merged
Merged
Create snapshots #19
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7dcc561
Add complete_register to ConsensusEngine
foriequal0 8fe1b7d
Remove outdated snapshot module
foriequal0 051e2ef
Implement Snapshot & Restore modules
foriequal0 ce3516e
Implement snapshot service
foriequal0 985167c
Add SnapshotNotifySender to Tendermint worker
foriequal0 23e90fd
Implement snapshot on term start
foriequal0 c13a61b
Add autoremoving expired snapshot feature
foriequal0 e3865be
Generate snapshot chunks for shard level state
remagpie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Copyright 2018-2019 Kodebox, Inc. | ||
| // This file is part of CodeChain. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use std::sync::mpsc::{sync_channel, Receiver, RecvError, SyncSender}; | ||
| use std::sync::{Arc, Weak}; | ||
|
|
||
| use ctypes::BlockHash; | ||
| use parking_lot::RwLock; | ||
|
|
||
| pub fn create() -> (NotifySender, NotifyReceiverSource) { | ||
| let (tx, rx) = sync_channel(1); | ||
| let tx = Arc::new(RwLock::new(Some(tx))); | ||
| let tx_weak = Arc::downgrade(&tx); | ||
| ( | ||
| NotifySender { | ||
| tx, | ||
| }, | ||
| NotifyReceiverSource( | ||
| ReceiverCanceller { | ||
| tx: tx_weak, | ||
| }, | ||
| NotifyReceiver { | ||
| rx, | ||
| }, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| pub struct NotifySender { | ||
| tx: Arc<RwLock<Option<SyncSender<BlockHash>>>>, | ||
| } | ||
|
|
||
| impl NotifySender { | ||
| pub fn notify(&self, block_hash: BlockHash) { | ||
| let guard = self.tx.read(); | ||
| if let Some(tx) = guard.as_ref() { | ||
| // TODO: Ignore the error. Receiver thread might be terminated or congested. | ||
| let _ = tx.try_send(block_hash); | ||
| } else { | ||
| // ReceiverCanceller is dropped. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct NotifyReceiverSource(pub ReceiverCanceller, pub NotifyReceiver); | ||
|
|
||
| /// Dropping this makes the receiver stopped. | ||
| /// | ||
| /// `recv()` method of the `Receiver` will stop and return `RecvError` when corresponding `Sender` is dropped. | ||
| /// This is an inherited behaviour of `std::sync::mpsc::{Sender, Receiver}`. | ||
| /// However, we need another way to stop the `Receiver`, since `Sender` is usually shared throughout our codes. | ||
| /// We can't collect them all and destory one by one. We need a kill switch. | ||
| /// | ||
| /// `ReceiverCanceller` holds weak reference to the `Sender`, so it doesn't prohibit the default behaviour. | ||
| /// Then, we can upgrade the weak reference and get the shared reference to `Sender` itself, and manually drop it with this. | ||
| pub struct ReceiverCanceller { | ||
| tx: Weak<RwLock<Option<SyncSender<BlockHash>>>>, | ||
| } | ||
|
|
||
| impl Drop for ReceiverCanceller { | ||
| fn drop(&mut self) { | ||
| if let Some(tx) = self.tx.upgrade() { | ||
| let mut guard = tx.write(); | ||
| if let Some(sender) = guard.take() { | ||
| drop(sender) | ||
| } | ||
| } else { | ||
| // All NotifySender is dropped. No droppable Sender. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Receiver is dropped when | ||
| /// 1. There are no NotifySenders out there. | ||
| /// 2. ReceiverCanceller is dropped. See the comment of `ReceiverCanceller`. | ||
| pub struct NotifyReceiver { | ||
| rx: Receiver<BlockHash>, | ||
| } | ||
|
|
||
| impl NotifyReceiver { | ||
| pub fn recv(&self) -> Result<BlockHash, RecvError> { | ||
| self.rx.recv() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.