abort GC on server shutdown

This commit is contained in:
Dietmar Maurer 2019-04-01 12:13:02 +02:00
parent 9136f857cc
commit 92da93b245
5 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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)?;

View File

@ -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 {:?} - {}",

View File

@ -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 {:?} - {}",

View File

@ -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(())
}