Java Code Examples for org.elasticsearch.cluster.node.DiscoveryNode

The following examples show how to use org.elasticsearch.cluster.node.DiscoveryNode. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: crate   Source File: IndicesClusterStateService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Removes shard entries from the failed shards cache that are no longer allocated to this node by the master.
 * Sends shard failures for shards that are marked as actively allocated to this node but don't actually exist on the node.
 * Resends shard failures for shards that are still marked as allocated to this node but previously failed.
 *
 * @param state new cluster state
 */
private void updateFailedShardsCache(final ClusterState state) {
    RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
    if (localRoutingNode == null) {
        failedShardsCache.clear();
        return;
    }

    DiscoveryNode masterNode = state.nodes().getMasterNode();

    // remove items from cache which are not in our routing table anymore and resend failures that have not executed on master yet
    for (Iterator<Map.Entry<ShardId, ShardRouting>> iterator = failedShardsCache.entrySet().iterator(); iterator.hasNext(); ) {
        ShardRouting failedShardRouting = iterator.next().getValue();
        ShardRouting matchedRouting = localRoutingNode.getByShardId(failedShardRouting.shardId());
        if (matchedRouting == null || matchedRouting.isSameAllocation(failedShardRouting) == false) {
            iterator.remove();
        } else {
            if (masterNode != null) { // TODO: can we remove this? Is resending shard failures the responsibility of shardStateAction?
                String message = "master " + masterNode + " has not removed previously failed shard. resending shard failure";
                LOGGER.trace("[{}] re-sending failed shard [{}], reason [{}]", matchedRouting.shardId(), matchedRouting, message);
                shardStateAction.localShardFailed(matchedRouting, message, null, SHARD_STATE_ACTION_LISTENER, state);
            }
        }
    }
}
 
Example 2
Source Project: crate   Source File: AllocateUnassignedDecision.java    License: Apache License 2.0 6 votes vote down vote up
private AllocateUnassignedDecision(AllocationStatus allocationStatus,
                                   DiscoveryNode assignedNode,
                                   String allocationId,
                                   List<NodeAllocationResult> nodeDecisions,
                                   boolean reuseStore,
                                   long remainingDelayInMillis,
                                   long configuredDelayInMillis) {
    super(assignedNode, nodeDecisions);
    assert assignedNode != null || allocationStatus != null :
        "a yes decision must have a node to assign the shard to";
    assert allocationId == null || assignedNode != null :
        "allocation id can only be null if the assigned node is null";
    this.allocationStatus = allocationStatus;
    this.allocationId = allocationId;
    this.reuseStore = reuseStore;
    this.remainingDelayInMillis = remainingDelayInMillis;
    this.configuredDelayInMillis = configuredDelayInMillis;
}
 
Example 3
Source Project: anomaly-detection   Source File: ADStatsTests.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    node1 = "node1";
    nodeName1 = "nodename1";
    clusterName = "test-cluster-name";
    discoveryNode1 = new DiscoveryNode(
        nodeName1,
        node1,
        new TransportAddress(TransportAddress.META_ADDRESS, 9300),
        emptyMap(),
        emptySet(),
        Version.CURRENT
    );
    clusterStats = new HashMap<>();
}
 
Example 4
Source Project: crate   Source File: NodeStatsContextFieldResolver.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
NodeStatsContextFieldResolver(Supplier<DiscoveryNode> localNode,
                              MonitorService monitorService,
                              Supplier<TransportAddress> boundHttpAddress,
                              Supplier<HttpStats> httpStatsSupplier,
                              ThreadPool threadPool,
                              ExtendedNodeInfo extendedNodeInfo,
                              Supplier<ConnectionStats> psqlStats,
                              Supplier<TransportAddress> boundPostgresAddress,
                              LongSupplier numOpenTransportConnections,
                              LongSupplier clusterStateVersion) {
    this.localNode = localNode;
    processService = monitorService.processService();
    osService = monitorService.osService();
    jvmService = monitorService.jvmService();
    fsService = monitorService.fsService();
    this.httpStatsSupplier = httpStatsSupplier;
    this.boundHttpAddress = boundHttpAddress;
    this.threadPool = threadPool;
    this.extendedNodeInfo = extendedNodeInfo;
    this.psqlStats = psqlStats;
    this.boundPostgresAddress = boundPostgresAddress;
    this.numOpenTransportConnections = numOpenTransportConnections;
    this.clusterStateVersion = clusterStateVersion;
}
 
