Java Code Examples for org.elasticsearch.transport.TransportService#registerRequestHandler()

The following examples show how to use org.elasticsearch.transport.TransportService#registerRequestHandler() . 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 File: LeaderChecker.java    From crate with Apache License 2.0 6 votes vote down vote up
public LeaderChecker(final Settings settings, final TransportService transportService, final Runnable onLeaderFailure) {
    this.settings = settings;
    leaderCheckInterval = LEADER_CHECK_INTERVAL_SETTING.get(settings);
    leaderCheckTimeout = LEADER_CHECK_TIMEOUT_SETTING.get(settings);
    leaderCheckRetryCount = LEADER_CHECK_RETRY_COUNT_SETTING.get(settings);
    this.transportService = transportService;
    this.onLeaderFailure = onLeaderFailure;

    transportService.registerRequestHandler(LEADER_CHECK_ACTION_NAME, Names.SAME, false, false, LeaderCheckRequest::new,
        (request, channel, task) -> {
            handleLeaderCheck(request);
            channel.sendResponse(Empty.INSTANCE);
        });

    transportService.addConnectionListener(new TransportConnectionListener() {
        @Override
        public void onNodeDisconnected(DiscoveryNode node) {
            handleDisconnectedNode(node);
        }
    });
}
 
Example 2
Source File: TransportKillNodeAction.java    From crate with Apache License 2.0 6 votes vote down vote up
TransportKillNodeAction(String name,
                        TasksService tasksService,
                        ClusterService clusterService,
                        TransportService transportService,
                        Writeable.Reader<Request> reader) {
    this.tasksService = tasksService;
    this.clusterService = clusterService;
    this.transportService = transportService;
    this.reader = reader;
    this.name = name;
    transportService.registerRequestHandler(
        name,
        reader,
        ThreadPool.Names.GENERIC,
        new NodeActionRequestHandler<>(this));
}
 
Example 3
Source File: IndicesStore.java    From crate with Apache License 2.0 6 votes vote down vote up
@Inject
public IndicesStore(Settings settings, IndicesService indicesService,
                    ClusterService clusterService, TransportService transportService, ThreadPool threadPool) {
    this.settings = settings;
    this.indicesService = indicesService;
    this.clusterService = clusterService;
    this.transportService = transportService;
    this.threadPool = threadPool;
    transportService.registerRequestHandler(ACTION_SHARD_EXISTS, ShardActiveRequest::new, ThreadPool.Names.SAME, new ShardActiveRequestHandler());
    this.deleteShardTimeout = INDICES_STORE_DELETE_SHARD_TIMEOUT.get(settings);
    // Doesn't make sense to delete shards on non-data nodes
    if (DiscoveryNode.isDataNode(settings)) {
        // we double check nothing has changed when responses come back from other nodes.
        // it's easier to do that check when the current cluster state is visible.
        // also it's good in general to let things settle down
        clusterService.addListener(this);
    }
}
 
Example 4
Source File: TransportCollectProfileNodeAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportCollectProfileNodeAction(TransportService transportService,
                                         Transports transports,
                                         TasksService tasksService) {
    this.transports = transports;
    this.tasksService = tasksService;

    transportService.registerRequestHandler(
        TRANSPORT_ACTION,
        NodeCollectProfileRequest::new,
        EXECUTOR,
        true,
        false,
        new NodeActionRequestHandler<>(this)
    );
}
 
Example 5
Source File: FollowersChecker.java    From crate with Apache License 2.0 6 votes vote down vote up
public FollowersChecker(Settings settings, TransportService transportService,
                        Consumer<FollowerCheckRequest> handleRequestAndUpdateState,
                        BiConsumer<DiscoveryNode, String> onNodeFailure) {
    this.settings = settings;
    this.transportService = transportService;
    this.handleRequestAndUpdateState = handleRequestAndUpdateState;
    this.onNodeFailure = onNodeFailure;

    followerCheckInterval = FOLLOWER_CHECK_INTERVAL_SETTING.get(settings);
    followerCheckTimeout = FOLLOWER_CHECK_TIMEOUT_SETTING.get(settings);
    followerCheckRetryCount = FOLLOWER_CHECK_RETRY_COUNT_SETTING.get(settings);

    updateFastResponseState(0, Mode.CANDIDATE);
    transportService.registerRequestHandler(FOLLOWER_CHECK_ACTION_NAME, Names.SAME, false, false, FollowerCheckRequest::new,
        (request, transportChannel, task) -> handleFollowerCheck(request, transportChannel));
    transportService.addConnectionListener(new TransportConnectionListener() {
        @Override
        public void onNodeDisconnected(DiscoveryNode node) {
            handleDisconnectedNode(node);
        }
    });
}
 
