This closes #531
This commit is contained in:
commit
316845cc4f
|
@ -25,7 +25,7 @@ import org.jboss.logging.Logger;
|
||||||
*
|
*
|
||||||
* <p>(Positives correspond either to adds or updates, and negatives correspond to deletes).</p>
|
* <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>
|
* <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 final Logger logger = Logger.getLogger(Reclaimer.class);
|
||||||
|
|
||||||
private static void trace(final String message) {
|
|
||||||
logger.trace(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void scan(final JournalFile[] files) {
|
public void scan(final JournalFile[] files) {
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (int i = 0; i < files.length; i++) {
|
||||||
// First we evaluate criterion 1)
|
|
||||||
|
|
||||||
JournalFile currentFile = files[i];
|
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);
|
currentFile.setCanReclaim(true);
|
||||||
|
|
||||||
if (posCount <= totNeg) {
|
// First we evaluate criterion 2)
|
||||||
// Now we evaluate criterion 2)
|
for (int j = i - 1; j >= 0; j--) {
|
||||||
|
JournalFile file = files[j];
|
||||||
for (int j = 0; j <= i; j++) {
|
if (currentFile.getNegCount(file) != 0 && !file.isCanReclaim()) {
|
||||||
JournalFile file = files[j];
|
logger.tracef("%s can't be reclaimed because %s has negative values", currentFile, file);
|
||||||
|
currentFile.setCanReclaim(false);
|
||||||
int negCount = currentFile.getNegCount(file);
|
break;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
currentFile.setCanReclaim(false);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
logger.tracef("%s can be reclaimed", currentFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue