Skip to main content

truncate_tail

Function truncate_tail 

Source
pub fn truncate_tail(path: &Path) -> Result<Option<Repaired>, LogError>
Expand description

Moves an unterminated final record into a sidecar and truncates the log to the last complete one.

The bytes are copied out before the file is cut, in that order, and the sidecar is synced before the truncation is issued. If the machine stops midway the worst case is a sidecar with no truncation – a spare copy of bytes that are still in the log – rather than a truncation with no sidecar, which would be the deletion this is written to avoid.

§Errors

LogError::Corrupt if the log has a fault that is not a torn tail. Refusing is the whole point: a mid-log break cannot be repaired by removing the end of the file, and doing it anyway would silently drop acknowledged ops. LogError::Io on filesystem failure.