Example 6
Source File: TransportResyncReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerRequestHandlers(String actionName,
                                       TransportService transportService,
                                       Writeable.Reader<ResyncReplicationRequest> reader,
                                       Writeable.Reader<ResyncReplicationRequest> replicaReader,
                                       String executor) {
    transportService.registerRequestHandler(actionName, reader, ThreadPool.Names.SAME, new OperationTransportHandler());
    // we should never reject resync because of thread pool capacity on primary
    transportService.registerRequestHandler(
        transportPrimaryAction,
        in -> new ConcreteShardRequest<>(in, reader),
        executor,
        true,
        true,
        new PrimaryOperationTransportHandler());
    transportService.registerRequestHandler(
        transportReplicaAction,
        in -> new ConcreteReplicaRequest<>(in, replicaReader),
        executor,
        true,
        true,
        new ReplicaOperationTransportHandler());
}
 
Example 7
Source File: TransportFetchNodeAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportFetchNodeAction(TransportService transportService,
                                Transports transports,
                                ThreadPool threadPool,
                                StatsTables statsTables,
                                CircuitBreakerService breakerService,
                                JobContextService jobContextService,
                                NodeFetchOperation nodeFetchOperation) {
    this.transports = transports;
    this.statsTables = statsTables;
    this.nodeFetchOperation = nodeFetchOperation;
    this.circuitBreaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    this.jobContextService = jobContextService;
    this.threadPool = threadPool;

    transportService.registerRequestHandler(TRANSPORT_ACTION,
            NodeFetchRequest.class,
            EXECUTOR_NAME,
            new NodeActionRequestHandler<NodeFetchRequest, NodeFetchResponse>(this) { });
}
 
Example 8
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected void registerRequestHandlers(String actionName,
                                       TransportService transportService,
                                       Writeable.Reader<Request> reader,
                                       Writeable.Reader<ReplicaRequest> replicaRequestReader,
                                       String executor) {
    transportService.registerRequestHandler(actionName, reader, ThreadPool.Names.SAME, new OperationTransportHandler());
    transportService.registerRequestHandler(
        transportPrimaryAction, in -> new ConcreteShardRequest<>(in, reader), executor, new PrimaryOperationTransportHandler());
    // we must never reject on because of thread pool capacity on replicas
    transportService.registerRequestHandler(
        transportReplicaAction,
        in -> new ConcreteReplicaRequest<>(in, replicaRequestReader),
        executor,
        true,
        true,
        new ReplicaOperationTransportHandler());
}
 
Example 9
Source File: ClusteringAction.java    From elasticsearch-carrot2 with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportClusteringAction(TransportService transportService,
                                 TransportSearchAction searchAction,
                                 ClusteringContext controllerSingleton,
                                 ActionFilters actionFilters) {
   super(ClusteringAction.NAME,
       actionFilters,
       transportService.getTaskManager());

   this.searchAction = searchAction;
   this.context = controllerSingleton;
   transportService.registerRequestHandler(
       ClusteringAction.NAME,
       ThreadPool.Names.SAME,
       ClusteringActionRequest::new,
       new TransportHandler());
}
 
Example 10
Source File: TransportKillAllNodeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportKillAllNodeAction(JobContextService jobContextService,
                                  ClusterService clusterService,
                                  TransportService transportService) {
    this.jobContextService = jobContextService;
    this.clusterService = clusterService;
    this.transportService = transportService;
    transportService.registerRequestHandler(TRANSPORT_ACTION,
            KillAllRequest.class,
            ThreadPool.Names.GENERIC,
            new NodeActionRequestHandler<KillAllRequest, KillResponse>(this) { });
}
 
Example 11
Source File: PreVoteCollector.java    From crate with Apache License 2.0 5 votes vote down vote up
PreVoteCollector(final TransportService transportService, final Runnable startElection, final LongConsumer updateMaxTermSeen) {
    this.transportService = transportService;
    this.startElection = startElection;
    this.updateMaxTermSeen = updateMaxTermSeen;

    // TODO does this need to be on the generic threadpool or can it use SAME?
    transportService.registerRequestHandler(REQUEST_PRE_VOTE_ACTION_NAME, Names.GENERIC, false, false,
        PreVoteRequest::new,
        (request, channel, task) -> channel.sendResponse(handlePreVoteRequest(request)));
}
 
