Use a lock instead of atomics for snapshot Progress (#11197)

* 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

* Use a lock instead of atomics for snapshot Progress

* Update ethcore/types/src/snapshot.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Avoid truncating cast
Cleanup
This commit is contained in:
David
2019-10-28 18:24:45 +01:00
committed by GitHub
parent 293e06e0f4
commit 0d3423cbe0
18 changed files with 105 additions and 111 deletions

View File

@@ -46,7 +46,7 @@ use ethereum_types::H256;
use parking_lot::{RwLock, Mutex};
/// Format byte counts to standard denominations.
pub fn format_bytes(b: usize) -> String {
pub fn format_bytes(b: u64) -> String {
match binary_prefix(b as f64) {
Standalone(bytes) => format!("{} bytes", bytes),
Prefixed(prefix, n) => format!("{:.0} {}B", n, prefix),
@@ -69,9 +69,8 @@ impl CacheSizes {
use std::fmt::Write;
let mut buf = String::new();
for (name, &size) in &self.sizes {
write!(buf, " {:>8} {}", paint(style, format_bytes(size)), name)
for (name, size) in &self.sizes {
write!(buf, " {:>8} {}", paint(style, format_bytes(*size as u64)), name)
.expect("writing to string won't fail unless OOM; qed")
}

View File

@@ -27,6 +27,7 @@ use snapshot::service::Service as SnapshotService;
use ethcore::client::{Client, DatabaseCompactionProfile, VMType};
use ethcore::miner::Miner;
use ethcore_service::ClientService;
use parking_lot::RwLock;
use types::{
ids::BlockId,
snapshot::Progress,
@@ -257,20 +258,25 @@ impl SnapshotCommand {
let writer = PackedWriter::new(&file_path)
.map_err(|e| format!("Failed to open snapshot writer: {}", e))?;
let progress = Arc::new(Progress::new());
let progress = Arc::new(RwLock::new(Progress::new()));
let p = progress.clone();
let informant_handle = ::std::thread::spawn(move || {
::std::thread::sleep(Duration::from_secs(5));
let mut last_size = 0;
while !p.done() {
let cur_size = p.bytes();
if cur_size != last_size {
last_size = cur_size;
let bytes = ::informant::format_bytes(cur_size as usize);
info!("Snapshot: {} accounts (state), {} blocks, {} bytes", p.accounts(), p.blocks(), bytes);
loop {
{
let progress = p.read();
if !progress.done() {
let cur_size = progress.bytes();
if cur_size != last_size {
last_size = cur_size;
let bytes = ::informant::format_bytes(cur_size);
info!("Snapshot: {} accounts (state), {} blocks, {} bytes", progress.accounts(), progress.blocks(), bytes);
}
} else {
break;
}
}
::std::thread::sleep(Duration::from_secs(5));
}
});
@@ -282,7 +288,7 @@ impl SnapshotCommand {
info!("snapshot creation complete");
assert!(progress.done());
assert!(progress.read().done());
informant_handle.join().map_err(|_| "failed to join logger thread")?;
Ok(())