pub fn check_compact(&mut self, max_len: usize) -> io::Result<()> {
		if !(max_len > 0 && self.remove_log.len() > max_len
			|| max_len == 0 && self.remove_log.len() > RM_LOG_MAX_NODES)
		{
			return Ok(());
		}

		// 0. validate none of the nodes in the rm log are in the prune list (to
  // avoid accidental double compaction)
		for pos in &self.remove_log.removed[..] {
			if let None = self.pruned_nodes.pruned_pos(pos.0) {
				// TODO we likely can recover from this by directly jumping to 3
				error!(
					LOGGER,
					"The remove log contains nodes that are already in the pruned \
					 list, a previous compaction likely failed."
				);
				return Ok(());
			}
		}

		// 1. save hashsum file to a compact copy, skipping data that's in the
  // remove list
		let tmp_prune_file = format!("{}/{}.prune", self.data_dir, PMMR_DATA_FILE);
		let record_len = (32 + T::sum_len()) as u64;
		let to_rm = self.remove_log
			.removed
			.iter()
			.map(|&(pos, _)| {
				let shift = self.pruned_nodes.get_shift(pos);
				(pos - 1 - shift.unwrap()) * record_len
			})
			.collect();
		self.hashsum_file
			.save_prune(tmp_prune_file.clone(), to_rm, record_len)?;

		// 2. update the prune list and save it in place
		for &(rm_pos, _) in &self.remove_log.removed[..] {
			self.pruned_nodes.add(rm_pos);
		}
		write_vec(
			format!("{}/{}", self.data_dir, PMMR_PRUNED_FILE),
			&self.pruned_nodes.pruned_nodes,
		)?;

		// 3. move the compact copy to the hashsum file and re-open it
		fs::rename(
			tmp_prune_file.clone(),
			format!("{}/{}", self.data_dir, PMMR_DATA_FILE),
		)?;
		self.hashsum_file = AppendOnlyFile::open(format!("{}/{}", self.data_dir, PMMR_DATA_FILE))?;
		self.hashsum_file.sync()?;

		// 4. truncate the rm log
		self.remove_log.truncate(0)?;
		self.remove_log.flush()?;

		Ok(())
	}
/// Checks the length of the remove log to see if it should get compacted.
/// If so, the remove log is flushed into the pruned list, which itself gets
/// saved, and the main hashsum data file is rewritten, cutting the removed
/// data.
///
/// If a max_len strictly greater than 0 is provided, the value will be used
/// to decide whether the remove log has reached its maximum length,
/// otherwise the RM_LOG_MAX_NODES default value is used.
///
/// TODO whatever is calling this should also clean up the commit to
/// position index in db
Checks the length of the remove log to see if it should get compacted.
If so, the remove log is flushed into the pruned list, which itself gets
saved, and the main hashsum data file is rewritten, cutting the removed
data.

If a max_len strictly greater than 0 is provided, the value will be used
to decide whether the remove log has reached its maximum length,
otherwise the RM_LOG_MAX_NODES default value is used.


Checks the length of the remove log to see if it should get compacted . If so the remove log is flushed into the pruned list which itself gets saved and the main hashsum data file is rewritten cutting the removed data . If a max_len strictly greater than 0 is provided the value will be used to decide whether the remove log has reached its maximum length otherwise the RM_LOG_MAX_NODES default value is used .
pub fn check_compact(&mut self, max_len: usize) -> io::Result<()> {
		if !(max_len > 0 && self.remove_log.len() > max_len
			|| max_len == 0 && self.remove_log.len() > RM_LOG_MAX_NODES)
		{
			return Ok(());
		}
		// 0. validate none of the nodes in the rm log are in the prune list (to
  // avoid accidental double compaction)
		for pos in &self.remove_log.removed[..] {
			if let None = self.pruned_nodes.pruned_pos(pos.0) {
				// TODO we likely can recover from this by directly jumping to 3
				error!(
					LOGGER,
					"The remove log contains nodes that are already in the pruned \
					 list, a previous compaction likely failed."
				);
				return Ok(());
			}
		}
		// 1. save hashsum file to a compact copy, skipping data that's in the
  // remove list
		let tmp_prune_file = format!("{}/{}.prune", self.data_dir, PMMR_DATA_FILE);
		let record_len = (32 + T::sum_len()) as u64;
		let to_rm = self.remove_log
			.removed
			.iter()
			.map(|&(pos, _)| {
				let shift = self.pruned_nodes.get_shift(pos);
				(pos - 1 - shift.unwrap()) * record_len
			})
			.collect();
		self.hashsum_file
			.save_prune(tmp_prune_file.clone(), to_rm, record_len)?;
		// 2. update the prune list and save it in place
		for &(rm_pos, _) in &self.remove_log.removed[..] {
			self.pruned_nodes.add(rm_pos);
		}
		write_vec(
			format!("{}/{}", self.data_dir, PMMR_PRUNED_FILE),
			&self.pruned_nodes.pruned_nodes,
		)?;
		// 3. move the compact copy to the hashsum file and re-open it
		fs::rename(
			tmp_prune_file.clone(),
			format!("{}/{}", self.data_dir, PMMR_DATA_FILE),
		)?;
		self.hashsum_file = AppendOnlyFile::open(format!("{}/{}", self.data_dir, PMMR_DATA_FILE))?;
		self.hashsum_file.sync()?;
		// 4. truncate the rm log
		self.remove_log.truncate(0)?;
		self.remove_log.flush()?;
		Ok(())
	}
pub fn check_compact ( & mut self , max_len : usize ) -> io :: Result < ( ) > { if ! ( max_len > 0 && self . remove_log . len ( ) > max_len || max_len == 0 && self . remove_log . len ( ) > RM_LOG_MAX_NODES ) { return Ok ( ( ) ) ; } // 0. validate none of the nodes in the rm log are in the prune list (to // avoid accidental double compaction) for pos in & self . remove_log . removed [ .. ] { if let None = self . pruned_nodes . pruned_pos ( pos . 0 ) { // TODO we likely can recover from this by directly jumping to 3 error ! ( LOGGER " \
 " ) ; return Ok ( ( ) ) ; } } // 1. save hashsum file to a compact copy, skipping data that's in the // remove list let tmp_prune_file = format ! ( " " self data_dir PMMR_DATA_FILE ) ; let record_len = ( 32 + T :: sum_len ( ) ) as u64 ; let to_rm = self . remove_log . removed . iter ( ) . map ( | & ( pos , _ ) | { let shift = self . pruned_nodes . get_shift ( pos ) ; ( pos - 1 - shift . unwrap ( ) ) * record_len } ) . collect ( ) ; self . hashsum_file . save_prune ( tmp_prune_file . clone ( ) , to_rm , record_len ) ? ; // 2. update the prune list and save it in place for & ( rm_pos , _ ) in & self . remove_log . removed [ .. ] { self . pruned_nodes . add ( rm_pos ) ; } write_vec ( format ! ( " " self data_dir PMMR_PRUNED_FILE ) , & self . pruned_nodes . pruned_nodes , ) ? ; // 3. move the compact copy to the hashsum file and re-open it fs :: rename ( tmp_prune_file . clone ( ) , format ! ( " " self data_dir PMMR_DATA_FILE ) , ) ? ; self . hashsum_file = AppendOnlyFile :: open ( format ! ( " " self data_dir PMMR_DATA_FILE ) ) ? ; self . hashsum_file . sync ( ) ? ; // 4. truncate the rm log self . remove_log . truncate ( 0 ) ? ; self . remove_log . flush ( ) ? ; Ok ( ( ) ) }
Checks the length of the remove log to see if it should get compacted.
Checks the length of the remove log to see if it should get compacted .
&mut self
max_len
usize