HBASE-8669 change exploring compaction policy to prefer smaller compactions on blocked stores
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1495261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fdcc2e4656
commit
181b4c8d03
|
@ -97,9 +97,7 @@ public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
++optsInRatio;
|
++optsInRatio;
|
||||||
// Keep if this gets rid of more files. Or the same number of files for less io.
|
if (isBetterSelection(bestSelection, bestSize, potentialMatchFiles, size, mightBeStuck)) {
|
||||||
if (potentialMatchFiles.size() > bestSelection.size()
|
|
||||||
|| (potentialMatchFiles.size() == bestSelection.size() && size < bestSize)) {
|
|
||||||
bestSelection = potentialMatchFiles;
|
bestSelection = potentialMatchFiles;
|
||||||
bestSize = size;
|
bestSize = size;
|
||||||
bestStart = start;
|
bestStart = start;
|
||||||
|
@ -117,6 +115,22 @@ public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy {
|
||||||
return new ArrayList<StoreFile>(bestSelection);
|
return new ArrayList<StoreFile>(bestSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isBetterSelection(List<StoreFile> bestSelection,
|
||||||
|
long bestSize, List<StoreFile> selection, long size, boolean mightBeStuck) {
|
||||||
|
if (mightBeStuck && bestSize > 0 && size > 0) {
|
||||||
|
// Keep the selection that removes most files for least size. That penaltizes adding
|
||||||
|
// large files to compaction, but not small files, so we don't become totally inefficient
|
||||||
|
// (might want to tweak that in future). Also, given the current order of looking at
|
||||||
|
// permutations, prefer earlier files and smaller selection if the difference is small.
|
||||||
|
final double REPLACE_IF_BETTER_BY = 1.05;
|
||||||
|
double thresholdQuality = ((double)bestSelection.size() / bestSize) * REPLACE_IF_BETTER_BY;
|
||||||
|
return thresholdQuality < ((double)selection.size() / size);
|
||||||
|
}
|
||||||
|
// Keep if this gets rid of more files. Or the same number of files for less io.
|
||||||
|
return selection.size() > bestSelection.size()
|
||||||
|
|| (selection.size() == bestSelection.size() && size < bestSize);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the total size of a list of store files.
|
* Find the total size of a list of store files.
|
||||||
* @param potentialMatchFiles StoreFile list.
|
* @param potentialMatchFiles StoreFile list.
|
||||||
|
|
|
@ -345,4 +345,18 @@ public class TestDefaultCompactSelection extends TestCase {
|
||||||
compactEquals(sfCreate(999, 50, 12, 12, 1), false, true, 50, 12, 12, 1);
|
compactEquals(sfCreate(999, 50, 12, 12, 1), false, true, 50, 12, 12, 1);
|
||||||
compactEquals(sfCreate(999, 50, 12, 12, 1), 12, 12, 1);
|
compactEquals(sfCreate(999, 50, 12, 12, 1), 12, 12, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testStuckStoreCompaction() throws IOException {
|
||||||
|
// Select the smallest compaction if the store is stuck.
|
||||||
|
compactEquals(sfCreate(99,99,99,99,99,99, 30,30,30,30), 30, 30, 30);
|
||||||
|
// If not stuck, standard policy applies.
|
||||||
|
compactEquals(sfCreate(99,99,99,99,99, 30,30,30,30), 99, 30, 30, 30, 30);
|
||||||
|
|
||||||
|
// Add sufficiently small files to compaction, though
|
||||||
|
compactEquals(sfCreate(99,99,99,99,99,99, 30,30,30,15), 30, 30, 30, 15);
|
||||||
|
// Prefer earlier compaction to latter if the benefit is not significant
|
||||||
|
compactEquals(sfCreate(99,99,99,99, 30,26,26,29,25,25), 30, 26, 26);
|
||||||
|
// Prefer later compaction if the benefit is significant.
|
||||||
|
compactEquals(sfCreate(99,99,99,99, 27,27,27,20,20,20), 20, 20, 20);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue