Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Dec 6, 2018
1 parent 8074705 commit feac528
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 49 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.replication.ReplicationRequest;
import org.elasticsearch.action.support.replication.ReplicationResponse;
import org.elasticsearch.action.support.replication.TransportReplicationAction;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
Expand All @@ -38,17 +39,19 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

public class TransportShardCloseAction extends TransportReplicationAction<ShardCloseRequest, ShardCloseRequest, ReplicationResponse> {
public class TransportVerifyShardBeforeCloseAction extends TransportReplicationAction<
TransportVerifyShardBeforeCloseAction.ShardCloseRequest, TransportVerifyShardBeforeCloseAction.ShardCloseRequest, ReplicationResponse> {

public static final String NAME = CloseIndexAction.NAME + "[s]";
private static final ClusterBlock EXPECTED_BLOCK = MetaDataIndexStateService.INDEX_CLOSED_BLOCK;

@Inject
public TransportShardCloseAction(final Settings settings, final TransportService transportService, final ClusterService clusterService,
final IndicesService indicesService, final ThreadPool threadPool, final ShardStateAction stateAction,
final ActionFilters actionFilters, final IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, NAME, transportService, clusterService, indicesService, threadPool, stateAction,
actionFilters, indexNameExpressionResolver, ShardCloseRequest::new, ShardCloseRequest::new, ThreadPool.Names.GENERIC);
public TransportVerifyShardBeforeCloseAction(final Settings settings, final TransportService transportService,
final ClusterService clusterService, final IndicesService indicesService,
final ThreadPool threadPool, final ShardStateAction stateAction,
final ActionFilters actionFilters, final IndexNameExpressionResolver resolver) {
super(settings, NAME, transportService, clusterService, indicesService, threadPool, stateAction, actionFilters, resolver,
ShardCloseRequest::new, ShardCloseRequest::new, ThreadPool.Names.MANAGEMENT);
}

@Override
Expand Down Expand Up @@ -103,6 +106,21 @@ private void executeShardOperation(final IndexShard indexShard) {
+ "] mismatches maximum sequence number [" + maxSeqNo + "] on index shard " + shardId);
}
indexShard.flush(new FlushRequest());
logger.debug("shard {} is ready for closing", shardId);
logger.debug("{} shard is ready for closing", shardId);
}

public static class ShardCloseRequest extends ReplicationRequest<ShardCloseRequest> {

ShardCloseRequest(){
}

public ShardCloseRequest(final ShardId shardId) {
super(shardId);
}

@Override
public String toString() {
return "close shard {" + shardId + "}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class TransportShardCloseActionTests extends ESTestCase {
public class TransportVerifyShardBeforeCloseActionTests extends ESTestCase {

private IndexShard indexShard;
private TransportShardCloseAction action;
private TransportVerifyShardBeforeCloseAction action;
private ClusterService clusterService;

@Override
Expand All @@ -68,16 +68,18 @@ public void setUp() throws Exception {
when(clusterService.state()).thenReturn(new ClusterState.Builder(new ClusterName("test"))
.blocks(ClusterBlocks.builder().addIndexBlock("index", INDEX_CLOSED_BLOCK).build()).build());

action = new TransportShardCloseAction(Settings.EMPTY, mock(TransportService.class), clusterService,
action = new TransportVerifyShardBeforeCloseAction(Settings.EMPTY, mock(TransportService.class), clusterService,
mock(IndicesService.class), mock(ThreadPool.class), mock(ShardStateAction.class), mock(ActionFilters.class),
mock(IndexNameExpressionResolver.class));
}

private void executeOnPrimaryOrReplica() throws Exception {
final TransportVerifyShardBeforeCloseAction.ShardCloseRequest request =
new TransportVerifyShardBeforeCloseAction.ShardCloseRequest(indexShard.shardId());
if (randomBoolean()) {
assertNotNull(action.shardOperationOnPrimary(new ShardCloseRequest(indexShard.shardId()), indexShard));
assertNotNull(action.shardOperationOnPrimary(request, indexShard));
} else {
assertNotNull(action.shardOperationOnPrimary(new ShardCloseRequest(indexShard.shardId()), indexShard));
assertNotNull(action.shardOperationOnPrimary(request, indexShard));
}
}

Expand Down

0 comments on commit feac528

Please sign in to comment.