remove impossible panickers related to infallible db transaction (#1947)

This commit is contained in:
Robert Habermeier
2016-08-18 09:43:56 +02:00
committed by Gav Wood
parent 108024e98d
commit 57dbdaada9
12 changed files with 60 additions and 68 deletions

View File

@@ -164,7 +164,7 @@ impl JournalDB for ArchiveDB {
let (key, (value, rc)) = i;
if rc > 0 {
assert!(rc == 1);
batch.put(self.column, &key, &value).expect("Low-level database error. Some issue with your hard disk?");
batch.put(self.column, &key, &value);
inserts += 1;
}
if rc < 0 {
@@ -175,11 +175,11 @@ impl JournalDB for ArchiveDB {
for (mut key, value) in self.overlay.drain_aux().into_iter() {
key.push(AUX_FLAG);
batch.put(self.column, &key, &value).expect("Low-level database error. Some issue with your hard disk?");
batch.put(self.column, &key, &value);
}
if self.latest_era.map_or(true, |e| now > e) {
try!(batch.put(self.column, &LATEST_ERA_KEY, &encode(&now)));
batch.put(self.column, &LATEST_ERA_KEY, &encode(&now));
self.latest_era = Some(now);
}
Ok((inserts + deletes) as u32)
@@ -196,7 +196,7 @@ impl JournalDB for ArchiveDB {
if try!(self.backing.get(self.column, &key)).is_some() {
return Err(BaseDataError::AlreadyExists(key).into());
}
try!(batch.put(self.column, &key, &value));
batch.put(self.column, &key, &value);
inserts += 1;
}
if rc < 0 {
@@ -204,14 +204,14 @@ impl JournalDB for ArchiveDB {
if try!(self.backing.get(self.column, &key)).is_none() {
return Err(BaseDataError::NegativelyReferencedHash(key).into());
}
try!(batch.delete(self.column, &key));
batch.delete(self.column, &key);
deletes += 1;
}
}
for (mut key, value) in self.overlay.drain_aux().into_iter() {
key.push(AUX_FLAG);
try!(batch.put(self.column, &key, &value));
batch.put(self.column, &key, &value);
}
Ok((inserts + deletes) as u32)

View File

@@ -101,8 +101,8 @@ impl EarlyMergeDB {
}
// The next three are valid only as long as there is an insert operation of `key` in the journal.
fn set_already_in(batch: &DBTransaction, col: Option<u32>, key: &H256) { batch.put(col, &Self::morph_key(key, 0), &[1u8]).expect("Low-level database error. Some issue with your hard disk?"); }
fn reset_already_in(batch: &DBTransaction, col: Option<u32>, key: &H256) { batch.delete(col, &Self::morph_key(key, 0)).expect("Low-level database error. Some issue with your hard disk?"); }
fn set_already_in(batch: &DBTransaction, col: Option<u32>, key: &H256) { batch.put(col, &Self::morph_key(key, 0), &[1u8]); }
fn reset_already_in(batch: &DBTransaction, col: Option<u32>, key: &H256) { batch.delete(col, &Self::morph_key(key, 0)); }
fn is_already_in(backing: &Database, col: Option<u32>, key: &H256) -> bool {
backing.get(col, &Self::morph_key(key, 0)).expect("Low-level database error. Some issue with your hard disk?").is_some()
}
@@ -132,7 +132,7 @@ impl EarlyMergeDB {
// Gets removed when a key leaves the journal, so should never be set when we're placing a new key.
//Self::reset_already_in(&h);
assert!(!Self::is_already_in(backing, col, &h));
batch.put(col, h, d).expect("Low-level database error. Some issue with your hard disk?");
batch.put(col, h, d);
refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: false});
if trace {
trace!(target: "jdb.fine", " insert({}): New to queue, not in DB: Inserting into queue and DB", h);
@@ -193,7 +193,7 @@ impl EarlyMergeDB {
}
Some(RefInfo{queue_refs: 1, in_archive: false}) => {
refs.remove(h);
batch.delete(col, h).expect("Low-level database error. Some issue with your hard disk?");
batch.delete(col, h);
if trace {
trace!(target: "jdb.fine", " remove({}): Not in archive, only 1 ref in queue: Removing from queue and DB", h);
}
@@ -201,7 +201,7 @@ impl EarlyMergeDB {
None => {
// Gets removed when moving from 1 to 0 additional refs. Should never be here at 0 additional refs.
//assert!(!Self::is_already_in(db, &h));
batch.delete(col, h).expect("Low-level database error. Some issue with your hard disk?");
batch.delete(col, h);
if trace {
trace!(target: "jdb.fine", " remove({}): Not in queue - MUST BE IN ARCHIVE: Removing from DB", h);
}
@@ -436,9 +436,9 @@ impl JournalDB for EarlyMergeDB {
trace!(target: "jdb.ops", " Inserts: {:?}", ins);
trace!(target: "jdb.ops", " Deletes: {:?}", removes);
}
try!(batch.put(self.column, &last, r.as_raw()));
batch.put(self.column, &last, r.as_raw());
if self.latest_era.map_or(true, |e| now > e) {
try!(batch.put(self.column, &LATEST_ERA_KEY, &encode(&now)));
batch.put(self.column, &LATEST_ERA_KEY, &encode(&now));
self.latest_era = Some(now);
}
}
@@ -499,7 +499,7 @@ impl JournalDB for EarlyMergeDB {
Self::remove_keys(&inserts, &mut refs, batch, self.column, RemoveFrom::Queue, trace);
}
try!(batch.delete(self.column, &last));
batch.delete(self.column, &last);
index += 1;
}
if trace {
@@ -525,13 +525,13 @@ impl JournalDB for EarlyMergeDB {
if try!(self.backing.get(self.column, &key)).is_some() {
return Err(BaseDataError::AlreadyExists(key).into());
}
try!(batch.put(self.column, &key, &value))
batch.put(self.column, &key, &value)
}
-1 => {
if try!(self.backing.get(self.column, &key)).is_none() {
return Err(BaseDataError::NegativelyReferencedHash(key).into());
}
try!(batch.delete(self.column, &key))
batch.delete(self.column, &key)
}
_ => panic!("Attempted to inject invalid state."),
}

View File

@@ -250,9 +250,9 @@ impl JournalDB for OverlayRecentDB {
k.append(&now);
k.append(&index);
k.append(&&PADDING[..]);
try!(batch.put_vec(self.column, &k.drain(), r.out()));
batch.put_vec(self.column, &k.drain(), r.out());
if journal_overlay.latest_era.map_or(true, |e| now > e) {
try!(batch.put_vec(self.column, &LATEST_ERA_KEY, encode(&now).to_vec()));
batch.put_vec(self.column, &LATEST_ERA_KEY, encode(&now).to_vec());
journal_overlay.latest_era = Some(now);
}
journal_overlay.journal.entry(now).or_insert_with(Vec::new).push(JournalEntry { id: id.clone(), insertions: inserted_keys, deletions: removed_keys });
@@ -272,7 +272,7 @@ impl JournalDB for OverlayRecentDB {
r.append(&end_era);
r.append(&index);
r.append(&&PADDING[..]);
try!(batch.delete(self.column, &r.drain()));
batch.delete(self.column, &r.drain());
trace!("commit: Delete journal for time #{}.{}: {}, (canon was {}): +{} -{} entries", end_era, index, journal.id, canon_id, journal.insertions.len(), journal.deletions.len());
{
if canon_id == journal.id {
@@ -291,7 +291,7 @@ impl JournalDB for OverlayRecentDB {
}
// apply canon inserts first
for (k, v) in canon_insertions {
try!(batch.put(self.column, &k, &v));
batch.put(self.column, &k, &v);
journal_overlay.pending_overlay.insert(to_short_key(&k), v);
}
// update the overlay
@@ -301,7 +301,7 @@ impl JournalDB for OverlayRecentDB {
// apply canon deletions
for k in canon_deletions {
if !journal_overlay.backing_overlay.contains(&to_short_key(&k)) {
try!(batch.delete(self.column, &k));
batch.delete(self.column, &k);
}
}
}
@@ -325,13 +325,13 @@ impl JournalDB for OverlayRecentDB {
if try!(self.backing.get(self.column, &key)).is_some() {
return Err(BaseDataError::AlreadyExists(key).into());
}
try!(batch.put(self.column, &key, &value))
batch.put(self.column, &key, &value)
}
-1 => {
if try!(self.backing.get(self.column, &key)).is_none() {
return Err(BaseDataError::NegativelyReferencedHash(key).into());
}
try!(batch.delete(self.column, &key))
batch.delete(self.column, &key)
}
_ => panic!("Attempted to inject invalid state."),
}

View File

@@ -141,7 +141,7 @@ impl JournalDB for RefCountedDB {
r.append(id);
r.append(&self.inserts);
r.append(&self.removes);
try!(batch.put(self.column, &last, r.as_raw()));
batch.put(self.column, &last, r.as_raw());
trace!(target: "rcdb", "new journal for time #{}.{} => {}: inserts={:?}, removes={:?}", now, index, id, self.inserts, self.removes);
@@ -149,7 +149,7 @@ impl JournalDB for RefCountedDB {
self.removes.clear();
if self.latest_era.map_or(true, |e| now > e) {
try!(batch.put(self.column, &LATEST_ERA_KEY, &encode(&now)));
batch.put(self.column, &LATEST_ERA_KEY, &encode(&now));
self.latest_era = Some(now);
}
}
@@ -176,7 +176,7 @@ impl JournalDB for RefCountedDB {
for i in &to_remove {
self.forward.remove(i);
}
try!(batch.delete(self.column, &last));
batch.delete(self.column, &last);
index += 1;
}
}