Example 5
Source Project: crate   Source File: RoutingProvider.java    License: Apache License 2.0 6 votes vote down vote up
public Routing forRandomMasterOrDataNode(RelationName relationName, DiscoveryNodes nodes) {
    DiscoveryNode localNode = nodes.getLocalNode();
    if (localNode.isMasterNode() || localNode.isDataNode()) {
        return forTableOnSingleNode(relationName, localNode.getId());
    }
    ImmutableOpenMap<String, DiscoveryNode> masterAndDataNodes = nodes.getMasterAndDataNodes();
    int randomIdx = seed % masterAndDataNodes.size();
    Iterator<DiscoveryNode> it = masterAndDataNodes.valuesIt();
    int currIdx = 0;
    while (it.hasNext()) {
        if (currIdx == randomIdx) {
            return forTableOnSingleNode(relationName, it.next().getId());
        }
        currIdx++;
    }
    throw new AssertionError("Cannot find a master or data node with given random index " + randomIdx);
}
 
Example 6
Source Project: Elasticsearch   Source File: PublishClusterStateAction.java    License: Apache License 2.0 6 votes vote down vote up
private void sendFullClusterState(ClusterState clusterState, @Nullable Map<Version, BytesReference> serializedStates,
                                  DiscoveryNode node, AtomicBoolean timedOutWaitingForNodes, TimeValue publishTimeout,
                                  BlockingClusterStatePublishResponseHandler publishResponseHandler) {
    BytesReference bytes = null;
    if (serializedStates != null) {
        bytes = serializedStates.get(node.version());
    }
    if (bytes == null) {
        try {
            bytes = serializeFullClusterState(clusterState, node.version());
            if (serializedStates != null) {
                serializedStates.put(node.version(), bytes);
            }
        } catch (Throwable e) {
            logger.warn("failed to serialize cluster_state before publishing it to node {}", e, node);
            publishResponseHandler.onFailure(node, e);
            return;
        }
    }
    publishClusterStateToNode(clusterState, bytes, node, timedOutWaitingForNodes, publishTimeout, publishResponseHandler, false);
}
 
Example 7
Source Project: crate   Source File: ClusterBootstrapServiceTests.java    License: Apache License 2.0 6 votes vote down vote up
public void testBootstrapsOnDiscoveryOfTwoOfThreeRequiredNodes() {
    final AtomicBoolean bootstrapped = new AtomicBoolean();

    ClusterBootstrapService clusterBootstrapService = new ClusterBootstrapService(Settings.builder().putList(
        INITIAL_MASTER_NODES_SETTING.getKey(), localNode.getName(), otherNode1.getName(), otherNode2.getName()).build(),
        transportService, () -> singletonList(otherNode1), () -> false, vc -> {
        assertTrue(bootstrapped.compareAndSet(false, true));
        assertThat(vc.getNodeIds(), hasSize(3));
        assertThat(vc.getNodeIds(), hasItem(localNode.getId()));
        assertThat(vc.getNodeIds(), hasItem(otherNode1.getId()));
        assertThat(vc.getNodeIds(), hasItem(allOf(startsWith(BOOTSTRAP_PLACEHOLDER_PREFIX), containsString(otherNode2.getName()))));
        assertTrue(vc.hasQuorum(Stream.of(localNode, otherNode1).map(DiscoveryNode::getId).collect(Collectors.toList())));
        assertFalse(vc.hasQuorum(singletonList(localNode.getId())));
        assertFalse(vc.hasQuorum(singletonList(otherNode1.getId())));
    });

    transportService.start();
    clusterBootstrapService.onFoundPeersUpdated();
    deterministicTaskQueue.runAllTasks();
    assertTrue(bootstrapped.get());

    bootstrapped.set(false);
    clusterBootstrapService.onFoundPeersUpdated();
    deterministicTaskQueue.runAllTasks();
    assertFalse(bootstrapped.get()); // should only bootstrap once
}
 
Example 8
Source Project: Elasticsearch   Source File: SnapshotsService.java    License: Apache License 2.0 6 votes vote down vote up
private boolean removedNodesCleanupNeeded(ClusterChangedEvent event) {
    // Check if we just became the master
    boolean newMaster = !event.previousState().nodes().localNodeMaster();
    SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE);
    if (snapshotsInProgress == null) {
        return false;
    }
    for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
        if (newMaster && (snapshot.state() == State.SUCCESS || snapshot.state() == State.INIT)) {
            // We just replaced old master and snapshots in intermediate states needs to be cleaned
            return true;
        }
        for (DiscoveryNode node : event.nodesDelta().removedNodes()) {
            for (ShardSnapshotStatus shardStatus : snapshot.shards().values()) {
                if (!shardStatus.state().completed() && node.getId().equals(shardStatus.nodeId())) {
                    // At least one shard was running on the removed node - we need to fail it
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 9
void executePhase(final int shardIndex, DiscoveryNode node, final long searchId) {
    InternalScrollSearchRequest internalRequest = internalScrollSearchRequest(searchId, request);
    searchService.sendExecuteFetch(node, internalRequest, new ActionListener<ScrollQueryFetchSearchResult>() {
        @Override
        public void onResponse(ScrollQueryFetchSearchResult result) {
            queryFetchResults.set(shardIndex, result.result());
            if (counter.decrementAndGet() == 0) {
                finishHim();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            onPhaseFailure(t, searchId, shardIndex);
        }
    });
}
 
Example 10
Source Project: Elasticsearch   Source File: NettyTransport.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Disconnects from a node if a channel is found as part of that nodes channels.
 */
protected void disconnectFromNodeChannel(final Channel channel, final Throwable failure) {
    threadPool().generic().execute(new Runnable() {

        @Override
        public void run() {
            for (DiscoveryNode node : connectedNodes.keySet()) {
                if (disconnectFromNode(node, channel, ExceptionsHelper.detailedMessage(failure))) {
                    // if we managed to find this channel and disconnect from it, then break, no need to check on
                    // the rest of the nodes
                    break;
                }
            }
        }
    });
}
 
Example 11
Source Project: dk-fitting   Source File: ElasticsearchUtil.java    License: Apache License 2.0 5 votes vote down vote up
public Client getEsClient(Map<String, Integer> esAddresses,Map<String, String> esConfig){
    Settings settings = Settings.builder().put(esConfig).put("client.transport.sniff", true).build();
    TransportClient transportClient = new PreBuiltTransportClient(settings);
    for (Map.Entry<String, Integer> esIpAndPort: esAddresses.entrySet()) {
        transportClient.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(esIpAndPort.getKey(), esIpAndPort.getValue())));
    }
    List<DiscoveryNode> discoveryNodes = transportClient.connectedNodes();
    if (discoveryNodes.isEmpty()) {
        throw new RuntimeException("Cannot connect to any elasticsearch nodes");
    }
   return transportClient;
}
 
Example 12
Source Project: crate   Source File: PreVoteCollectorTests.java    License: Apache License 2.0 5 votes vote down vote up
public void testAcceptsPreVotesFromAnyVersionInEarlierTerms() {
    assumeTrue("unluckily hit 0 for lastAcceptedTerm, cannot decrement", 0 < lastAcceptedTerm);

    final DiscoveryNode otherNode = new DiscoveryNode("other-node", buildNewFakeTransportAddress(), Version.CURRENT);
    responsesByNode.put(otherNode,
        new PreVoteResponse(currentTerm, randomLongBetween(0, lastAcceptedTerm - 1), randomNonNegativeLong()));
    startAndRunCollector(otherNode);
    assertTrue(electionOccurred);
}
 
Example 13
Source Project: Elasticsearch   Source File: TransportClientNodesService.java    License: Apache License 2.0 5 votes vote down vote up
public <Response> void execute(NodeListenerCallback<Response> callback, ActionListener<Response> listener) {
    List<DiscoveryNode> nodes = this.nodes;
    ensureNodesAreAvailable(nodes);
    int index = getNodeNumber();
    RetryListener<Response> retryListener = new RetryListener<>(callback, listener, nodes, index);
    DiscoveryNode node = nodes.get((index) % nodes.size());
    try {
        callback.doWithNode(node, retryListener);
    } catch (Throwable t) {
        //this exception can't come from the TransportService as it doesn't throw exception at all
        listener.onFailure(t);
    }
}
 
Example 14
Source Project: Elasticsearch   Source File: PublishClusterStateAction.java    License: Apache License 2.0 5 votes vote down vote up
public void publish(ClusterChangedEvent clusterChangedEvent, final Discovery.AckListener ackListener) {
    Set<DiscoveryNode> nodesToPublishTo = new HashSet<>(clusterChangedEvent.state().nodes().size());
    DiscoveryNode localNode = nodesProvider.nodes().localNode();
    for (final DiscoveryNode node : clusterChangedEvent.state().nodes()) {
        if (node.equals(localNode)) {
            continue;
        }
        nodesToPublishTo.add(node);
    }
    publish(clusterChangedEvent, nodesToPublishTo, new AckClusterStatePublishResponseHandler(nodesToPublishTo, ackListener));
}
 
Example 15
public void testRerouteAfterRemovingNodes() throws Exception {
    final AllocationService allocationService = mock(AllocationService.class);
    when(allocationService.disassociateDeadNodes(any(ClusterState.class), eq(true), any(String.class)))
        .thenAnswer(im -> im.getArguments()[0]);

    final AtomicReference<ClusterState> remainingNodesClusterState = new AtomicReference<>();
    final NodeRemovalClusterStateTaskExecutor executor =
            new NodeRemovalClusterStateTaskExecutor(allocationService, logger) {
                @Override
                protected ClusterState remainingNodesClusterState(ClusterState currentState,
                                                                  DiscoveryNodes.Builder remainingNodesBuilder) {
                    remainingNodesClusterState.set(super.remainingNodesClusterState(currentState, remainingNodesBuilder));
                    return remainingNodesClusterState.get();
                }
            };

    final DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
    final int nodes = randomIntBetween(2, 16);
    final List<NodeRemovalClusterStateTaskExecutor.Task> tasks = new ArrayList<>();
    // to ensure that there is at least one removal
    boolean first = true;
    for (int i = 0; i < nodes; i++) {
        final DiscoveryNode node = node(i);
        builder.add(node);
        if (first || randomBoolean()) {
            tasks.add(new NodeRemovalClusterStateTaskExecutor.Task(node, randomBoolean() ? "left" : "failed"));
        }
        first = false;
    }
    final ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(builder).build();

    final ClusterStateTaskExecutor.ClusterTasksResult<NodeRemovalClusterStateTaskExecutor.Task> result =
            executor.execute(clusterState, tasks);

    verify(allocationService).disassociateDeadNodes(eq(remainingNodesClusterState.get()), eq(true), any(String.class));

    for (final NodeRemovalClusterStateTaskExecutor.Task task : tasks) {
        assertNull(result.resultingState.nodes().get(task.node().getId()));
    }
}
 
Example 16
Source Project: crate   Source File: PreVoteCollectorTests.java    License: Apache License 2.0 5 votes vote down vote up
public void testResponseIfCandidate() {
    final long term = randomNonNegativeLong();
    final DiscoveryNode otherNode = new DiscoveryNode("other-node", buildNewFakeTransportAddress(), Version.CURRENT);

    PreVoteResponse newPreVoteResponse = new PreVoteResponse(currentTerm, lastAcceptedTerm, lastAcceptedVersion);
    preVoteCollector.update(newPreVoteResponse, null);

    assertThat(handlePreVoteRequestViaTransportService(new PreVoteRequest(otherNode, term)), equalTo(newPreVoteResponse));
}
 
Example 17
Source Project: elasticsearch-helper   Source File: TransportClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current registered transport addresses to use.
 * @return list of transport addresess
 */
public List<TransportAddress> transportAddresses() {
    List<TransportAddress> lstBuilder = new ArrayList<>();
    for (DiscoveryNode listedNode : listedNodes) {
        lstBuilder.add(listedNode.address());
    }
    return Collections.unmodifiableList(lstBuilder);
}
 
Example 18
Source Project: Elasticsearch   Source File: ShardStateAction.java    License: Apache License 2.0 5 votes vote down vote up
public void shardFailed(final ShardRouting shardRouting, final String indexUUID, final String message, @Nullable final Throwable failure) {
    DiscoveryNode masterNode = clusterService.state().nodes().masterNode();
    if (masterNode == null) {
        logger.warn("can't send shard failed for {}, no master known.", shardRouting);
        return;
    }
    innerShardFailed(shardRouting, indexUUID, masterNode, message, failure);
}
 
Example 19
public void start() {
    if (scrollId.getContext().length == 0) {
        listener.onFailure(new SearchPhaseExecutionException("query", "no nodes to search on", ShardSearchFailure.EMPTY_ARRAY));
        return;
    }
    final AtomicInteger counter = new AtomicInteger(scrollId.getContext().length);

    ScrollIdForNode[] context = scrollId.getContext();
    for (int i = 0; i < context.length; i++) {
        ScrollIdForNode target = context[i];
        DiscoveryNode node = nodes.get(target.getNode());
        if (node != null) {
            executeQueryPhase(i, counter, node, target.getScrollId());
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Node [" + target.getNode() + "] not available for scroll request [" + scrollId.getSource() + "]");
            }
            successfulOps.decrementAndGet();
            if (counter.decrementAndGet() == 0) {
                try {
                    executeFetchPhase();
                } catch (Throwable e) {
                    listener.onFailure(new SearchPhaseExecutionException("query", "Fetch failed", e, ShardSearchFailure.EMPTY_ARRAY));
                    return;
                }
            }
        }
    }
}
 
Example 20
Source Project: Elasticsearch   Source File: TransportKillAllNodeAction.java    License: Apache License 2.0 5 votes vote down vote up
public void broadcast(KillAllRequest request, ActionListener<KillResponse> listener) {
    DiscoveryNodes nodes = clusterService.state().nodes();
    listener = new MultiActionListener<>(nodes.size(), KillResponse.MERGE_FUNCTION, listener);
    DefaultTransportResponseHandler<KillResponse> responseHandler = new DefaultTransportResponseHandler<KillResponse>(listener) {
        @Override
        public KillResponse newInstance() {
            return new KillResponse(0);
        }
    };
    for (DiscoveryNode node : nodes) {
        transportService.sendRequest(node, TRANSPORT_ACTION, request, responseHandler);
    }
}
 
Example 21
Source Project: crate   Source File: TcpTransport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request,
                          TransportRequestOptions finalOptions) {
    for (TransportMessageListener listener : listeners) {
        listener.onRequestSent(node, requestId, action, request, finalOptions);
    }
}
 
