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

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

Introduction

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

Prototype

public static Map<InetAddressAndPort, UUID> loadHostIds() 

Source Link

Document

Return a map of store host_ids to IP addresses

Usage

From source file:org.elasticsearch.cassandra.discovery.CassandraDiscovery.java

License:Apache License

@Override
protected void doStart() {

    synchronized (clusterGroup) {
        logger.debug("Connected to cluster [{}]", clusterName.value());

        localAddress = FBUtilities.getLocalAddress();
        localDc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(localAddress);

        InetSocketTransportAddress elasticAddress = (InetSocketTransportAddress) transportService.boundAddress()
                .publishAddress();//from   w  w  w  .  j a  v a  2 s  .  c  o m
        logger.info("Listening address Cassandra=" + localAddress + " Elastic=" + elasticAddress.toString());

        // get local node from cassandra cluster
        {
            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(localAddress));

            String hostId = SystemKeyspace.getLocalHostId().toString();
            localNode = new DiscoveryNode(buildNodeName(localAddress), hostId,
                    transportService.boundAddress().publishAddress(), attrs, version);
            localNode.status(DiscoveryNodeStatus.ALIVE);
            this.transportService.setLocalNode(localNode); // clusterService start before DiscoveryService.
            master = true;
            clusterGroup.put(this.localNode.getId(), this.localNode);
            logger.info("localNode name={} id={}", this.localNode.getName(), this.localNode.getId());
        }

        // initialize cluster from cassandra system.peers 
        Map<InetAddress, UUID> peers = SystemKeyspace.loadHostIds();
        Map<InetAddress, Map<String, String>> endpointInfo = SystemKeyspace.loadDcRackInfo();
        for (Entry<InetAddress, UUID> entry : peers.entrySet()) {
            if ((!entry.getKey().equals(localAddress))
                    && (localDc.equals(endpointInfo.get(entry.getKey()).get("data_center")))) {
                Map<String, String> attrs = Maps.newHashMap();
                attrs.put("data", "true");
                attrs.put("master", "true");
                attrs.putAll(endpointInfo.get(entry.getKey()));
                DiscoveryNode dn = new DiscoveryNode(buildNodeName(entry.getKey()), entry.getValue().toString(),
                        new InetSocketTransportAddress(entry.getKey(),
                                settings.getAsInt("transport.tcp.port", 9300)),
                        attrs, version);
                EndpointState endpointState = Gossiper.instance.getEndpointStateForEndpoint(entry.getKey());
                if (endpointState == null) {
                    dn.status(DiscoveryNodeStatus.UNKNOWN);
                } else {
                    dn.status((endpointState.isAlive()) ? DiscoveryNodeStatus.ALIVE : DiscoveryNodeStatus.DEAD);
                }
                clusterGroup.put(dn.getId(), dn);
                logger.debug("remanent node addr_ip={} node_name={} host_id={} ", entry.getKey().toString(),
                        dn.getId(), dn.getName());
            }
        }

        Gossiper.instance.register(this);
        updateClusterGroupsFromGossiper();
        updateClusterState("starting-cassandra-discovery", null);
    }
}