Bring back batching.

This commit is contained in:
Gav Wood 2016-03-13 21:54:06 +01:00
parent 0ccb9df4f1
commit 26f41b711c
3 changed files with 12 additions and 13 deletions

View File

@ -21,12 +21,13 @@ use network::NetworkError;
use rlp::DecoderError; use rlp::DecoderError;
use io; use io;
use std::fmt; use std::fmt;
use hash::H256;
#[derive(Debug)] #[derive(Debug)]
/// Error in database subsystem. /// Error in database subsystem.
pub enum BaseDataError { pub enum BaseDataError {
/// An entry was removed more times than inserted. /// An entry was removed more times than inserted.
NegativelyReferencedHash, NegativelyReferencedHash(H256),
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -126,6 +126,7 @@ impl JournalDB for RefCountedDB {
// of its inserts otherwise. // of its inserts otherwise.
// record new commit's details. // record new commit's details.
let batch = DBTransaction::new();
{ {
let mut index = 0usize; let mut index = 0usize;
let mut last; let mut last;
@ -145,7 +146,7 @@ impl JournalDB for RefCountedDB {
r.append(id); r.append(id);
r.append(&self.inserts); r.append(&self.inserts);
r.append(&self.removes); r.append(&self.removes);
try!(self.backing.put(&last, r.as_raw())); try!(batch.put(&last, r.as_raw()));
trace!(target: "rcdb", "new journal for time #{}.{} => {}: inserts={:?}, removes={:?}", now, index, id, self.inserts, self.removes); trace!(target: "rcdb", "new journal for time #{}.{} => {}: inserts={:?}, removes={:?}", now, index, id, self.inserts, self.removes);
@ -153,7 +154,7 @@ impl JournalDB for RefCountedDB {
self.removes.clear(); self.removes.clear();
if self.latest_era.map_or(true, |e| now > e) { if self.latest_era.map_or(true, |e| now > e) {
try!(self.backing.put(&LATEST_ERA_KEY, &encode(&now))); try!(batch.put(&LATEST_ERA_KEY, &encode(&now)));
self.latest_era = Some(now); self.latest_era = Some(now);
} }
} }
@ -180,12 +181,13 @@ impl JournalDB for RefCountedDB {
for i in &to_remove { for i in &to_remove {
self.forward.remove(i); self.forward.remove(i);
} }
try!(self.backing.delete(&last)); try!(batch.delete(&last));
index += 1; index += 1;
} }
} }
let r = try!(self.forward.commit()); let r = try!(self.forward.commit_to_batch(&batch));
try!(self.backing.write(batch));
Ok(r) Ok(r)
} }
} }

View File

@ -70,15 +70,13 @@ impl OverlayDB {
let (back_value, back_rc) = x; let (back_value, back_rc) = x;
let total_rc: i32 = back_rc as i32 + rc; let total_rc: i32 = back_rc as i32 + rc;
if total_rc < 0 { if total_rc < 0 {
warn!("NEGATIVELY REFERENCED HASH {:?}", key); return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
return Err(From::from(BaseDataError::NegativelyReferencedHash));
} }
deletes += if self.put_payload_in_batch(batch, &key, (back_value, total_rc as u32)) {1} else {0}; deletes += if self.put_payload_in_batch(batch, &key, (back_value, total_rc as u32)) {1} else {0};
} }
None => { None => {
if rc < 0 { if rc < 0 {
warn!("NEGATIVELY REFERENCED HASH {:?}", key); return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
return Err(From::from(BaseDataError::NegativelyReferencedHash));
} }
self.put_payload_in_batch(batch, &key, (value, rc as u32)); self.put_payload_in_batch(batch, &key, (value, rc as u32));
} }
@ -128,15 +126,13 @@ impl OverlayDB {
let (back_value, back_rc) = x; let (back_value, back_rc) = x;
let total_rc: i32 = back_rc as i32 + rc; let total_rc: i32 = back_rc as i32 + rc;
if total_rc < 0 { if total_rc < 0 {
warn!("NEGATIVELY REFERENCED HASH {:?}", key); return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
return Err(From::from(BaseDataError::NegativelyReferencedHash));
} }
deletes += if self.put_payload(&key, (back_value, total_rc as u32)) {1} else {0}; deletes += if self.put_payload(&key, (back_value, total_rc as u32)) {1} else {0};
} }
None => { None => {
if rc < 0 { if rc < 0 {
warn!("NEGATIVELY REFERENCED HASH {:?}", key); return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
return Err(From::from(BaseDataError::NegativelyReferencedHash));
} }
self.put_payload(&key, (value, rc as u32)); self.put_payload(&key, (value, rc as u32));
} }