abort GC on server shutdown
This commit is contained in:
		@ -271,6 +271,9 @@ impl ChunkStore {
 | 
			
		||||
        min_atime -= 300; // add 5 mins gap for safety
 | 
			
		||||
 | 
			
		||||
        for entry in self.get_chunk_iterator(true)? {
 | 
			
		||||
 | 
			
		||||
            tools::fail_on_shutdown()?;
 | 
			
		||||
 | 
			
		||||
            let (dirfd, entry) = match entry {
 | 
			
		||||
                Ok(entry) => (entry.parent_fd(), entry),
 | 
			
		||||
                Err(_) => continue, // ignore errors
 | 
			
		||||
 | 
			
		||||
@ -209,6 +209,9 @@ impl DataStore {
 | 
			
		||||
        let image_list = self.list_images()?;
 | 
			
		||||
 | 
			
		||||
        for path in image_list {
 | 
			
		||||
 | 
			
		||||
            tools::fail_on_shutdown()?;
 | 
			
		||||
 | 
			
		||||
            if let Some(ext) = path.extension() {
 | 
			
		||||
                if ext == "fidx" {
 | 
			
		||||
                    let index = self.open_fixed_reader(&path)?;
 | 
			
		||||
 | 
			
		||||
@ -149,6 +149,9 @@ impl DynamicIndexReader {
 | 
			
		||||
    pub fn mark_used_chunks(&self, _status: &mut GarbageCollectionStatus) -> Result<(), Error> {
 | 
			
		||||
 | 
			
		||||
        for pos in 0..self.index_entries {
 | 
			
		||||
 | 
			
		||||
            tools::fail_on_shutdown()?;
 | 
			
		||||
 | 
			
		||||
            let digest = self.chunk_digest(pos);
 | 
			
		||||
            if let Err(err) = self.store.touch_chunk(digest) {
 | 
			
		||||
                bail!("unable to access chunk {}, required by {:?} - {}",
 | 
			
		||||
 | 
			
		||||
@ -147,6 +147,8 @@ impl FixedIndexReader {
 | 
			
		||||
 | 
			
		||||
        for pos in 0..index_count {
 | 
			
		||||
 | 
			
		||||
            tools::fail_on_shutdown()?;
 | 
			
		||||
 | 
			
		||||
            let digest = self.index_digest(pos).unwrap();
 | 
			
		||||
            if let Err(err) = self.store.touch_chunk(digest) {
 | 
			
		||||
                bail!("unable to access chunk {}, required by {:?} - {}",
 | 
			
		||||
 | 
			
		||||
@ -557,3 +557,10 @@ pub fn request_shutdown() {
 | 
			
		||||
pub fn shutdown_requested() -> bool {
 | 
			
		||||
    unsafe { SHUTDOWN_REQUESTED }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn fail_on_shutdown() -> Result<(), Error> {
 | 
			
		||||
    if shutdown_requested() {
 | 
			
		||||
        bail!("Server shutdown requested - aborting task");
 | 
			
		||||
    }
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user