Add option to run non aggressive gc to gc-conductor

Before this fix gc-executor had hardcoded setAgressive(true) for each gc
invocation. Running gc without aggressive mode allowed gc to reuse delta
and reduce gc time.

Change-Id: I7c80372d5aa14db3d9385df10fd43f7b50fc8e74
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/CommonConfig.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/CommonConfig.java
index 4081ed0..3c591c4 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/CommonConfig.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/CommonConfig.java
@@ -27,6 +27,7 @@
   public static final String DB_PASS_KEY = "password";
   public static final String PACKED_KEY = "packed";
   public static final String LOOSE_KEY = "loose";
+  public static final String GC_FORCE_AGGRESSIVE_KEY = "forceAggressive";
 
   public static final String DEFAULT_DB_URL = "jdbc:postgresql://localhost:5432/";
   public static final String DEFAULT_DB_NAME = "gc";
@@ -34,6 +35,7 @@
   public static final String DEFAULT_DB_PASSWORD = DEFAULT_DB_NAME;
   public static final int PACKED_DEFAULT = 40;
   public static final int LOOSE_DEFAULT = 400;
+  public static final boolean DEFAULT_GC_FORCE_AGGRESSIVE = false;
 
   private final String databaseUrl;
   private final String databaseName;
@@ -42,6 +44,7 @@
   private final String password;
   private final int packed;
   private final int loose;
+  private final boolean aggressive;
 
   /**
    * Create CommonConfig from the specified parameters.
@@ -53,6 +56,7 @@
    * @param password The password of the database server user.
    * @param loose The number of loose objects to consider a repo dirty
    * @param packed The number of packs to consider a repo dirty
+   * @param aggressive default gc mode aggressive or not.
    */
   public CommonConfig(
       String databaseUrl,
@@ -61,7 +65,8 @@
       String username,
       String password,
       int packed,
-      int loose) {
+      int loose,
+      boolean aggressive) {
     this.databaseUrl = databaseUrl.replaceFirst("/?$", "/");
     this.databaseName = databaseName;
     this.databaseUrlOptions = databaseUrlOptions;
@@ -69,6 +74,7 @@
     this.password = password;
     this.packed = packed;
     this.loose = loose;
+    this.aggressive = aggressive;
   }
 
   /** @return the database server URL. */
@@ -106,6 +112,11 @@
     return loose;
   }
 
+  /** @return if gc mode is set to aggressive, by default its not aggressive */
+  public boolean isAggressive() {
+    return aggressive;
+  }
+
   protected static String getString(
       Config config, String section, String subsection, String key, String defaultValue) {
     String value = config.getString(section, subsection, key);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTask.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTask.java
index 43803e4..8ca6897 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTask.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTask.java
@@ -25,10 +25,12 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.internal.storage.file.FileRepository;
 import org.eclipse.jgit.internal.storage.file.GC;
 import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
@@ -232,7 +234,14 @@
 
   private void insertRepository() {
     try {
-      queue.add(repositoryPath, hostname);
+      boolean isAggressive = cfg.isAggressive();
+      if (!isAggressive) // Force is aggressive option is not set then read repo config
+      {
+        // isAggressive based on current repo config
+        isAggressive = getGcModeFromRepository(repositoryPath);
+      }
+      queue.add(repositoryPath, hostname, isAggressive);
+
     } catch (GcQueueException e) {
       log.error("Error adding repository in queue {}", repositoryPath, e);
     }
@@ -242,4 +251,17 @@
   public String toString() {
     return "Evaluate if repository need GC: " + repositoryPath;
   }
+
+  public static boolean getGcModeFromRepository(String repositoryPath) {
+    try {
+      Git git = Git.open(new File(repositoryPath));
+      return git.getRepository()
+          .getConfig()
+          .getBoolean(ConfigConstants.CONFIG_GC_SECTION, "aggressive", false);
+    } catch (IOException e) {
+      log.error(
+          "Error reading repository config returns default non-aggressive{}", repositoryPath, e);
+    }
+    return false;
+  }
 }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/GcQueue.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/GcQueue.java
index cc2560e..a1ae883 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/GcQueue.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/GcQueue.java
@@ -33,9 +33,10 @@
    *
    * @param repository The path to the repository.
    * @param queuedFrom The hostname from which the repository is queued from.
+   * @param isAggressive sets gc mode to aggressive or non-aggressive.
    * @throws GcQueueException if an error occur while adding the repository.
    */
-  void add(String repository, String queuedFrom) throws GcQueueException;
+  void add(String repository, String queuedFrom, boolean isAggressive) throws GcQueueException;
 
   /**
    * Pick a repository from the queue.
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfo.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfo.java
index a7eedec..3079c11 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfo.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfo.java
@@ -23,12 +23,15 @@
   private final Timestamp queuedAt;
   private final String executor;
   private final String queuedFrom;
+  private final boolean aggressive;
 
-  public RepositoryInfo(String path, Timestamp queuedAt, String executor, String queuedFrom) {
+  public RepositoryInfo(
+      String path, Timestamp queuedAt, String executor, String queuedFrom, boolean aggressive) {
     this.path = path;
     this.queuedAt = queuedAt;
     this.executor = executor;
     this.queuedFrom = queuedFrom;
+    this.aggressive = aggressive;
   }
 
   /** @return the path to the repository. */
@@ -50,4 +53,8 @@
   public String getQueuedFrom() {
     return queuedFrom;
   }
+
+  public boolean isAggressive() {
+    return aggressive;
+  }
 }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java
