Merge pull request #60 from overleaf/sk-gc-before-swap

Run GC before swap
This commit is contained in:
Shane Kilkelly 2019-05-16 11:43:56 +01:00 committed by GitHub
commit 980a2ab98f
3 changed files with 13 additions and 2 deletions

View file

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

View file

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

View file

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