Search in sources :

Example 1 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey 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 DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class ReplicaFilteringProtection method mergeController.

/**
 * Returns a merge listener that skips the merged rows for which any of the replicas doesn't have a version,
 * pessimistically assuming that they are outdated. It is intended to be used during a first merge of per-replica
 * query results to ensure we fetch enough results from the replicas to ensure we don't miss any potentially
 * outdated result.
 * <p>
 * The listener will track both the accepted data and the primary keys of the rows that are considered as outdated.
 * That way, once the query results would have been merged using this listener, further calls to
 * {@link #queryProtectedPartitions(PartitionIterator, int)} will use the collected data to return a copy of the
 * data originally collected from the specified replica, completed with the potentially outdated rows.
 */
UnfilteredPartitionIterators.MergeListener mergeController() {
    return new UnfilteredPartitionIterators.MergeListener() {

        @Override
        public void close() {
            // If we hit the failure threshold before consuming a single partition, record the current rows cached.
            tableMetrics.rfpRowsCachedPerQuery.update(Math.max(currentRowsCached, maxRowsCached));
        }

        @Override
        public UnfilteredRowIterators.MergeListener getRowMergeListener(DecoratedKey partitionKey, List<UnfilteredRowIterator> versions) {
            List<PartitionBuilder> builders = new ArrayList<>(sources.size());
            RegularAndStaticColumns columns = columns(versions);
            EncodingStats stats = EncodingStats.merge(versions, NULL_TO_NO_STATS);
            for (int i = 0; i < sources.size(); i++) builders.add(i, new PartitionBuilder(partitionKey, sources.get(i), columns, stats));
            return new UnfilteredRowIterators.MergeListener() {

                @Override
                public void onMergedPartitionLevelDeletion(DeletionTime mergedDeletion, DeletionTime[] versions) {
                    // cache the deletion time versions to be able to regenerate the original row iterator
                    for (int i = 0; i < versions.length; i++) builders.get(i).setDeletionTime(versions[i]);
                }

                @Override
                public Row onMergedRows(Row merged, Row[] versions) {
                    // cache the row versions to be able to regenerate the original row iterator
                    for (int i = 0; i < versions.length; i++) builders.get(i).addRow(versions[i]);
                    if (merged.isEmpty())
                        return merged;
                    boolean isPotentiallyOutdated = false;
                    boolean isStatic = merged.isStatic();
                    for (int i = 0; i < versions.length; i++) {
                        Row version = versions[i];
                        if (version == null || (isStatic && version.isEmpty())) {
                            isPotentiallyOutdated = true;
                            builders.get(i).addToFetch(merged);
                        }
                    }
                    // to look at enough data to ultimately fulfill the query limit.
                    return isPotentiallyOutdated ? null : merged;
                }

                @Override
                public void onMergedRangeTombstoneMarkers(RangeTombstoneMarker merged, RangeTombstoneMarker[] versions) {
                    // cache the marker versions to be able to regenerate the original row iterator
                    for (int i = 0; i < versions.length; i++) builders.get(i).addRangeTombstoneMarker(versions[i]);
                }

                @Override
                public void close() {
                    for (int i = 0; i < sources.size(); i++) originalPartitions.get(i).add(builders.get(i));
                }
            };
        }
    };
}
Also used : UnfilteredRowIterators(org.apache.cassandra.db.rows.UnfilteredRowIterators) DecoratedKey(org.apache.cassandra.db.DecoratedKey) DeletionTime(org.apache.cassandra.db.DeletionTime) ArrayList(java.util.ArrayList) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) RangeTombstoneMarker(org.apache.cassandra.db.rows.RangeTombstoneMarker) List(java.util.List) ArrayList(java.util.ArrayList) Row(org.apache.cassandra.db.rows.Row) RegularAndStaticColumns(org.apache.cassandra.db.RegularAndStaticColumns)

Example 3 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class CompactionIteratorTest method iterate.

