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

@@ -25,6 +25,7 @@
package sonia.scm.repository;
import com.aragost.javahg.RepositoryConfiguration;
import com.aragost.javahg.ext.purge.PurgeExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.hooks.HookEnvironment;
@@ -69,6 +70,7 @@ public class HgRepositoryFactory {
RepositoryConfiguration repoConfiguration = RepositoryConfiguration.DEFAULT;
repoConfiguration.getEnvironment().putAll(environment);
repoConfiguration.addExtension(HgFileviewExtension.class);
repoConfiguration.addExtension(PurgeExtension.class);
boolean pending = hookEnvironment.isPending();
repoConfiguration.setEnablePendingChangesets(pending);

View File

@@ -32,6 +32,7 @@ import com.aragost.javahg.commands.PullCommand;
import com.aragost.javahg.commands.StatusCommand;
import com.aragost.javahg.commands.UpdateCommand;
import com.aragost.javahg.commands.flags.CloneCommandFlags;
import com.aragost.javahg.ext.purge.PurgeCommand;
import io.micrometer.core.instrument.MeterRegistry;
import sonia.scm.repository.HgExtensions;
import sonia.scm.repository.InternalRepositoryException;
@@ -78,7 +79,9 @@ public class SimpleHgWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposit
for (String unknown : StatusCommand.on(clone).execute().getUnknown()) {
delete(clone.getDirectory(), unknown);
}
UpdateCommand.on(clone).rev(initialBranch).clean().execute();
String branchToCheckOut = initialBranch == null ? "default" : initialBranch;
UpdateCommand.on(clone).rev(branchToCheckOut).clean().execute();
PurgeCommand.on(clone).execute();
return new ParentAndClone<>(centralRepository, clone, target);
} catch (ExecutionException | IOException e) {
throw new ReclaimFailedException(e);