From c7d8c1c6b544051c7b588f5ca0aa4d7781f3ffea Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 9 May 2019 15:01:29 +0100 Subject: [PATCH] Run GC on a project at start of swap job. When there is an exception during swap, add project name to log --- .../uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java | 7 +++++++ .../java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java | 2 ++ .../uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java index 47a7eede67..72eb44a5b4 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java @@ -139,6 +139,13 @@ public class FSGitRepoStore implements RepoStore { return Tar.bz2.zip(getDotGitForProject(projectName), sizePtr); } + @Override + public void gcProject(String projectName) throws IOException { + Project.checkValidProjectName(projectName); + ProjectRepo repo = getExistingRepo(projectName); + repo.runGC(); + } + @Override public void remove(String projectName) throws IOException { Project.checkValidProjectName(projectName); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java index 18bea89cd5..737d065f34 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java @@ -50,6 +50,8 @@ public interface RepoStore { return bzip2Project(projectName, null); } + void gcProject(String projectName) throws IOException; + /** * Called after {@link #bzip2Project(String, long[])}'s has been safely * uploaded to the swap store. Removes all traces of the project from disk, diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java index ddf309786a..6be11626b5 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java @@ -118,10 +118,11 @@ public class SwapJobImpl implements SwapJob { (totalSize = repoStore.totalSize()) > lowWatermarkBytes && (numProjects = dbStore.getNumUnswappedProjects()) > minProjects ) { + String projectName = dbStore.getOldestUnswappedProject(); try { - evict(dbStore.getOldestUnswappedProject()); + evict(projectName); } catch (IOException e) { - Log.warn("Exception while swapping, giving up", e); + Log.warn("[{}] Exception while swapping, giving up", projectName, e); } } if (totalSize > lowWatermarkBytes) { @@ -161,6 +162,7 @@ public class SwapJobImpl implements SwapJob { Preconditions.checkNotNull(projName, "projName was null"); Log.info("Evicting project: {}", projName); try (LockGuard __ = lock.lockGuard(projName)) { + repoStore.gcProject(projName); long[] sizePtr = new long[1]; try (InputStream blob = repoStore.bzip2Project(projName, sizePtr)) { swapStore.upload(projName, blob, sizePtr[0]);