* 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.common.settings.Settings;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.transport.TransportMessage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -39,7 +38,6 @@ import java.util.Set;
|
|||
*/
|
||||
public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequest<CreateIndexClusterStateUpdateRequest> {
|
||||
|
||||
private final TransportMessage originalMessage;
|
||||
private final String cause;
|
||||
private final String index;
|
||||
private final String providedName;
|
||||
|
@ -47,8 +45,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
|||
private ResizeType resizeType;
|
||||
private boolean copySettings;
|
||||
|
||||
private IndexMetaData.State state = IndexMetaData.State.OPEN;
|
||||
|
||||
private Settings settings = Settings.Builder.EMPTY_SETTINGS;
|
||||
|
||||
private final Map<String, String> mappings = new HashMap<>();
|
||||
|
@ -59,8 +55,7 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
|||
|
||||
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
|
||||
|
||||
public CreateIndexClusterStateUpdateRequest(TransportMessage originalMessage, String cause, String index, String providedName) {
|
||||
this.originalMessage = originalMessage;
|
||||
public CreateIndexClusterStateUpdateRequest(String cause, String index, String providedName) {
|
||||
this.cause = cause;
|
||||
this.index = index;
|
||||
this.providedName = providedName;
|
||||
|
@ -81,16 +76,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
|||
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) {
|
||||
this.recoverFrom = recoverFrom;
|
||||
return this;
|
||||
|
@ -111,10 +96,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
|||
return this;
|
||||
}
|
||||
|
||||
public TransportMessage originalMessage() {
|
||||
return originalMessage;
|
||||
}
|
||||
|
||||
public String cause() {
|
||||
return cause;
|
||||
}
|
||||
|
@ -123,10 +104,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ
|
|||
return index;
|
||||
}
|
||||
|
||||
public IndexMetaData.State state() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public Settings settings() {
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TransportCreateIndexAction extends TransportMasterNodeAction<Create
|
|||
|
||||
final String indexName = indexNameExpressionResolver.resolveDateMathExpression(request.index());
|
||||
final CreateIndexClusterStateUpdateRequest updateRequest =
|
||||
new CreateIndexClusterStateUpdateRequest(request, cause, indexName, request.index())
|
||||
new CreateIndexClusterStateUpdateRequest(cause, indexName, request.index())
|
||||
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
||||
.settings(request.settings()).mappings(request.mappings())
|
||||
.aliases(request.aliases())
|
||||
|
|
|
@ -289,7 +289,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
|||
final CreateIndexRequest createIndexRequest = rolloverRequest.getCreateIndexRequest();
|
||||
createIndexRequest.cause("rollover_index");
|
||||
createIndexRequest.index(targetIndexName);
|
||||
return new CreateIndexClusterStateUpdateRequest(createIndexRequest,
|
||||
return new CreateIndexClusterStateUpdateRequest(
|
||||
"rollover_index", targetIndexName, providedIndexName)
|
||||
.ackTimeout(createIndexRequest.timeout())
|
||||
.masterNodeTimeout(createIndexRequest.masterNodeTimeout())
|
||||
|
|
|
@ -173,7 +173,7 @@ public class TransportResizeAction extends TransportMasterNodeAction<ResizeReque
|
|||
settingsBuilder.put("index.number_of_shards", numShards);
|
||||
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
|
||||
// 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
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.elasticsearch.cluster.ack.CreateIndexClusterStateUpdateResponse;
|
|||
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData.State;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
|
@ -294,8 +293,6 @@ public class MetaDataCreateIndexService {
|
|||
List<IndexTemplateMetaData> templates =
|
||||
MetaDataIndexTemplateService.findTemplates(currentState.metaData(), request.index());
|
||||
|
||||
Map<String, Map<String, String>> customs = new HashMap<>();
|
||||
|
||||
// add the request mapping
|
||||
Map<String, Map<String, Object>> mappings = new HashMap<>();
|
||||
|
||||
|
@ -542,11 +539,7 @@ public class MetaDataCreateIndexService {
|
|||
indexMetaDataBuilder.putAlias(aliasMetaData);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Map<String, String>> customEntry : customs.entrySet()) {
|
||||
indexMetaDataBuilder.putCustom(customEntry.getKey(), customEntry.getValue());
|
||||
}
|
||||
|
||||
indexMetaDataBuilder.state(request.state());
|
||||
indexMetaDataBuilder.state(IndexMetaData.State.OPEN);
|
||||
|
||||
final IndexMetaData indexMetaData;
|
||||
try {
|
||||
|
@ -577,13 +570,11 @@ public class MetaDataCreateIndexService {
|
|||
|
||||
ClusterState updatedState = ClusterState.builder(currentState).blocks(blocks).metaData(newMetaData).build();
|
||||
|
||||
if (request.state() == State.OPEN) {
|
||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
|
||||
.addAsNew(updatedState.metaData().index(request.index()));
|
||||
updatedState = allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
|
||||
"index [" + request.index() + "] created");
|
||||
}
|
||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
|
||||
.addAsNew(updatedState.metaData().index(request.index()));
|
||||
updatedState = allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
|
||||
"index [" + request.index() + "] created");
|
||||
removalExtraInfo = "cleaning up after validating index on master";
|
||||
removalReason = IndexRemovalReason.NO_LONGER_ASSIGNED;
|
||||
return updatedState;
|
||||
|
@ -626,11 +617,11 @@ public class MetaDataCreateIndexService {
|
|||
|
||||
private void validate(CreateIndexClusterStateUpdateRequest request, ClusterState 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,
|
||||
final boolean forbidPrivateIndexSettings) throws IndexCreationException {
|
||||
public void validateIndexSettings(String indexName, final Settings settings, final boolean forbidPrivateIndexSettings)
|
||||
throws IndexCreationException {
|
||||
List<String> validationErrors = getIndexSettingsValidationErrors(settings, forbidPrivateIndexSettings);
|
||||
|
||||
if (validationErrors.isEmpty() == false) {
|
||||
|
@ -736,9 +727,9 @@ public class MetaDataCreateIndexService {
|
|||
|
||||
}
|
||||
|
||||
static IndexMetaData validateResize(ClusterState state, String sourceIndex,
|
||||
Set<String> targetIndexMappingsTypes, String targetIndexName,
|
||||
Settings targetIndexSettings) {
|
||||
private static IndexMetaData validateResize(ClusterState state, String sourceIndex,
|
||||
Set<String> targetIndexMappingsTypes, String targetIndexName,
|
||||
Settings targetIndexSettings) {
|
||||
if (state.metaData().hasIndex(targetIndexName)) {
|
||||
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
|
||||
// Make sure that the index we are about to create has a validate name
|
||||
MetaDataCreateIndexService.validateIndexName(renamedIndexName, currentState);
|
||||
createIndexService.validateIndexSettings(renamedIndexName,
|
||||
snapshotIndexMetaData.getSettings(),
|
||||
currentState,
|
||||
false);
|
||||
createIndexService.validateIndexSettings(renamedIndexName, snapshotIndexMetaData.getSettings(), false);
|
||||
IndexMetaData.Builder indexMdBuilder = IndexMetaData.builder(snapshotIndexMetaData)
|
||||
.state(IndexMetaData.State.OPEN)
|
||||
.index(renamedIndexName);
|
||||
|
|
|
@ -55,6 +55,7 @@ import org.elasticsearch.indices.InvalidAliasNameException;
|
|||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.IOException;
|
||||
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.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.anyMap;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.eq;
|
||||
|
@ -236,10 +239,7 @@ public class IndexCreationTaskTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testRequestStateOpen() throws Exception {
|
||||
when(request.state()).thenReturn(IndexMetaData.State.OPEN);
|
||||
|
||||
executeTask();
|
||||
|
||||
verify(allocationService, times(1)).reroute(anyObject(), anyObject());
|
||||
}
|
||||
|
||||
|
@ -491,5 +491,7 @@ public class IndexCreationTaskTests extends ESTestCase {
|
|||
when(service.getIndexEventListener()).thenReturn(mock(IndexEventListener.class));
|
||||
|
||||
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