Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report warning and possible cause if metadata cleanup fails #1554

Merged
merged 1 commit into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions snakemake/persistence.py
Expand Up @@ -186,7 +186,7 @@ def cleanup_locks(self):
shutil.rmtree(self._lockdir)

def cleanup_metadata(self, path):
self._delete_record(self._metadata_path, path)
return self._delete_record(self._metadata_path, path)

def cleanup_shadow(self):
if os.path.exists(self.shadow_path):
Expand Down Expand Up @@ -403,9 +403,14 @@ def _delete_record(self, subject, id):
recdirs = os.path.relpath(os.path.dirname(recpath), start=subject)
if recdirs != ".":
os.removedirs(recdirs)
return True
except OSError as e:
if e.errno != 2: # not missing
if e.errno != 2:
# not missing
raise e
else:
# file is missing, report failure
return False

@lru_cache()
def _read_record_cached(self, subject, id):
Expand Down
12 changes: 11 additions & 1 deletion snakemake/workflow.py
Expand Up @@ -764,8 +764,18 @@ def files(items):
self.persistence.deactivate_cache()

if cleanup_metadata:
failed = []
for f in cleanup_metadata:
self.persistence.cleanup_metadata(f)
success = self.persistence.cleanup_metadata(f)
if not success:
failed.append(f)
if failed:
logger.warning(
"Failed to clean up metadata for the following files because the metadata was not present.\n"
"If this is expected, there is nothing to do.\nOtherwise, the reason might be file system latency "
"or still running jobs.\nConsider running metadata cleanup again.\nFiles:\n"
+ "\n".join(failed)
)
return True

if unlock:
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.py
Expand Up @@ -1589,3 +1589,7 @@ def test_github_issue1500():

def test_github_issue1542():
run(dpath("test_github_issue1542"), dryrun=True)


def test_cleanup_metadata_fail():
run(dpath("test09"), cleanup_metadata=["xyz"])