index 25939a2..eadf28c 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java
@@ -51,6 +51,9 @@
   @Option(name = "--first", usage = "add repository as first priority in GC queue")
   private boolean first;
 
+  @Option(name = "--aggressive", usage = "add repository as aggressive GC")
+  private boolean aggressive;
+
   @Inject private GcQueue queue;
 
   @Inject @Hostname private String hostName;
@@ -70,7 +73,7 @@
         repositoryPath = resolvePath();
       }
       repository = repositoryPath.toString();
-      queue.add(repository, hostName);
+      queue.add(repository, hostName, aggressive);
       if (first) {
         queue.bumpToFirst(repository);
       }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorConfig.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorConfig.java
index acb3600..34b6d62 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorConfig.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorConfig.java
@@ -43,7 +43,8 @@
         cfg.getString(DB_USERNAME_KEY, DEFAULT_DB_USERNAME),
         cfg.getString(DB_PASS_KEY, DEFAULT_DB_PASSWORD),
         cfg.getInt(PACKED_KEY, PACKED_DEFAULT),
-        cfg.getInt(LOOSE_KEY, LOOSE_DEFAULT));
+        cfg.getInt(LOOSE_KEY, LOOSE_DEFAULT),
+        cfg.getBoolean(GC_FORCE_AGGRESSIVE_KEY, DEFAULT_GC_FORCE_AGGRESSIVE));
     threadPoolSize = cfg.getInt(THREAD_POOL_KEY, THREAD_POOL_DEFAULT);
 
     String expireTimeRecheckString =
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorConfig.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorConfig.java
index f339302..84ce8ce 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorConfig.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorConfig.java
@@ -73,7 +73,9 @@
         getString(config, DB_SECTION, null, DB_USERNAME_KEY, DEFAULT_DB_USERNAME),
         getString(config, DB_SECTION, null, DB_PASS_KEY, DEFAULT_DB_PASSWORD),
         config.getInt(EVALUATION_SECTION, PACKED_KEY, PACKED_DEFAULT),