Example 22
Source Project: Elasticsearch   Source File: CopyStatementPlanner.java    License: Apache License 2.0 5 votes vote down vote up
private static Collection<String> getExecutionNodes(DiscoveryNodes allNodes,
                                                    int maxNodes,
                                                    final Predicate<DiscoveryNode> nodeFilters) {
    final AtomicInteger counter = new AtomicInteger(maxNodes);
    final List<String> nodes = new ArrayList<>(allNodes.size());
    allNodes.dataNodes().values().forEach(new ObjectProcedure<DiscoveryNode>() {
        @Override
        public void apply(DiscoveryNode value) {
            if (nodeFilters.apply(value) && counter.getAndDecrement() > 0) {
                nodes.add(value.id());
            }
        }
    });
    return nodes;
}
 
Example 23
Source Project: Elasticsearch   Source File: SnapshotsService.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public SnapshotsService(Settings settings, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, RepositoriesService repositoriesService, ThreadPool threadPool) {
    super(settings);
    this.clusterService = clusterService;
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    this.repositoriesService = repositoriesService;
    this.threadPool = threadPool;

    if (DiscoveryNode.masterNode(settings)) {
        // addLast to make sure that Repository will be created before snapshot
        clusterService.addLast(this);
    }
}
 
Example 24
Source Project: crate   Source File: MockTransportService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void traceReceivedResponse(long requestId, DiscoveryNode sourceNode, String action) {
    super.traceReceivedResponse(requestId, sourceNode, action);
    for (Tracer tracer : activeTracers) {
        tracer.receivedResponse(requestId, sourceNode, action);
    }
}
 
