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);
}
}
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));
}
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);
}
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));
}
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();
}
}
Aggregations