Example 12
Source File: TransportFetchNodeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportFetchNodeAction(Settings settings,
                                TransportService transportService,
                                Transports transports,
                                ThreadPool threadPool,
                                JobsLogs jobsLogs,
                                TasksService tasksService,
                                CircuitBreakerService circuitBreakerService) {
    this.transports = transports;
    this.nodeFetchOperation = new NodeFetchOperation(
        (ThreadPoolExecutor) threadPool.executor(ThreadPool.Names.SEARCH),
        EsExecutors.numberOfProcessors(settings),
        jobsLogs,
        tasksService,
        circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY)
    );

    transportService.registerRequestHandler(
        TRANSPORT_ACTION,
        NodeFetchRequest::new,
        EXECUTOR_NAME,
        // force execution because this handler might receive empty close requests which
        // need to be processed to not leak the FetchTask.
        // This shouldn't cause too much of an issue because fetch requests always happen after a query phase.
        // If the threadPool is overloaded the query phase would fail first.
        true,
        false,
        new NodeActionRequestHandler<>(this)
    );
}
 
Example 13
Source File: VerifyNodeRepositoryAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public VerifyNodeRepositoryAction(Settings settings, TransportService transportService, ClusterService clusterService, RepositoriesService repositoriesService) {
    super(settings);
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.repositoriesService = repositoriesService;
    transportService.registerRequestHandler(ACTION_NAME, VerifyNodeRepositoryRequest.class, ThreadPool.Names.SAME, new VerifyNodeRepositoryRequestHandler());
}
 
Example 14
Source File: LocalAllocateDangledIndices.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public LocalAllocateDangledIndices(TransportService transportService, ClusterService clusterService,
                                   AllocationService allocationService, MetaDataIndexUpgradeService metaDataIndexUpgradeService) {
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.allocationService = allocationService;
    this.metaDataIndexUpgradeService = metaDataIndexUpgradeService;
    transportService.registerRequestHandler(
        ACTION_NAME,
        AllocateDangledRequest::new,
        ThreadPool.Names.SAME,
        new AllocateDangledRequestHandler());
}
 
Example 15
Source File: RestoreService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public RestoreService(Settings settings, ClusterService clusterService, RepositoriesService repositoriesService, TransportService transportService,
                      AllocationService allocationService, MetaDataCreateIndexService createIndexService, @ClusterDynamicSettings DynamicSettings dynamicSettings,
                      MetaDataIndexUpgradeService metaDataIndexUpgradeService) {
    super(settings);
    this.clusterService = clusterService;
    this.repositoriesService = repositoriesService;
    this.transportService = transportService;
    this.allocationService = allocationService;
    this.createIndexService = createIndexService;
    this.dynamicSettings = dynamicSettings;
    this.metaDataIndexUpgradeService = metaDataIndexUpgradeService;
    transportService.registerRequestHandler(UPDATE_RESTORE_ACTION_NAME, UpdateIndexShardRestoreStatusRequest.class, ThreadPool.Names.SAME, new UpdateRestoreStateRequestHandler());
    clusterService.add(this);
}
 
Example 16
Source File: ListAlgorithmsAction.java    From elasticsearch-carrot2 with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportListAlgorithmsAction(TransportService transportService,
                                     ClusteringContext controllerSingleton,
                                     ActionFilters actionFilters) {
    super(ListAlgorithmsAction.NAME,
          actionFilters,
          transportService.getTaskManager());
    this.controllerSingleton = controllerSingleton;
    transportService.registerRequestHandler(
            ListAlgorithmsAction.NAME,
            ThreadPool.Names.SAME,
            ListAlgorithmsActionRequest::new,
            new TransportHandler());
}
 
Example 17
Source File: PeerRecoverySourceService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public PeerRecoverySourceService(TransportService transportService,
                                 IndicesService indicesService,
                                 RecoverySettings recoverySettings) {
    this.transportService = transportService;
    this.indicesService = indicesService;
    this.recoverySettings = recoverySettings;
    transportService.registerRequestHandler(Actions.START_RECOVERY, StartRecoveryRequest::new, ThreadPool.Names.GENERIC, new StartRecoveryTransportRequestHandler());
}
 
