|
27 | 27 | import java.util.function.BiConsumer; |
28 | 28 | import java.util.function.Consumer; |
29 | 29 | import java.util.function.Function; |
| 30 | +import java.util.function.Predicate; |
30 | 31 |
|
31 | 32 | import com.google.common.base.Verify; |
32 | 33 | import org.slf4j.Logger; |
@@ -57,6 +58,22 @@ public RangeComparator(DiffContext context, |
57 | 58 | public RangeStats compare(Iterator<PartitionKey> sourceKeys, |
58 | 59 | Iterator<PartitionKey> targetKeys, |
59 | 60 | Function<PartitionKey, PartitionComparator> partitionTaskProvider) { |
| 61 | + return compare(sourceKeys,targetKeys,partitionTaskProvider, partitionKey -> true); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Compares partitions in src and target clusters. |
| 66 | + * |
| 67 | + * @param sourceKeys partition keys in the source cluster |
| 68 | + * @param targetKeys partition keys in the target cluster |
| 69 | + * @param partitionTaskProvider comparision task |
| 70 | + * @param partitionSampler samples partitions based on the probability for probabilistic diff |
| 71 | + * @return stats about the diff |
| 72 | + */ |
| 73 | + public RangeStats compare(Iterator<PartitionKey> sourceKeys, |
| 74 | + Iterator<PartitionKey> targetKeys, |
| 75 | + Function<PartitionKey, PartitionComparator> partitionTaskProvider, |
| 76 | + Predicate<PartitionKey> partitionSampler) { |
60 | 77 |
|
61 | 78 | final RangeStats rangeStats = RangeStats.newStats(); |
62 | 79 | // We can catch this condition earlier, but it doesn't hurt to also check here |
@@ -115,11 +132,16 @@ public RangeStats compare(Iterator<PartitionKey> sourceKeys, |
115 | 132 |
|
116 | 133 | BigInteger token = sourceKey.getTokenAsBigInteger(); |
117 | 134 | try { |
118 | | - PartitionComparator comparisonTask = partitionTaskProvider.apply(sourceKey); |
119 | | - comparisonExecutor.submit(comparisonTask, |
120 | | - onSuccess(rangeStats, partitionCount, token, highestTokenSeen, mismatchReporter, journal), |
121 | | - onError(rangeStats, token, errorReporter), |
122 | | - phaser); |
| 135 | + // Use probabilisticPartitionSampler for sampling partitions, skip partition |
| 136 | + // if the sampler returns false otherwise run diff on that partition |
| 137 | + if (partitionSampler.test(sourceKey)) { |
| 138 | + PartitionComparator comparisonTask = partitionTaskProvider.apply(sourceKey); |
| 139 | + comparisonExecutor.submit(comparisonTask, |
| 140 | + onSuccess(rangeStats, partitionCount, token, highestTokenSeen, mismatchReporter, journal), |
| 141 | + onError(rangeStats, token, errorReporter), |
| 142 | + phaser); |
| 143 | + } |
| 144 | + |
123 | 145 | } catch (Throwable t) { |
124 | 146 | // Handle errors thrown when creating the comparison task. This should trap timeouts and |
125 | 147 | // unavailables occurring when performing the initial query to read the full partition. |
|
0 commit comments