本文整理了Java中org.elasticsearch.cluster.node.DiscoveryNodes.masterNodeId()
方法的一些代码示例,展示了DiscoveryNodes.masterNodeId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DiscoveryNodes.masterNodeId()
方法的具体详情如下:
包路径:org.elasticsearch.cluster.node.DiscoveryNodes
类名称:DiscoveryNodes
方法名:masterNodeId
[英]Get the id of the master node
[中]获取主节点的id
代码示例来源:origin: harbby/presto-connectors
/**
* Get the id of the master node
*
* @return id of the master
*/
public String getMasterNodeId() {
return masterNodeId();
}
代码示例来源:origin: harbby/presto-connectors
@Override
public boolean apply(ClusterState previousState, ClusterState.ClusterStateStatus previousStatus,
ClusterState newState, ClusterState.ClusterStateStatus newStatus) {
// The condition !newState.nodes().masterNodeId().equals(previousState.nodes().masterNodeId()) is not sufficient as the same master node might get reelected after a disruption.
return newState.nodes().masterNodeId() != null && newState != previousState;
}
代码示例来源:origin: harbby/presto-connectors
if (!Objects.equals(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) {
break;
代码示例来源:origin: harbby/presto-connectors
public Builder(DiscoveryNodes nodes) {
this.masterNodeId = nodes.masterNodeId();
this.localNodeId = nodes.localNodeId();
this.nodes = ImmutableOpenMap.builder(nodes.nodes());
}
代码示例来源:origin: harbby/presto-connectors
@Override
public ClusterState execute(ClusterState currentState) {
if (!masterNode.id().equals(currentState.nodes().masterNodeId())) {
// master got switched on us, no need to send anything
return currentState;
}
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(currentState.nodes())
// make sure the old master node, which has failed, is not part of the nodes we publish
.remove(masterNode.id())
.masterNodeId(null).build();
// flush any pending cluster states from old master, so it will not be set as master again
ArrayList<ProcessClusterState> pendingNewClusterStates = new ArrayList<>();
processNewClusterStates.drainTo(pendingNewClusterStates);
logger.trace("removed [{}] pending cluster states", pendingNewClusterStates.size());
return rejoin(ClusterState.builder(currentState).nodes(discoveryNodes).build(), "master left (reason = " + reason + ")");
}
代码示例来源:origin: harbby/presto-connectors
/**
* In the case we follow an elected master the new cluster state needs to have the same elected master and
* the new cluster state version needs to be equal or higher than our cluster state version.
* If the first condition fails we reject the cluster state and throw an error.
* If the second condition fails we ignore the cluster state.
*/
static boolean shouldIgnoreOrRejectNewClusterState(ESLogger logger, ClusterState currentState, ClusterState newClusterState) {
if (currentState.nodes().masterNodeId() == null) {
return false;
}
if (!currentState.nodes().masterNodeId().equals(newClusterState.nodes().masterNodeId())) {
logger.warn("received a cluster state from a different master then the current one, rejecting (received {}, current {})", newClusterState.nodes().masterNode(), currentState.nodes().masterNode());
throw new IllegalStateException("cluster state from a different master than the current one, rejecting (received " + newClusterState.nodes().masterNode() + ", current " + currentState.nodes().masterNode() + ")");
} else if (newClusterState.version() < currentState.version()) {
// if the new state has a smaller version, and it has the same master node, then no need to process it
logger.debug("received a cluster state that has a lower version than the current one, ignoring (received {}, current {})", newClusterState.version(), currentState.version());
return true;
} else {
return false;
}
}
代码示例来源:origin: harbby/presto-connectors
@Override
public void clusterChanged(ClusterChangedEvent event) {
try {
SnapshotsInProgress prev = event.previousState().custom(SnapshotsInProgress.TYPE);
SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE);
if (prev == null) {
if (curr != null) {
processIndexShardSnapshots(event);
}
} else if (prev.equals(curr) == false) {
processIndexShardSnapshots(event);
}
String masterNodeId = event.state().nodes().masterNodeId();
if (masterNodeId != null && masterNodeId.equals(event.previousState().nodes().masterNodeId()) == false) {
syncShardStatsOnNewMaster(event);
}
} catch (Throwable t) {
logger.warn("Failed to update snapshot state ", t);
}
}
代码示例来源:origin: harbby/presto-connectors
@Override
public ClusterState execute(ClusterState currentState) {
if (nodeSpecificClusterState.version() < currentState.version() && Objects.equals(nodeSpecificClusterState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) {
return currentState;
}
if (currentState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock())) {
// its a fresh update from the master as we transition from a start of not having a master to having one
logger.debug("got first state from fresh master [{}]", nodeSpecificClusterState.nodes().masterNodeId());
return nodeSpecificClusterState;
}
ClusterState.Builder builder = ClusterState.builder(nodeSpecificClusterState);
// if the routing table did not change, use the original one
if (nodeSpecificClusterState.routingTable().version() == currentState.routingTable().version()) {
builder.routingTable(currentState.routingTable());
}
if (nodeSpecificClusterState.metaData().version() == currentState.metaData().version()) {
builder.metaData(currentState.metaData());
}
return builder.build();
}
代码示例来源:origin: io.fabric8.insight/insight-elasticsearch
if (!Objects.equal(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) {
break;
if (updatedState.version() < currentState.version() && Objects.equal(updatedState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) {
return currentState;
代码示例来源:origin: io.fabric8.insight/insight-elasticsearch-discovery
if (!Objects.equal(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) {
break;
if (updatedState.version() < currentState.version() && Objects.equal(updatedState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) {
return currentState;
代码示例来源:origin: jboss-fuse/fabric8
if (!Objects.equal(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) {
break;
if (updatedState.version() < currentState.version() && Objects.equal(updatedState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) {
return currentState;
代码示例来源:origin: io.fabric8.insight/insight-elasticsearch
String masterNodeId = state.getState().nodes().masterNodeId();
String localNodeId = state.getState().nodes().getLocalNodeId();
if (localNodeId == null || !localNodeId.equals(masterNodeId)) {
代码示例来源:origin: harbby/presto-connectors
String masterNodeId = masterNodeId();
if (masterNodeId != null) {
resolvedNodesIds.add(masterNodeId);
代码示例来源:origin: org.fusesource.insight/insight-elasticsearch
@Override
public ClusterState execute(ClusterState currentState) {
// Rebuild state
ClusterState.Builder stateBuilder = newClusterStateBuilder().state(currentState);
// Rebuild nodes
DiscoveryNodes.Builder nodesBuilder = newNodesBuilder()
.localNodeId(localNode.id())
.masterNodeId(singleton.master().get().node().id())
.put(singleton.master().get().node);
for (ESNode node : JavaConversions$.MODULE$.asJavaCollection(singleton.slaves())) {
nodesBuilder.put(node.node());
}
latestDiscoNodes = nodesBuilder.build();
stateBuilder.nodes(latestDiscoNodes);
for (DiscoveryNode node : latestDiscoNodes) {
if (!currentState.nodes().nodeExists(node.id())) {
transportService.connectToNode(node);
}
}
// update the fact that we are the master...
if (!localNode().id().equals(currentState.nodes().masterNodeId())) {
ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build();
stateBuilder.blocks(clusterBlocks);
}
return stateBuilder.build();
}
代码示例来源:origin: harbby/presto-connectors
private Table buildTable(RestRequest request, ClusterStateResponse state) {
Table table = getTableWithHeader(request);
DiscoveryNodes nodes = state.getState().nodes();
table.startRow();
DiscoveryNode master = nodes.get(nodes.masterNodeId());
if (master == null) {
table.addCell("-");
table.addCell("-");
table.addCell("-");
table.addCell("-");
} else {
table.addCell(master.getId());
table.addCell(master.getHostName());
table.addCell(master.getHostAddress());
table.addCell(master.getName());
}
table.endRow();
return table;
}
}
代码示例来源:origin: io.fabric8.insight/insight-elasticsearch
@Override
public ClusterState execute(ClusterState currentState) {
// Rebuild state
ClusterState.Builder stateBuilder = ClusterState.builder(currentState);
// Rebuild nodes
DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder()
.localNodeId(localNode.id())
.masterNodeId(singleton.master().getNode().id())
.put(singleton.master().getNode());
for (ESNode node : singleton.slaves()) {
nodesBuilder.put(node.getNode());
}
latestDiscoNodes = nodesBuilder.build();
stateBuilder.nodes(latestDiscoNodes);
for (DiscoveryNode node : latestDiscoNodes) {
if (!currentState.nodes().nodeExists(node.id())) {
transportService.connectToNode(node);
}
}
// update the fact that we are the master...
if (!localNode().id().equals(currentState.nodes().masterNodeId())) {
ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build();
stateBuilder.blocks(clusterBlocks);
}
return stateBuilder.build();
}
代码示例来源:origin: io.fabric8.insight/insight-elasticsearch-discovery
@Override
public ClusterState execute(ClusterState currentState) {
// Rebuild state
ClusterState.Builder stateBuilder = ClusterState.builder(currentState);
// Rebuild nodes
DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder()
.localNodeId(localNode.id())
.masterNodeId(singleton.master().getNode().id())
.put(singleton.master().getNode());
for (ESNode node : singleton.slaves()) {
nodesBuilder.put(node.getNode());
}
latestDiscoNodes = nodesBuilder.build();
stateBuilder.nodes(latestDiscoNodes);
for (DiscoveryNode node : latestDiscoNodes) {
if (!currentState.nodes().nodeExists(node.id())) {
transportService.connectToNode(node);
}
}
// update the fact that we are the master...
if (!localNode().id().equals(currentState.nodes().masterNodeId())) {
ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build();
stateBuilder.blocks(clusterBlocks);
}
return stateBuilder.build();
}
代码示例来源:origin: jboss-fuse/fabric8
@Override
public ClusterState execute(ClusterState currentState) {
// Rebuild state
ClusterState.Builder stateBuilder = ClusterState.builder(currentState);
// Rebuild nodes
DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder()
.localNodeId(localNode.id())
.masterNodeId(singleton.master().getNode().id())
.put(singleton.master().getNode());
for (ESNode node : singleton.slaves()) {
nodesBuilder.put(node.getNode());
}
latestDiscoNodes = nodesBuilder.build();
stateBuilder.nodes(latestDiscoNodes);
for (DiscoveryNode node : latestDiscoNodes) {
if (!currentState.nodes().nodeExists(node.id())) {
transportService.connectToNode(node);
}
}
// update the fact that we are the master...
if (!localNode().id().equals(currentState.nodes().masterNodeId())) {
ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build();
stateBuilder.blocks(clusterBlocks);
}
return stateBuilder.build();
}
代码示例来源:origin: harbby/presto-connectors
logger.debug("got first state from fresh master [{}]", updatedState.nodes().masterNodeId());
long count = clusterJoinsCounter.incrementAndGet();
logger.trace("updated cluster join cluster to [{}]", count);
代码示例来源:origin: harbby/presto-connectors
String masterId = nodes.masterNodeId();
Table table = getTableWithHeader(req);
内容来源于网络,如有侵权,请联系作者删除!