List of usage examples for org.apache.cassandra.gms ApplicationState HOST_ID
ApplicationState HOST_ID
To view the source code for org.apache.cassandra.gms ApplicationState HOST_ID.
Click Source Link
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 . ja va 2 s .co 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);/* w w w.jav a 2 s . com*/ 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)); } }
From source file:org.elasticsearch.cassandra.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 www . j a v a2s .com*/ 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())); dn = new DiscoveryNode(buildNodeName(entry.getKey()), hostId.toString(), new InetSocketTransportAddress(entry.getKey(), settings.getAsInt("transport.tcp.port", 9300)), attrs, version); dn.status(status); if (localAddress.equals(entry.getKey())) { logger.debug("Update local node host_id={} status={} timestamp={}", entry.getKey().toString(), 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={}", entry.getKey().toString(), dn.getId(), dn.getName(), entry.getValue().isAlive(), entry.getValue().getUpdateTimestamp()); } clusterGroup.put(dn.getId(), dn); } else { // may update DiscoveryNode status. if (!dn.getStatus().equals(status)) { dn.status(status); } } } } } }
From source file:org.elasticsearch.cassandra.discovery.CassandraDiscovery.java
License:Apache License
public void updateNode(InetAddress addr, EndpointState state) { DiscoveryNodeStatus status = (state.isAlive()) ? DiscoveryNode.DiscoveryNodeStatus.ALIVE : DiscoveryNode.DiscoveryNodeStatus.DEAD; boolean updatedNode = false; if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) { 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)); dn = new DiscoveryNode(buildNodeName(addr), hostId.toString(), new InetSocketTransportAddress(addr, settings.getAsInt("transport.tcp.port", 9300)), attrs, version);/*from w ww .j a v a2 s . c o m*/ dn.status(status); logger.debug("New node soure=updateNode addr_ip={} node_name={} host_id={} status={} timestamp={}", addr.getHostAddress(), dn.getId(), dn.getName(), status, state.getUpdateTimestamp()); clusterGroup.members.put(dn.getId(), dn); updatedNode = true; } else { // may update DiscoveryNode status. if (!dn.getStatus().equals(status)) { dn.status(status); updatedNode = true; } } } if (updatedNode) updateClusterState("update-node-" + addr.getHostAddress(), null); }