-        config.getInt(EVALUATION_SECTION, LOOSE_KEY, LOOSE_DEFAULT));
+        config.getInt(EVALUATION_SECTION, LOOSE_KEY, LOOSE_DEFAULT),
+        config.getBoolean(
+            EVALUATION_SECTION, GC_FORCE_AGGRESSIVE_KEY, DEFAULT_GC_FORCE_AGGRESSIVE));
     delay = config.getInt(CORE_SECTION, DELAY_KEY, DEFAULT_DELAY);
     executors = config.getInt(CORE_SECTION, EXECUTOR_KEY, DEFAULT_EXECUTORS);
     pickOwnHostOnly = config.getBoolean(CORE_SECTION, PICK_OWN_HOST_KEY, true);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GarbageCollector.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GarbageCollector.java
index bc825d0..e905a35 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GarbageCollector.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GarbageCollector.java
@@ -24,6 +24,7 @@
 class GarbageCollector implements Callable<Boolean> {
   private String repositoryPath;
   private ProgressMonitor pm;
+  private boolean aggressive;
 
   void setRepositoryPath(String repositoryPath) {
     this.repositoryPath = repositoryPath;
@@ -33,11 +34,15 @@
     this.pm = pm;
   }
 
+  void setAggressive(boolean aggressive) {
+    this.aggressive = aggressive;
+  }
+
   @Override
   public Boolean call() throws Exception {
     try (Git git = Git.open(new File(repositoryPath))) {
       git.gc()
-          .setAggressive(true)
+          .setAggressive(aggressive)
           .setPreserveOldPacks(true)
           .setPrunePreserved(true)
           .setProgressMonitor(pm)
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorker.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorker.java
index 14ea8fc..2d68097 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorker.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorker.java
@@ -69,9 +69,9 @@
   @Override
   public void run() {
     while (!cpm.isCancelled()) {
-      String repoPath = pickRepository();
-      if (repoPath != null) {
-        runGc(repoPath);
+      RepositoryInfo repoInfo = pickRepository();
+      if (null != repoInfo && null != repoInfo.getPath()) {
+        runGc(repoInfo.getPath(), repoInfo.isAggressive());
       } else {
         log.debug("No repository picked, going to sleep");
         try {
@@ -85,11 +85,11 @@
     }
   }
 
-  private String pickRepository() {
+  private RepositoryInfo pickRepository() {
     try {
       RepositoryInfo repoInfo = queue.pick(name, queuedForLongerThan, queuedFrom);
       if (repoInfo != null) {
-        return repoInfo.getPath();
+        return repoInfo;
       }
     } catch (GcQueueException e) {
       log.error("Unable to pick repository from the queue", e);
@@ -97,11 +97,12 @@
     return null;
   }
 
-  private void runGc(String repoPath) {
+  private void runGc(String repoPath, boolean aggressive) {
     try {
-      log.info("Starting gc on repository {}", repoPath);
+      log.info("Starting {} gc on repository {}", aggressive ? "aggressive" : "normal", repoPath);
       gc.setRepositoryPath(repoPath);
       gc.setPm(cpm);
+      gc.setAggressive(aggressive);
       retryer.call(gc);
       log.info("Gc completed on repository {}", repoPath);
     } catch (Throwable e) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/DatabaseConstants.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/DatabaseConstants.java
index 0b66cf3..cdd7dd9 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/DatabaseConstants.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/DatabaseConstants.java
@@ -33,6 +33,7 @@
   private static final String SEQUENCE = "sequence";
   static final String QUEUED_AT = "queued_at";
   static final String HOSTNAME = "hostname";
+  static final String AGGRESSIVE = "aggressive";
 
   static final String CREATE_OR_UPDATE_SCHEMA =
       "DO"
@@ -50,7 +51,10 @@
           + EXECUTOR
           + " VARCHAR(258), "
           + HOSTNAME
-          + " VARCHAR(255) NOT NULL);"
+          + " VARCHAR(255) NOT NULL, "
+          + AGGRESSIVE
+          + " BOOLEAN NOT NULL"
+          + ");"
           // This section is temporary to support migrating live, next version will
           // drop the executor tables, only drop the foreign key for now.
           + " IF EXISTS ("
@@ -64,6 +68,17 @@
           + REPOSITORIES_TABLE
           + " DROP CONSTRAINT repositories_executor_fkey;"
           + " END IF;"
+          + " BEGIN ALTER TABLE "
+          + REPOSITORIES_TABLE
+          + " ADD COLUMN "
+          + AGGRESSIVE
+          + " BOOLEAN NOT NULL DEFAULT (true);"
+          + " EXCEPTION WHEN duplicate_column THEN RAISE NOTICE 'column "
+          + AGGRESSIVE
+          + " already exists in "
+          + REPOSITORIES_TABLE
+          + ".';"
+          + " END;"
           + " END "
           + " $$";
 
@@ -89,10 +104,17 @@
     return SELECT_REPOSITORIES + " WHERE " + REPOSITORY + "='" + repository + "'";
   }
 
-  static final String insert(String repository, String hostname) {
+  static final String insert(String repository, String hostname, boolean isAggressive) {
     return format(
-        "INSERT INTO %s (%s,%s) SELECT '%s','%s' WHERE NOT EXISTS (%s)",
-        REPOSITORIES_TABLE, REPOSITORY, HOSTNAME, repository, hostname, select(repository));
+        "INSERT INTO %s (%s,%s,%s) SELECT '%s','%s','%b' WHERE NOT EXISTS (%s)",
+        REPOSITORIES_TABLE,
+        REPOSITORY,
+        HOSTNAME,
+        AGGRESSIVE,
+        repository,
+        hostname,
+        isAggressive,
+        select(repository));
   }
 
   static final String delete(String repository) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueue.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueue.java
index d2dca5a..2cddb3e 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueue.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueue.java
@@ -14,6 +14,7 @@
 
 package com.ericsson.gerrit.plugins.gcconductor.postgresqueue;
 
+import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.DatabaseConstants.AGGRESSIVE;
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.DatabaseConstants.CREATE_OR_UPDATE_SCHEMA;
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.DatabaseConstants.EXECUTOR;
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.DatabaseConstants.HOSTNAME;
@@ -55,9 +56,10 @@
   }
 
   @Override
-  public void add(String repository, String queuedFrom) throws GcQueueException {
+  public void add(String repository, String queuedFrom, boolean isAggressive)
+      throws GcQueueException {
     try {
-      executeStatement(dataSource, insert(repository, queuedFrom));
+      executeStatement(dataSource, insert(repository, queuedFrom, isAggressive));
     } catch (SQLException e) {
       if (!"23505".equals(e.getSQLState())) {
         // UNIQUE CONSTRAINT violation means repository is already in the queue
@@ -152,10 +154,12 @@
     int queuedAtColumn = resultSet.findColumn(QUEUED_AT);
     int executorColumn = resultSet.findColumn(EXECUTOR);
     int hostnameColumn = resultSet.findColumn(HOSTNAME);
+    int aggressiveColumn = resultSet.findColumn(AGGRESSIVE);
     return new RepositoryInfo(
         resultSet.getString(repositoryColumn),
         resultSet.getTimestamp(queuedAtColumn),
         resultSet.getString(executorColumn),
-        resultSet.getString(hostnameColumn));
+        resultSet.getString(hostnameColumn),
+        resultSet.getBoolean(aggressiveColumn));
   }
 }
diff --git a/src/main/resources/Documentation/cmd-add-to-queue.md b/src/main/resources/Documentation/cmd-add-to-queue.md
index 326174f..a9df7b6 100644
--- a/src/main/resources/Documentation/cmd-add-to-queue.md
+++ b/src/main/resources/Documentation/cmd-add-to-queue.md
@@ -33,6 +33,9 @@
 `--first`
 :	Add repository as first priority in GC queue.
 
+`--aggressive`
+: Add repository for aggressive GC (default gc mode is non-aggressive).
+
 EXAMPLES
 --------
 Absolute path to a repository:
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTaskTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTaskTest.java
index 8106a71..2ccdd0d 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTaskTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTaskTest.java
@@ -67,7 +67,7 @@
     when(queue.contains(repositoryPath)).thenReturn(false);
     task = new EvaluationTask(cfg, queue, SOME_HOSTNAME, repositoryPath);
     task.run();
-    verify(queue).add(repositoryPath, SOME_HOSTNAME);
+    verify(queue).add(repositoryPath, SOME_HOSTNAME, false);
   }
 
   @Test
@@ -78,14 +78,14 @@
     gc(repository);
     task = new EvaluationTask(cfg, queue, SOME_HOSTNAME, repositoryPath);
     task.run();
-    verify(queue).add(repositoryPath, SOME_HOSTNAME);
+    verify(queue).add(repositoryPath, SOME_HOSTNAME, false);
   }
 
   @Test
   public void repositoryShouldNotBeAddedIfAlreadyInQueue() throws Exception {
     when(queue.contains(repositoryPath)).thenReturn(true);
     task.run();
-    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME);
+    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME, false);
   }
 
   @Test
@@ -94,7 +94,7 @@
     when(cfg.getPackedThreshold()).thenReturn(1);
     when(queue.contains(repositoryPath)).thenReturn(false);
     task.run();
-    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME);
+    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME, false);
   }
 
   @Test
@@ -103,7 +103,7 @@
         .when(queue)
         .contains(repositoryPath);
     task.run();
-    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME);
+    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME, false);
   }
 
   @Test
