Class IndicesService

    • Field Detail


        public static final java.lang.String INDICES_SHARDS_CLOSED_TIMEOUT
        See Also:
        Constant Field Values

        public static final Setting<TimeValue> INDICES_CACHE_CLEAN_INTERVAL_SETTING
    • Method Detail

      • awaitClose

        public boolean awaitClose​(long timeout,
                                  java.util.concurrent.TimeUnit timeUnit)
                           throws java.lang.InterruptedException
        Wait for this IndicesService to be effectively closed. When this returns true, all shards and shard stores are closed and all shard closed listeners have run. However some shard closed listeners might not have run.
        true if all shards closed within the given timeout, false otherwise
        java.lang.InterruptedException - if the current thread got interrupted while waiting for shards to close
      • iterator

        public java.util.Iterator<IndexService> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<IndexService>
      • hasIndex

        public boolean hasIndex​(Index index)
      • createIndexMapperService

        public MapperService createIndexMapperService​(IndexMetaData indexMetaData)
        creates a new mapper service for the given index, in order to do administrative work like mapping updates. This *should not* be used for document parsing. Doing so will result in an exception. Note: the returned MapperService should be closed when unneeded.
      • verifyIndexMetadata

        public void verifyIndexMetadata​(IndexMetaData metaData,
                                        IndexMetaData metaDataUpdate)
        This method verifies that the given metaData holds sane values to create an IndexService. This method tries to update the meta data of the created IndexService if the given metaDataUpdate is different from the given metaData. This method will throw an exception if the creation or the update fails. The created IndexService will not be registered and will be closed immediately.
      • deleteShardStore

        public void deleteShardStore​(java.lang.String reason,
                                     ShardLock lock,
                                     IndexSettings indexSettings)
        Deletes the shard with an already acquired shard lock.
        Specified by:
        deleteShardStore in interface IndexService.ShardStoreDeleter
        reason - the reason for the shard deletion
        lock - the lock of the shard to delete
        indexSettings - the shards index settings.
        Throws: - if an IOException occurs
      • deleteShardStore

        public void deleteShardStore​(java.lang.String reason,
                                     ShardId shardId,
                                     ClusterState clusterState)
        This method deletes the shard contents on disk for the given shard ID. This method will fail if the shard deleting is prevented by canDeleteShardContent(ShardId, IndexSettings) of if the shards lock can not be acquired. On data nodes, if the deleted shard is the last shard folder in its index, the method will attempt to remove the index folder as well.
        reason - the reason for the shard deletion
        shardId - the shards ID to delete
        clusterState - . This is required to access the indexes settings etc.
        Throws: - if an IOException occurs
      • canDeleteIndexContents

        public boolean canDeleteIndexContents​(Index index,
                                              IndexSettings indexSettings)
        This method returns true if the current node is allowed to delete the given index. This is the case if the index is deleted in the metadata or there is no allocation on the local node and the index isn't on a shared file system.
        index - Index to check whether deletion is allowed
        indexSettings - IndexSettings for the given index
        true if the index can be deleted on this node
      • verifyIndexIsDeleted

        public IndexMetaData verifyIndexIsDeleted​(Index index,
                                                  ClusterState clusterState)
        Verify that the contents on disk for the given index is deleted; if not, delete the contents. This method assumes that an index is already deleted in the cluster state and/or explicitly through index tombstones.
        Specified by:
        verifyIndexIsDeleted in interface IndicesClusterStateService.AllocatedIndices<IndexShard,​IndexService>
        index - Index to make sure its deleted from disk
        clusterState - ClusterState to ensure the index is not part of it
        IndexMetaData for the index loaded from disk
      • canDeleteShardContent

        public IndicesService.ShardDeletionCheckResult canDeleteShardContent​(ShardId shardId,
                                                                             IndexSettings indexSettings)
        Returns ShardDeletionCheckResult signaling whether the shards content for the given shard can be deleted.
        shardId - the shard to delete.
        indexSettings - the shards's relevant IndexSettings. This is required to access the indexes settings etc.
      • addPendingDelete

        public void addPendingDelete​(Index index,
                                     IndexSettings settings)
        Adds a pending delete for the given index.
      • processPendingDeletes

        public void processPendingDeletes​(Index index,
                                          IndexSettings indexSettings,
                                          TimeValue timeout)
        Processes all pending deletes for the given index. This method will acquire all locks for the given index and will process all pending deletes for this index. Pending deletes might occur if the OS doesn't allow deletion of files because they are used by a different process ie. on Windows where files might still be open by a virus scanner. On a shared filesystem a replica might not have been closed when the primary is deleted causing problems on delete calls so we schedule there deletes later.
        Specified by:
        processPendingDeletes in interface IndicesClusterStateService.AllocatedIndices<IndexShard,​IndexService>
        index - the index to process the pending deletes for
        timeout - the timeout used for processing pending deletes
      • hasUncompletedPendingDeletes

        public boolean hasUncompletedPendingDeletes()
        Checks if all pending deletes have completed. Used by tests to ensure we don't check directory contents while deletion still ongoing. * The reason is that, on Windows, browsing the directory contents can interfere with the deletion process and delay it unnecessarily.
      • loadIntoContext

        public void loadIntoContext​(ShardSearchRequest request,
                                    SearchContext context,
                                    QueryPhase queryPhase)
                             throws java.lang.Exception
        Loads the cache result, computing it if needed by executing the query phase and otherwise deserializing the cached value into the context's query result. The combination of load + compute allows to have a single load operation that will cause other requests with the same key to wait till its loaded an reuse the same cache.
      • getTotalIndexingBufferBytes

        public ByteSizeValue getTotalIndexingBufferBytes()
      • buildAliasFilter

        public AliasFilter buildAliasFilter​(ClusterState state,
                                            java.lang.String index,
                                            java.util.Set<java.lang.String> resolvedExpressions)
      • clearIndexShardCache

        public void clearIndexShardCache​(ShardId shardId,
                                         boolean queryCache,
                                         boolean fieldDataCache,
                                         boolean requestCache,
                                         java.lang.String... fields)
        Clears the caches for the given shard id if the shard is still allocated on this node
      • getFieldFilter

        public java.util.function.Function<java.lang.String,​java.util.function.Predicate<java.lang.String>> getFieldFilter()
        Returns a function which given an index name, returns a predicate which fields must match in order to be returned by get mappings, get index, get field mappings and field capabilities API. Useful to filter the fields that such API return. The predicate receives the field name as input argument. In case multiple plugins register a field filter through MapperPlugin.getFieldFilter(), only fields that match all the registered filters will be returned by get mappings, get index, get field mappings and field capabilities API.
      • isMetaDataField

        public boolean isMetaDataField​(Version indexCreatedVersion,
                                       java.lang.String field)
        Returns true if the provided field is a registered metadata field (including ones registered via plugins), false otherwise.
      • checkShardLimit

        public static java.util.Optional<java.lang.String> checkShardLimit​(int newShards,
                                                                           ClusterState state)
        Checks to see if an operation can be performed without taking the cluster over the cluster-wide shard limit. Adds a deprecation warning or returns an error message as appropriate
        newShards - The number of shards to be added by this operation
        state - The current cluster state
        If present, an error message to be given as the reason for failing an operation. If empty, a sign that the operation is valid.