Module org.elasticsearch.server
Class MetadataCreateIndexService
java.lang.Object
org.elasticsearch.cluster.metadata.MetadataCreateIndexService
Service responsible for submitting create index requests
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetadataCreateIndexService
(Settings settings, ClusterService clusterService, IndicesService indicesService, AllocationService allocationService, ShardLimitValidator shardLimitValidator, Environment env, IndexScopedSettings indexScopedSettings, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, SystemIndices systemIndices, boolean forbidPrivateIndexSettings, IndexSettingProviders indexSettingProviders) -
Method Summary
Modifier and TypeMethodDescriptionapplyCreateIndexRequest
(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent, BiConsumer<Metadata.Builder, IndexMetadata> metadataTransformer, ActionListener<Void> rerouteListener) Handles the cluster state transition to a version that reflects theCreateIndexClusterStateUpdateRequest
.applyCreateIndexRequest
(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent, ActionListener<Void> rerouteListener) static int
calculateNumRoutingShards
(int numShards, IndexVersion indexVersionCreated) Returns a default number of routing shards based on the number of shards of the index.static List<CompressedXContent>
collectV2Mappings
(String requestMappings, ClusterState currentState, String templateName, NamedXContentRegistry xContentRegistry, String indexName) void
createIndex
(TimeValue masterNodeTimeout, TimeValue ackTimeout, TimeValue waitForActiveShardsTimeout, CreateIndexClusterStateUpdateRequest request, ActionListener<ShardsAcknowledgedResponse> 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.parseV1Mappings
(String mappingsJson, List<CompressedXContent> templateMappings, NamedXContentRegistry xContentRegistry) Parses the provided mappings json and the inheritable mappings from the templates (if any) into a map.static List<AliasMetadata>
resolveAndValidateAliases
(String index, Set<Alias> aliases, List<Map<String, AliasMetadata>> templateAliases, Metadata metadata, NamedXContentRegistry xContentRegistry, SearchExecutionContext searchExecutionContext, Function<String, String> indexNameExpressionResolver, Predicate<String> systemNamePredicate) Validate and resolve the aliases explicitly set for the index, together with the ones inherited from the specified templates.static void
validateAdditionalSettings
(IndexSettingProvider provider, Settings additionalSettings, Settings.Builder allAdditionalSettings) Validates whether additional settings don't have keys that are already defined in all additional settings.boolean
validateDotIndex
(String index, Boolean isHidden) Validates (if this index has a dot-prefixed name) whether it follows the rules for dot-prefixed indices.static void
validateIndexName
(String index, Metadata metadata, RoutingTable routingTable) Validate the name for an index against some static rules and a cluster state.static void
validateIndexOrAliasName
(String index, BiFunction<String, String, ? extends RuntimeException> exceptionCtor) Validate the name for an index or alias against some static rules.void
validateIndexSettings
(String indexName, Settings settings, boolean forbidPrivateIndexSettings) static void
validateStoreTypeSetting
(Settings indexSettings) static void
validateTranslogRetentionSettings
(Settings indexSettings)
-
Field Details
-
MAX_INDEX_NAME_BYTES
public static final int MAX_INDEX_NAME_BYTES- See Also:
-
-
Constructor Details
-
MetadataCreateIndexService
public MetadataCreateIndexService(Settings settings, ClusterService clusterService, IndicesService indicesService, AllocationService allocationService, ShardLimitValidator shardLimitValidator, Environment env, IndexScopedSettings indexScopedSettings, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, SystemIndices systemIndices, boolean forbidPrivateIndexSettings, IndexSettingProviders indexSettingProviders)
-
-
Method Details
-
validateIndexName
Validate the name for an index against some static rules and a cluster state. -
validateDotIndex
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 questionisHidden
- Whether or not this is a hidden index
-
getSystemIndices
-
validateIndexOrAliasName
public static void validateIndexOrAliasName(String index, BiFunction<String, String, ? extends RuntimeException> exceptionCtor) Validate the name for an index or alias against some static rules. -
createIndex
public void createIndex(TimeValue masterNodeTimeout, TimeValue ackTimeout, @Nullable TimeValue waitForActiveShardsTimeout, CreateIndexClusterStateUpdateRequest request, ActionListener<ShardsAcknowledgedResponse> 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, thenAcknowledgedResponse.isAcknowledged()
will return true, otherwise it will return false and no waiting will occur for started shards (ShardsAcknowledgedResponse.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, thenShardsAcknowledgedResponse.isShardsAcknowledged()
will return true, otherwise if the operation timed out, then it will return false.- Parameters:
masterNodeTimeout
- timeout on cluster state update in pending task queueackTimeout
- timeout on waiting for all nodes to ack the cluster state updatewaitForActiveShardsTimeout
- timeout for waiting for theActiveShardCount
specified inCreateIndexClusterStateUpdateRequest.waitForActiveShards()
to be satisfied. May also benull
, in which case it waits forever.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, BiConsumer<Metadata.Builder, IndexMetadata> metadataTransformer, ActionListener<Void> rerouteListener) throws ExceptionHandles the cluster state transition to a version that reflects theCreateIndexClusterStateUpdateRequest
. All the requested changes are firstly validated before mutating theClusterState
.- Throws:
Exception
-
applyCreateIndexRequest
public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, boolean silent, ActionListener<Void> rerouteListener) throws Exception - Throws:
Exception
-
collectV2Mappings
public static List<CompressedXContent> collectV2Mappings(@Nullable String requestMappings, ClusterState currentState, String templateName, NamedXContentRegistry xContentRegistry, String indexName) throws Exception - Throws:
Exception
-
parseV1Mappings
public static Map<String,Object> parseV1Mappings(String mappingsJson, List<CompressedXContent> templateMappings, NamedXContentRegistry xContentRegistry) throws IOException Parses the provided mappings json and the inheritable mappings from the templates (if any) into a map. 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()
). This merging makes no distinction between field definitions, as may result in an invalid field definition- Throws:
IOException
-
validateAdditionalSettings
public static void validateAdditionalSettings(IndexSettingProvider provider, Settings additionalSettings, Settings.Builder allAdditionalSettings) throws IllegalArgumentException Validates whether additional settings don't have keys that are already defined in all additional settings.- Parameters:
provider
- TheIndexSettingProvider
that producedadditionalSettings
additionalSettings
- The settings produced by the specifiedprovider
allAdditionalSettings
- A settings builder containing all additional settings produced by anyIndexSettingProvider
that already executed- Throws:
IllegalArgumentException
- If keys in additionalSettings are already defined in allAdditionalSettings
-
resolveAndValidateAliases
public static List<AliasMetadata> resolveAndValidateAliases(String index, Set<Alias> aliases, List<Map<String, AliasMetadata>> templateAliases, Metadata metadata, NamedXContentRegistry xContentRegistry, SearchExecutionContext searchExecutionContext, Function<String, String> indexNameExpressionResolver, Predicate<String> systemNamePredicate) 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(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
-
validateStoreTypeSetting
-