Java Code Examples for org.apache.cassandra.db.DecoratedKey#getKey()

The following examples show how to use org.apache.cassandra.db.DecoratedKey#getKey() . 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: AntiCompactionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private ColumnFamilyStore prepareColumnFamilyStore()
{
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
    store.truncateBlocking();
    store.disableAutoCompaction();
    long timestamp = System.currentTimeMillis();
    for (int i = 0; i < 10; i++)
    {
        DecoratedKey key = Util.dk(Integer.toString(i));
        Mutation rm = new Mutation(KEYSPACE1, key.getKey());
        for (int j = 0; j < 10; j++)
            rm.add("Standard1", Util.cellname(Integer.toString(j)),
                   ByteBufferUtil.EMPTY_BYTE_BUFFER,
                   timestamp,
                   0);
        rm.apply();
    }
    store.forceBlockingFlush();
    return store;
}
 
Example 2
Source File: DateTieredCompactionStrategyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterOldSSTables()
{
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    cfs.truncateBlocking();
    cfs.disableAutoCompaction();

    ByteBuffer value = ByteBuffer.wrap(new byte[100]);

    // create 3 sstables
    int numSSTables = 3;
    for (int r = 0; r < numSSTables; r++)
    {
        DecoratedKey key = Util.dk(String.valueOf(r));
        Mutation rm = new Mutation(KEYSPACE1, key.getKey());
        rm.add(CF_STANDARD1, Util.cellname("column"), value, r);
        rm.apply();
        cfs.forceBlockingFlush();
    }
    cfs.forceBlockingFlush();

    Iterable<SSTableReader> filtered;
    List<SSTableReader> sstrs = new ArrayList<>(cfs.getSSTables());

    filtered = filterOldSSTables(sstrs, 0, 2);
    assertEquals("when maxSSTableAge is zero, no sstables should be filtered", sstrs.size(), Iterables.size(filtered));

    filtered = filterOldSSTables(sstrs, 1, 2);
    assertEquals("only the newest 2 sstables should remain", 2, Iterables.size(filtered));

    filtered = filterOldSSTables(sstrs, 1, 3);
    assertEquals("only the newest sstable should remain", 1, Iterables.size(filtered));

    filtered = filterOldSSTables(sstrs, 1, 4);
    assertEquals("no sstables should remain when all are too old", 0, Iterables.size(filtered));
}
 
Example 3
Source File: NativeAllocator.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public DecoratedKey clone(DecoratedKey key, OpOrder.Group writeOp)
{
    return new NativeDecoratedKey(key.getToken(), this, writeOp, key.getKey());
}
 
Example 4
Source File: RowCacheKey.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public RowCacheKey(UUID cfId, DecoratedKey key)
{
    this(cfId, key.getKey());
}
 
Example 5
Source File: SSTableWriter.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * @throws IOException if a read from the DataInput fails
 * @throws FSWriteError if a write to the dataFile fails
 */