Example 18
Source File: VerifyNodeRepositoryAction.java    From crate with Apache License 2.0 4 votes vote down vote up
public VerifyNodeRepositoryAction(TransportService transportService, ClusterService clusterService, RepositoriesService repositoriesService) {
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.repositoriesService = repositoriesService;
    transportService.registerRequestHandler(ACTION_NAME, VerifyNodeRepositoryRequest::new, ThreadPool.Names.SNAPSHOT, new VerifyNodeRepositoryRequestHandler());
}
 
Example 19
Source File: JoinHelper.java    From crate with Apache License 2.0 4 votes vote down vote up
JoinHelper(Settings settings, AllocationService allocationService, MasterService masterService,
           TransportService transportService, LongSupplier currentTermSupplier, Supplier<ClusterState> currentStateSupplier,
           BiConsumer<JoinRequest, JoinCallback> joinHandler, Function<StartJoinRequest, Join> joinLeaderInTerm,
           Collection<BiConsumer<DiscoveryNode, ClusterState>> joinValidators) {
    this.masterService = masterService;
    this.transportService = transportService;
    this.joinTimeout = JOIN_TIMEOUT_SETTING.get(settings);
    this.joinTaskExecutor = new JoinTaskExecutor(allocationService, LOGGER) {

        @Override
        public ClusterTasksResult<JoinTaskExecutor.Task> execute(ClusterState currentState, List<JoinTaskExecutor.Task> joiningTasks)
            throws Exception {
            // This is called when preparing the next cluster state for publication. There is no guarantee that the term we see here is
            // the term under which this state will eventually be published: the current term may be increased after this check due to
            // some other activity. That the term is correct is, however, checked properly during publication, so it is sufficient to
            // check it here on a best-effort basis. This is fine because a concurrent change indicates the existence of another leader
            // in a higher term which will cause this node to stand down.

            final long currentTerm = currentTermSupplier.getAsLong();
            if (currentState.term() != currentTerm) {
                final CoordinationMetaData coordinationMetaData =
                        CoordinationMetaData.builder(currentState.coordinationMetaData()).term(currentTerm).build();
                final MetaData metaData = MetaData.builder(currentState.metaData()).coordinationMetaData(coordinationMetaData).build();
                currentState = ClusterState.builder(currentState).metaData(metaData).build();
            }
            return super.execute(currentState, joiningTasks);
        }

    };

    transportService.registerRequestHandler(JOIN_ACTION_NAME, ThreadPool.Names.GENERIC, false, false, JoinRequest::new,
        (request, channel, task) -> joinHandler.accept(request, transportJoinCallback(request, channel)));

    transportService.registerRequestHandler(START_JOIN_ACTION_NAME, Names.GENERIC, false, false,
        StartJoinRequest::new,
        (request, channel, task) -> {
            final DiscoveryNode destination = request.getSourceNode();
            sendJoinRequest(destination, Optional.of(joinLeaderInTerm.apply(request)));
            channel.sendResponse(Empty.INSTANCE);
        });

    transportService.registerRequestHandler(
        VALIDATE_JOIN_ACTION_NAME,
        ValidateJoinRequest::new,
        ThreadPool.Names.GENERIC,
        (request, channel, task) -> {
            final ClusterState localState = currentStateSupplier.get();
            if (localState.metaData().clusterUUIDCommitted() &&
                localState.metaData().clusterUUID().equals(request.getState().metaData().clusterUUID()) == false) {
                throw new CoordinationStateRejectedException("join validation on cluster state" +
                    " with a different cluster uuid " + request.getState().metaData().clusterUUID() +
                    " than local cluster uuid " + localState.metaData().clusterUUID() + ", rejecting");
            }
            joinValidators.forEach(action -> action.accept(transportService.getLocalNode(), request.getState()));
            channel.sendResponse(Empty.INSTANCE);
        });
}
 
Example 20
Source File: HandledTransportAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
protected HandledTransportAction(Settings settings, String actionName, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Class<Request> request) {
    super(settings, actionName, threadPool, actionFilters, indexNameExpressionResolver, transportService.getTaskManager());
    transportService.registerRequestHandler(actionName, request, ThreadPool.Names.SAME, new TransportHandler());
}