Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit ffeaee7

Browse files
authored
Pause pruning while snapshotting (#11178)
* WIP. Typos and logging. * Format todos * Pause pruning while a snapshot is under way Logs, docs and todos * Allocate memory for the full chunk * Name snapshotting threads * Ensure `taking_snapshot` is set to false whenever and however `take_snapshot`returns Rename `take_at` to `request_snapshot_at` Cleanup * Let "in_progress" deletion fail Fix tests * Just use an atomic * Review grumbles * Finish the sentence * Resolve a few todos and clarify comments. * Calculate progress rate since last update * Lockfile * Fix tests * typo * Reinstate default snapshotting frequency Cut down on the logging noise * address grumble * Log memory use with `journal_size()` and explain why.
1 parent acf7c48 commit ffeaee7

File tree

24 files changed

+345
-206
lines changed

24 files changed

+345
-206
lines changed

Cargo.lock

Lines changed: 88 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ rayon = "1.1"
5151
registrar = { path = "../util/registrar" }
5252
rlp = "0.4.0"
5353
rustc-hex = "2"
54+
scopeguard = "1.0.0"
5455
serde = "1.0"
5556
serde_derive = "1.0"
5657
snapshot = { path = "snapshot" }

ethcore/service/src/service.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,12 @@ where
270270
ClientIoMessage::TakeSnapshot(num) => {
271271
let client = self.client.clone();
272272
let snapshot = self.snapshot.clone();
273-
274273
let res = thread::Builder::new().name("Periodic Snapshot".into()).spawn(move || {
275274
if let Err(e) = snapshot.take_snapshot(&*client, num) {
276275
match e {
277276
EthcoreError::Snapshot(SnapshotError::SnapshotAborted) => info!("Snapshot aborted"),
278277
_ => warn!("Failed to take snapshot at block #{}: {}", num, e),
279278
}
280-
281279
}
282280
});
283281

ethcore/snapshot/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ rand_xorshift = "0.2"
3333
parking_lot = "0.9"
3434
rlp = "0.4.2"
3535
rlp_derive = { path = "../../util/rlp-derive" }
36+
scopeguard = "1.0.0"
3637
snappy = { package = "parity-snappy", version ="0.1.0" }
3738
state-db = { path = "../state-db" }
3839
trie-db = "0.15.0"

ethcore/snapshot/snapshot-tests/src/account.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn encoding_basic() {
4848

4949
let thin_rlp = ::rlp::encode(&account);
5050
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
51-
let p = Progress::default();
51+
let p = Progress::new();
5252
let fat_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap();
5353
let fat_rlp = Rlp::new(&fat_rlps[0]).at(1).unwrap();
5454
assert_eq!(from_fat_rlp(&mut AccountDBMut::from_hash(db.as_hash_db_mut(), keccak(addr)), fat_rlp, H256::zero()).unwrap().0, account);
@@ -69,7 +69,7 @@ fn encoding_version() {
6969

7070
let thin_rlp = ::rlp::encode(&account);
7171
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
72-
let p = Progress::default();
72+
let p = Progress::new();
7373
let fat_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap();
7474
let fat_rlp = Rlp::new(&fat_rlps[0]).at(1).unwrap();
7575
assert_eq!(from_fat_rlp(&mut AccountDBMut::from_hash(db.as_hash_db_mut(), keccak(addr)), fat_rlp, H256::zero()).unwrap().0, account);
@@ -96,7 +96,7 @@ fn encoding_storage() {
9696
let thin_rlp = ::rlp::encode(&account);
9797
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
9898

99-
let p = Progress::default();
99+
let p = Progress::new();
100100

101101
let fat_rlp = to_fat_rlps(&keccak(&addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap();
102102
let fat_rlp = Rlp::new(&fat_rlp[0]).at(1).unwrap();
@@ -124,7 +124,7 @@ fn encoding_storage_split() {
124124
let thin_rlp = ::rlp::encode(&account);
125125
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
126126

127-
let p = Progress::default();
127+
let p = Progress::new();
128128
let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), 500, 1000, &p).unwrap();
129129
let mut root = KECCAK_NULL_RLP;
130130
let mut restored_account = None;
@@ -170,8 +170,8 @@ fn encoding_code() {
170170
};
171171

172172
let mut used_code = HashSet::new();
173-
let p1 = Progress::default();
174-
let p2 = Progress::default();
173+
let p1 = Progress::new();
174+
let p2 = Progress::new();
175175
let fat_rlp1 = to_fat_rlps(&keccak(&addr1), &account1, &AccountDB::from_hash(db.as_hash_db(), keccak(addr1)), &mut used_code, usize::max_value(), usize::max_value(), &p1).unwrap();
176176
let fat_rlp2 = to_fat_rlps(&keccak(&addr2), &account2, &AccountDB::from_hash(db.as_hash_db(), keccak(addr2)), &mut used_code, usize::max_value(), usize::max_value(), &p2).unwrap();
177177
assert_eq!(used_code.len(), 1);

ethcore/snapshot/snapshot-tests/src/helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use client_traits::ChainInfo;
2727
use common_types::{
2828
ids::BlockId,
2929
basic_account::BasicAccount,
30-
errors::EthcoreError
30+
errors::EthcoreError,
31+
snapshot::Progress,
3132
};
3233
use engine::Engine;
3334
use ethcore::client::Client;
@@ -145,7 +146,7 @@ pub fn snap(client: &Client) -> (Box<dyn SnapshotReader>, TempDir) {
145146
let tempdir = TempDir::new("").unwrap();
146147
let path = tempdir.path().join("file");
147148
let writer = PackedWriter::new(&path).unwrap();
148-
let progress = Default::default();
149+
let progress = Progress::new();
149150

150151
let hash = client.chain_info().best_block_hash;
151152
client.take_snapshot(writer, BlockId::Hash(hash), &progress).unwrap();

ethcore/snapshot/snapshot-tests/src/proof_of_work.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn chunk_and_restore(amount: u64) {
7474
&bc,
7575
best_hash,
7676
&writer,
77-
&Progress::default()
77+
&Progress::new()
7878
).unwrap();
7979

8080
let manifest = ManifestData {

ethcore/snapshot/snapshot-tests/src/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn keep_ancient_blocks() {
278278
&bc,
279279
best_hash,
280280
&writer,
281-
&Progress::default()
281+
&Progress::new()
282282
).unwrap();
283283
let state_db = client.state_db().journal_db().boxed_clone();
284284
let start_header = bc.block_header_data(&best_hash).unwrap();
@@ -287,7 +287,7 @@ fn keep_ancient_blocks() {
287287
state_db.as_hash_db(),
288288
&state_root,
289289
&writer,
290-
&Progress::default(),
290+
&Progress::new(),
291291
None,
292292
0
293293
).unwrap();

ethcore/snapshot/snapshot-tests/src/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn snap_and_restore() {
6262

6363
let mut state_hashes = Vec::new();
6464
for part in 0..SNAPSHOT_SUBPARTS {
65-
let mut hashes = chunk_state(&old_db, &state_root, &writer, &Progress::default(), Some(part), 0).unwrap();
65+
let mut hashes = chunk_state(&old_db, &state_root, &writer, &Progress::new(), Some(part), 0).unwrap();
6666
state_hashes.append(&mut hashes);
6767
}
6868

@@ -133,7 +133,7 @@ fn get_code_from_prev_chunk() {
133133
let mut make_chunk = |acc, hash| {
134134
let mut db = journaldb::new_memory_db();
135135
AccountDBMut::from_hash(&mut db, hash).insert(EMPTY_PREFIX, &code[..]);
136-
let p = Progress::default();
136+
let p = Progress::new();
137137
let fat_rlp = to_fat_rlps(&hash, &acc, &AccountDB::from_hash(&db, hash), &mut used_code, usize::max_value(), usize::max_value(), &p).unwrap();
138138
let mut stream = RlpStream::new_list(1);
139139
stream.append_raw(&fat_rlp[0], 1);
@@ -178,7 +178,7 @@ fn checks_flag() {
178178
let state_root = producer.state_root();
179179
let writer = Mutex::new(PackedWriter::new(&snap_file).unwrap());
180180

181-
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::default(), None, 0).unwrap();
181+
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::new(), None, 0).unwrap();
182182

183183
writer.into_inner().finish(ManifestData {
184184
version: 2,

ethcore/snapshot/snapshot-tests/src/watcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl Oracle for TestOracle {
4141

4242
struct TestBroadcast(Option<u64>);
4343
impl Broadcast for TestBroadcast {
44-
fn take_at(&self, num: Option<u64>) {
45-
if num != self.0 {
44+
fn request_snapshot_at(&self, num: u64) {
45+
if Some(num) != self.0 {
4646
panic!("Watcher broadcast wrong number. Expected {:?}, found {:?}", self.0, num);
4747
}
4848
}

0 commit comments

Comments
 (0)