Search in sources :

Example 21 with DecoratedKey

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

the class PartitionSerializationExceptionTest method testMessageWithSimplePartitionKey.

@Test
public void testMessageWithSimplePartitionKey() {
    TableMetadata metadata = TableMetadata.builder("ks", "tbl").addPartitionKeyColumn("pk", UTF8Type.instance).build();
    DecoratedKey key = mock(DecoratedKey.class);
    when(key.getKey()).thenReturn(UTF8Type.instance.decompose("foo"));
    @SuppressWarnings("unchecked") BaseRowIterator<Unfiltered> partition = mock(BaseRowIterator.class);
    when(partition.metadata()).thenReturn(metadata);
    when(partition.partitionKey()).thenReturn(key);
    PartitionSerializationException pse = new PartitionSerializationException(partition, new RuntimeException());
    assertEquals("Failed to serialize partition key 'foo' on table 'tbl' in keyspace 'ks'.", pse.getMessage());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Test(org.junit.Test)

Example 22 with DecoratedKey

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

the class SSTableRewriterTest method validateKeys.

private void validateKeys(Keyspace ks) {
    for (int i = 0; i < 100; i++) {
        DecoratedKey key = Util.dk(Integer.toString(i));
        ImmutableBTreePartition partition = Util.getOnlyPartitionUnfiltered(Util.cmd(ks.getColumnFamilyStore(CF), key).build());
        assertTrue(partition != null && partition.rowCount() > 0);
    }
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition)

Example 23 with DecoratedKey

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

the class SSTableRewriterTest method testNumberOfFiles_abort.

private void testNumberOfFiles_abort(RewriterTest test) {
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    truncate(cfs);
    SSTableReader s = writeFile(cfs, 1000);
    cfs.addSSTable(s);
    DecoratedKey origFirst = s.first;
    DecoratedKey origLast = s.last;
    long startSize = cfs.metric.liveDiskSpaceUsed.getCount();
    Set<SSTableReader> compacting = Sets.newHashSet(s);
    try (ISSTableScanner scanner = s.getScanner();
        CompactionController controller = new CompactionController(cfs, compacting, 0);
        LifecycleTransaction txn = cfs.getTracker().tryModify(compacting, OperationType.UNKNOWN);
        SSTableRewriter rewriter = new SSTableRewriter(txn, 1000, 10000000, false, true)) {
        rewriter.switchWriter(getWriter(cfs, s.descriptor.directory, txn));
        test.run(scanner, controller, s, cfs, rewriter, txn);
    }
    LifecycleTransaction.waitForDeletions();
    assertEquals(startSize, cfs.metric.liveDiskSpaceUsed.getCount());
    assertEquals(1, cfs.getLiveSSTables().size());
    assertFileCounts(s.descriptor.directory.tryListNames());
    assertEquals(cfs.getLiveSSTables().iterator().next().first, origFirst);
    assertEquals(cfs.getLiveSSTables().iterator().next().last, origLast);
    validateCFS(cfs);
}
Also used : CompactionController(org.apache.cassandra.db.compaction.CompactionController) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 24 with DecoratedKey

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

the class BigTableZeroCopyWriterTest method defineSchema.

@BeforeClass
public static void defineSchema() throws Exception {
    SchemaLoader.prepareServer();
    SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD2), SchemaLoader.compositeIndexCFMD(KEYSPACE1, CF_INDEXED, true), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARDLOWINDEXINTERVAL).minIndexInterval(8).maxIndexInterval(256).caching(CachingParams.CACHE_NOTHING));
    String ks = KEYSPACE1;
    String cf = "Standard1";
    // clear and create just one sstable for this test
    Keyspace keyspace = Keyspace.open(ks);
    store = keyspace.getColumnFamilyStore(cf);
    store.clearUnsafe();
    store.disableAutoCompaction();
    DecoratedKey firstKey = null, lastKey = null;
    long timestamp = System.currentTimeMillis();
    for (int i = 0; i < store.metadata().params.minIndexInterval; i++) {
        DecoratedKey key = Util.dk(String.valueOf(i));
        if (firstKey == null)
            firstKey = key;
        if (lastKey == null)
            lastKey = key;
        if (store.metadata().partitionKeyType.compare(lastKey.getKey(), key.getKey()) < 0)
            lastKey = key;
        new RowUpdateBuilder(store.metadata(), timestamp, key.getKey()).clustering("col").add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
        expectedRowCount++;
    }
    store.forceBlockingFlush();
    sstable = store.getLiveSSTables().iterator().next();
}
Also used : RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Keyspace(org.apache.cassandra.db.Keyspace) DecoratedKey(org.apache.cassandra.db.DecoratedKey) BeforeClass(org.junit.BeforeClass)

Example 25 with DecoratedKey

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

the class HintsTestUtil method sendHintsAndResponses.

static MockMessagingSpy sendHintsAndResponses(TableMetadata metadata, int noOfHints, int noOfResponses) {
    // create spy for hint messages, but only create responses for noOfResponses hints
    Message<NoPayload> message = Message.internalResponse(HINT_RSP, NoPayload.noPayload);
    MockMessagingSpy spy;
    if (noOfResponses != -1) {
        spy = MockMessagingService.when(verb(HINT_REQ)).respondN(message, noOfResponses);
    } else {
        spy = MockMessagingService.when(verb(HINT_REQ)).respond(message);
    }
    // create and write noOfHints using service
    UUID hostId = StorageService.instance.getLocalHostUUID();
    for (int i = 0; i < noOfHints; i++) {
        long now = Clock.Global.currentTimeMillis();
        DecoratedKey dkey = dk(String.valueOf(i));
        PartitionUpdate.SimpleBuilder builder = PartitionUpdate.simpleBuilder(metadata, dkey).timestamp(now);
        builder.row("column0").add("val", "value0");
        Hint hint = Hint.create(builder.buildAsMutation(), now);
        HintsService.instance.write(hostId, hint);
    }
    return spy;
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) UUID(java.util.UUID) NoPayload(org.apache.cassandra.net.NoPayload) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

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