Example 25
Source Project: crate   Source File: LocalAllocateDangledIndices.java    License: Apache License 2.0 5 votes vote down vote up
public void allocateDangled(Collection<IndexMetaData> indices, final Listener listener) {
    ClusterState clusterState = clusterService.state();
    DiscoveryNode masterNode = clusterState.nodes().getMasterNode();
    if (masterNode == null) {
        listener.onFailure(new MasterNotDiscoveredException("no master to send allocate dangled request"));
        return;
    }
    AllocateDangledRequest request = new AllocateDangledRequest(clusterService.localNode(),
        indices.toArray(new IndexMetaData[indices.size()]));
    transportService.sendRequest(masterNode, ACTION_NAME, request, new TransportResponseHandler<AllocateDangledResponse>() {
        @Override
        public AllocateDangledResponse read(StreamInput in) throws IOException {
            return new AllocateDangledResponse(in);
        }

        @Override
        public void handleResponse(AllocateDangledResponse response) {
            listener.onResponse(response);
        }

        @Override
        public void handleException(TransportException exp) {
            listener.onFailure(exp);
        }

        @Override
        public String executor() {
            return ThreadPool.Names.SAME;
        }
    });
}
 
Example 26
Source Project: crate   Source File: Publication.java    License: Apache License 2.0 5 votes vote down vote up
void onFaultyNode(DiscoveryNode faultyNode) {
    if (isActive() && discoveryNode.equals(faultyNode)) {
        logger.debug("onFaultyNode: [{}] is faulty, failing target in publication {}", faultyNode, Publication.this);
        setFailed(new ElasticsearchException("faulty node"));
        onPossibleCommitFailure();
    }
}
 
