Class IndicesService

    • Field Detail

      • INDICES_SHARDS_CLOSED_TIMEOUT

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

        public static final Setting<TimeValue> INDICES_CACHE_CLEAN_INTERVAL_SETTING
    • Method Detail

      • stats

        public NodeIndicesStats stats​(boolean includePrevious)
        Returns the node stats indices stats. The includePrevious flag controls if old shards stats will be aggregated as well (only for relevant stats, such as refresh and indexing, not for docs/store).
      • 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)
                                               throws java.io.IOException
        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.
        Throws:
        java.io.IOException
      • verifyIndexMetadata

        public void verifyIndexMetadata​(IndexMetaData metaData,
                                        IndexMetaData metaDataUpdate)
                                 throws java.io.IOException
        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.
        Throws:
        java.io.IOException
      • deleteShardStore

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

        public void deleteShardStore​(java.lang.String reason,
                                     ShardId shardId,
                                     ClusterState clusterState)
                              throws java.io.IOException,
                                     ShardLockObtainFailedException
        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.
        Parameters:
        reason - the reason for the shard deletion
        shardId - the shards ID to delete
        clusterState - . This is required to access the indexes settings etc.
        Throws:
        java.io.IOException - if an IOException occurs
        ShardLockObtainFailedException
      • 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.
        Parameters:
        index - Index to check whether deletion is allowed
        indexSettings - IndexSettings for the given index
        Returns:
        true if the index can be deleted on this node
      • verifyIndexIsDeleted

        @Nullable
        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>
        Parameters:
        index - Index to make sure its deleted from disk
        clusterState - ClusterState to ensure the index is not part of it
        Returns:
        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.
        Parameters:
        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)
                                   throws java.io.IOException,
                                          java.lang.InterruptedException,
                                          ShardLockObtainFailedException
        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>
        Parameters:
        index - the index to process the pending deletes for
        timeout - the timeout used for processing pending deletes
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        ShardLockObtainFailedException
      • 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.
        Throws:
        java.lang.Exception
      • 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 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​(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,
                                                                           DeprecationLogger deprecationLogger)
        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
        Parameters:
        newShards - The number of shards to be added by this operation
        state - The current cluster state
        deprecationLogger - The logger to use for deprecation warnings
        Returns:
        If present, an error message to be given as the reason for failing an operation. If empty, a sign that the operation is valid.