Example usage for org.apache.cassandra.gms Gossiper instance

List of usage examples for org.apache.cassandra.gms Gossiper instance

Introduction

In this page you can find the example usage for org.apache.cassandra.gms Gossiper instance.

Prototype

Gossiper instance

To view the source code for org.apache.cassandra.gms Gossiper instance.

Click Source Link

Usage

From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java

License:Apache License

public String getRack(InetAddress endpoint) {
    if (endpoint.equals(FBUtilities.getBroadcastAddress()))
        return rack;
    EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
    if (state == null || state.getApplicationState(ApplicationState.RACK) == null)
        return DEFAULT_RACK;
    return state.getApplicationState(ApplicationState.RACK).value;
}

From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java

License:Apache License

public String getDatacenter(InetAddress endpoint) {
    if (endpoint.equals(FBUtilities.getBroadcastAddress()))
        return datacenter;
    EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
    if (state == null || state.getApplicationState(ApplicationState.DC) == null)
        return DEFAULT_DC;
    return state.getApplicationState(ApplicationState.DC).value;
}

From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java

License:Apache License

@Override
public void gossiperStarting() {
    super.gossiperStarting();
    Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP,
            StorageService.instance.valueFactory.internalIP(private_ip));
    Gossiper.instance.register(this);
}

From source file:com.tuplejump.stargate.Stargate.java

License:Apache License

private Stargate() {
    try {//from   w  w w .  ja  v  a  2s .c  o m
        queue = getQueue();
        writes = getAtomicLong(COMMIT_LOGS + "writes");
        indexingService = new IndexingService(getAtomicLong(COMMIT_LOGS + "reads"));
        indexEventSubscriber = new IndexEventSubscriber(indexingService, queue);
        Gossiper.instance.register(this);
    } catch (IOException e) {
        constructionException = e;
    }
}

From source file:me.tango.cassandra.bench.SchemaLoader.java

License:Apache License

public static void startGossiper() {
    Gossiper.instance.start((int) (System.currentTimeMillis() / 1000));
}

From source file:me.tango.cassandra.bench.SchemaLoader.java

License:Apache License

public static void stopGossiper() {
    Gossiper.instance.stop();
}

From source file:org.elassandra.discovery.CassandraDiscovery.java

License:Apache License

@Override
protected void doStart() {

    synchronized (clusterGroup) {
        logger.debug("Connected to cluster [{}]", clusterName.value());
        // initialize cluster from cassandra system.peers 
        // WARNING: system.peers may be incomplete because commitlogs not yet applied
        for (UntypedResultSet.Row row : executeInternal(
                "SELECT peer, data_center, rack, rpc_address, host_id from system." + SystemKeyspace.PEERS)) {
            InetAddress peer = row.getInetAddress("peer");
            InetAddress rpc_address = row.getInetAddress("rpc_address");
            String datacenter = row.getString("data_center");
            if ((!peer.equals(localAddress)) && (localDc.equals(datacenter))) {
                Map<String, String> attrs = Maps.newHashMap();
                attrs.put("data", "true");
                attrs.put("master", "true");
                attrs.put("data_center", datacenter);
                attrs.put("rack", row.getString("rack"));

                DiscoveryNode dn = new DiscoveryNode(buildNodeName(peer), row.getUUID("host_id").toString(),
                        new InetSocketTransportAddress(rpc_address, publishPort()), attrs, version);
                EndpointState endpointState = Gossiper.instance.getEndpointStateForEndpoint(peer);
                if (endpointState == null) {
                    dn.status(DiscoveryNodeStatus.UNKNOWN);
                } else {
                    dn.status((endpointState.isAlive()) ? DiscoveryNodeStatus.ALIVE : DiscoveryNodeStatus.DEAD);
                }//from   w  ww .  j  ava 2s  .c  o m
                clusterGroup.put(dn.getId(), dn);
                logger.debug("  node internal_ip={} host_id={} node_name={} ", NetworkAddress.format(peer),
                        dn.getId(), dn.getName());
            }
        }

        Gossiper.instance.register(this);
        updateClusterGroupsFromGossiper();
        updateRoutingTable("starting-cassandra-discovery");
    }
}

From source file:org.elassandra.discovery.CassandraDiscovery.java

License:Apache License

/**
 * Update cluster group members from cassandra topology (should only be triggered by IEndpointStateChangeSubscriber events).
 * This should trigger re-sharding of index for new nodes (when token distribution change).
 *//*from w ww. ja  v  a 2s . c  o m*/
