HBASE-8448 RatioBasedCompactionPolicy (and derived ones) can select already-compacting files for compaction
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1477391 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
efd752b5b4
commit
d1f0efc81c
@ -37,8 +37,6 @@ import org.apache.hadoop.hbase.regionserver.StoreFile;
|
|||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy {
|
public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy {
|
||||||
|
|
||||||
/** Computed number of files that are needed to assume compactions are stuck. */
|
|
||||||
private final long filesNeededToForce;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for ExploringCompactionPolicy.
|
* Constructor for ExploringCompactionPolicy.
|
||||||
@ -48,20 +46,17 @@ public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy {
|
|||||||
public ExploringCompactionPolicy(final Configuration conf,
|
public ExploringCompactionPolicy(final Configuration conf,
|
||||||
final StoreConfigInformation storeConfigInfo) {
|
final StoreConfigInformation storeConfigInfo) {
|
||||||
super(conf, storeConfigInfo);
|
super(conf, storeConfigInfo);
|
||||||
filesNeededToForce = storeConfigInfo.getBlockingFileCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final ArrayList<StoreFile> applyCompactionPolicy(final ArrayList<StoreFile> candidates,
|
final ArrayList<StoreFile> applyCompactionPolicy(final ArrayList<StoreFile> candidates,
|
||||||
final boolean mayUseOffPeak) throws IOException {
|
final boolean mayUseOffPeak, final boolean mightBeStuck) throws IOException {
|
||||||
// Start off choosing nothing.
|
// Start off choosing nothing.
|
||||||
List<StoreFile> bestSelection = new ArrayList<StoreFile>(0);
|
List<StoreFile> bestSelection = new ArrayList<StoreFile>(0);
|
||||||
List<StoreFile> smallest = new ArrayList<StoreFile>(0);
|
List<StoreFile> smallest = new ArrayList<StoreFile>(0);
|
||||||
long bestSize = 0;
|
long bestSize = 0;
|
||||||
long smallestSize = Long.MAX_VALUE;
|
long smallestSize = Long.MAX_VALUE;
|
||||||
|
|
||||||
boolean mightBeStuck = candidates.size() >= filesNeededToForce;
|
|
||||||
|
|
||||||
// Consider every starting place.
|
// Consider every starting place.
|
||||||
for (int start = 0; start < candidates.size(); start++) {
|
for (int start = 0; start < candidates.size(); start++) {
|
||||||
// Consider every different sub list permutation in between start and end with min files.
|
// Consider every different sub list permutation in between start and end with min files.
|
||||||
|
@ -82,6 +82,12 @@ public class RatioBasedCompactionPolicy extends CompactionPolicy {
|
|||||||
final boolean mayUseOffPeak, final boolean forceMajor) throws IOException {
|
final boolean mayUseOffPeak, final boolean forceMajor) throws IOException {
|
||||||
// Preliminary compaction subject to filters
|
// Preliminary compaction subject to filters
|
||||||
ArrayList<StoreFile> candidateSelection = new ArrayList<StoreFile>(candidateFiles);
|
ArrayList<StoreFile> candidateSelection = new ArrayList<StoreFile>(candidateFiles);
|
||||||
|
// Stuck and not compacting enough (estimate). It is not guaranteed that we will be
|
||||||
|
// able to compact more if stuck and compacting, because ratio policy excludes some
|
||||||
|
// non-compacting files from consideration during compaction (see getCurrentEligibleFiles).
|
||||||
|
int futureFiles = filesCompacting.isEmpty() ? 0 : 1;
|
||||||
|
boolean mayBeStuck = (candidateFiles.size() - filesCompacting.size() + futureFiles)
|
||||||
|
>= storeConfigInfo.getBlockingFileCount();
|
||||||
candidateSelection = getCurrentEligibleFiles(candidateSelection, filesCompacting);
|
candidateSelection = getCurrentEligibleFiles(candidateSelection, filesCompacting);
|
||||||
long cfTtl = this.storeConfigInfo.getStoreFileTtl();
|
long cfTtl = this.storeConfigInfo.getStoreFileTtl();
|
||||||
if (!forceMajor) {
|
if (!forceMajor) {
|
||||||
@ -110,18 +116,10 @@ public class RatioBasedCompactionPolicy extends CompactionPolicy {
|
|||||||
if (!majorCompaction) {
|
if (!majorCompaction) {
|
||||||
// we're doing a minor compaction, let's see what files are applicable
|
// we're doing a minor compaction, let's see what files are applicable
|
||||||
candidateSelection = filterBulk(candidateSelection);
|
candidateSelection = filterBulk(candidateSelection);
|
||||||
candidateSelection = applyCompactionPolicy(candidateSelection, mayUseOffPeak);
|
candidateSelection = applyCompactionPolicy(candidateSelection, mayUseOffPeak, mayBeStuck);
|
||||||
candidateSelection = checkMinFilesCriteria(candidateSelection);
|
candidateSelection = checkMinFilesCriteria(candidateSelection);
|
||||||
}
|
}
|
||||||
candidateSelection = removeExcessFiles(candidateSelection, isUserCompaction, majorCompaction);
|
candidateSelection = removeExcessFiles(candidateSelection, isUserCompaction, majorCompaction);
|
||||||
|
|
||||||
if (candidateSelection.size() == 0
|
|
||||||
&& candidateFiles.size() >= storeConfigInfo.getBlockingFileCount()) {
|
|
||||||
candidateSelection = new ArrayList<StoreFile>(candidateFiles);
|
|
||||||
candidateSelection
|
|
||||||
.subList(0, Math.max(0,candidateSelection.size() - comConf.getMinFilesToCompact()))
|
|
||||||
.clear();
|
|
||||||
}
|
|
||||||
CompactionRequest result = new CompactionRequest(candidateSelection);
|
CompactionRequest result = new CompactionRequest(candidateSelection);
|
||||||
result.setOffPeak(!candidateSelection.isEmpty() && !majorCompaction && mayUseOffPeak);
|
result.setOffPeak(!candidateSelection.isEmpty() && !majorCompaction && mayUseOffPeak);
|
||||||
return result;
|
return result;
|
||||||
@ -261,8 +259,8 @@ public class RatioBasedCompactionPolicy extends CompactionPolicy {
|
|||||||
* | | | | | | | | | | | |
|
* | | | | | | | | | | | |
|
||||||
* | | | | | | | | | | | |
|
* | | | | | | | | | | | |
|
||||||
*/
|
*/
|
||||||
ArrayList<StoreFile> applyCompactionPolicy(
|
ArrayList<StoreFile> applyCompactionPolicy(ArrayList<StoreFile> candidates,
|
||||||
ArrayList<StoreFile> candidates, boolean mayUseOffPeak) throws IOException {
|
boolean mayUseOffPeak, boolean mayBeStuck) throws IOException {
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
@ -298,11 +296,14 @@ public class RatioBasedCompactionPolicy extends CompactionPolicy {
|
|||||||
if (start < countOfFiles) {
|
if (start < countOfFiles) {
|
||||||
LOG.info("Default compaction algorithm has selected " + (countOfFiles - start)
|
LOG.info("Default compaction algorithm has selected " + (countOfFiles - start)
|
||||||
+ " files from " + countOfFiles + " candidates");
|
+ " files from " + countOfFiles + " candidates");
|
||||||
|
} else if (mayBeStuck) {
|
||||||
|
// We may be stuck. Compact the latest files if we can.
|
||||||
|
int filesToLeave = candidates.size() - comConf.getMinFilesToCompact();
|
||||||
|
if (filesToLeave >= 0) {
|
||||||
|
start = filesToLeave;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start > 0) {
|
|
||||||
candidates.subList(0, start).clear();
|
candidates.subList(0, start).clear();
|
||||||
}
|
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class EverythingPolicy extends RatioBasedCompactionPolicy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
final ArrayList<StoreFile> applyCompactionPolicy(final ArrayList<StoreFile> candidates,
|
final ArrayList<StoreFile> applyCompactionPolicy(final ArrayList<StoreFile> candidates,
|
||||||
final boolean mayUseOffPeak) throws IOException {
|
final boolean mayUseOffPeak, final boolean mayBeStuck) throws IOException {
|
||||||
|
|
||||||
if (candidates.size() < comConf.getMinFilesToCompact()) {
|
if (candidates.size() < comConf.getMinFilesToCompact()) {
|
||||||
return new ArrayList<StoreFile>(0);
|
return new ArrayList<StoreFile>(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user