echauchot commented on code in PR #3: URL: https://github.com/apache/flink-connector-cassandra/pull/3#discussion_r1073554548
########## flink-connector-cassandra/src/main/java/org/apache/flink/connector/cassandra/source/split/RingRange.java: ########## @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.cassandra.source.split; + +import javax.annotation.Nullable; + +import java.io.Serializable; +import java.math.BigInteger; + +/** + * Represents a portion of Cassandra token ring. It is a range between a start token and an end + * token. + */ +public final class RingRange implements Serializable { + + private final BigInteger start; + private final BigInteger end; + + private RingRange(BigInteger start, BigInteger end) { + this.start = start; + this.end = end; + } + + public static RingRange of(BigInteger start, BigInteger end) { + return new RingRange(start, end); + } + + public BigInteger getStart() { + return start; + } + + public BigInteger getEnd() { + return end; + } + + /** + * Returns the size of this range. + * + * @return size of the range, max - range, in case of wrap + */ + BigInteger span(BigInteger ringSize) { Review Comment: See my general comments about Apache Beam Cassandra partitionner ########## flink-connector-cassandra/src/main/java/org/apache/flink/connector/cassandra/source/split/SplitsGenerator.java: ########## @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.cassandra.source.split; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +/** + * This class generates {@link CassandraSplit}s by generating {@link RingRange}s based on Cassandra + * cluster partitioner and Flink source parallelism. + */ +public final class SplitsGenerator { + private static final Logger LOG = LoggerFactory.getLogger(SplitsGenerator.class); + + private final String partitioner; + private final BigInteger rangeMin; + private final BigInteger rangeMax; + private final BigInteger rangeSize; + + public SplitsGenerator(String partitioner) { + this.partitioner = partitioner; + rangeMin = getRangeMin(); + rangeMax = getRangeMax(); + rangeSize = getRangeSize(); + } + + private BigInteger getRangeMin() { + if (partitioner.endsWith("RandomPartitioner")) { + return BigInteger.ZERO; + } else if (partitioner.endsWith("Murmur3Partitioner")) { + return BigInteger.valueOf(2).pow(63).negate(); + } else { + throw new UnsupportedOperationException( + "Unsupported partitioner. " + "Only Random and Murmur3 are supported"); + } + } + + private BigInteger getRangeMax() { + if (partitioner.endsWith("RandomPartitioner")) { + return BigInteger.valueOf(2).pow(127).subtract(BigInteger.ONE); + } else if (partitioner.endsWith("Murmur3Partitioner")) { + return BigInteger.valueOf(2).pow(63).subtract(BigInteger.ONE); + } else { + throw new UnsupportedOperationException( + "Unsupported partitioner. " + "Only Random and Murmur3 are supported"); + } + } + + private BigInteger getRangeSize() { + return rangeMax.subtract(rangeMin).add(BigInteger.ONE); + } + + /** + * Given properly ordered list of Cassandra tokens, compute at least {@code totalSplitCount} Review Comment: See my general comments about Apache Beam Cassandra partitionner -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
