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

@@ -24,6 +24,7 @@
package sonia.scm.repository.spi;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.Before;
import org.junit.Rule;
@@ -44,17 +45,19 @@ public class SimpleSvnWorkingCopyFactoryTest extends AbstractSvnCommandTestBase
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private MeterRegistry meterRegistry = new SimpleMeterRegistry();
// keep this so that it will not be garbage collected (Transport keeps this in a week reference)
private WorkdirProvider workdirProvider;
@Before
public void initWorkDirProvider() throws IOException {
workdirProvider = new WorkdirProvider(temporaryFolder.newFolder(), repositoryLocationResolver, false);
}
@Test
public void shouldCheckoutLatestRevision() throws SVNException, IOException {
public void shouldCheckoutLatestRevision() {
SimpleSvnWorkingCopyFactory factory = new SimpleSvnWorkingCopyFactory(new NoneCachingWorkingCopyPool(workdirProvider), new SimpleMeterRegistry());
try (WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null)) {
@@ -96,7 +99,7 @@ public class SimpleSvnWorkingCopyFactoryTest extends AbstractSvnCommandTestBase
@Test
public void shouldDeleteUntrackedFileOnReclaim() throws IOException {
SimpleSvnWorkingCopyFactory factory = new SimpleSvnWorkingCopyFactory(new SimpleCachingWorkingCopyPool(workdirProvider), new SimpleMeterRegistry());
SimpleSvnWorkingCopyFactory factory = new SimpleSvnWorkingCopyFactory(new SimpleCachingWorkingCopyPool(workdirProvider, meterRegistry), new SimpleMeterRegistry());
WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null);
File directory = workingCopy.getWorkingRepository();
@@ -113,8 +116,8 @@ public class SimpleSvnWorkingCopyFactoryTest extends AbstractSvnCommandTestBase
}
@Test
public void shouldRestoreDeletedFileOnReclaim() throws IOException {
SimpleSvnWorkingCopyFactory factory = new SimpleSvnWorkingCopyFactory(new SimpleCachingWorkingCopyPool(workdirProvider), new SimpleMeterRegistry());
public void shouldRestoreDeletedFileOnReclaim() {
SimpleSvnWorkingCopyFactory factory = new SimpleSvnWorkingCopyFactory(new SimpleCachingWorkingCopyPool(workdirProvider, meterRegistry), new SimpleMeterRegistry());
WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null);
File directory = workingCopy.getWorkingRepository();