Example usage for org.apache.cassandra.concurrent Stage GOSSIP

List of usage examples for org.apache.cassandra.concurrent Stage GOSSIP

Introduction

In this page you can find the example usage for org.apache.cassandra.concurrent Stage GOSSIP.

Prototype

Stage GOSSIP

To view the source code for org.apache.cassandra.concurrent Stage GOSSIP.

Click Source Link

Usage

From source file:org.wildfly.extension.cassandra.WildflyCassandraDaemon.java

License:Apache License

private void waitForGossipToSettle() {
    int forceAfter = Integer.getInteger("cassandra.skip_wait_for_gossip_to_settle", -1);
    if (forceAfter == 0) {
        return;//from  ww w .j  a  va  2  s.com
    }
    final int GOSSIP_SETTLE_MIN_WAIT_MS = 5000;
    final int GOSSIP_SETTLE_POLL_INTERVAL_MS = 1000;
    final int GOSSIP_SETTLE_POLL_SUCCESSES_REQUIRED = 3;

    CassandraLogger.LOGGER.infof("Waiting for gossip to settle before accepting client requests...");
    Uninterruptibles.sleepUninterruptibly(GOSSIP_SETTLE_MIN_WAIT_MS, TimeUnit.MILLISECONDS);
    int totalPolls = 0;
    int numOkay = 0;
    JMXEnabledThreadPoolExecutor gossipStage = (JMXEnabledThreadPoolExecutor) StageManager
            .getStage(Stage.GOSSIP);
    while (numOkay < GOSSIP_SETTLE_POLL_SUCCESSES_REQUIRED) {
        Uninterruptibles.sleepUninterruptibly(GOSSIP_SETTLE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
        long completed = gossipStage.getCompletedTasks();
        long active = gossipStage.getActiveCount();
        long pending = gossipStage.getPendingTasks();
        totalPolls++;
        if (active == 0 && pending == 0) {
            CassandraLogger.LOGGER.debugf("Gossip looks settled. CompletedTasks: {}", completed);
            numOkay++;
        } else {
            CassandraLogger.LOGGER.infof(
                    "Gossip not settled after {} polls. Gossip Stage active/pending/completed: {}/{}/{}",
                    totalPolls, active, pending, completed);
            numOkay = 0;
        }
        if (forceAfter > 0 && totalPolls > forceAfter) {
            CassandraLogger.LOGGER.warnf(
                    "Gossip not settled but startup forced by cassandra.skip_wait_for_gossip_to_settle. Gossip Stage total/active/pending/completed: {}/{}/{}/{}",
                    totalPolls, active, pending, completed);
            break;
        }
    }
    if (totalPolls > GOSSIP_SETTLE_POLL_SUCCESSES_REQUIRED)
        CassandraLogger.LOGGER.infof("Gossip settled after {} extra polls; proceeding",
                totalPolls - GOSSIP_SETTLE_POLL_SUCCESSES_REQUIRED);
    else
        CassandraLogger.LOGGER.infof("No gossip backlog; proceeding");
}