Avoid batches for now.

This commit is contained in:
Gav Wood 2016-03-13 19:22:42 +01:00
parent 706c56f56a
commit 81291622eb
4 changed files with 52 additions and 12 deletions

View File

@ -427,9 +427,9 @@ impl Configuration {
} }
client_config.pruning = match self.args.flag_pruning.as_str() { client_config.pruning = match self.args.flag_pruning.as_str() {
"" | "archive" => journaldb::Algorithm::Archive, "" | "archive" => journaldb::Algorithm::Archive,
"pruned" => journaldb::Algorithm::EarlyMerge, "light" => journaldb::Algorithm::EarlyMerge,
"fast" => journaldb::Algorithm::OverlayRecent, "fast" => journaldb::Algorithm::OverlayRecent,
"slow" => journaldb::Algorithm::RefCounted, "basic" => journaldb::Algorithm::RefCounted,
_ => { die!("Invalid pruning method given."); } _ => { die!("Invalid pruning method given."); }
}; };
client_config.name = self.args.flag_identity.clone(); client_config.name = self.args.flag_identity.clone();

View File

@ -132,7 +132,7 @@ impl JournalDB for ArchiveDB {
Box::new(ArchiveDB { Box::new(ArchiveDB {
overlay: MemoryDB::new(), overlay: MemoryDB::new(),
backing: self.backing.clone(), backing: self.backing.clone(),
latest_era: None, latest_era: self.latest_era,
}) })
} }
@ -144,7 +144,7 @@ impl JournalDB for ArchiveDB {
self.latest_era.is_none() self.latest_era.is_none()
} }
fn commit(&mut self, _: u64, _: &H256, _: Option<(u64, H256)>) -> Result<u32, UtilError> { fn commit(&mut self, now: u64, _: &H256, _: Option<(u64, H256)>) -> Result<u32, UtilError> {
let batch = DBTransaction::new(); let batch = DBTransaction::new();
let mut inserts = 0usize; let mut inserts = 0usize;
let mut deletes = 0usize; let mut deletes = 0usize;
@ -160,6 +160,10 @@ impl JournalDB for ArchiveDB {
deletes += 1; deletes += 1;
} }
} }
if self.latest_era.map_or(true, |e| now > e) {
try!(batch.put(&LATEST_ERA_KEY, &encode(&now)));
self.latest_era = Some(now);
}
try!(self.backing.write(batch)); try!(self.backing.write(batch));
Ok((inserts + deletes) as u32) Ok((inserts + deletes) as u32)
} }

View File

@ -176,7 +176,7 @@ impl JournalDB for RefCountedDB {
} }
} }
let r = try!(self.forward.commit_to_batch(&batch)); let r = try!(self.forward.commit());
try!(self.backing.write(batch)); try!(self.backing.write(batch));
Ok(r) Ok(r)
} }

View File

@ -72,13 +72,13 @@ impl OverlayDB {
if total_rc < 0 { if total_rc < 0 {
return Err(From::from(BaseDataError::NegativelyReferencedHash)); return Err(From::from(BaseDataError::NegativelyReferencedHash));
} }
deletes += if self.put_payload(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 {
return Err(From::from(BaseDataError::NegativelyReferencedHash)); return Err(From::from(BaseDataError::NegativelyReferencedHash));
} }
self.put_payload(batch, &key, (value, rc as u32)); self.put_payload_in_batch(batch, &key, (value, rc as u32));
} }
}; };
ret += 1; ret += 1;
@ -116,10 +116,32 @@ impl OverlayDB {
/// } /// }
/// ``` /// ```
pub fn commit(&mut self) -> Result<u32, UtilError> { pub fn commit(&mut self) -> Result<u32, UtilError> {
let batch = DBTransaction::new(); let mut ret = 0u32;
let r = try!(self.commit_to_batch(&batch)); let mut deletes = 0usize;
try!(self.backing.write(batch)); for i in self.overlay.drain().into_iter() {
Ok(r) let (key, (value, rc)) = i;
if rc != 0 {
match self.payload(&key) {
Some(x) => {
let (back_value, back_rc) = x;
let total_rc: i32 = back_rc as i32 + rc;
if total_rc < 0 {
return Err(From::from(BaseDataError::NegativelyReferencedHash));
}
deletes += if self.put_payload(&key, (back_value, total_rc as u32)) {1} else {0};
}
None => {
if rc < 0 {
return Err(From::from(BaseDataError::NegativelyReferencedHash));
}
self.put_payload(&key, (value, rc as u32));
}
};
ret += 1;
}
}
trace!("OverlayDB::commit() deleted {} nodes", deletes);
Ok(ret)
} }
/// Revert all operations on this object (i.e. `insert()`s and `kill()`s) since the /// Revert all operations on this object (i.e. `insert()`s and `kill()`s) since the
@ -156,7 +178,7 @@ impl OverlayDB {
} }
/// Put the refs and value of the given key, possibly deleting it from the db. /// Put the refs and value of the given key, possibly deleting it from the db.
fn put_payload(&self, batch: &DBTransaction, key: &H256, payload: (Bytes, u32)) -> bool { fn put_payload_in_batch(&self, batch: &DBTransaction, key: &H256, payload: (Bytes, u32)) -> bool {
if payload.1 > 0 { if payload.1 > 0 {
let mut s = RlpStream::new_list(2); let mut s = RlpStream::new_list(2);
s.append(&payload.1); s.append(&payload.1);
@ -168,6 +190,20 @@ impl OverlayDB {
true true
} }
} }
/// Put the refs and value of the given key, possibly deleting it from the db.
fn put_payload(&self, key: &H256, payload: (Bytes, u32)) -> bool {
if payload.1 > 0 {
let mut s = RlpStream::new_list(2);
s.append(&payload.1);
s.append(&payload.0);
self.backing.put(&key.bytes(), s.as_raw()).expect("Low-level database error. Some issue with your hard disk?");
false
} else {
self.backing.delete(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?");
true
}
}
} }
impl HashDB for OverlayDB { impl HashDB for OverlayDB {