test_class.file: src/server/src/test/java/io/cassandrareaper/service/SegmentGeneratorTest.java
test_class.identifier: SegmentGeneratorTest
test_case.body: @Test
    public void coalesceTokenRangesBy200TokensPerSegmentTests() throws ReaperException {
      SegmentGenerator sg = new SegmentGenerator(BigInteger.valueOf(1), BigInteger.valueOf(1500));
      Map<List<String>, List<String>> rangeToEndpoint = Maps.newHashMap();
      rangeToEndpoint.put(Arrays.asList("1", "200"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("200", "400"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("400", "600"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("600", "800"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("800", "1000"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("1100", "1200"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("1200", "1300"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("1300", "1400"), Arrays.asList("node1", "node2", "node3"));
      rangeToEndpoint.put(Arrays.asList("1400", "1500"), Arrays.asList("node1", "node2", "node3"));
  
      Map<List<String>, List<RingRange>> replicasToRangeMap
          = RepairRunService.buildReplicasToRangeMap(rangeToEndpoint);
  
      List<Segment> segments = sg.coalesceTokenRanges(BigInteger.valueOf(200), replicasToRangeMap);
  
      // Ranges with 100 tokens will get coalesced two by two
      assertEquals(7, segments.size());
    }
test_case.class_method_signature: SegmentGeneratorTest.coalesceTokenRangesBy200TokensPerSegmentTests()
test_case.full_signature: @Test public void coalesceTokenRangesBy200TokensPerSegmentTests()
test_case.identifier: coalesceTokenRangesBy200TokensPerSegmentTests
test_case.invocations: valueOf valueOf newHashMap put asList asList put asList asList put asList asList put asList asList put asList asList put asList asList put asList asList put asList asList put asList asList buildReplicasToRangeMap coalesceTokenRanges valueOf assertEquals size
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void coalesceTokenRangesBy200TokensPerSegmentTests()
focal_class.declarator: LOG = LoggerFactory.getLogger(SegmentGenerator.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOG = LoggerFactory.getLogger(SegmentGenerator.class);
focal_class.type: Logger
focal_class.var_name: LOG
focal_class.declarator: COALESCING_DISABLED
        = Boolean.getBoolean(SegmentGenerator.class.getName() + ".disable.tokenrange.coalescing")
focal_class.modifier: private static final
focal_class.original_string: private static final boolean COALESCING_DISABLED
        = Boolean.getBoolean(SegmentGenerator.class.getName() + ".disable.tokenrange.coalescing");
focal_class.type: boolean
focal_class.var_name: COALESCING_DISABLED
focal_class.declarator: partitioner
focal_class.modifier: private final
focal_class.original_string: private final String partitioner;
focal_class.type: String
focal_class.var_name: partitioner
focal_class.declarator: rangeMin
focal_class.modifier: private final
focal_class.original_string: private final BigInteger rangeMin;
focal_class.type: BigInteger
focal_class.var_name: rangeMin
focal_class.declarator: rangeMax
focal_class.modifier: private final
focal_class.original_string: private final BigInteger rangeMax;
focal_class.type: BigInteger
focal_class.var_name: rangeMax
focal_class.declarator: rangeSize
focal_class.modifier: private final
focal_class.original_string: private final BigInteger rangeSize;
focal_class.type: BigInteger
focal_class.var_name: rangeSize
focal_class.file: src/server/src/main/java/io/cassandrareaper/service/SegmentGenerator.java
focal_class.identifier: SegmentGenerator
focal_class.class_method_signature: SegmentGenerator.SegmentGenerator(String partitioner)
focal_class.full_signature:   SegmentGenerator(String partitioner)
focal_class.identifier: SegmentGenerator
focal_class.parameters: (String partitioner)
focal_class.signature:  SegmentGenerator(String partitioner)
focal_class.class_method_signature: SegmentGenerator.SegmentGenerator(BigInteger rangeMin, BigInteger rangeMax)
focal_class.full_signature:   SegmentGenerator(BigInteger rangeMin, BigInteger rangeMax)
focal_class.identifier: SegmentGenerator
focal_class.parameters: (BigInteger rangeMin, BigInteger rangeMax)
focal_class.signature:  SegmentGenerator(BigInteger rangeMin, BigInteger rangeMax)
focal_class.class_method_signature: SegmentGenerator.max(BigInteger big0, BigInteger big1)
focal_class.full_signature: static BigInteger max(BigInteger big0, BigInteger big1)
focal_class.identifier: max
focal_class.modifiers: static
focal_class.parameters: (BigInteger big0, BigInteger big1)
focal_class.return: BigInteger
focal_class.signature: BigInteger max(BigInteger big0, BigInteger big1)
focal_class.class_method_signature: SegmentGenerator.min(BigInteger big0, BigInteger big1)
focal_class.full_signature: static BigInteger min(BigInteger big0, BigInteger big1)
focal_class.identifier: min
focal_class.modifiers: static
focal_class.parameters: (BigInteger big0, BigInteger big1)
focal_class.return: BigInteger
focal_class.signature: BigInteger min(BigInteger big0, BigInteger big1)
focal_class.class_method_signature: SegmentGenerator.lowerThan(BigInteger big0, BigInteger big1)
focal_class.full_signature: static boolean lowerThan(BigInteger big0, BigInteger big1)
focal_class.identifier: lowerThan
focal_class.modifiers: static
focal_class.parameters: (BigInteger big0, BigInteger big1)
focal_class.return: boolean
focal_class.signature: boolean lowerThan(BigInteger big0, BigInteger big1)
focal_class.class_method_signature: SegmentGenerator.lowerThanOrEqual(BigInteger big0, BigInteger big1)
focal_class.full_signature: static boolean lowerThanOrEqual(BigInteger big0, BigInteger big1)
focal_class.identifier: lowerThanOrEqual
focal_class.modifiers: static
focal_class.parameters: (BigInteger big0, BigInteger big1)
focal_class.return: boolean
focal_class.signature: boolean lowerThanOrEqual(BigInteger big0, BigInteger big1)
focal_class.class_method_signature: SegmentGenerator.greaterThan(BigInteger big0, BigInteger big1)
focal_class.full_signature: static boolean greaterThan(BigInteger big0, BigInteger big1)
focal_class.identifier: greaterThan
focal_class.modifiers: static
focal_class.parameters: (BigInteger big0, BigInteger big1)
focal_class.return: boolean
focal_class.signature: boolean greaterThan(BigInteger big0, BigInteger big1)
focal_class.class_method_signature: SegmentGenerator.greaterThanOrEqual(BigInteger big0, BigInteger big1)
focal_class.full_signature: static boolean greaterThanOrEqual(BigInteger big0, BigInteger big1)
focal_class.identifier: greaterThanOrEqual
focal_class.modifiers: static
focal_class.parameters: (BigInteger big0, BigInteger big1)
focal_class.return: boolean
focal_class.signature: boolean greaterThanOrEqual(BigInteger big0, BigInteger big1)
focal_class.class_method_signature: SegmentGenerator.generateSegments(
        int totalSegmentCount,
        List<BigInteger> ringTokens,
        Boolean incrementalRepair,
        Map<List<String>, List<RingRange>> replicasToRange,
        String cassandraVersion)
focal_class.full_signature:  List<Segment> generateSegments(
        int totalSegmentCount,
        List<BigInteger> ringTokens,
        Boolean incrementalRepair,
        Map<List<String>, List<RingRange>> replicasToRange,
        String cassandraVersion)
focal_class.identifier: generateSegments
focal_class.parameters: (
        int totalSegmentCount,
        List<BigInteger> ringTokens,
        Boolean incrementalRepair,
        Map<List<String>, List<RingRange>> replicasToRange,
        String cassandraVersion)
focal_class.return: List<Segment>
focal_class.signature: List<Segment> generateSegments(
        int totalSegmentCount,
        List<BigInteger> ringTokens,
        Boolean incrementalRepair,
        Map<List<String>, List<RingRange>> replicasToRange,
        String cassandraVersion)
focal_class.class_method_signature: SegmentGenerator.coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.full_signature: @VisibleForTesting List<Segment> coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.identifier: coalesceTokenRanges
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.return: List<Segment>
focal_class.signature: List<Segment> coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.class_method_signature: SegmentGenerator.allTokensHaveBeenCoalesced(
        List<Segment> coalescedRepairSegments, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.full_signature: private static boolean allTokensHaveBeenCoalesced(
        List<Segment> coalescedRepairSegments, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.identifier: allTokensHaveBeenCoalesced
focal_class.modifiers: private static
focal_class.parameters: (
        List<Segment> coalescedRepairSegments, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.return: boolean
focal_class.signature: boolean allTokensHaveBeenCoalesced(
        List<Segment> coalescedRepairSegments, Map<List<String>, List<RingRange>> replicasToRange)
focal_class.class_method_signature: SegmentGenerator.getTargetSegmentSize(int segmentCount)
focal_class.full_signature: private BigInteger getTargetSegmentSize(int segmentCount)
focal_class.identifier: getTargetSegmentSize
focal_class.modifiers: private
focal_class.parameters: (int segmentCount)
focal_class.return: BigInteger
focal_class.signature: BigInteger getTargetSegmentSize(int segmentCount)
focal_class.class_method_signature: SegmentGenerator.inRange(BigInteger token)
focal_class.full_signature: protected boolean inRange(BigInteger token)
focal_class.identifier: inRange
focal_class.modifiers: protected
focal_class.parameters: (BigInteger token)
focal_class.return: boolean
focal_class.signature: boolean inRange(BigInteger token)
focal_class.class_method_signature: SegmentGenerator.supportsSegmentCoalescing(String cassandraVersion)
focal_class.full_signature: private boolean supportsSegmentCoalescing(String cassandraVersion)
focal_class.identifier: supportsSegmentCoalescing
focal_class.modifiers: private
focal_class.parameters: (String cassandraVersion)
focal_class.return: boolean
focal_class.signature: boolean supportsSegmentCoalescing(String cassandraVersion)
focal_method.body: @VisibleForTesting
    List<Segment> coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange) {
  
      List<Segment> coalescedRepairSegments = Lists.newArrayList();
      List<RingRange> tokenRangesForCurrentSegment = Lists.newArrayList();
      BigInteger tokenCount = BigInteger.ZERO;
  
      for (Entry<List<String>, List<RingRange>> tokenRangesByReplica : replicasToRange.entrySet()) {
        LOG.info("Coalescing segments for nodes {}", tokenRangesByReplica.getKey());
        for (RingRange tokenRange : tokenRangesByReplica.getValue()) {
          if (tokenRange.span(rangeSize).add(tokenCount).compareTo(targetSegmentSize) > 0
              && !tokenRangesForCurrentSegment.isEmpty()) {
            // enough tokens in that segment
            LOG.info(
                "Got enough tokens for one segment ({}) : {}",
                tokenCount,
                tokenRangesForCurrentSegment);
            coalescedRepairSegments.add(
                Segment.builder().withTokenRanges(tokenRangesForCurrentSegment).build());
            tokenRangesForCurrentSegment = Lists.newArrayList();
            tokenCount = BigInteger.ZERO;
          }
  
          tokenCount = tokenCount.add(tokenRange.span(rangeSize));
          tokenRangesForCurrentSegment.add(tokenRange);
  
        }
  
        if (!tokenRangesForCurrentSegment.isEmpty()) {
          coalescedRepairSegments.add(
              Segment.builder().withTokenRanges(tokenRangesForCurrentSegment).build());
          tokenRangesForCurrentSegment = Lists.newArrayList();
        }
      }
  
  
      // Check that we haven't left any token range outside of the resulting segments
      Preconditions.checkState(
          allTokensHaveBeenCoalesced(coalescedRepairSegments, replicasToRange),
          "Number of coalesced tokens doesn't match with the total number of tokens");
  
      return coalescedRepairSegments;
    }
focal_method.class_method_signature: SegmentGenerator.coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_method.full_signature: @VisibleForTesting List<Segment> coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_method.identifier: coalesceTokenRanges
focal_method.invocations: newArrayList newArrayList entrySet info getKey getValue compareTo add span isEmpty info add build withTokenRanges builder newArrayList add span add isEmpty add build withTokenRanges builder newArrayList checkState allTokensHaveBeenCoalesced
focal_method.modifiers: @VisibleForTesting
focal_method.parameters: (
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)
focal_method.return: List<Segment>
focal_method.signature: List<Segment> coalesceTokenRanges(
        BigInteger targetSegmentSize, Map<List<String>, List<RingRange>> replicasToRange)