Search in sources :

Example 6 with WrappedRunnable

use of org.apache.cassandra.utils.WrappedRunnable in project eiger by wlloyd.

the class TableTest method testGetSliceFromAdvanced.

@Test
public void testGetSliceFromAdvanced() throws Throwable {
    // tests slicing against data from one row spread across two sstables
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
    final DecoratedKey ROW = Util.dk("row2");
    RowMutation rm = new RowMutation("Keyspace1", ROW.key);
    ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
    cf.addColumn(column("col1", "val1", 1L));
    cf.addColumn(column("col2", "val2", 1L));
    cf.addColumn(column("col3", "val3", 1L));
    cf.addColumn(column("col4", "val4", 1L));
    cf.addColumn(column("col5", "val5", 1L));
    cf.addColumn(column("col6", "val6", 1L));
    rm.add(cf);
    rm.apply();
    cfStore.forceBlockingFlush();
    rm = new RowMutation("Keyspace1", ROW.key);
    cf = ColumnFamily.create("Keyspace1", "Standard1");
    cf.addColumn(column("col1", "valx", 2L));
    cf.addColumn(column("col2", "valx", 2L));
    cf.addColumn(column("col3", "valx", 2L));
    rm.add(cf);
    rm.apply();
    Runnable verify = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            ColumnFamily cf;
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3);
            assertColumns(cf, "col2", "col3", "col4");
            ByteBuffer col = cf.getColumn(ByteBufferUtil.bytes("col2")).value();
            assertEquals(ByteBufferUtil.string(col), "valx");
            col = cf.getColumn(ByteBufferUtil.bytes("col3")).value();
            assertEquals(ByteBufferUtil.string(col), "valx");
            col = cf.getColumn(ByteBufferUtil.bytes("col4")).value();
            assertEquals(ByteBufferUtil.string(col), "val4");
        }
    };
    reTest(table.getColumnFamilyStore("Standard1"), verify);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with WrappedRunnable

use of org.apache.cassandra.utils.WrappedRunnable in project cassandra by apache.

the class TraceStateImpl method executeMutation.

void executeMutation(final Mutation mutation) {
    CompletableFuture<Void> fut = CompletableFuture.runAsync(new WrappedRunnable() {

        protected void runMayThrow() {
            mutateWithCatch(mutation);
        }
    }, StageManager.getStage(Stage.TRACING));
    boolean ret = pendingFutures.add(fut);
    if (!ret)
        logger.warn("Failed to insert pending future, tracing synchronization may not work");
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable)

Example 8 with WrappedRunnable

use of org.apache.cassandra.utils.WrappedRunnable in project cassandra by apache.

the class TracingImpl method trace.

/**
     * Called from {@link org.apache.cassandra.net.OutboundTcpConnection} for non-local traces (traces
     * that are not initiated by local node == coordinator).
     */
public void trace(final ByteBuffer sessionId, final String message, final int ttl) {
    final String threadName = Thread.currentThread().getName();
    StageManager.getStage(Stage.TRACING).execute(new WrappedRunnable() {

        public void runMayThrow() {
            TraceStateImpl.mutateWithCatch(TraceKeyspace.makeEventMutation(sessionId, message, -1, threadName, ttl));
        }
    });
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable)

Example 9 with WrappedRunnable

use of org.apache.cassandra.utils.WrappedRunnable in project cassandra by apache.

the class ViewLongTest method testConflictResolution.

