Search in sources :

Example 1 with MultiActionListener

use of io.crate.execution.support.MultiActionListener in project crate by crate.

the class TransportAnalyzeAction method publishTableStats.

private CompletableFuture<AcknowledgedResponse> publishTableStats(Map<RelationName, Stats> newTableStats) {
    List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false).filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0)).collect(Collectors.toList());
    var listener = new FutureActionListener<AcknowledgedResponse, AcknowledgedResponse>(x -> x);
    var multiListener = new MultiActionListener<>(nodesOn41OrAfter.size(), Collectors.reducing(new AcknowledgedResponse(true), (resp1, resp2) -> new AcknowledgedResponse(resp1.isAcknowledged() && resp2.isAcknowledged())), listener);
    var responseHandler = new ActionListenerResponseHandler<>(multiListener, AcknowledgedResponse::new, ThreadPool.Names.SAME);
    PublishTableStatsRequest request = new PublishTableStatsRequest(newTableStats);
    for (DiscoveryNode node : nodesOn41OrAfter) {
        transportService.sendRequest(node, RECEIVE_TABLE_STATS, request, responseHandler);
    }
    return listener;
}
Also used : Arrays(java.util.Arrays) RelationName(io.crate.metadata.RelationName) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) Symbols(io.crate.expression.symbol.Symbols) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) FutureActionListener(io.crate.action.FutureActionListener) SchemaInfo(io.crate.metadata.table.SchemaInfo) TableInfo(io.crate.metadata.table.TableInfo) Streamer(io.crate.Streamer) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) CompletableFutures(io.crate.concurrent.CompletableFutures) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) AnalyzeRequest(io.crate.execution.ddl.AnalyzeRequest) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MultiActionListener(io.crate.execution.support.MultiActionListener) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) FutureActionListener(io.crate.action.FutureActionListener)

Example 2 with MultiActionListener

use of io.crate.execution.support.MultiActionListener in project crate by crate.

the class TransportAnalyzeAction method fetchSamples.

private CompletableFuture<Samples> fetchSamples(RelationName relationName, List<Reference> columns) {
    FutureActionListener<FetchSampleResponse, Samples> listener = new FutureActionListener<>(FetchSampleResponse::samples);
    List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false).filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0)).collect(Collectors.toList());
    MultiActionListener<FetchSampleResponse, ?, FetchSampleResponse> multiListener = new MultiActionListener<>(nodesOn41OrAfter.size(), Collectors.reducing(new FetchSampleResponse(Samples.EMPTY), (FetchSampleResponse s1, FetchSampleResponse s2) -> FetchSampleResponse.merge(TransportAnalyzeAction.NUM_SAMPLES, s1, s2)), listener);
    List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
    ActionListenerResponseHandler<FetchSampleResponse> responseHandler = new ActionListenerResponseHandler<>(multiListener, in -> new FetchSampleResponse(streamers, in), ThreadPool.Names.SAME);
    for (DiscoveryNode node : nodesOn41OrAfter) {
        transportService.sendRequest(node, FETCH_SAMPLES, new FetchSampleRequest(relationName, columns, TransportAnalyzeAction.NUM_SAMPLES), responseHandler);
    }
    return listener;
}
Also used : Arrays(java.util.Arrays) RelationName(io.crate.metadata.RelationName) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) Symbols(io.crate.expression.symbol.Symbols) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) FutureActionListener(io.crate.action.FutureActionListener) SchemaInfo(io.crate.metadata.table.SchemaInfo) TableInfo(io.crate.metadata.table.TableInfo) Streamer(io.crate.Streamer) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) CompletableFutures(io.crate.concurrent.CompletableFutures) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) AnalyzeRequest(io.crate.execution.ddl.AnalyzeRequest) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MultiActionListener(io.crate.execution.support.MultiActionListener) FutureActionListener(io.crate.action.FutureActionListener) Streamer(io.crate.Streamer) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler)

Example 3 with MultiActionListener

use of io.crate.execution.support.MultiActionListener in project crate by crate.

the class TransportKillNodeAction method broadcast.

public void broadcast(Request request, ActionListener<Long> listener, Collection<String> excludedNodeIds) {
    Stream<DiscoveryNode> nodes = StreamSupport.stream(clusterService.state().nodes().spliterator(), false);
    Collection<DiscoveryNode> filteredNodes = nodes.filter(node -> !excludedNodeIds.contains(node.getId())).collect(Collectors.toList());
    MultiActionListener<KillResponse, ?, Long> multiListener = new MultiActionListener<>(filteredNodes.size(), Collectors.summingLong(KillResponse::numKilled), listener);
    TransportResponseHandler<KillResponse> responseHandler = new ActionListenerResponseHandler<>(multiListener, KillResponse::new);
    for (DiscoveryNode node : filteredNodes) {
        transportService.sendRequest(node, name, request, responseHandler);
    }
}
Also used : TransportRequest(org.elasticsearch.transport.TransportRequest) Collection(java.util.Collection) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ClusterService(org.elasticsearch.cluster.service.ClusterService) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) TasksService(io.crate.execution.jobs.TasksService) NodeAction(io.crate.execution.support.NodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Stream(java.util.stream.Stream) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) Writeable(org.elasticsearch.common.io.stream.Writeable) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MultiActionListener(io.crate.execution.support.MultiActionListener) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler)

Aggregations

MultiActionListener (io.crate.execution.support.MultiActionListener)3 NodeActionRequestHandler (io.crate.execution.support.NodeActionRequestHandler)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Collectors (java.util.stream.Collectors)3 StreamSupport (java.util.stream.StreamSupport)3 ActionListenerResponseHandler (org.elasticsearch.action.ActionListenerResponseHandler)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)3 ClusterService (org.elasticsearch.cluster.service.ClusterService)3 ThreadPool (org.elasticsearch.threadpool.ThreadPool)3 TransportService (org.elasticsearch.transport.TransportService)3 Streamer (io.crate.Streamer)2 FutureActionListener (io.crate.action.FutureActionListener)2 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)2 CompletableFutures (io.crate.concurrent.CompletableFutures)2 Row (io.crate.data.Row)2 AnalyzeRequest (io.crate.execution.ddl.AnalyzeRequest)2 Symbols (io.crate.expression.symbol.Symbols)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 Reference (io.crate.metadata.Reference)2 RelationName (io.crate.metadata.RelationName)2