Search in sources :

Example 11 with WrappedRunnable

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

the class StorageService method initServer.

public synchronized void initServer(int delay) throws IOException, ConfigurationException {
    logger_.info("Cassandra version: " + FBUtilities.getReleaseVersionString());
    logger_.info("Thrift API version: " + Constants.VERSION);
    if (initialized) {
        if (isClientMode)
            throw new UnsupportedOperationException("StorageService does not support switching modes.");
        return;
    }
    initialized = true;
    isClientMode = false;
    if (Boolean.parseBoolean(System.getProperty("cassandra.load_ring_state", "true"))) {
        logger_.info("Loading persisted ring state");
        for (Map.Entry<Token, InetAddress> entry : SystemTable.loadTokens().entrySet()) {
            if (entry.getValue() == FBUtilities.getLocalAddress()) {
                // entry has been mistakenly added, delete it
                SystemTable.removeToken(entry.getKey());
            } else {
                tokenMetadata_.updateNormalToken(entry.getKey(), entry.getValue());
                Gossiper.instance.addSavedEndpoint(entry.getValue());
            }
        }
    }
    if (Boolean.parseBoolean(System.getProperty("cassandra.renew_counter_id", "false"))) {
        logger_.info("Renewing local node id (as requested)");
        NodeId.renewLocalId();
    }
    // daemon threads, like our executors', continue to run while shutdown hooks are invoked
    Thread drainOnShutdown = new Thread(new WrappedRunnable() {

        @Override
        public void runMayThrow() throws ExecutionException, InterruptedException, IOException {
            ThreadPoolExecutor mutationStage = StageManager.getStage(Stage.MUTATION);
            if (mutationStage.isShutdown())
                // drained already
                return;
            stopRPCServer();
            optionalTasks.shutdown();
            Gossiper.instance.stop();
            // In-progress writes originating here could generate hints to be written, so shut down MessagingService
            // before mutation stage, so we can get all the hints saved before shutting down
            MessagingService.instance().shutdown();
            mutationStage.shutdown();
            mutationStage.awaitTermination(3600, TimeUnit.SECONDS);
            StorageProxy.instance.verifyNoHintsInProgress();
            List<Future<?>> flushes = new ArrayList<Future<?>>();
            for (Table table : Table.all()) {
                KSMetaData ksm = Schema.instance.getKSMetaData(table.name);
                if (!ksm.durableWrites) {
                    for (ColumnFamilyStore cfs : table.getColumnFamilyStores()) {
                        Future<?> future = cfs.forceFlush();
                        if (future != null)
                            flushes.add(future);
                    }
                }
            }
            FBUtilities.waitOnFutures(flushes);
            CommitLog.instance.shutdownBlocking();
            // wait for miscellaneous tasks like sstable and commitlog segment deletion
            tasks.shutdown();
            if (!tasks.awaitTermination(1, TimeUnit.MINUTES))
                logger_.warn("Miscellaneous task executor still busy after one minute; proceeding with shutdown");
        }
    }, "StorageServiceShutdownHook");
    Runtime.getRuntime().addShutdownHook(drainOnShutdown);
    if (Boolean.parseBoolean(System.getProperty("cassandra.join_ring", "true"))) {
        joinTokenRing(delay);
    } else {
        logger_.info("Not joining ring as requested. Use JMX (StorageService->joinRing()) to initiate ring joining");
    }
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) Table(org.apache.cassandra.db.Table) IOException(java.io.IOException) DebuggableScheduledThreadPoolExecutor(org.apache.cassandra.concurrent.DebuggableScheduledThreadPoolExecutor) InetAddress(java.net.InetAddress)

Example 12 with WrappedRunnable

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

the class ColumnFamilyStoreTest method testEmptyRow.

@Test
public void testEmptyRow() throws Exception {
    Table table = Table.open("Keyspace1");
    final ColumnFamilyStore store = table.getColumnFamilyStore("Standard2");
    RowMutation rm;
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1"));
    rm.delete(new QueryPath("Standard2", null, null), System.currentTimeMillis());
    rm.apply();
    Runnable r = new WrappedRunnable() {

        public void runMayThrow() throws IOException {
            QueryFilter sliceFilter = QueryFilter.getSliceFilter(Util.dk("key1"), new QueryPath("Standard2", null, null), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1);
            ColumnFamily cf = store.getColumnFamily(sliceFilter);
            assert cf.isMarkedForDelete();
            assert cf.isEmpty();
            QueryFilter namesFilter = QueryFilter.getNamesFilter(Util.dk("key1"), new QueryPath("Standard2", null, null), ByteBufferUtil.bytes("a"));
            cf = store.getColumnFamily(namesFilter);
            assert cf.isMarkedForDelete();
            assert cf.isEmpty();
        }
    };
    TableTest.reTest(store, r);
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) SSTable(org.apache.cassandra.io.sstable.SSTable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) Test(org.junit.Test)

Example 13 with WrappedRunnable

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

the class LongTableTest method testGetRowMultiColumn.

@Test
public void testGetRowMultiColumn() throws Throwable {
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
    for (int i = 1; i < 5000; i += 100) {
        RowMutation rm = new RowMutation("Keyspace1", Util.dk("key" + i).key);
        ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
        for (int j = 0; j < i; j++) cf.addColumn(column("c" + j, "v" + j, 1L));
        rm.add(cf);
        rm.applyUnsafe();
    }
    Runnable verify = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            ColumnFamily cf;
            for (int i = 1; i < 5000; i += 100) {
                for (int j = 0; j < i; j++) {
                    cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key" + i), new QueryPath("Standard1"), ByteBufferUtil.bytes("c" + j)));
                    TableTest.assertColumns(cf, "c" + j);
                }
            }
        }
    };
    TableTest.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) Test(org.junit.Test)

Example 14 with WrappedRunnable

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

the class HintedHandOffManager method scheduleHintDelivery.

/*
     * This method is used to deliver hints to a particular endpoint.
     * When we learn that some endpoint is back up we deliver the data
     * to him via an event driven mechanism.
    */
public void scheduleHintDelivery(final InetAddress to) {
    logger_.debug("deliverHints to {}", to);
    if (!queuedDeliveries.add(to))
        return;
    Runnable r = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            deliverHintsToEndpoint(to);
        }
    };
    executor_.execute(r);
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable)

Example 15 with WrappedRunnable

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

the class DataTracker method incrementallyBackup.

public void incrementallyBackup(final SSTableReader sstable) {
    if (!DatabaseDescriptor.isIncrementalBackupsEnabled())
        return;
    Runnable runnable = new WrappedRunnable() {

        protected void runMayThrow() throws Exception {
            File backupsDir = Directories.getBackupsDirectory(sstable.descriptor);
            sstable.createLinks(backupsDir.getCanonicalPath());
        }
    };
    StorageService.tasks.execute(runnable);
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) File(java.io.File)

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