public void updateClusterGroupsFromGossiper() {
    for (Entry<InetAddress, EndpointState> entry : Gossiper.instance.getEndpointStates()) {
        DiscoveryNodeStatus status = (entry.getValue().isAlive()) ? DiscoveryNode.DiscoveryNodeStatus.ALIVE
                : DiscoveryNode.DiscoveryNodeStatus.DEAD;

        if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(entry.getKey()).equals(localDc)) {
            VersionedValue vv = entry.getValue().getApplicationState(ApplicationState.HOST_ID);
            if (vv != null) {
                String hostId = vv.value;
                DiscoveryNode dn = clusterGroup.get(hostId);
                if (dn == null) {
                    Map<String, String> attrs = Maps.newHashMap();
                    attrs.put("data", "true");
                    attrs.put("master", "true");
                    attrs.put("data_center", localDc);
                    attrs.put("rack", DatabaseDescriptor.getEndpointSnitch().getRack(entry.getKey()));

                    InetAddress rpc_address = com.google.common.net.InetAddresses.forString(
                            entry.getValue().getApplicationState(ApplicationState.RPC_ADDRESS).value);
                    dn = new DiscoveryNode(buildNodeName(entry.getKey()), hostId.toString(),
                            new InetSocketTransportAddress(rpc_address, publishPort()), attrs, version);
                    dn.status(status);

                    if (localAddress.equals(entry.getKey())) {
                        logger.debug("Update local node host_id={} status={} timestamp={}",
                                NetworkAddress.format(entry.getKey()), dn.getId(), dn.getName(),
                                entry.getValue().isAlive(), entry.getValue().getUpdateTimestamp());
                        clusterGroup.remove(this.localNode.id());
                        this.localNode = dn;
                    } else {
                        logger.debug("New node addr_ip={} node_name={} host_id={} status={} timestamp={}",
                                NetworkAddress.format(entry.getKey()), dn.getId(), dn.getName(),
                                entry.getValue().isAlive(), entry.getValue().getUpdateTimestamp());
                    }
                    clusterGroup.put(dn.getId(), dn);
                    if (entry.getValue().getApplicationState(ApplicationState.X1) != null
                            || entry.getValue().getApplicationState(ApplicationState.X2) != null) {
                        SystemKeyspace.updatePeerInfo(entry.getKey(), "workload", "elasticsearch");
                    }
                } else {
                    // may update DiscoveryNode status.
                    if (!dn.getStatus().equals(status)) {
                        dn.status(status);
                    }
                }
            }
        }
    }
}

From source file:org.elassandra.discovery.CassandraDiscovery.java

License:Apache License

/**
 * Release listeners who have reached the expected metadat version.
 *///  w  w w.  ja v a  2 s. co m
public void checkMetaDataVersion() {
    for (Iterator<MetaDataVersionListener> it = this.metaDataVersionListeners.iterator(); it.hasNext();) {
        MetaDataVersionListener listener = it.next();
        boolean versionReached = true;
        for (InetAddress addr : Gossiper.instance.getLiveTokenOwners()) {
            if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) {
                EndpointState endPointState = Gossiper.instance.getEndpointStateForEndpoint(addr);
                VersionedValue vv = endPointState.getApplicationState(ELASTIC_META_DATA);
                if (vv != null && vv.value.lastIndexOf('/') > 0) {
                    Long version = Long.valueOf(vv.value.substring(vv.value.lastIndexOf('/') + 1));
                    if (version < listener.version()) {
                        versionReached = false;
                        break;
                    }
                }
            }
        }
        if (versionReached) {
            logger.debug("MetaData.version = {} reached", listener.version());
            listener.release();
            metaDataVersionListeners.remove(listener);
        }
    }
}

From source file:org.elassandra.discovery.CassandraDiscovery.java

License:Apache License

@Override
public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue versionValue) {
    EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
    if (epState == null || Gossiper.instance.isDeadState(epState)) {
        if (logger.isTraceEnabled())
            logger.trace("Ignoring state change for dead or unknown endpoint: {}", endpoint);
        return;//from   ww  w  .  j  a  v  a 2 s  . c  o  m
    }
    if (!this.localAddress.equals(endpoint)) {
        if (state == ApplicationState.X1
                && DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint).equals(localDc)) {
            // X1: update local shard state
            if (logger.isTraceEnabled())
                logger.trace("Endpoint={} ApplicationState={} value={} => update routingTable", endpoint, state,
                        versionValue.value);
            updateRoutingTable("onChange-" + endpoint + "-" + state.toString() + " X1=" + versionValue.value);
            connectToNode(endpoint);
        } else if (state == ApplicationState.X2 && clusterService.isDatacenterGroupMember(endpoint)) {
            // X2 from datacenter.group: update metadata if metadata version is higher than our.
            if (versionValue != null) {
                int i = versionValue.value.lastIndexOf('/');
                if (i > 0) {
                    Long version = Long.valueOf(versionValue.value.substring(i + 1));
                    if (version > this.clusterService.state().metaData().version()) {
                        MetaData metadata = clusterService.checkForNewMetaData(version);
                        if (metadata != null) {
                            if (logger.isTraceEnabled())
                                logger.trace(
                                        "Endpoint={} ApplicationState={} value={} => update metaData {}/{}",
                                        endpoint, state, versionValue.value, metadata.uuid(),
                                        metadata.version());
                            updateMetadata("onChange-" + endpoint + "-" + state.toString() + " metadata="
                                    + metadata.uuid() + "/" + metadata.version(), metadata);
                        }
                    }
                }
            }
            if (metaDataVersionListeners.size() > 0
                    && DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint).equals(localDc)) {
                checkMetaDataVersion();
            }
        }
    }
}