Bring back batching.
This commit is contained in:
parent
0ccb9df4f1
commit
26f41b711c
@ -21,12 +21,13 @@ use network::NetworkError;
|
||||
use rlp::DecoderError;
|
||||
use io;
|
||||
use std::fmt;
|
||||
use hash::H256;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Error in database subsystem.
|
||||
pub enum BaseDataError {
|
||||
/// An entry was removed more times than inserted.
|
||||
NegativelyReferencedHash,
|
||||
NegativelyReferencedHash(H256),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -126,6 +126,7 @@ impl JournalDB for RefCountedDB {
|
||||
// of its inserts otherwise.
|
||||
|
||||
// record new commit's details.
|
||||
let batch = DBTransaction::new();
|
||||
{
|
||||
let mut index = 0usize;
|
||||
let mut last;
|
||||
@ -145,7 +146,7 @@ impl JournalDB for RefCountedDB {
|
||||
r.append(id);
|
||||
r.append(&self.inserts);
|
||||
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);
|
||||
|
||||
@ -153,7 +154,7 @@ impl JournalDB for RefCountedDB {
|
||||
self.removes.clear();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -180,12 +181,13 @@ impl JournalDB for RefCountedDB {
|
||||
for i in &to_remove {
|
||||
self.forward.remove(i);
|
||||
}
|
||||
try!(self.backing.delete(&last));
|
||||
try!(batch.delete(&last));
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let r = try!(self.forward.commit());
|
||||
let r = try!(self.forward.commit_to_batch(&batch));
|
||||
try!(self.backing.write(batch));
|
||||
Ok(r)
|
||||
}
|
||||
}
|
||||
|
@ -70,15 +70,13 @@ impl OverlayDB {
|
||||
let (back_value, back_rc) = x;
|
||||
let total_rc: i32 = back_rc as i32 + rc;
|
||||
if total_rc < 0 {
|
||||
warn!("NEGATIVELY REFERENCED HASH {:?}", key);
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash));
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
|
||||
}
|
||||
deletes += if self.put_payload_in_batch(batch, &key, (back_value, total_rc as u32)) {1} else {0};
|
||||
}
|
||||
None => {
|
||||
if rc < 0 {
|
||||
warn!("NEGATIVELY REFERENCED HASH {:?}", key);
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash));
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
|
||||
}
|
||||
self.put_payload_in_batch(batch, &key, (value, rc as u32));
|
||||
}
|
||||
@ -128,15 +126,13 @@ impl OverlayDB {
|
||||
let (back_value, back_rc) = x;
|
||||
let total_rc: i32 = back_rc as i32 + rc;
|
||||
if total_rc < 0 {
|
||||
warn!("NEGATIVELY REFERENCED HASH {:?}", key);
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash));
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
|
||||
}
|
||||
deletes += if self.put_payload(&key, (back_value, total_rc as u32)) {1} else {0};
|
||||
}
|
||||
None => {
|
||||
if rc < 0 {
|
||||
warn!("NEGATIVELY REFERENCED HASH {:?}", key);
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash));
|
||||
return Err(From::from(BaseDataError::NegativelyReferencedHash(key)));
|
||||
}
|
||||
self.put_payload(&key, (value, rc as u32));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user