@Test
public void testConflictResolution() throws Throwable {
    final int writers = 96;
    final int insertsPerWriter = 50;
    final Map<Integer, Exception> failedWrites = new ConcurrentHashMap<>();
    createTable("CREATE TABLE %s (" + "a int," + "b int," + "c int," + "PRIMARY KEY (a, b))");
    executeNet(protocolVersion, "USE " + keyspace());
    createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE c IS NOT NULL AND a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (c, a, b)");
    CyclicBarrier semaphore = new CyclicBarrier(writers);
    Thread[] threads = new Thread[writers];
    for (int i = 0; i < writers; i++) {
        final int writer = i;
        Thread t = NamedThreadFactory.createThread(new WrappedRunnable() {

            public void runMayThrow() {
                try {
                    int writerOffset = writer * insertsPerWriter;
                    semaphore.await();
                    for (int i = 0; i < insertsPerWriter; i++) {
                        try {
                            executeNet(protocolVersion, "INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP 1", 1, 1, i + writerOffset);
                        } catch (NoHostAvailableException | WriteTimeoutException e) {
                            failedWrites.put(i + writerOffset, e);
                        }
                    }
                } catch (Throwable e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();
        threads[i] = t;
    }
    for (int i = 0; i < writers; i++) threads[i].join();
    for (int i = 0; i < writers * insertsPerWriter; i++) {
        if (executeNet(protocolVersion, "SELECT COUNT(*) FROM system.batches").one().getLong(0) == 0)
            break;
        try {
            // This will throw exceptions whenever there are exceptions trying to push the view values out, caused
            // by the view becoming overwhelmed.
            BatchlogManager.instance.startBatchlogReplay().get();
        } catch (Throwable ignore) {
        }
    }
    int value = executeNet(protocolVersion, "SELECT c FROM %s WHERE a = 1 AND b = 1").one().getInt("c");
    List<Row> rows = executeNet(protocolVersion, "SELECT c FROM " + keyspace() + ".mv").all();
    boolean containsC = false;
    StringBuilder others = new StringBuilder();
    StringBuilder overlappingFailedWrites = new StringBuilder();
    for (Row row : rows) {
        int c = row.getInt("c");
        if (c == value)
            containsC = true;
        else {
            if (others.length() != 0)
                others.append(' ');
            others.append(c);
            if (failedWrites.containsKey(c)) {
                if (overlappingFailedWrites.length() != 0)
                    overlappingFailedWrites.append(' ');
                overlappingFailedWrites.append(c).append(':').append(failedWrites.get(c).getMessage());
            }
        }
    }
    if (rows.size() > 1) {
        throw new AssertionError(String.format("Expected 1 row, but found %d; %s c = %d, and (%s) of which (%s) failed to insert", rows.size(), containsC ? "found row with" : "no rows contained", value, others, overlappingFailedWrites));
    } else if (rows.isEmpty()) {
        throw new AssertionError(String.format("Could not find row with c = %d", value));
    } else if (rows.size() == 1 && !containsC) {
        throw new AssertionError(String.format("Single row had c = %d, expected %d", rows.get(0).getInt("c"), value));
    }
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WriteTimeoutException(com.datastax.driver.core.exceptions.WriteTimeoutException) NoHostAvailableException(com.datastax.driver.core.exceptions.NoHostAvailableException) CyclicBarrier(java.util.concurrent.CyclicBarrier) Row(com.datastax.driver.core.Row) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 10 with WrappedRunnable

use of org.apache.cassandra.utils.WrappedRunnable in project cassandra by apache.

the class ColumnFamilyStoreTest method testEmptyRow.

@Test
public void testEmptyRow() throws Exception {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD2);
    RowUpdateBuilder.deleteRow(cfs.metadata(), FBUtilities.timestampMicros(), "key1", "Column1").applyUnsafe();
    Runnable r = new WrappedRunnable() {

        public void runMayThrow() throws IOException {
            Row toCheck = Util.getOnlyRowUnfiltered(Util.cmd(cfs, "key1").build());
            Iterator<Cell> iter = toCheck.cells().iterator();
            assert (Iterators.size(iter) == 0);
        }
    };
    reTest(cfs, r);
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) Test(org.junit.Test)

Aggregations

WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)21 Test (org.junit.Test)12 QueryPath (org.apache.cassandra.db.filter.QueryPath)7 ByteBuffer (java.nio.ByteBuffer)3 IOException (java.io.IOException)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Row (com.datastax.driver.core.Row)1 NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)1 WriteTimeoutException (com.datastax.driver.core.exceptions.WriteTimeoutException)1 File (java.io.File)1 IOError (java.io.IOError)1 InetAddress (java.net.InetAddress)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Future (java.util.concurrent.Future)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CRC32 (java.util.zip.CRC32)1