Skip to content

Commit

Permalink
Clean logs using the usual process even in case of replay or db failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Oct 17, 2022
1 parent ca04149 commit fdf50e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl DbInner {
Ok(reader) => reader,
Err(Error::Corruption(_)) if validation_mode => {
log::debug!(target: "parity-db", "Bad log header");
self.log.clear_replay_logs()?;
self.log.clear_replay_logs();
return Ok(false)
},
Err(e) => return Err(e),
Expand All @@ -539,7 +539,7 @@ impl DbInner {
reader.record_id(),
);
drop(reader);
self.log.clear_replay_logs()?;
self.log.clear_replay_logs();
return Ok(false)
}
// Validate all records before applying anything
Expand All @@ -549,15 +549,15 @@ impl DbInner {
Err(e) => {
log::debug!(target: "parity-db", "Error reading log: {:?}", e);
drop(reader);
self.log.clear_replay_logs()?;
self.log.clear_replay_logs();
return Ok(false)
},
};
match next {
LogAction::BeginRecord => {
log::debug!(target: "parity-db", "Unexpected log header");
drop(reader);
self.log.clear_replay_logs()?;
self.log.clear_replay_logs();
return Ok(false)
},
LogAction::EndRecord => break,
Expand All @@ -574,7 +574,7 @@ impl DbInner {
) {
log::warn!(target: "parity-db", "Error replaying log: {:?}. Reverting", e);
drop(reader);
self.log.clear_replay_logs()?;
self.log.clear_replay_logs();
return Ok(false)
}
},
Expand All @@ -591,7 +591,7 @@ impl DbInner {
) {
log::warn!(target: "parity-db", "Error replaying log: {:?}. Reverting", e);
drop(reader);
self.log.clear_replay_logs()?;
self.log.clear_replay_logs();
return Ok(false)
}
},
Expand Down Expand Up @@ -741,7 +741,7 @@ impl DbInner {
// On error the log reader may be left in inconsistent state. So it is important
// to no attempt any further log enactment.
log::debug!(target: "parity-db", "Shutdown with error state {}", err);
return Ok(())
return self.log.kill_logs()
}
}
log::debug!(target: "parity-db", "Processing leftover commits");
Expand Down Expand Up @@ -1401,7 +1401,7 @@ enum OpeningMode {

#[cfg(test)]
mod tests {
use crate::{ColumnOptions, Value};
use crate::{ColumnOptions, Operation, Value};

use super::{Db, Options};
use crate::{
Expand Down
20 changes: 5 additions & 15 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,29 +580,19 @@ impl Log {
Ok(())
}

pub fn clear_replay_logs(&self) -> Result<()> {
{
let mut reading = self.reading.write();
let id = reading.as_ref().map(|r| r.id);
*reading = None;
if let Some(id) = id {
self.drop_log(id)?;
}
pub fn clear_replay_logs(&self) {
if let Some(reading) = self.reading.write().take() {
self.cleanup_queue.write().push_back((reading.id, reading.file.into_inner()));
}
{
let replay_logs = std::mem::take(&mut *self.replay_queue.write());
for (id, _, file) in replay_logs {
drop(file);
self.drop_log(id)?;
}
for (id, _, file) in self.replay_queue.write().drain(0..) {
self.cleanup_queue.write().push_back((id, file));
}
let mut overlays = self.overlays.write();
overlays.index.clear();
overlays.value.clear();
overlays.last_record_id.clear();
*self.reading_state.lock() = ReadingState::Idle;
self.dirty.store(false, Ordering::Relaxed);
Ok(())
}

pub fn begin_record(&self) -> LogWriter<'_> {
Expand Down

0 comments on commit fdf50e7

Please sign in to comment.