Example usage for org.apache.cassandra.db SystemKeyspace updatePeerInfo

List of usage examples for org.apache.cassandra.db SystemKeyspace updatePeerInfo

Introduction

In this page you can find the example usage for org.apache.cassandra.db SystemKeyspace updatePeerInfo.

Prototype

public static synchronized void updatePeerInfo(InetAddressAndPort ep, String columnName, Object value) 

Source Link

Usage

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 w  w  . j a  v  a  2 s.  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

public void updateNode(InetAddress addr, EndpointState state) {
    if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) {
        DiscoveryNodeStatus status = (state.isAlive()) ? DiscoveryNode.DiscoveryNodeStatus.ALIVE
                : DiscoveryNode.DiscoveryNodeStatus.DEAD;
        boolean updatedNode = false;
        String hostId = state.getApplicationState(ApplicationState.HOST_ID).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(addr));

            InetAddress rpc_address = com.google.common.net.InetAddresses
                    .forString(state.getApplicationState(ApplicationState.RPC_ADDRESS).value);
            dn = new DiscoveryNode(buildNodeName(addr), hostId.toString(),
                    new InetSocketTransportAddress(rpc_address, publishPort()), attrs, version);
            dn.status(status);/*from w ww.j a v  a2  s . co m*/
            logger.debug(
                    "New node soure=updateNode internal_ip={} rpc_address={}, node_name={} host_id={} status={} timestamp={}",
                    NetworkAddress.format(addr), NetworkAddress.format(rpc_address), dn.getId(), dn.getName(),
                    status, state.getUpdateTimestamp());
            clusterGroup.members.put(dn.getId(), dn);
            if (state.getApplicationState(ApplicationState.X1) != null
                    || state.getApplicationState(ApplicationState.X2) != null) {
                SystemKeyspace.updatePeerInfo(addr, "workload", "elasticsearch");
            }
            updatedNode = true;
        } else {
            // may update DiscoveryNode status.
            if (!dn.getStatus().equals(status)) {
                dn.status(status);
                updatedNode = true;
            }
        }
        if (updatedNode)
            updateRoutingTable("update-node-" + NetworkAddress.format(addr));
    }
}