@@ -111,7 +111,7 @@
     when(queue.contains(repositoryPath)).thenReturn(false);
     doThrow(new GcQueueException("some message", new Throwable()))
         .when(queue)
-        .add(repositoryPath, SOME_HOSTNAME);
+        .add(repositoryPath, SOME_HOSTNAME, false);
     task.run();
   }
 
@@ -120,7 +120,7 @@
     when(queue.contains(repositoryPath)).thenReturn(false);
     dir.delete();
     task.run();
-    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME);
+    verify(queue, never()).add(repositoryPath, SOME_HOSTNAME, true);
   }
 
   @Test
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfoTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfoTest.java
index ba78afc..355ffb4 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfoTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/RepositoryInfoTest.java
@@ -24,28 +24,28 @@
   @Test
   public void shouldReturnPath() {
     String path = "/path/someRepo.git";
-    RepositoryInfo repoInfo = new RepositoryInfo(path, null, null, null);
+    RepositoryInfo repoInfo = new RepositoryInfo(path, null, null, null, true);
     assertThat(repoInfo.getPath()).isEqualTo(path);
   }
 
   @Test
   public void shouldReturnQueuedAt() {
     Timestamp time = new Timestamp(System.currentTimeMillis());
-    RepositoryInfo repoInfo = new RepositoryInfo(null, time, null, null);
+    RepositoryInfo repoInfo = new RepositoryInfo(null, time, null, null, true);
     assertThat(repoInfo.getQueuedAt()).isEqualTo(time);
   }
 
   @Test
   public void shouldReturnExecutor() {
     String executor = "someHost-1";
-    RepositoryInfo repoInfo = new RepositoryInfo(null, null, executor, null);
+    RepositoryInfo repoInfo = new RepositoryInfo(null, null, executor, null, true);
     assertThat(repoInfo.getExecutor()).isEqualTo(executor);
   }
 
   @Test
   public void shouldReturnQueuedFrom() {
     String hostname = "someHost-2";
-    RepositoryInfo repoInfo = new RepositoryInfo(null, null, null, hostname);
+    RepositoryInfo repoInfo = new RepositoryInfo(null, null, null, hostname, true);
     assertThat(repoInfo.getQueuedFrom()).isEqualTo(hostname);
   }
 }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcExecutorTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcExecutorTest.java
