Search in sources :

Example 6 with Mutation

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

the class WriteCallbackInfoTest method testShouldHint.

private void testShouldHint(Verb verb, ConsistencyLevel cl, boolean allowHints, boolean expectHint) throws Exception {
    Object payload = verb == Verb.PAXOS_COMMIT ? new Commit(UUID.randomUUID(), new PartitionUpdate(MockSchema.newTableMetadata("", ""), ByteBufferUtil.EMPTY_BYTE_BUFFER, RegularAndStaticColumns.NONE, 1)) : new Mutation("", new BufferDecoratedKey(new Murmur3Partitioner.LongToken(0), ByteBufferUtil.EMPTY_BYTE_BUFFER));
    WriteCallbackInfo wcbi = new WriteCallbackInfo(InetAddress.getByName("192.168.1.1"), null, new MessageOut(verb, payload, null), null, cl, allowHints);
    Assert.assertEquals(expectHint, wcbi.shouldHint());
    if (expectHint) {
        Assert.assertNotNull(wcbi.mutation());
    } else {
        boolean fail = false;
        try {
            wcbi.mutation();
        } catch (Throwable t) {
            fail = true;
        }
        Assert.assertTrue(fail);
    }
}
Also used : Commit(org.apache.cassandra.service.paxos.Commit) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) Mutation(org.apache.cassandra.db.Mutation) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 7 with Mutation

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

the class SchemaKeyspaceTest method createTable.

private static void createTable(String keyspace, String cql) {
    TableMetadata table = CreateTableStatement.parse(cql, keyspace).build();
    KeyspaceMetadata ksm = KeyspaceMetadata.create(keyspace, KeyspaceParams.simple(1), Tables.of(table));
    Mutation mutation = SchemaKeyspace.makeCreateTableMutation(ksm, table, FBUtilities.timestampMicros()).build();
    Schema.instance.merge(Collections.singleton(mutation));
}
Also used : Mutation(org.apache.cassandra.db.Mutation)

Example 8 with Mutation

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

the class SchemaKeyspaceTest method checkInverses.

private static void checkInverses(TableMetadata metadata) throws Exception {
    KeyspaceMetadata keyspace = Schema.instance.getKeyspaceMetadata(metadata.keyspace);
    // Test schema conversion
    Mutation rm = SchemaKeyspace.makeCreateTableMutation(keyspace, metadata, FBUtilities.timestampMicros()).build();
    PartitionUpdate serializedCf = rm.getPartitionUpdate(Schema.instance.getTableMetadata(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.TABLES));
    PartitionUpdate serializedCD = rm.getPartitionUpdate(Schema.instance.getTableMetadata(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.COLUMNS));
    UntypedResultSet.Row tableRow = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.TABLES), UnfilteredRowIterators.filter(serializedCf.unfilteredIterator(), FBUtilities.nowInSeconds())).one();
    TableParams params = SchemaKeyspace.createTableParamsFromRow(tableRow);
    UntypedResultSet columnsRows = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.COLUMNS), UnfilteredRowIterators.filter(serializedCD.unfilteredIterator(), FBUtilities.nowInSeconds()));
    Set<ColumnMetadata> columns = new HashSet<>();
    for (UntypedResultSet.Row row : columnsRows) columns.add(SchemaKeyspace.createColumnFromRow(row, Types.none()));
    assertEquals(metadata.params, params);
    assertEquals(new HashSet<>(metadata.columns()), columns);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Mutation(org.apache.cassandra.db.Mutation) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) HashSet(java.util.HashSet)

Example 9 with Mutation

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

the class SchemaKeyspaceTest method updateTable.

private static void updateTable(String keyspace, TableMetadata oldTable, TableMetadata newTable) {
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceInstance(keyspace).getMetadata();
    Mutation mutation = SchemaKeyspace.makeUpdateTableMutation(ksm, oldTable, newTable, FBUtilities.timestampMicros()).build();
    Schema.instance.merge(Collections.singleton(mutation));
}
Also used : Mutation(org.apache.cassandra.db.Mutation)

Example 10 with Mutation

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

the class CommitLogSegmentManagerTest method testCompressedCommitLogBackpressure.

@Test
@BMRules(rules = { @BMRule(name = "Acquire Semaphore before sync", targetClass = "AbstractCommitLogService$1", targetMethod = "run", targetLocation = "AT INVOKE org.apache.cassandra.db.commitlog.CommitLog.sync", action = "org.apache.cassandra.db.commitlog.CommitLogSegmentManagerTest.allowSync.acquire()"), @BMRule(name = "Release Semaphore after sync", targetClass = "AbstractCommitLogService$1", targetMethod = "run", targetLocation = "AFTER INVOKE org.apache.cassandra.db.commitlog.CommitLog.sync", action = "org.apache.cassandra.db.commitlog.CommitLogSegmentManagerTest.allowSync.release()") })
public void testCompressedCommitLogBackpressure() throws Throwable {
    // Perform all initialization before making CommitLog.Sync blocking
    // Doing the initialization within the method guarantee that Byteman has performed its injections when we start
    new Random().nextBytes(entropy);
    DatabaseDescriptor.daemonInitialization();
    DatabaseDescriptor.setCommitLogCompression(new ParameterizedClass("LZ4Compressor", ImmutableMap.of()));
    DatabaseDescriptor.setCommitLogSegmentSize(1);
    DatabaseDescriptor.setCommitLogSync(CommitLogSync.periodic);
    DatabaseDescriptor.setCommitLogSyncPeriod(10 * 1000);
    DatabaseDescriptor.setCommitLogMaxCompressionBuffersPerPool(3);
    SchemaLoader.prepareServer();
    SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE1, STANDARD1, 0, AsciiType.instance, BytesType.instance), SchemaLoader.standardCFMD(KEYSPACE1, STANDARD2, 0, AsciiType.instance, BytesType.instance));
    CompactionManager.instance.disableAutoCompaction();
    ColumnFamilyStore cfs1 = Keyspace.open(KEYSPACE1).getColumnFamilyStore(STANDARD1);
    final Mutation m = new RowUpdateBuilder(cfs1.metadata(), 0, "k").clustering("bytes").add("val", ByteBuffer.wrap(entropy)).build();
    Thread dummyThread = new Thread(() -> {
        for (int i = 0; i < 20; i++) CommitLog.instance.add(m);
    });
    try {
        // Makes sure any call to CommitLog.sync is blocking
        allowSync.acquire();
        dummyThread.start();
        AbstractCommitLogSegmentManager clsm = CommitLog.instance.segmentManager;
        Util.spinAssertEquals(3, () -> clsm.getActiveSegments().size(), 5);
        Thread.sleep(1000);
        // Should only be able to create 3 segments not 7 because it blocks waiting for truncation that never comes
        Assert.assertEquals(3, clsm.getActiveSegments().size());
        // Discard the currently active segments so allocation can continue.
        // Take snapshot of the list, otherwise this will also discard newly allocated segments.
        new ArrayList<>(clsm.getActiveSegments()).forEach(clsm::archiveAndDiscard);
        // The allocated count should reach the limit again.
        Util.spinAssertEquals(3, () -> clsm.getActiveSegments().size(), 5);
    } finally {
        // Allow the CommitLog.sync to perform normally.
        allowSync.release();
    }
    try {
        // Wait for the dummy thread to die
        dummyThread.join();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : Random(java.util.Random) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

Mutation (org.apache.cassandra.db.Mutation)16 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)9 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)5 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 Row (org.apache.cassandra.db.rows.Row)3 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)3 Test (org.junit.Test)3 UUID (java.util.UUID)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)2 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1