org.apache.cassandra.dht.Murmur3Partitioner Java Examples

The following examples show how to use org.apache.cassandra.dht.Murmur3Partitioner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraKeyComparatorTest.java    From hdfs2cass with Apache License 2.0 6 votes vote down vote up
@Test
public void compareMurmur3Partitioner() throws IOException {
  conf.set(CassandraParams.SCRUB_CASSANDRACLUSTER_PARTITIONER_CONFIG,
      Murmur3Partitioner.class.getName());
  comparator.setConf(conf);
  // murmur3_128("foo")[0] = -2129773440516405919
  // murmur3_128("bar")[0] = -7911037993560119804
  // murmur3_128("baz")[0] = 8295379539955784970
  checkOrder("bar", "foo");
  checkOrder("foo", "baz");
  checkOrder("bar", "baz");

  // Murmur3Partitioner maps empty string to Long.MIN_VALUE
  checkOrder("", "foo");
  checkOrder("", "bar");
}
 
Example #2
Source File: CassandraShard.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public CassandraShard(CassandraSessionPool.Session session,
                      String keyspace, String table) {
    this.session = session;
    this.keyspace = keyspace;
    this.table = table;

    this.partitioner = new Murmur3Partitioner();
}
 
Example #3
Source File: SSTableAttachedSecondaryIndex.java    From sasi with Apache License 2.0 5 votes vote down vote up
public void init()
{
    if (!(StorageService.getPartitioner() instanceof Murmur3Partitioner))
        throw new UnsupportedOperationException("SASI supported only with Murmur3Partitioner.");

    isInitialized = true;

    metrics = new IndexMetrics(baseCfs);

    // init() is called by SIM only on the instance that it will keep around, but will call addColumnDef on any instance
    // that it happens to create (and subsequently/immediately throw away)
    track(columnDefs);

    baseCfs.getDataTracker().subscribe(this);
}
 
Example #4
Source File: OperationTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeTest()
{
    ExtendedFilter filter = ExtendedFilter.create(BACKEND.getBaseCfs(),
                                                  DataRange.allData(new Murmur3Partitioner()),
                                                  null,
                                                  Integer.MAX_VALUE,
                                                  false,
                                                  System.currentTimeMillis());

    controller = new QueryController(BACKEND, filter, TimeUnit.SECONDS.toMillis(10));
}
 
Example #5
Source File: TokenMapper.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link TokenMapper} instance for the current partitioner using the specified column family
 * metadata.
 *
 * @param metadata The column family metadata.
 * @return A new {@link TokenMapper} instance for the current partitioner.
 */
public static TokenMapper instance(CFMetaData metadata) {
    IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
    if (partitioner instanceof Murmur3Partitioner) {
        return new TokenMapperMurmur(metadata);
    } else {
        return new TokenMapperGeneric(metadata);
    }
}
 
Example #6
Source File: ThriftRangeUtilsTest.java    From deep-spark with Apache License 2.0 4 votes vote down vote up
@Test
public void testFetchSortedTokensWithMurmur3Partitioner() {
    testStringComparableConversion(new Murmur3Partitioner());
}
 
Example #7
Source File: ThriftRangeUtilsTest.java    From deep-spark with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeepTokenRangesWithMurmur3Partitioner() {
    testDeepTokenRangesAux(new Murmur3Partitioner(), 10L, 20L);
}
 
Example #8
Source File: CassandraParams.java    From hdfs2cass with Apache License 2.0 4 votes vote down vote up
public GroupingOptions createGroupingOptions() {
  logger.info("GroupingOptions.numReducers: " + this.getReducers());
  GroupingOptions.Builder builder = GroupingOptions.builder()
      .partitionerClass(CassandraPartitioner.class)
      .sortComparatorClass(CassandraKeyComparator.class)
      .numReducers(this.getReducers());

  final BigInteger maxToken;
  final BigInteger minToken;
  switch (clusterInfo.getPartitionerClass()) {
    case "org.apache.cassandra.dht.RandomPartitioner":
      maxToken = RandomPartitioner.MAXIMUM.subtract(BigInteger.ONE);
      minToken = RandomPartitioner.ZERO;
      break;
    case "org.apache.cassandra.dht.Murmur3Partitioner":
      maxToken = BigInteger.valueOf(Murmur3Partitioner.MAXIMUM);
      minToken = BigInteger.valueOf(Murmur3Partitioner.MINIMUM.token);
      break;
    default:
      throw new IllegalArgumentException("Unknown partitioner class: " + clusterInfo.getPartitionerClass());
  }

  final BigInteger[] rangeWidth = maxToken
      .subtract(minToken)
      .add(BigInteger.ONE)
      .divideAndRemainder(BigInteger.valueOf(this.getReducers()));
  if (!rangeWidth[1].equals(BigInteger.ZERO)) {
    rangeWidth[0] = rangeWidth[0].add(BigInteger.ONE);
  }
  BigInteger rangePerReducer = rangeWidth[0];

  ArrayList<Integer> reducerList = new ArrayList<>(this.getReducers());
  for (int i = 0; i < this.getReducers(); i++) {
    reducerList.add(i);
  }

  Collections.shuffle(reducerList, new Random());

  builder.conf(SCRUB_CASSANDRACLUSTER_PARTITIONER_CONFIG, clusterInfo.getPartitionerClass());
  builder.conf(SCRUB_CASSANDRACLUSTER_RANGE_PER_REDUCER_CONFIG, rangePerReducer.toString());
  builder.conf(SCRUB_CASSANDRACLUSTER_REDUCERS_CONFIG, StringUtils.join(reducerList, ","));
  if (this.getDistributeRandomly()) {
    builder.conf(SCRUB_CASSANDRACLUSTER_DISTRIBUTE_RANDOMLY_CONFIG, Boolean.TRUE.toString());
  }

  return builder.build();
}