org.elasticsearch.action.admin.indices.refresh.TransportShardRefreshAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.action.admin.indices.refresh;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.replication.BasicReplicationRequest;
import org.elasticsearch.action.support.replication.ReplicationResponse;
import org.elasticsearch.action.support.replication.TransportReplicationAction;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.io.IOException;
public class TransportShardRefreshAction extends TransportReplicationAction<
BasicReplicationRequest,
BasicReplicationRequest,
ReplicationResponse> {
public static final String NAME = RefreshAction.NAME + "[s]";
public static final ActionType TYPE = new ActionType<>(NAME, ReplicationResponse::new);
@Inject
public TransportShardRefreshAction(
Settings settings,
TransportService transportService,
ClusterService clusterService,
IndicesService indicesService,
ThreadPool threadPool,
ShardStateAction shardStateAction,
ActionFilters actionFilters
) {
super(
settings,
NAME,
transportService,
clusterService,
indicesService,
threadPool,
shardStateAction,
actionFilters,
BasicReplicationRequest::new,
BasicReplicationRequest::new,
ThreadPool.Names.REFRESH
);
}
@Override
protected ReplicationResponse newResponseInstance(StreamInput in) throws IOException {
return new ReplicationResponse(in);
}
@Override
protected void shardOperationOnPrimary(
BasicReplicationRequest shardRequest,
IndexShard primary,
ActionListener> listener
) {
ActionListener.completeWith(listener, () -> {
primary.refresh("api");
logger.trace("{} refresh request executed on primary", primary.shardId());
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
});
}
@Override
protected void shardOperationOnReplica(BasicReplicationRequest request, IndexShard replica, ActionListener listener) {
ActionListener.completeWith(listener, () -> {
replica.refresh("api");
logger.trace("{} refresh request executed on replica", replica.shardId());
return new ReplicaResult();
});
}
}