You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2014/01/27 20:50:51 UTC
svn commit: r1561811 - in /hbase/branches/0.96/hbase-server/src:
main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java
test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java
Author: larsh
Date: Mon Jan 27 19:50:50 2014
New Revision: 1561811
URL: http://svn.apache.org/r1561811
Log:
HBASE-10371 Compaction creates empty hfile, then selects this file for compaction and creates empty hfile and over again. (binlijin)
Modified:
hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java
hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java
Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java?rev=1561811&r1=1561810&r2=1561811&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java (original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java Mon Jan 27 19:50:50 2014
@@ -156,7 +156,11 @@ public class RatioBasedCompactionPolicy
expiredStoreFiles.add(storeFile);
}
}
-
+ if (expiredStoreFiles != null && expiredStoreFiles.size() == 1
+ && expiredStoreFiles.get(0).getReader().getEntries() == 0) {
+ // If just one empty store file, do not select for compaction.
+ return null;
+ }
return expiredStoreFiles;
}
Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java?rev=1561811&r1=1561810&r2=1561811&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java (original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java Mon Jan 27 19:50:50 2014
@@ -130,6 +130,8 @@ public class TestDefaultCompactSelection
boolean isRef = false;
long ageInDisk;
long sequenceid;
+ TimeRangeTracker timeRangeTracker;
+ long entryCount;
MockStoreFile(long length, long ageInDisk, boolean isRef, long sequenceid) throws IOException {
super(TEST_UTIL.getTestFileSystem(), TEST_FILE, TEST_UTIL.getConfiguration(),
@@ -159,14 +161,35 @@ public class TestDefaultCompactSelection
return this.isRef;
}
+ void setTimeRangeTracker(TimeRangeTracker timeRangeTracker) {
+ this.timeRangeTracker = timeRangeTracker;
+ }
+
+ void setEntries(long entryCount) {
+ this.entryCount = entryCount;
+ }
+
@Override
public StoreFile.Reader getReader() {
final long len = this.length;
+ final TimeRangeTracker timeRange = this.timeRangeTracker;
+ final long entries = this.entryCount;
return new StoreFile.Reader() {
@Override
public long length() {
return len;
}
+
+ @Override
+ public long getMaxTimestamp() {
+ return timeRange == null ? Long.MAX_VALUE
+ : timeRange.maximumTimestamp;
+ }
+
+ @Override
+ public long getEntries() {
+ return entries;
+ }
};
}
@@ -359,4 +382,29 @@ public class TestDefaultCompactSelection
// Prefer later compaction if the benefit is significant.
compactEquals(sfCreate(99,99,99,99, 27,27,27,20,20,20), 20, 20, 20);
}
+
+ public void testCompactionEmptyHFile() throws IOException {
+ // Set TTL
+ ScanInfo oldScanInfo = store.getScanInfo();
+ ScanInfo newScanInfo = new ScanInfo(oldScanInfo.getFamily(),
+ oldScanInfo.getMinVersions(), oldScanInfo.getMaxVersions(), 600,
+ oldScanInfo.getKeepDeletedCells(), oldScanInfo.getTimeToPurgeDeletes(),
+ oldScanInfo.getComparator());
+ store.setScanInfo(newScanInfo);
+ // Do not compact empty store file
+ List<StoreFile> candidates = sfCreate(0);
+ for (StoreFile file : candidates) {
+ if (file instanceof MockStoreFile) {
+ MockStoreFile mockFile = (MockStoreFile) file;
+ mockFile.setTimeRangeTracker(new TimeRangeTracker(-1, -1));
+ mockFile.setEntries(0);
+ }
+ }
+ // Test Default compactions
+ CompactionRequest result = ((RatioBasedCompactionPolicy) store.storeEngine
+ .getCompactionPolicy()).selectCompaction(candidates,
+ new ArrayList<StoreFile>(), false, false, false);
+ assertTrue(result.getFiles().size() == 0);
+ store.setScanInfo(oldScanInfo);
+ }
}