Repository: activemq-artemis
Updated Branches:
  refs/heads/master 8df8d7616 -> 316845cc4


Rework journal reclaimer


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/3f131fc5
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/3f131fc5
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/3f131fc5

Branch: refs/heads/master
Commit: 3f131fc594ccef38500d01b5853aa49dfe3392d3
Parents: 8df8d76
Author: barreiro <[email protected]>
Authored: Thu May 19 01:51:19 2016 +0100
Committer: Clebert Suconic <[email protected]>
Committed: Mon May 23 18:25:23 2016 -0400

----------------------------------------------------------------------
 .../artemis/core/journal/impl/Reclaimer.java    | 75 +++++++-------------
 1 file changed, 26 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3f131fc5/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/Reclaimer.java
----------------------------------------------------------------------
diff --git 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/Reclaimer.java
 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/Reclaimer.java
index 2b028ab..c83e2af 100644
--- 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/Reclaimer.java
+++ 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/Reclaimer.java
@@ -25,7 +25,7 @@ import org.jboss.logging.Logger;
  *
  * <p>(Positives correspond either to adds or updates, and negatives 
correspond to deletes).</p>
  *
- * <p>A file Fn can be deleted if, and only if the following criteria are 
satisified</p>
+ * <p>A file Fn can be deleted if, and only if the following criteria are 
satisfied</p>
  *
  * <p>1) All pos in a file Fn, must have corresponding neg in any file Fm 
where {@code m >= n}.</p>
  *
@@ -36,67 +36,44 @@ public class Reclaimer {
 
    private static final Logger logger = Logger.getLogger(Reclaimer.class);
 
-   private static void trace(final String message) {
-      logger.trace(message);
-   }
-
    public void scan(final JournalFile[] files) {
       for (int i = 0; i < files.length; i++) {
-         // First we evaluate criterion 1)
-
          JournalFile currentFile = files[i];
+         currentFile.setCanReclaim(true);
 
-         int posCount = currentFile.getPosCount();
-
-         int totNeg = 0;
-
-         if (logger.isTraceEnabled()) {
-            logger.trace("posCount on " + currentFile + " = " + posCount);
-         }
-
-         for (int j = i; j < files.length; j++) {
-            if (logger.isTraceEnabled()) {
-               if (files[j].getNegCount(currentFile) != 0) {
-                  logger.trace("Negative from " + files[j] +
-                                     " into " +
-                                     currentFile +
-                                     " = " +
-                                     files[j].getNegCount(currentFile));
-               }
+         // First we evaluate criterion 2)
+         for (int j = i - 1; j >= 0; j--) {
+            JournalFile file = files[j];
+            if (currentFile.getNegCount(file) != 0 && !file.isCanReclaim()) {
+               logger.tracef("%s can't be reclaimed because %s has negative 
values", currentFile, file);
+               currentFile.setCanReclaim(false);
+               break;
             }
-
-            totNeg += files[j].getNegCount(currentFile);
+         }
+         if (!currentFile.isCanReclaim()) {
+            continue; // Move to next file as we already know that this file 
can't be reclaimed because criterion 2)
          }
 
-         currentFile.setCanReclaim(true);
-
-         if (posCount <= totNeg) {
-            // Now we evaluate criterion 2)
-
-            for (int j = 0; j <= i; j++) {
-               JournalFile file = files[j];
-
-               int negCount = currentFile.getNegCount(file);
-
-               if (negCount != 0) {
-                  if (file.isCanReclaim()) {
-                     // Ok
-                  }
-                  else {
-                     if (logger.isTraceEnabled()) {
-                        logger.trace(currentFile + " Can't be reclaimed 
because " + file + " has negative values");
-                     }
+         // Now we evaluate criterion 1)
+         int negCount = 0, posCount = currentFile.getPosCount();
+         logger.tracef("posCount on %s = %d", currentFile, posCount);
 
-                     currentFile.setCanReclaim(false);
+         for (int j = i; j < files.length && negCount < posCount; j++) {
+            int toNeg = files[j].getNegCount(currentFile);
+            negCount += toNeg;
 
-                     break;
-                  }
-               }
+            if (logger.isTraceEnabled() && toNeg != 0) {
+               logger.tracef("Negative from %s into %s = %d", files[j], 
currentFile, toNeg);
             }
          }
-         else {
+
+         if (negCount < posCount ) {
+            logger.tracef("%s can't be reclaimed because there are not enough 
negatives %d", currentFile, negCount);
             currentFile.setCanReclaim(false);
          }
+         else {
+            logger.tracef("%s can be reclaimed", currentFile);
+         }
       }
    }
 }

Reply via email to