index 4c74510..b3cad54 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcExecutorTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcExecutorTest.java
@@ -70,7 +70,8 @@
     when(config.getExecutors()).thenReturn(1);
     when(gcWorkerFactory.create(EXECUTOR)).thenReturn(gcWorker);
     when(gcQueue.list())
-        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, EXECUTOR, HOSTNAME)));
+        .thenReturn(
+            ImmutableList.of(new RepositoryInfo(REPOSITORY, null, EXECUTOR, HOSTNAME, true)));
     GcExecutor gcExecutor =
         new GcExecutor(gcQueue, config, gcWorkerFactory, scheduledEvaluator, HOSTNAME);
     verify(gcQueue).unpick(REPOSITORY);
@@ -84,7 +85,7 @@
     when(config.getExecutors()).thenReturn(1);
     when(gcWorkerFactory.create(EXECUTOR)).thenReturn(gcWorker);
     when(gcQueue.list())
-        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, null, HOSTNAME)));
+        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, null, HOSTNAME, true)));
     GcExecutor gcExecutor =
         new GcExecutor(gcQueue, config, gcWorkerFactory, scheduledEvaluator, HOSTNAME);
     verify(gcQueue, never()).unpick(REPOSITORY);
@@ -100,7 +101,8 @@
     when(gcQueue.list())
         .thenReturn(
             ImmutableList.of(
-                new RepositoryInfo(REPOSITORY, null, "another executor", "another hostname")));
+                new RepositoryInfo(
+                    REPOSITORY, null, "another executor", "another hostname", true)));
     GcExecutor gcExecutor =
         new GcExecutor(gcQueue, config, gcWorkerFactory, scheduledEvaluator, HOSTNAME);
     verify(gcQueue, never()).unpick(REPOSITORY);