public long appendFromStream(DecoratedKey key, CFMetaData metadata, DataInput in, Descriptor.Version version) throws IOException
{
    long currentPosition = beforeAppend(key);

    ColumnStats.MaxLongTracker maxTimestampTracker = new ColumnStats.MaxLongTracker(Long.MAX_VALUE);
    ColumnStats.MinLongTracker minTimestampTracker = new ColumnStats.MinLongTracker(Long.MIN_VALUE);
    ColumnStats.MaxIntTracker maxDeletionTimeTracker = new ColumnStats.MaxIntTracker(Integer.MAX_VALUE);
    List<ByteBuffer> minColumnNames = Collections.emptyList();
    List<ByteBuffer> maxColumnNames = Collections.emptyList();
    StreamingHistogram tombstones = new StreamingHistogram(TOMBSTONE_HISTOGRAM_BIN_SIZE);
    boolean hasLegacyCounterShards = false;

    ColumnFamily cf = ArrayBackedSortedColumns.factory.create(metadata);
    cf.delete(DeletionTime.serializer.deserialize(in));

    ColumnIndex.Builder columnIndexer = new ColumnIndex.Builder(cf, key.getKey(), dataFile.stream);

    if (cf.deletionInfo().getTopLevelDeletion().localDeletionTime < Integer.MAX_VALUE)
    {
        tombstones.update(cf.deletionInfo().getTopLevelDeletion().localDeletionTime);
        maxDeletionTimeTracker.update(cf.deletionInfo().getTopLevelDeletion().localDeletionTime);
        minTimestampTracker.update(cf.deletionInfo().getTopLevelDeletion().markedForDeleteAt);
        maxTimestampTracker.update(cf.deletionInfo().getTopLevelDeletion().markedForDeleteAt);
    }

    Iterator<RangeTombstone> rangeTombstoneIterator = cf.deletionInfo().rangeIterator();
    while (rangeTombstoneIterator.hasNext())
    {
        RangeTombstone rangeTombstone = rangeTombstoneIterator.next();
        tombstones.update(rangeTombstone.getLocalDeletionTime());
        minTimestampTracker.update(rangeTombstone.timestamp());
        maxTimestampTracker.update(rangeTombstone.timestamp());
        maxDeletionTimeTracker.update(rangeTombstone.getLocalDeletionTime());
        minColumnNames = ColumnNameHelper.minComponents(minColumnNames, rangeTombstone.min, metadata.comparator);
        maxColumnNames = ColumnNameHelper.maxComponents(maxColumnNames, rangeTombstone.max, metadata.comparator);
    }

    Iterator<OnDiskAtom> iter = metadata.getOnDiskIterator(in, ColumnSerializer.Flag.PRESERVE_SIZE, Integer.MIN_VALUE, version);
    try
    {
        while (iter.hasNext())
        {
            OnDiskAtom atom = iter.next();
            if (atom == null)
                break;

            if (atom instanceof CounterCell)
            {
                atom = ((CounterCell) atom).markLocalToBeCleared();
                hasLegacyCounterShards = hasLegacyCounterShards || ((CounterCell) atom).hasLegacyShards();
            }

            int deletionTime = atom.getLocalDeletionTime();
            if (deletionTime < Integer.MAX_VALUE)
                tombstones.update(deletionTime);
            minTimestampTracker.update(atom.timestamp());
            maxTimestampTracker.update(atom.timestamp());
            minColumnNames = ColumnNameHelper.minComponents(minColumnNames, atom.name(), metadata.comparator);
            maxColumnNames = ColumnNameHelper.maxComponents(maxColumnNames, atom.name(), metadata.comparator);
            maxDeletionTimeTracker.update(atom.getLocalDeletionTime());

            columnIndexer.add(atom); // This write the atom on disk too
        }

        columnIndexer.maybeWriteEmptyRowHeader();
        dataFile.stream.writeShort(END_OF_ROW);
    }
    catch (IOException e)
    {
        throw new FSWriteError(e, dataFile.getPath());
    }

    sstableMetadataCollector.updateMinTimestamp(minTimestampTracker.get())
                            .updateMaxTimestamp(maxTimestampTracker.get())
                            .updateMaxLocalDeletionTime(maxDeletionTimeTracker.get())
                            .addRowSize(dataFile.getFilePointer() - currentPosition)
                            .addColumnCount(columnIndexer.writtenAtomCount())
                            .mergeTombstoneHistogram(tombstones)
                            .updateMinColumnNames(minColumnNames)
                            .updateMaxColumnNames(maxColumnNames)
                            .updateHasLegacyCounterShards(hasLegacyCounterShards);
    afterAppend(key, currentPosition, RowIndexEntry.create(currentPosition, cf.deletionInfo().getTopLevelDeletion(), columnIndexer.build()));
    return currentPosition;
}
 
Example 6
Source File: SSTableReader.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public void invalidateCacheKey(DecoratedKey key)
{
    KeyCacheKey cacheKey = new KeyCacheKey(metadata.cfId, descriptor, key.getKey());
    keyCache.remove(cacheKey);
}
 
Example 7
Source File: DateTieredCompactionStrategyTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testPrepBucket()
{
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    cfs.truncateBlocking();
    cfs.disableAutoCompaction();

    ByteBuffer value = ByteBuffer.wrap(new byte[100]);

    // create 3 sstables
    int numSSTables = 3;
    for (int r = 0; r < numSSTables; r++)
    {
        DecoratedKey key = Util.dk(String.valueOf(r));
        Mutation rm = new Mutation(KEYSPACE1, key.getKey());
        rm.add(CF_STANDARD1, Util.cellname("column"), value, r);
        rm.apply();
        cfs.forceBlockingFlush();
    }
    cfs.forceBlockingFlush();

    List<SSTableReader> sstrs = new ArrayList<>(cfs.getSSTables());

    List<SSTableReader> newBucket = newestBucket(Collections.singletonList(sstrs.subList(0, 2)), 4, 32, 9, 10);
    assertTrue("incoming bucket should not be accepted when it has below the min threshold SSTables", newBucket.isEmpty());

    newBucket = newestBucket(Collections.singletonList(sstrs.subList(0, 2)), 4, 32, 10, 10);
    assertFalse("non-incoming bucket should be accepted when it has at least 2 SSTables", newBucket.isEmpty());

    assertEquals("an sstable with a single value should have equal min/max timestamps", sstrs.get(0).getMinTimestamp(), sstrs.get(0).getMaxTimestamp());
    assertEquals("an sstable with a single value should have equal min/max timestamps", sstrs.get(1).getMinTimestamp(), sstrs.get(1).getMaxTimestamp());
    assertEquals("an sstable with a single value should have equal min/max timestamps", sstrs.get(2).getMinTimestamp(), sstrs.get(2).getMaxTimestamp());

    // if we have more than the max threshold, the oldest should be dropped
    Collections.sort(sstrs, Collections.reverseOrder(new Comparator<SSTableReader>() {
        public int compare(SSTableReader o1, SSTableReader o2) {
            return Long.compare(o1.getMinTimestamp(), o2.getMinTimestamp()) ;
        }
    }));

    List<SSTableReader> bucket = trimToThreshold(sstrs, 2);
    assertEquals("one bucket should have been dropped", 2, bucket.size());
    for (SSTableReader sstr : bucket)
        assertFalse("the oldest sstable should be dropped", sstr.getMinTimestamp() == 0);
}