Search in sources :

Example 1 with Murmur3Partitioner

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);
    }
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with Murmur3Partitioner

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();
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) OperationType(org.apache.cassandra.db.compaction.OperationType) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IndexMode(org.apache.cassandra.index.sasi.conf.IndexMode) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner)

Example 3 with Murmur3Partitioner

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);
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) InetSocketAddress(java.net.InetSocketAddress) LongToken(org.apache.cassandra.dht.Murmur3Partitioner.LongToken) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) Token(org.apache.cassandra.dht.Token) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) PendingRangeMaps(org.apache.cassandra.locator.PendingRangeMaps) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy)

Example 4 with Murmur3Partitioner

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);
    }
}
Also used : RandomStringGenerator(org.apache.cassandra.utils.KeyGenerator.RandomStringGenerator) Random(java.util.Random) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) ByteBuffer(java.nio.ByteBuffer) FilterKey(org.apache.cassandra.utils.IFilter.FilterKey) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 5 with Murmur3Partitioner

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);
    }
}
Also used : FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) DataInputStream(java.io.DataInputStream) File(org.apache.cassandra.io.util.File)

Aggregations

Murmur3Partitioner (org.apache.cassandra.dht.Murmur3Partitioner)5 DataInputStream (java.io.DataInputStream)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 Random (java.util.Random)1 OperationType (org.apache.cassandra.db.compaction.OperationType)1 AbstractType (org.apache.cassandra.db.marshal.AbstractType)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)1 Token (org.apache.cassandra.dht.Token)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 IndexMode (org.apache.cassandra.index.sasi.conf.IndexMode)1 File (org.apache.cassandra.io.util.File)1 FileInputStreamPlus (org.apache.cassandra.io.util.FileInputStreamPlus)1 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)1 EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)1 PendingRangeMaps (org.apache.cassandra.locator.PendingRangeMaps)1