@@ -129,7 +131,7 @@
     when(config.getInterval()).thenReturn(1L);
     when(gcWorkerFactory.create(EXECUTOR)).thenReturn(gcWorker);
     when(gcQueue.list())
-        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, null, HOSTNAME)));
+        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, null, HOSTNAME, true)));
     GcExecutor gcExecutor =
         new GcExecutor(gcQueue, config, gcWorkerFactory, scheduledEvaluator, HOSTNAME);
     verify(gcWorker).start();
@@ -144,7 +146,7 @@
     when(config.getInitialDelay()).thenReturn(1L);
     when(gcWorkerFactory.create(EXECUTOR)).thenReturn(gcWorker);
     when(gcQueue.list())
-        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, null, HOSTNAME)));
+        .thenReturn(ImmutableList.of(new RepositoryInfo(REPOSITORY, null, null, HOSTNAME, true)));
     GcExecutor gcExecutor =
         new GcExecutor(gcQueue, config, gcWorkerFactory, scheduledEvaluator, HOSTNAME);
     verify(gcWorker).start();
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorkerTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorkerTest.java
index c9b8e5d..1073869 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorkerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/GcWorkerTest.java
@@ -50,7 +50,7 @@
   @Before
   public void setUp() {
     Thread.interrupted(); // reset the flag
-    repoInfo = new RepositoryInfo(REPO_PATH, null, EXEC_NAME, HOSTNAME);
+    repoInfo = new RepositoryInfo(REPO_PATH, null, EXEC_NAME, HOSTNAME, true);
     gcTask = new GcWorker(queue, garbageCollector, cpm, QUEUED_FROM, 0, EXEC_NAME);
   }
 
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java
index aab695c..5c947a1 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java
@@ -85,18 +85,18 @@
     assertThat(queue.list()).isEmpty();
     assertThat(queue.contains(repoPath)).isFalse();
 
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     assertThat(queue.list().size()).isEqualTo(1);
     assertThat(queue.contains(repoPath)).isTrue();
 
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     assertThat(queue.list().size()).isEqualTo(1);
     assertThat(queue.contains(repoPath)).isTrue();
 
     String repoPath2 = "/some/path/to/some/repository2";
     String hostname2 = "someHostname2";
 
-    queue.add(repoPath2, hostname2);
+    queue.add(repoPath2, hostname2, true);
     assertThat(queue.list().size()).isEqualTo(2);
     assertThat(queue.contains(repoPath)).isTrue();
     assertThat(queue.contains(repoPath2)).isTrue();
