Class MetadataCreateIndexService
java.lang.Object
org.elasticsearch.cluster.metadata.MetadataCreateIndexService
public class MetadataCreateIndexService
extends java.lang.Object
Service responsible for submitting create index requests
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_INDEX_NAME_BYTES
-
Constructor Summary
Constructors Constructor Description MetadataCreateIndexService(Settings settings, ClusterService clusterService, IndicesService indicesService, AllocationService allocationService, AliasValidator aliasValidator, ShardLimitValidator shardLimitValidator, Environment env, IndexScopedSettings indexScopedSettings, ThreadPool threadPool, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, java.util.Collection<SystemIndexDescriptor> systemIndexDescriptors, boolean forbidPrivateIndexSettings)
-
Method Summary
Modifier and Type Method Description ClusterState
applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent)
ClusterState
applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent, java.util.function.BiConsumer<Metadata.Builder,IndexMetadata> metadataTransformer)
Handles the cluster state transition to a version that reflects theCreateIndexClusterStateUpdateRequest
.static int
calculateNumRoutingShards(int numShards, Version indexVersionCreated)
Returns a default number of routing shards based on the number of shards of the index.static java.util.List<java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>>
collectV2Mappings(java.util.Map<java.lang.String,java.lang.String> requestMappings, ClusterState currentState, java.lang.String templateName, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, java.lang.String indexName)
void
createIndex(CreateIndexClusterStateUpdateRequest request, ActionListener<CreateIndexClusterStateUpdateResponse> listener)
Creates an index in the cluster state and waits for the specified number of shard copies to become active (as specified inCreateIndexClusterStateUpdateRequest.waitForActiveShards()
) before sending the response on the listener.static java.util.List<AliasMetadata>
resolveAndValidateAliases(java.lang.String index, java.util.Set<Alias> aliases, java.util.List<java.util.Map<java.lang.String,AliasMetadata>> templateAliases, Metadata metadata, AliasValidator aliasValidator, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, QueryShardContext queryShardContext)
Validate and resolve the aliases explicitly set for the index, together with the ones inherited from the specified templates.void
validateDotIndex(java.lang.String index, ClusterState state, java.lang.Boolean isHidden)
Validates (if this index has a dot-prefixed name) whether it follows the rules for dot-prefixed indices.void
validateIndexName(java.lang.String index, ClusterState state)
Validate the name for an index against some static rules and a cluster state.static void
validateIndexOrAliasName(java.lang.String index, java.util.function.BiFunction<java.lang.String,java.lang.String,? extends java.lang.RuntimeException> exceptionCtor)
Validate the name for an index or alias against some static rules.void
validateIndexSettings(java.lang.String indexName, Settings settings, boolean forbidPrivateIndexSettings)
static void
validateTranslogRetentionSettings(Settings indexSettings)
-
Field Details
-
MAX_INDEX_NAME_BYTES
public static final int MAX_INDEX_NAME_BYTES- See Also:
- Constant Field Values
-
-
Constructor Details
-
MetadataCreateIndexService
public MetadataCreateIndexService(Settings settings, ClusterService clusterService, IndicesService indicesService, AllocationService allocationService, AliasValidator aliasValidator, ShardLimitValidator shardLimitValidator, Environment env, IndexScopedSettings indexScopedSettings, ThreadPool threadPool, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, java.util.Collection<SystemIndexDescriptor> systemIndexDescriptors, boolean forbidPrivateIndexSettings)
-
-
Method Details
-
validateIndexName
Validate the name for an index against some static rules and a cluster state. -
validateDotIndex
public void validateDotIndex(java.lang.String index, ClusterState state, @Nullable java.lang.Boolean isHidden)Validates (if this index has a dot-prefixed name) whether it follows the rules for dot-prefixed indices.- Parameters:
index
- The name of the index in questionstate
- The current cluster stateisHidden
- Whether or not this is a hidden index
-
validateIndexOrAliasName
public static void validateIndexOrAliasName(java.lang.String index, java.util.function.BiFunction<java.lang.String,java.lang.String,? extends java.lang.RuntimeException> exceptionCtor)Validate the name for an index or alias against some static rules. -
createIndex
public void createIndex(CreateIndexClusterStateUpdateRequest request, ActionListener<CreateIndexClusterStateUpdateResponse> listener)Creates an index in the cluster state and waits for the specified number of shard copies to become active (as specified inCreateIndexClusterStateUpdateRequest.waitForActiveShards()
) before sending the response on the listener. If the index creation was successfully applied on the cluster state, thenClusterStateUpdateResponse.isAcknowledged()
will return true, otherwise it will return false and no waiting will occur for started shards (CreateIndexClusterStateUpdateResponse.isShardsAcknowledged()
will also be false). If the index creation in the cluster state was successful and the requisite shard copies were started before the timeout, thenCreateIndexClusterStateUpdateResponse.isShardsAcknowledged()
will return true, otherwise if the operation timed out, then it will return false.- Parameters:
request
- the index creation cluster state update requestlistener
- the listener on which to send the index creation cluster state update response
-
applyCreateIndexRequest
public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent, java.util.function.BiConsumer<Metadata.Builder,IndexMetadata> metadataTransformer) throws java.lang.ExceptionHandles the cluster state transition to a version that reflects theCreateIndexClusterStateUpdateRequest
. All the requested changes are firstly validated before mutating theClusterState
.- Throws:
java.lang.Exception
-
applyCreateIndexRequest
public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent) throws java.lang.Exception- Throws:
java.lang.Exception
-
collectV2Mappings
public static java.util.List<java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>> collectV2Mappings(java.util.Map<java.lang.String,java.lang.String> requestMappings, ClusterState currentState, java.lang.String templateName, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, java.lang.String indexName) throws java.lang.Exception- Throws:
java.lang.Exception
-
resolveAndValidateAliases
public static java.util.List<AliasMetadata> resolveAndValidateAliases(java.lang.String index, java.util.Set<Alias> aliases, java.util.List<java.util.Map<java.lang.String,AliasMetadata>> templateAliases, Metadata metadata, AliasValidator aliasValidator, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, QueryShardContext queryShardContext)Validate and resolve the aliases explicitly set for the index, together with the ones inherited from the specified templates. The template mappings are applied in the order they are encountered in the list (clients should make sure the lower index, closer to the head of the list, templates have the highestIndexTemplateMetadata.order()
)- Returns:
- the list of resolved aliases, with the explicitly provided aliases occurring first (having a higher priority) followed by the ones inherited from the templates
-
validateIndexSettings
public void validateIndexSettings(java.lang.String indexName, Settings settings, boolean forbidPrivateIndexSettings) throws IndexCreationException- Throws:
IndexCreationException
-
calculateNumRoutingShards
Returns a default number of routing shards based on the number of shards of the index. The default number of routing shards will allow any index to be split at least once and at most 10 times by a factor of two. The closer the number or shards gets to 1024 the less default split operations are supported -
validateTranslogRetentionSettings
-