* Cleanup Dead Code in Index Creation * This is all unused and the state of a create request is always `OPEN`
This commit is contained in:
parent
53f409e5ae
commit
383d7b7713
|
@ -27,7 +27,6 @@ import org.elasticsearch.cluster.block.ClusterBlock;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.transport.TransportMessage;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -39,7 +38,6 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequest<CreateIndexClusterStateUpdateRequest> {
|
public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequest<CreateIndexClusterStateUpdateRequest> {
|
||||||
|
|
||||||
private final TransportMessage originalMessage;
|
|
||||||
private final String cause;
|
private final String cause;
|
||||||
private final String index;
|
private final String index;
|
||||||
private final String providedName;
|
private final String providedName;
|
||||||
|
@ -47,8 +45,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
||||||
private ResizeType resizeType;
|
private ResizeType resizeType;
|
||||||
private boolean copySettings;
|
private boolean copySettings;
|
||||||
|
|
||||||
private IndexMetaData.State state = IndexMetaData.State.OPEN;
|
|
||||||
|
|
||||||
private Settings settings = Settings.Builder.EMPTY_SETTINGS;
|
private Settings settings = Settings.Builder.EMPTY_SETTINGS;
|
||||||
|
|
||||||
private final Map<String, String> mappings = new HashMap<>();
|
private final Map<String, String> mappings = new HashMap<>();
|
||||||
|
@ -59,8 +55,7 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
||||||
|
|
||||||
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
|
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
|
||||||
|
|
||||||
public CreateIndexClusterStateUpdateRequest(TransportMessage originalMessage, String cause, String index, String providedName) {
|
public CreateIndexClusterStateUpdateRequest(String cause, String index, String providedName) {
|
||||||
this.originalMessage = originalMessage;
|
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.providedName = providedName;
|
this.providedName = providedName;
|
||||||
|
@ -81,16 +76,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateIndexClusterStateUpdateRequest blocks(Set<ClusterBlock> blocks) {
|
|
||||||
this.blocks.addAll(blocks);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreateIndexClusterStateUpdateRequest state(IndexMetaData.State state) {
|
|
||||||
this.state = state;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreateIndexClusterStateUpdateRequest recoverFrom(Index recoverFrom) {
|
public CreateIndexClusterStateUpdateRequest recoverFrom(Index recoverFrom) {
|
||||||
this.recoverFrom = recoverFrom;
|
this.recoverFrom = recoverFrom;
|
||||||
return this;
|
return this;
|
||||||
|
@ -111,10 +96,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportMessage originalMessage() {
|
|
||||||
return originalMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String cause() {
|
public String cause() {
|
||||||
return cause;
|
return cause;
|
||||||
}
|
}
|
||||||
|
@ -123,10 +104,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexMetaData.State state() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Settings settings() {
|
public Settings settings() {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class TransportCreateIndexAction extends TransportMasterNodeAction<Create
|
||||||
|
|
||||||
final String indexName = indexNameExpressionResolver.resolveDateMathExpression(request.index());
|
final String indexName = indexNameExpressionResolver.resolveDateMathExpression(request.index());
|
||||||
final CreateIndexClusterStateUpdateRequest updateRequest =
|
final CreateIndexClusterStateUpdateRequest updateRequest =
|
||||||
new CreateIndexClusterStateUpdateRequest(request, cause, indexName, request.index())
|
new CreateIndexClusterStateUpdateRequest(cause, indexName, request.index())
|
||||||
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
||||||
.settings(request.settings()).mappings(request.mappings())
|
.settings(request.settings()).mappings(request.mappings())
|
||||||
.aliases(request.aliases())
|
.aliases(request.aliases())
|
||||||
|
|
|
@ -289,7 +289,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
||||||
final CreateIndexRequest createIndexRequest = rolloverRequest.getCreateIndexRequest();
|
final CreateIndexRequest createIndexRequest = rolloverRequest.getCreateIndexRequest();
|
||||||
createIndexRequest.cause("rollover_index");
|
createIndexRequest.cause("rollover_index");
|
||||||
createIndexRequest.index(targetIndexName);
|
createIndexRequest.index(targetIndexName);
|
||||||
return new CreateIndexClusterStateUpdateRequest(createIndexRequest,
|
return new CreateIndexClusterStateUpdateRequest(
|
||||||
"rollover_index", targetIndexName, providedIndexName)
|
"rollover_index", targetIndexName, providedIndexName)
|
||||||
.ackTimeout(createIndexRequest.timeout())
|
.ackTimeout(createIndexRequest.timeout())
|
||||||
.masterNodeTimeout(createIndexRequest.masterNodeTimeout())
|
.masterNodeTimeout(createIndexRequest.masterNodeTimeout())
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class TransportResizeAction extends TransportMasterNodeAction<ResizeReque
|
||||||
settingsBuilder.put("index.number_of_shards", numShards);
|
settingsBuilder.put("index.number_of_shards", numShards);
|
||||||
targetIndex.settings(settingsBuilder);
|
targetIndex.settings(settingsBuilder);
|
||||||
|
|
||||||
return new CreateIndexClusterStateUpdateRequest(targetIndex, cause, targetIndex.index(), targetIndexName)
|
return new CreateIndexClusterStateUpdateRequest(cause, targetIndex.index(), targetIndexName)
|
||||||
// mappings are updated on the node when creating in the shards, this prevents race-conditions since all mapping must be
|
// mappings are updated on the node when creating in the shards, this prevents race-conditions since all mapping must be
|
||||||
// applied once we took the snapshot and if somebody messes things up and switches the index read/write and adds docs we
|
// applied once we took the snapshot and if somebody messes things up and switches the index read/write and adds docs we
|
||||||
// miss the mappings for everything is corrupted and hard to debug
|
// miss the mappings for everything is corrupted and hard to debug
|
||||||
|
|
|
@ -39,7 +39,6 @@ import org.elasticsearch.cluster.ack.CreateIndexClusterStateUpdateResponse;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlock;
|
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData.State;
|
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||||
|
@ -294,8 +293,6 @@ public class MetaDataCreateIndexService {
|
||||||
List<IndexTemplateMetaData> templates =
|
List<IndexTemplateMetaData> templates =
|
||||||
MetaDataIndexTemplateService.findTemplates(currentState.metaData(), request.index());
|
MetaDataIndexTemplateService.findTemplates(currentState.metaData(), request.index());
|
||||||
|
|
||||||
Map<String, Map<String, String>> customs = new HashMap<>();
|
|
||||||
|
|
||||||
// add the request mapping
|
// add the request mapping
|
||||||
Map<String, Map<String, Object>> mappings = new HashMap<>();
|
Map<String, Map<String, Object>> mappings = new HashMap<>();
|
||||||
|
|
||||||
|
@ -542,11 +539,7 @@ public class MetaDataCreateIndexService {
|
||||||
indexMetaDataBuilder.putAlias(aliasMetaData);
|
indexMetaDataBuilder.putAlias(aliasMetaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, String>> customEntry : customs.entrySet()) {
|
indexMetaDataBuilder.state(IndexMetaData.State.OPEN);
|
||||||
indexMetaDataBuilder.putCustom(customEntry.getKey(), customEntry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
indexMetaDataBuilder.state(request.state());
|
|
||||||
|
|
||||||
final IndexMetaData indexMetaData;
|
final IndexMetaData indexMetaData;
|
||||||
try {
|
try {
|
||||||
|
@ -577,13 +570,11 @@ public class MetaDataCreateIndexService {
|
||||||
|
|
||||||
ClusterState updatedState = ClusterState.builder(currentState).blocks(blocks).metaData(newMetaData).build();
|
ClusterState updatedState = ClusterState.builder(currentState).blocks(blocks).metaData(newMetaData).build();
|
||||||
|
|
||||||
if (request.state() == State.OPEN) {
|
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
|
||||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
|
.addAsNew(updatedState.metaData().index(request.index()));
|
||||||
.addAsNew(updatedState.metaData().index(request.index()));
|
updatedState = allocationService.reroute(
|
||||||
updatedState = allocationService.reroute(
|
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
|
||||||
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
|
"index [" + request.index() + "] created");
|
||||||
"index [" + request.index() + "] created");
|
|
||||||
}
|
|
||||||
removalExtraInfo = "cleaning up after validating index on master";
|
removalExtraInfo = "cleaning up after validating index on master";
|
||||||
removalReason = IndexRemovalReason.NO_LONGER_ASSIGNED;
|
removalReason = IndexRemovalReason.NO_LONGER_ASSIGNED;
|
||||||
return updatedState;
|
return updatedState;
|
||||||
|
@ -626,11 +617,11 @@ public class MetaDataCreateIndexService {
|
||||||
|
|
||||||
private void validate(CreateIndexClusterStateUpdateRequest request, ClusterState state) {
|
private void validate(CreateIndexClusterStateUpdateRequest request, ClusterState state) {
|
||||||
validateIndexName(request.index(), state);
|
validateIndexName(request.index(), state);
|
||||||
validateIndexSettings(request.index(), request.settings(), state, forbidPrivateIndexSettings);
|
validateIndexSettings(request.index(), request.settings(), forbidPrivateIndexSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateIndexSettings(String indexName, final Settings settings, final ClusterState clusterState,
|
public void validateIndexSettings(String indexName, final Settings settings, final boolean forbidPrivateIndexSettings)
|
||||||
final boolean forbidPrivateIndexSettings) throws IndexCreationException {
|
throws IndexCreationException {
|
||||||
List<String> validationErrors = getIndexSettingsValidationErrors(settings, forbidPrivateIndexSettings);
|
List<String> validationErrors = getIndexSettingsValidationErrors(settings, forbidPrivateIndexSettings);
|
||||||
|
|
||||||
if (validationErrors.isEmpty() == false) {
|
if (validationErrors.isEmpty() == false) {
|
||||||
|
@ -736,9 +727,9 @@ public class MetaDataCreateIndexService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static IndexMetaData validateResize(ClusterState state, String sourceIndex,
|
private static IndexMetaData validateResize(ClusterState state, String sourceIndex,
|
||||||
Set<String> targetIndexMappingsTypes, String targetIndexName,
|
Set<String> targetIndexMappingsTypes, String targetIndexName,
|
||||||
Settings targetIndexSettings) {
|
Settings targetIndexSettings) {
|
||||||
if (state.metaData().hasIndex(targetIndexName)) {
|
if (state.metaData().hasIndex(targetIndexName)) {
|
||||||
throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
|
throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,10 +273,7 @@ public class RestoreService implements ClusterStateApplier {
|
||||||
// Index doesn't exist - create it and start recovery
|
// Index doesn't exist - create it and start recovery
|
||||||
// Make sure that the index we are about to create has a validate name
|
// Make sure that the index we are about to create has a validate name
|
||||||
MetaDataCreateIndexService.validateIndexName(renamedIndexName, currentState);
|
MetaDataCreateIndexService.validateIndexName(renamedIndexName, currentState);
|
||||||
createIndexService.validateIndexSettings(renamedIndexName,
|
createIndexService.validateIndexSettings(renamedIndexName, snapshotIndexMetaData.getSettings(), false);
|
||||||
snapshotIndexMetaData.getSettings(),
|
|
||||||
currentState,
|
|
||||||
false);
|
|
||||||
IndexMetaData.Builder indexMdBuilder = IndexMetaData.builder(snapshotIndexMetaData)
|
IndexMetaData.Builder indexMdBuilder = IndexMetaData.builder(snapshotIndexMetaData)
|
||||||
.state(IndexMetaData.State.OPEN)
|
.state(IndexMetaData.State.OPEN)
|
||||||
.index(renamedIndexName);
|
.index(renamedIndexName);
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.elasticsearch.indices.InvalidAliasNameException;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -71,7 +72,9 @@ import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyObject;
|
import static org.mockito.Matchers.anyObject;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Mockito.anyMap;
|
import static org.mockito.Mockito.anyMap;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.eq;
|
import static org.mockito.Mockito.eq;
|
||||||
|
@ -236,10 +239,7 @@ public class IndexCreationTaskTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRequestStateOpen() throws Exception {
|
public void testRequestStateOpen() throws Exception {
|
||||||
when(request.state()).thenReturn(IndexMetaData.State.OPEN);
|
|
||||||
|
|
||||||
executeTask();
|
executeTask();
|
||||||
|
|
||||||
verify(allocationService, times(1)).reroute(anyObject(), anyObject());
|
verify(allocationService, times(1)).reroute(anyObject(), anyObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,5 +491,7 @@ public class IndexCreationTaskTests extends ESTestCase {
|
||||||
when(service.getIndexEventListener()).thenReturn(mock(IndexEventListener.class));
|
when(service.getIndexEventListener()).thenReturn(mock(IndexEventListener.class));
|
||||||
|
|
||||||
when(indicesService.createIndex(anyObject(), anyObject())).thenReturn(service);
|
when(indicesService.createIndex(anyObject(), anyObject())).thenReturn(service);
|
||||||
|
when(allocationService.reroute(any(ClusterState.class), anyString())).thenAnswer(
|
||||||
|
(Answer<ClusterState>) invocationOnMock -> (ClusterState) invocationOnMock.getArguments()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue