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