private void iterate(Unfiltered... unfiltereds) {
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    DecoratedKey key = cfs.getPartitioner().decorateKey(ByteBufferUtil.bytes("key"));
    try (CompactionController controller = new CompactionController(cfs, Integer.MAX_VALUE);
        UnfilteredRowIterator rows = rows(cfs.metadata(), key, false, unfiltereds);
        ISSTableScanner scanner = new Scanner(Collections.singletonList(rows));
        CompactionIterator iter = new CompactionIterator(OperationType.COMPACTION, Collections.singletonList(scanner), controller, FBUtilities.nowInSeconds(), null)) {
        while (iter.hasNext()) {
            try (UnfilteredRowIterator partition = iter.next()) {
                partition.forEachRemaining(u -> {
                });
            }
        }
    }
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 4 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class CompactionIteratorTest method generateContent.

NavigableMap<DecoratedKey, List<Unfiltered>> generateContent(Random rand, UnfilteredRowsGenerator generator, List<DecoratedKey> keys, int pcount, int rcount) {
    NavigableMap<DecoratedKey, List<Unfiltered>> map = new TreeMap<>();
    for (int i = 0; i < pcount; ++i) {
        DecoratedKey key = keys.get(rand.nextInt(keys.size()));
        map.put(key, generator.generateSource(rand, rcount, RANGE, NOW - 5, x -> NOW - 1));
    }
    return map;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) java.util(java.util) CQLTester(org.apache.cassandra.cql3.CQLTester) DuplicateRowCheckerTest.rows(org.apache.cassandra.db.transform.DuplicateRowCheckerTest.rows) Message(org.apache.cassandra.net.Message) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) org.apache.cassandra.db.rows(org.apache.cassandra.db.rows) Int32Type(org.apache.cassandra.db.marshal.Int32Type) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) DuplicateRowCheckerTest.makeRow(org.apache.cassandra.db.transform.DuplicateRowCheckerTest.makeRow) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Matcher(java.util.regex.Matcher) com.google.common.collect(com.google.common.collect) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Keyspace(org.apache.cassandra.db.Keyspace) MessagingService(org.apache.cassandra.net.MessagingService) FBUtilities(org.apache.cassandra.utils.FBUtilities) Util(org.apache.cassandra.Util) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) KeyspaceParams(org.apache.cassandra.schema.KeyspaceParams) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) Test(org.junit.Test) DuplicateRowCheckerTest.assertCommandIssued(org.apache.cassandra.db.transform.DuplicateRowCheckerTest.assertCommandIssued) SchemaLoader(org.apache.cassandra.SchemaLoader) DeletionTime(org.apache.cassandra.db.DeletionTime) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) AbstractUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.AbstractUnfilteredPartitionIterator) TableMetadata(org.apache.cassandra.schema.TableMetadata) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) DecoratedKey(org.apache.cassandra.db.DecoratedKey)

Example 5 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class CompactionStrategyManagerTest method createSSTableWithKey.

private static SSTableReader createSSTableWithKey(String keyspace, String table, int key) {
    long timestamp = System.currentTimeMillis();
    DecoratedKey dk = Util.dk(String.format("%04d", key));
    ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(table);
    new RowUpdateBuilder(cfs.metadata(), timestamp, dk.getKey()).clustering(Integer.toString(key)).add("val", "val").build().applyUnsafe();
    Set<SSTableReader> before = cfs.getLiveSSTables();
    cfs.forceBlockingFlush();
    Set<SSTableReader> after = cfs.getLiveSSTables();
    return Iterables.getOnlyElement(Sets.difference(after, before));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Aggregations

DecoratedKey (org.apache.cassandra.db.DecoratedKey)80 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)31 Test (org.junit.Test)28 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)22 ByteBuffer (java.nio.ByteBuffer)21 TableMetadata (org.apache.cassandra.schema.TableMetadata)20 Keyspace (org.apache.cassandra.db.Keyspace)18 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)8 File (org.apache.cassandra.io.util.File)8 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 RowMutation (org.apache.cassandra.db.RowMutation)7 Table (org.apache.cassandra.db.Table)7 Row (org.apache.cassandra.db.rows.Row)7 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)7 Token (org.apache.cassandra.dht.Token)7 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)6 RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)5