Example 27
Source Project: Elasticsearch   Source File: LocalTransport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException {
    final Version version = Version.smallest(node.version(), this.version);

    try (BytesStreamOutput stream = new BytesStreamOutput()) {
        stream.setVersion(version);

        stream.writeLong(requestId);
        byte status = 0;
        status = TransportStatus.setRequest(status);
        stream.writeByte(status); // 0 for request, 1 for response.

        stream.writeString(action);
        request.writeTo(stream);

        stream.close();

        final LocalTransport targetTransport = connectedNodes.get(node);
        if (targetTransport == null) {
            throw new NodeNotConnectedException(node, "Node not connected");
        }

        final byte[] data = stream.bytes().toBytes();

        transportServiceAdapter.sent(data.length);
        transportServiceAdapter.onRequestSent(node, requestId, action, request, options);
        targetTransport.workers().execute(new Runnable() {
            @Override
            public void run() {
                targetTransport.messageReceived(data, action, LocalTransport.this, version, requestId);
            }
        });
    }
}
 
Example 28
public void sendExecuteFetch(DiscoveryNode node, final ShardSearchTransportRequest request, final ActionListener<QueryFetchSearchResult> listener) {
    transportService.sendRequest(node, QUERY_FETCH_ACTION_NAME, request, new ActionListenerResponseHandler<QueryFetchSearchResult>(listener) {
        @Override
        public QueryFetchSearchResult newInstance() {
            return new QueryFetchSearchResult();
        }
    });
}
 
Example 29
Source Project: crate   Source File: CoordinatorTests.java    License: Apache License 2.0 5 votes vote down vote up
ClusterNode restartedNode(Function<MetaData, MetaData> adaptGlobalMetaData, Function<Long, Long> adaptCurrentTerm,
                          Settings nodeSettings) {
    final TransportAddress address = randomBoolean() ? buildNewFakeTransportAddress() : localNode.getAddress();
    final DiscoveryNode newLocalNode = new DiscoveryNode(localNode.getName(), localNode.getId(),
        UUIDs.randomBase64UUID(random()), // generated deterministically for repeatable tests
        address.address().getHostString(), address.getAddress(), address, Collections.emptyMap(),
        localNode.isMasterNode() ? EnumSet.allOf(Role.class) : emptySet(), Version.CURRENT);
    return new ClusterNode(nodeIndex, newLocalNode,
        node -> new MockPersistedState(newLocalNode, persistedState, adaptGlobalMetaData, adaptCurrentTerm), nodeSettings);
}
 
Example 30
Source Project: crate   Source File: GatewayMetaState.java    License: Apache License 2.0 5 votes vote down vote up
public PersistedState getPersistedState(Settings settings, ClusterApplierService clusterApplierService) {
    applyClusterStateUpdaters();
    if (DiscoveryNode.isMasterNode(settings) == false) {
        // use Zen1 way of writing cluster state for non-master-eligible nodes
        // this avoids concurrent manipulating of IndexMetadata with IndicesStore
        clusterApplierService.addLowPriorityApplier(this);
        return new InMemoryPersistedState(getCurrentTerm(), getLastAcceptedState());
    }
    return this;
}