Merge pull request #6792 from paritytech/kvdb_error

consistent KeyValueDB errors
This commit is contained in:
Marek Kotewicz
2017-10-16 18:19:18 +02:00
committed by GitHub
25 changed files with 154 additions and 133 deletions

View File

@@ -29,7 +29,7 @@ use bytes::Bytes;
use util::{Address, journaldb, DBValue};
use util_error::UtilError;
use trie::{TrieSpec, TrieFactory, Trie};
use kvdb::*;
use kvdb::{KeyValueDB, DBTransaction};
// other
use bigint::prelude::U256;

View File

@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util_error::UtilError;
use std::fmt::{Display, Formatter, Error as FmtError};
use util_error::UtilError;
use kvdb;
use trie::TrieError;
/// Client configuration errors.
@@ -25,7 +25,7 @@ pub enum Error {
/// TrieDB-related error.
Trie(TrieError),
/// Database error
Database(String),
Database(kvdb::Error),
/// Util error
Util(UtilError),
}

View File

@@ -38,7 +38,7 @@ pub enum EvmTestError {
/// Initialization error.
ClientError(::error::Error),
/// Low-level database error.
Database(String),
Database(kvdb::Error),
/// Post-condition failure,
PostCondition(String),
}

View File

@@ -23,7 +23,7 @@ use bigint::hash::H256;
use util::Address;
use bytes::Bytes;
use kvdb_rocksdb::Database;
use migration::{Batch, Config, Error, Migration, SimpleMigration, Progress};
use migration::{Batch, Config, Error, ErrorKind, Migration, SimpleMigration, Progress};
use hash::keccak;
use std::sync::Arc;
@@ -109,7 +109,7 @@ impl OverlayRecentV7 {
// walk all journal entries in the database backwards.
// find migrations for any possible inserted keys.
fn walk_journal(&mut self, source: Arc<Database>) -> Result<(), Error> {
if let Some(val) = source.get(None, V7_LATEST_ERA_KEY).map_err(Error::Custom)? {
if let Some(val) = source.get(None, V7_LATEST_ERA_KEY)? {
let mut era = decode::<u64>(&val);
loop {
let mut index: usize = 0;
@@ -120,7 +120,7 @@ impl OverlayRecentV7 {
r.out()
};
if let Some(journal_raw) = source.get(None, &entry_key).map_err(Error::Custom)? {
if let Some(journal_raw) = source.get(None, &entry_key)? {
let rlp = Rlp::new(&journal_raw);
// migrate all inserted keys.
@@ -153,7 +153,7 @@ impl OverlayRecentV7 {
// replace all possible inserted/deleted keys with their migrated counterparts
// and commit the altered entries.
fn migrate_journal(&self, source: Arc<Database>, mut batch: Batch, dest: &mut Database) -> Result<(), Error> {
if let Some(val) = source.get(None, V7_LATEST_ERA_KEY).map_err(Error::Custom)? {
if let Some(val) = source.get(None, V7_LATEST_ERA_KEY)? {
batch.insert(V7_LATEST_ERA_KEY.into(), val.clone().into_vec(), dest)?;
let mut era = decode::<u64>(&val);
@@ -166,7 +166,7 @@ impl OverlayRecentV7 {
r.out()
};
if let Some(journal_raw) = source.get(None, &entry_key).map_err(Error::Custom)? {
if let Some(journal_raw) = source.get(None, &entry_key)? {
let rlp = Rlp::new(&journal_raw);
let id: H256 = rlp.val_at(0);
let mut inserted_keys: Vec<(H256, Bytes)> = Vec::new();
@@ -233,9 +233,9 @@ impl Migration for OverlayRecentV7 {
let mut batch = Batch::new(config, col);
// check version metadata.
match source.get(None, V7_VERSION_KEY).map_err(Error::Custom)? {
match source.get(None, V7_VERSION_KEY)? {
Some(ref version) if decode::<u32>(&*version) == DB_VERSION => {}
_ => return Err(Error::MigrationImpossible), // missing or wrong version
_ => return Err(ErrorKind::MigrationImpossible.into()), // missing or wrong version
}
let mut count = 0;

View File

@@ -22,11 +22,11 @@ use state_db::{ACCOUNT_BLOOM_SPACE, DEFAULT_ACCOUNT_PRESET, StateDB};
use trie::TrieDB;
use views::HeaderView;
use bloom_journal::Bloom;
use migration::{Error, Migration, Progress, Batch, Config};
use migration::{Error, Migration, Progress, Batch, Config, ErrorKind};
use util::journaldb;
use bigint::hash::H256;
use trie::Trie;
use kvdb::DBTransaction;
use kvdb::{DBTransaction, ResultExt};
use kvdb_rocksdb::Database;
/// Account bloom upgrade routine. If bloom already present, does nothing.
@@ -60,9 +60,9 @@ pub fn generate_bloom(source: Arc<Database>, dest: &mut Database) -> Result<(),
source.clone(),
journaldb::Algorithm::OverlayRecent,
COL_STATE);
let account_trie = TrieDB::new(state_db.as_hashdb(), &state_root).map_err(|e| Error::Custom(format!("Cannot open trie: {:?}", e)))?;
for item in account_trie.iter().map_err(|_| Error::MigrationImpossible)? {
let (ref account_key, _) = item.map_err(|_| Error::MigrationImpossible)?;
let account_trie = TrieDB::new(state_db.as_hashdb(), &state_root).chain_err(|| "Cannot open trie")?;
for item in account_trie.iter().map_err(|_| ErrorKind::MigrationImpossible)? {
let (ref account_key, _) = item.map_err(|_| ErrorKind::MigrationImpossible)?;
let account_key_hash = H256::from_slice(account_key);
bloom.set(&*account_key_hash);
}
@@ -73,7 +73,7 @@ pub fn generate_bloom(source: Arc<Database>, dest: &mut Database) -> Result<(),
trace!(target: "migration", "Generated {} bloom updates", bloom_journal.entries.len());
let mut batch = DBTransaction::new();
StateDB::commit_bloom(&mut batch, bloom_journal).map_err(|_| Error::Custom("Failed to commit bloom".to_owned()))?;
StateDB::commit_bloom(&mut batch, bloom_journal).chain_err(|| "Failed to commit bloom")?;
dest.write(batch)?;
trace!(target: "migration", "Finished bloom update");