HBASE-13412 Region split decisions should have jitter

This commit is contained in:
Elliott Clark 2015-04-06 10:22:32 -07:00
parent 9ac3c5f16d
commit b6756b39c2
2 changed files with 19 additions and 6 deletions

View File

@ -23,6 +23,8 @@ import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import java.util.Random;
/**
* A {@link RegionSplitPolicy} implementation which splits a region
* as soon as any of its store files exceeds a maximum configurable
@ -34,6 +36,8 @@ import org.apache.hadoop.hbase.HTableDescriptor;
*/
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
public class ConstantSizeRegionSplitPolicy extends RegionSplitPolicy {
private static final Random RANDOM = new Random();
private long desiredMaxFileSize;
@Override
@ -48,6 +52,8 @@ public class ConstantSizeRegionSplitPolicy extends RegionSplitPolicy {
this.desiredMaxFileSize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
HConstants.DEFAULT_MAX_FILE_SIZE);
}
double jitter = conf.getDouble("hbase.hregion.max.filesize.jitter", 0.25D);
this.desiredMaxFileSize += (long)(desiredMaxFileSize * (RANDOM.nextFloat() - 0.5D) * jitter);
}
@Override

View File

@ -110,14 +110,21 @@ public class TestRegionSplitPolicy {
// now be no longer be splittable since split size has gone up.
regions.add(mockRegion);
assertFalse(policy.shouldSplit());
// Quadruple (2 squared) the store size and make sure its just over; verify it'll split
Mockito.doReturn((flushSize * 2 * 2 * 2) + 1).when(mockStore).getSize();
// make sure its just over; verify it'll split
Mockito.doReturn((long)(maxSplitSize * 1.025 + 1)).when(mockStore).getSize();
assertTrue(policy.shouldSplit());
// Finally assert that even if loads of regions, we'll split at max size
assertEquals(maxSplitSize, policy.getSizeToCheck(1000));
assertWithinJitter(maxSplitSize, policy.getSizeToCheck(1000));
// Assert same is true if count of regions is zero.
assertEquals(maxSplitSize, policy.getSizeToCheck(0));
assertWithinJitter(maxSplitSize, policy.getSizeToCheck(0));
}
private void assertWithinJitter(long maxSplitSize, long sizeToCheck) {
assertTrue("Size greater than lower bound of jitter",
(long)(maxSplitSize * 0.75) <= sizeToCheck);
assertTrue("Size less than upper bound of jitter",
(long)(maxSplitSize * 1.25) >= sizeToCheck);
}
@Test
@ -129,13 +136,13 @@ public class TestRegionSplitPolicy {
ConstantSizeRegionSplitPolicy policy =
(ConstantSizeRegionSplitPolicy)RegionSplitPolicy.create(
mockRegion, conf);
assertEquals(1234L, policy.getDesiredMaxFileSize());
assertWithinJitter(1234L, policy.getDesiredMaxFileSize());
// If specified in HTD, should use that
htd.setMaxFileSize(9999L);
policy = (ConstantSizeRegionSplitPolicy)RegionSplitPolicy.create(
mockRegion, conf);
assertEquals(9999L, policy.getDesiredMaxFileSize());
assertWithinJitter(9999L, policy.getDesiredMaxFileSize());
}
/**