mirror of https://github.com/apache/cassandra
Extract calculateSplitCount method
Also added characterization tests Co-Authored-By: Danny Faught <13002425+swalchemist@users.noreply.github.com>
This commit is contained in:
parent
fe025c7f79
commit
2d950d5bd0
|
|
@ -3546,15 +3546,24 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
|
||||
long totalRowCountEstimate = cfs.estimatedKeysForRange(range);
|
||||
|
||||
// splitCount should be much smaller than number of key samples, to avoid huge sampling error
|
||||
int minSamplesPerSplit = 4;
|
||||
int maxSplitCount = keys.size() / minSamplesPerSplit + 1;
|
||||
int splitCount = Math.max(1, Math.min(maxSplitCount, (int)(totalRowCountEstimate / keysPerSplit)));
|
||||
int splitCount = calculateSplitCount(keysPerSplit, totalRowCountEstimate, keys.size());
|
||||
|
||||
List<Token> tokens = keysToTokens(range, keys);
|
||||
return getSplits(tokens, splitCount, cfs);
|
||||
}
|
||||
|
||||
static int calculateSplitCount(int keysPerSplit, long totalRowCountEstimate, int numberOfKeys)
|
||||
{
|
||||
// splitCount should be much smaller than number of key samples, to avoid huge sampling error
|
||||
int minSamplesPerSplit = 4;
|
||||
int maxSplitCount = numberOfKeys / minSamplesPerSplit + 1;
|
||||
int splitCount = Math.max(1,
|
||||
Math.min(
|
||||
maxSplitCount,
|
||||
(int) (totalRowCountEstimate / keysPerSplit)));
|
||||
return splitCount;
|
||||
}
|
||||
|
||||
private List<Pair<Range<Token>, Long>> getSplits(List<Token> tokens, int splitCount, ColumnFamilyStore cfs)
|
||||
{
|
||||
double step = (double) (tokens.size() - 1) / splitCount;
|
||||
|
|
|
|||
|
|
@ -316,4 +316,25 @@ public class StorageServiceTest extends TestBaseImpl
|
|||
assertEquals("Cannot specify tokens without keyspace.", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateSplitCountHappyPath()
|
||||
{
|
||||
int result = StorageService.calculateSplitCount(2, 4, 40);
|
||||
assertEquals(2, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateSplitCountForMin()
|
||||
{
|
||||
int result = StorageService.calculateSplitCount(2, 100, 40);
|
||||
assertEquals(11, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateSplitCountForMaxWithOverflow()
|
||||
{
|
||||
int result = StorageService.calculateSplitCount(1, Long.MAX_VALUE, 4);
|
||||
assertEquals(1, result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue