-
-
Notifications
You must be signed in to change notification settings - Fork 29
Delete git/RO directories when not needed, delete old files/dirs in cron #426
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
Conversation
Note to self: confirm we are deleting these files when they are no longer necessary, and not too early. |
888269b
to
9516d2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still in draft as I want to see if we can have unit tests — it's hard to mock some I/O features, not sure if testing is easy/feasible for deleting files, especially by age. I also need to do some more manual testing on my environment 👍
But I think it's going in the right direction! The GitHub issues regarding temporary files and directories appear to date from about 2 years ago. Hopefully we will be able to close these issues in the next release. 🤞
List<String> temporaryDirectories = Stream.of(bundleStorage, graphvizStorage, gitStorage) | ||
.distinct() | ||
.toList(); | ||
temporaryDirectories.forEach(this::clearDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mr-c , @tetron , this change should delete all files older than a certain limit from the server.
But I was thinking, maybe we want to keep the files from the workflows listed in the first page of the CWL Viewer app (or two first, or three first pages, or first 15 workflows, etc.)?
I can probably use the same code used when you visit "Explore", but requesting just one page or a certain number of workflows. Then I would get the git and RO directories locations from the PostgreSQL table and skip these.
Or is that a bit too much? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the ROs but delete the old Git checkouts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Do you mean keep all the ROs, or just the ones in the first page of the workflows listing?
I was going to send a screenshot of the first page, but the server appears to be unwell again.
I'll leave a message on the Matrix CWLViewer and in some room at Curii to see if someone can kick that server or container, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much disk space do the ROs take up? An estimate based upon some "typical" ROs is fine as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, cc'ing @tetron
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code above to skip bundles 👍
Things to think about (from last week's meetings):
|
A data point about the lingering git repositories:
So it might also be a good idea to introduce a cap on the size of research object bundles, even if we clean up the git repos, keeping around a bunch of 500-1000 MB RO bundles is a huge disk space hog. |
Note: I spent some time debugging the main flow of importing a workflow, and there are a few things that are not perfect in this PR. Namely, sometimes an exception is triggered as a graph already exists, and that's breaking the process due to the changes here (this exception is old, I've seen it before), and I think I am deleting the |
Rebased, fixed the code I remembered wasn't working as expected, fixed unit tests, and manually testing found no issues. Waiting for CI to review the code coverage, then either mark as ready for review or add new unit tests. Also need to test the scheduler/cron. Note to self & reviewers, here's how I tested it: # create containers
$ docker-compose up --no-start
# start DB & Jena/SPARQL
$ docker-compose start postgres sparql
# create temporary directory, and separate directories for each service (production uses a single one, but it's handy for testing)
$ tree /tmp/cwlviewer/
/tmp/cwlviewer/
├── bundles
├── git
└── graphviz
$ mkdir -p /tmp/cwlviewer/{bundles,git,graphviz}
# in IntelliJ, start the `CwlViewerApplication` with the following JVM settings:
# -Djava.io.tmpdir=/tmp/cwlviewer/ -DbundleStorage=/tmp/cwlviewer/bundles -DgitStorage=/tmp/cwlviewer/git -DgraphvizStorage=/tmp/cwlviewer/graphviz
# Visit http://localhost:8080/ Now import
The most important part here is the removal of the Git repositories after they have been successfully used. There are cases where we could have an issue in the middle of the process execution, and the git and bundle directories could be left behind. Unfortunately the only way to remove them is periodically based on some file-age (hence the Scheduler/cron change). -Bruno |
Just pending some manual testing, and I will try to add a few mocked tests, but looks like the code that's not covered contains mostly exception handling, which is hard to be covered. For the Scheduler tomorrow I will start the server with a shorter cron expression (run every 2 minutes or so), and confirm it's deleting the files correctly. |
Something strange with the coverage reports. The code changed in the services & bundle factory is calling |
@@ -195,7 +203,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep | |||
addAggregation(bundle, manifestAnnotations, | |||
"merged.cwl", cwlTool.getPackedVersion(rawUrl)); | |||
} catch (CWLValidationException ex) { | |||
logger.error("Could not pack workflow when creating Research Object", ex.getMessage()); | |||
logger.error(String.format("Could not pack workflow when creating Research Object: %s", ex.getMessage()), ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug found with IDE.
} finally { | ||
gitSemaphore.release(gitInfo.getRepoUrl()); | ||
org.commonwl.view.util.FileUtils.deleteGitRepository(gitRepo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove git folder in the finally
statement since we won't need it after this point (i.e. the graphs are created, the cwltool has been executed and populated the DB, and now the git artefacts are already in the bundle).
Tested the Then started the docker cluster and imported kinow@ranma:/tmp/cwlviewer/graphviz$ ls -lah
total 96K
drwxrwxr-x 2 kinow kinow 4.0K Aug 16 18:34 .
drwxrwxr-x 10 kinow kinow 4.0K Aug 16 18:34 ..
-rw-rw-r-- 1 kinow kinow 15K Aug 15 18:35 03e3eb2c-fe6b-4cab-ab8d-db6747bd03bf.png
-rw-rw-r-- 1 kinow kinow 7.0K Aug 15 18:35 03e3eb2c-fe6b-4cab-ab8d-db6747bd03bf.svg
-rw-rw-r-- 1 kinow kinow 12K Aug 16 18:34 2b3c799c-a9a4-4e15-9cb3-475930324952.png
-rw-rw-r-- 1 kinow kinow 22K Aug 16 18:34 8053cbf6-df50-412e-85dc-7465a2303764.png
-rw-rw-r-- 1 kinow kinow 7.2K Aug 16 18:34 8053cbf6-df50-412e-85dc-7465a2303764.svg
-rw-rw-r-- 1 kinow kinow 19K Aug 16 18:34 da75c0ec-9565-4f2e-9fcf-ef2a453cfda9.png The bundles are never touched as we they are in another directory. Then I modified the access and modified dates of two files. kinow@ranma:/tmp/cwlviewer/graphviz$ date
Tue 16 Aug 2022 18:35:47 NZST
kinow@ranma:/tmp/cwlviewer/graphviz$ touch -a -m -t 202208151835.00 03e3eb2c-fe6b-4cab-ab8d-db6747bd03bf.png
kinow@ranma:/tmp/cwlviewer/graphviz$ touch -a -m -t 202208151835.00 03e3eb2c-fe6b-4cab-ab8d-db6747bd03bf.svg After a few minutes the scheduler runs and deletes the old files. kinow@ranma:/tmp/cwlviewer/graphviz$ ls -lah
total 72K
drwxrwxr-x 2 kinow kinow 4.0K Aug 16 18:38 .
drwxrwxr-x 10 kinow kinow 4.0K Aug 16 18:34 ..
-rw-rw-r-- 1 kinow kinow 12K Aug 16 18:34 2b3c799c-a9a4-4e15-9cb3-475930324952.png
-rw-rw-r-- 1 kinow kinow 22K Aug 16 18:34 8053cbf6-df50-412e-85dc-7465a2303764.png
-rw-rw-r-- 1 kinow kinow 7.2K Aug 16 18:34 8053cbf6-df50-412e-85dc-7465a2303764.svg
-rw-rw-r-- 1 kinow kinow 19K Aug 16 18:34 da75c0ec-9565-4f2e-9fcf-ef2a453cfda9.png Accessing both workflows in CWL Viewer re-created the images almost instantaneously. Bundles still OK: kinow@ranma:/tmp/cwlviewer/graphviz$ ls -lah /tmp/cwlviewer/bundles/
total 60K
drwxrwxr-x 2 kinow kinow 4.0K Aug 16 18:34 .
drwxrwxr-x 10 kinow kinow 4.0K Aug 16 18:34 ..
-rw-rw-r-- 1 kinow kinow 28K Aug 16 18:34 bundle-47e8c47c-91af-44de-a02a-3cb6f20a89a9.zip
-rw-rw-r-- 1 kinow kinow 21K Aug 16 18:34 bundle-ac6285ef-e6d5-49df-b988-6105412798e9.zip |
@mr-c , @tetron ready for review. See previous comments for notes on how to test/how it was tested. One thing I just realized, is that the The default settings are pointing to the same temporary directory. I do not have access to production, so someone would have to confirm. If we have a single directory, then we can either change it, or I can remove Thanks! 🖖 |
… and Commons IO to traverse and delete old files and directories.
…rocess succeeed and they are not used, or process failed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to merge this, make a pre-release, and ask UniTo to test it
Great! I had forgotten about this PR. Hopefully it will help us with disk space issues 🤞 Thanks @mr-c ! |
Closes #424
Closes #200
Closes #279
Supersedes and closes #344
Description
See #424
Motivation and Context
See #424
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: