use of org.apache.cassandra.dht.Murmur3Partitioner in project cassandra by apache.
the class SerializationsTest method testBloomFilterTable.
private static void testBloomFilterTable(String file) throws Exception {
Murmur3Partitioner partitioner = new Murmur3Partitioner();
try (DataInputStream in = new DataInputStream(new FileInputStream(new File(file)));
IFilter filter = FilterFactory.deserialize(in, true)) {
for (int i = 1; i <= 10; i++) {
DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
boolean present = filter.isPresent(decoratedKey);
Assert.assertTrue(present);
}
int positives = 0;
for (int i = 11; i <= 1000010; i++) {
DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
boolean present = filter.isPresent(decoratedKey);
if (present)
positives++;
}
double fpr = positives;
fpr /= 1000000;
Assert.assertTrue(fpr <= 0.011d);
}
}
use of org.apache.cassandra.dht.Murmur3Partitioner in project cassandra by apache.
the class SASIIndex method validateOptions.
/**
* Called via reflection at {@link IndexMetadata#validateCustomIndexOptions}
*/
public static Map<String, String> validateOptions(Map<String, String> options, TableMetadata metadata) {
if (!(metadata.partitioner instanceof Murmur3Partitioner))
throw new ConfigurationException("SASI only supports Murmur3Partitioner.");
String targetColumn = options.get("target");
if (targetColumn == null)
throw new ConfigurationException("unknown target column");
Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(metadata, targetColumn);
if (target == null)
throw new ConfigurationException("failed to retrieve target column for: " + targetColumn);
if (target.left.isComplex())
throw new ConfigurationException("complex columns are not yet supported by SASI");
if (target.left.isPartitionKey())
throw new ConfigurationException("partition key columns are not yet supported by SASI");
IndexMode.validateAnalyzer(options, target.left);
IndexMode mode = IndexMode.getMode(target.left, options);
if (mode.mode == Mode.SPARSE) {
if (mode.isLiteral)
throw new ConfigurationException("SPARSE mode is only supported on non-literal columns.");
if (mode.isAnalyzed)
throw new ConfigurationException("SPARSE mode doesn't support analyzers.");
}
return Collections.emptyMap();
}
use of org.apache.cassandra.dht.Murmur3Partitioner in project cassandra by apache.
the class KeyspaceActions method recomputeTopology.
private Topology recomputeTopology() {
AbstractReplicationStrategy strategy = strategy();
Map<InetSocketAddress, Integer> lookup = Cluster.getUniqueAddressLookup(cluster, i -> i.config().num());
int[][] replicasForKey = new int[primaryKeys.length][];
int[][] pendingReplicasForKey = new int[primaryKeys.length][];
for (int i = 0; i < primaryKeys.length; ++i) {
int primaryKey = primaryKeys[i];
Token token = new Murmur3Partitioner().getToken(Int32Type.instance.decompose(primaryKey));
replicasForKey[i] = strategy.calculateNaturalReplicas(token, tokenMetadata).endpointList().stream().mapToInt(lookup::get).toArray();
PendingRangeMaps pendingRanges = tokenMetadata.getPendingRanges(keyspace);
EndpointsForToken pendingEndpoints = pendingRanges == null ? null : pendingRanges.pendingEndpointsFor(token);
if (pendingEndpoints == null)
pendingReplicasForKey[i] = new int[0];
else
pendingReplicasForKey[i] = pendingEndpoints.endpointList().stream().mapToInt(lookup::get).toArray();
}
int[] membersOfRing = joined.toArray();
long[] membersOfRingTokens = IntStream.of(membersOfRing).mapToLong(nodeLookup::tokenOf).toArray();
return new Topology(primaryKeys, membersOfRing, membersOfRingTokens, membersOfQuorum(), currentRf.clone(), quorumRf(), replicasForKey, pendingReplicasForKey);
}
use of org.apache.cassandra.dht.Murmur3Partitioner in project cassandra by apache.
the class BloomFilterTest method testMurmur3FilterHash.
@Test
public void testMurmur3FilterHash() {
IPartitioner partitioner = new Murmur3Partitioner();
Iterator<ByteBuffer> gen = new KeyGenerator.RandomStringGenerator(new Random().nextInt(), FilterTestHelper.ELEMENTS);
long[] expected = new long[2];
long[] actual = new long[2];
while (gen.hasNext()) {
expected[0] = 1;
expected[1] = 2;
actual[0] = 3;
actual[1] = 4;
ByteBuffer key = gen.next();
FilterKey expectedKey = FilterTestHelper.wrap(key);
FilterKey actualKey = partitioner.decorateKey(key);
actualKey.filterHash(actual);
expectedKey.filterHash(expected);
Assert.assertArrayEquals(expected, actual);
}
}
use of org.apache.cassandra.dht.Murmur3Partitioner in project cassandra by apache.
the class SerializationsTest method testBloomFilterTable.
private static void testBloomFilterTable(String file, boolean oldBfFormat) throws Exception {
Murmur3Partitioner partitioner = new Murmur3Partitioner();
try (DataInputStream in = new DataInputStream(new FileInputStreamPlus(new File(file)));
IFilter filter = BloomFilterSerializer.deserialize(in, oldBfFormat)) {
for (int i = 1; i <= 10; i++) {
DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
boolean present = filter.isPresent(decoratedKey);
Assert.assertTrue(present);
}
int positives = 0;
for (int i = 11; i <= 1000010; i++) {
DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
boolean present = filter.isPresent(decoratedKey);
if (present)
positives++;
}
double fpr = positives;
fpr /= 1000000;
Assert.assertTrue(fpr <= 0.011d);
}
}
Aggregations