LRU semantic for workdir cache (#1735)

Introduces a maximum size for the simple workdir cache. On cache overflow workdirs are evicted using an LRU strategy.
Furthermore parallel requests for the same repository will now block until the workdir is released.
This commit is contained in:
René Pfeuffer
2021-07-28 07:54:37 +02:00
committed by GitHub
parent f2cc9f67ac
commit ad6000722d
17 changed files with 578 additions and 97 deletions

View File

@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.GitTestHelper;
import sonia.scm.repository.PreProcessorUtil;
@@ -149,6 +150,32 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
assertBranchCheckedOutAndClean(workdir, "master");
}
@Test
public void shouldReclaimCleanDirectoryConfiguredDefaultBranch() throws Exception {
SimpleGitWorkingCopyFactory factory = new SimpleGitWorkingCopyFactory(new NoneCachingWorkingCopyPool(workdirProvider), new SimpleMeterRegistry());
File workdir = createExistingClone(factory);
GitContext context = createContext();
GitRepositoryConfig config = context.getConfig();
config.setDefaultBranch("master");
context.setConfig(config);
factory.reclaim(context, workdir, null);
assertBranchCheckedOutAndClean(workdir, "master");
}
@Test
public void shouldReclaimCleanDirectoryGloballyConfiguredDefaultBranch() throws Exception {
SimpleGitWorkingCopyFactory factory = new SimpleGitWorkingCopyFactory(new NoneCachingWorkingCopyPool(workdirProvider), new SimpleMeterRegistry());
File workdir = createExistingClone(factory);
GitContext context = createContext();
context.getGlobalConfig().setDefaultBranch("master");
factory.reclaim(context, workdir, null);
assertBranchCheckedOutAndClean(workdir, "master");
}
@Test
public void shouldReclaimCleanDirectoryWithOtherBranch() throws Exception {
SimpleGitWorkingCopyFactory factory = new SimpleGitWorkingCopyFactory(new NoneCachingWorkingCopyPool(workdirProvider), new SimpleMeterRegistry());
@@ -192,6 +219,7 @@ public class SimpleGitWorkingCopyFactoryTest extends AbstractGitCommandTestBase
factory.reclaim(createContext(), workdir, "master");
assertBranchCheckedOutAndClean(workdir, "master");
assertThat(newDirectory).doesNotExist();
}
public File createExistingClone(SimpleGitWorkingCopyFactory factory) throws Exception {