Check pruning by db modification date (#1924)
This commit is contained in:
parent
8741d0d155
commit
425e1ce04c
@ -15,11 +15,10 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::fs;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use util::{contents, Database, DatabaseConfig, journaldb, H256, Address, U256, version_data};
|
use util::{contents, H256, Address, U256, version_data};
|
||||||
use util::journaldb::Algorithm;
|
use util::journaldb::Algorithm;
|
||||||
use ethcore::client;
|
|
||||||
use ethcore::spec::Spec;
|
use ethcore::spec::Spec;
|
||||||
use ethcore::ethereum;
|
use ethcore::ethereum;
|
||||||
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
|
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
|
||||||
@ -100,20 +99,13 @@ impl Pruning {
|
|||||||
|
|
||||||
fn find_best_db(dirs: &Directories, genesis_hash: H256, fork_name: Option<&String>) -> Algorithm {
|
fn find_best_db(dirs: &Directories, genesis_hash: H256, fork_name: Option<&String>) -> Algorithm {
|
||||||
let mut algo_types = Algorithm::all_types();
|
let mut algo_types = Algorithm::all_types();
|
||||||
|
// if all dbs have the same modification time, the last element is the default one
|
||||||
// if all dbs have the same latest era, the last element is the default one
|
|
||||||
algo_types.push(Algorithm::default());
|
algo_types.push(Algorithm::default());
|
||||||
|
|
||||||
algo_types.into_iter().max_by_key(|i| {
|
algo_types.into_iter().max_by_key(|i| {
|
||||||
let client_path = dirs.client_path(genesis_hash, fork_name, *i);
|
let mut client_path = dirs.client_path(genesis_hash, fork_name, *i);
|
||||||
let config = DatabaseConfig::with_columns(client::DB_NO_OF_COLUMNS);
|
client_path.push("CURRENT");
|
||||||
let db = match Database::open(&config, client_path.to_str().unwrap()) {
|
fs::metadata(&client_path).and_then(|m| m.modified()).ok()
|
||||||
Ok(db) => db,
|
|
||||||
Err(_) => return 0,
|
|
||||||
};
|
|
||||||
let db = journaldb::new(Arc::new(db), *i, client::DB_COL_STATE);
|
|
||||||
trace!(target: "parity", "Looking for best DB: {} at {:?}", i, db.latest_era());
|
|
||||||
db.latest_era().unwrap_or(0)
|
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user