@@ -118,19 +118,19 @@
   @Test
   public void testAddThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname"));
+    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname", true));
   }
 
   @Test
   public void testAddThatFailsWhenCreatingStatement() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname"));
+    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname", true));
   }
 
   @Test
   public void testAddThatFailsWhenExecutingQuery() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname"));
+    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname", true));
   }
 
   @Test
@@ -184,8 +184,8 @@
 
     assertThat(queue.list()).isEmpty();
     Timestamp before = new Timestamp(System.currentTimeMillis());
-    queue.add(repoPath, hostname);
-    queue.add(repoPath2, hostname);
+    queue.add(repoPath, hostname, true);
+    queue.add(repoPath2, hostname, true);
     queue.pick(executor, 0, Optional.empty());
 
     assertThat(queue.list().size()).isEqualTo(2);
@@ -244,7 +244,7 @@
     assertThat(queue.pick(executor, 0, Optional.empty())).isNull();
 
     // queue contains 1 repository, should pick that one
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     RepositoryInfo picked = queue.pick(executor, 0, Optional.empty());
     assertThat(picked).isNotNull();
     assertThat(picked.getPath()).isEqualTo(repoPath);
@@ -265,7 +265,7 @@
   public void testPickRepositoriesInOrder() throws Exception {
     String repositoryFormat = "my/path%s.git";
     for (int i = 0; i < 100; i++) {
-      queue.add(String.format(repositoryFormat, i), "someHostname");
+      queue.add(String.format(repositoryFormat, i), "someHostname", true);
     }
     for (int i = 0; i < 100; i++) {
       String pickedRepo = queue.pick("someExecutor", 0, Optional.empty()).getPath();
@@ -281,7 +281,7 @@
     String executor = "someExecutor";
 
     // pick repository older than 10 seconds, nothing to pick
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     assertThat(queue.pick(executor, 10, Optional.empty())).isNull();
     assertThat(queue.list().get(0).getExecutor()).isNull();
 
@@ -300,7 +300,7 @@
     String executor = "hostname-1";
 
     // pick repository queued from otherHostname, nothing to pick
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     assertThat(queue.pick(executor, 0, Optional.of(otherHostname))).isNull();
     assertThat(queue.list().get(0).getExecutor()).isNull();
 
@@ -341,7 +341,7 @@
     String executor = "someExecutor";
 
     // queue contains 1 repository, should pick that one
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     RepositoryInfo picked = queue.pick(executor, 0, Optional.empty());
     assertThat(picked.getPath()).isEqualTo(repoPath);
     assertThat(picked.getExecutor()).isEqualTo(executor);
@@ -379,8 +379,8 @@
     String hostname = "hostname";
     String otherHostname = "otherHostname";
 
-    queue.add(repoPath, hostname);
-    queue.add(repoPath2, hostname);
+    queue.add(repoPath, hostname, true);
+    queue.add(repoPath2, hostname, true);
     assertThat(queue.list().get(0).getQueuedFrom()).isEqualTo(hostname);
     assertThat(queue.list().get(1).getQueuedFrom()).isEqualTo(hostname);
 
@@ -415,14 +415,14 @@
     String hostname = "hostname";
 
     // Queue contains 1 repository, bumping should have no effect
-    queue.add(repoPath, hostname);
+    queue.add(repoPath, hostname, true);
     assertThat(queue.list().get(0).getPath()).isEqualTo(repoPath);
     queue.bumpToFirst(repoPath);
     assertThat(queue.list().get(0).getPath()).isEqualTo(repoPath);
 
     // Queue has 3 repositories, should be able to change their order
-    queue.add(repoPath2, hostname);
-    queue.add(repoPath3, hostname);
+    queue.add(repoPath2, hostname, true);
+    queue.add(repoPath3, hostname, true);
     assertThat(queue.list().get(1).getPath()).isEqualTo(repoPath2);
     assertThat(queue.list().get(2).getPath()).isEqualTo(repoPath3);