This closes #531

This commit is contained in:
Clebert Suconic 2016-05-23 18:25:24 -04:00
commit 316845cc4f
1 changed files with 30 additions and 53 deletions

View File

@ -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];
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));
}
}
totNeg += files[j].getNegCount(currentFile);
}
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");
}
currentFile.setCanReclaim(false);
break;
}
}
// 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;
}
}
else {
if (!currentFile.isCanReclaim()) {
continue; // Move to next file as we already know that this file can't be reclaimed because criterion 2)
}
// Now we evaluate criterion 1)
int negCount = 0, posCount = currentFile.getPosCount();
logger.tracef("posCount on %s = %d", currentFile, posCount);
for (int j = i; j < files.length && negCount < posCount; j++) {
int toNeg = files[j].getNegCount(currentFile);
negCount += toNeg;
if (logger.isTraceEnabled() && toNeg != 0) {
logger.tracef("Negative from %s into %s = %d", files[j], currentFile, toNeg);
}
}
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);
}
}
}
}