Class RepositoriesService

java.lang.Object
org.elasticsearch.common.component.AbstractLifecycleComponent
org.elasticsearch.repositories.RepositoriesService
All Implemented Interfaces:
Closeable, AutoCloseable, ClusterStateApplier, LifecycleComponent, Releasable

public class RepositoriesService extends AbstractLifecycleComponent implements ClusterStateApplier
Service responsible for maintaining and providing access to multiple repositories. The elected master creates new repositories on request and persists the RepositoryMetadata in the cluster state. The cluster state update then goes out to the rest of the cluster nodes so that all nodes know how to access the new repository. This class contains factory information to create new repositories, and provides access to and maintains the lifecycle of repositories. New nodes can easily find all the repositories via the cluster state after joining a cluster. repository(ProjectId, String) can be used to fetch a repository. createRepository(ProjectId, RepositoryMetadata) does the heavy lifting of creation. applyClusterState(ClusterChangedEvent) handles adding and removing repositories per cluster state updates.
  • Field Details

    • REPOSITORIES_STATS_ARCHIVE_RETENTION_PERIOD

      public static final Setting<TimeValue> REPOSITORIES_STATS_ARCHIVE_RETENTION_PERIOD
    • REPOSITORIES_STATS_ARCHIVE_MAX_ARCHIVED_STATS

      public static final Setting<Integer> REPOSITORIES_STATS_ARCHIVE_MAX_ARCHIVED_STATS
    • COUNT_USAGE_STATS_NAME

      public static final String COUNT_USAGE_STATS_NAME
      See Also:
  • Constructor Details

  • Method Details

    • registerRepository

      public void registerRepository(ProjectId projectId, PutRepositoryRequest request, ActionListener<AcknowledgedResponse> responseListener)
      Registers new repository in the cluster

      This method can be only called on the master node. It tries to create a new repository on the master, and if it was successful, it adds a new repository to cluster metadata.

      Parameters:
      projectId - the project ID to which the repository belongs.
      request - register repository request
      responseListener - register repository listener
    • validateRepositoryCanBeCreated

      public void validateRepositoryCanBeCreated(ProjectId projectId, PutRepositoryRequest request)
      Ensures that we can create the repository and that it's creation actually works

      This verification method will create and then close the repository we want to create.

      Parameters:
      request -
    • updateRepositoryUuidInMetadata

      public static void updateRepositoryUuidInMetadata(ClusterService clusterService, ProjectId projectId, String repositoryName, RepositoryData repositoryData, ActionListener<Void> listener)
      Set the repository UUID in the named repository's RepositoryMetadata to match the UUID in its RepositoryData, which may involve a cluster state update.
      Parameters:
      listener - notified when the RepositoryMetadata is updated, possibly on this thread or possibly on the master service thread
    • unregisterRepository

      public void unregisterRepository(ProjectId projectId, DeleteRepositoryRequest request, ActionListener<AcknowledgedResponse> listener)
      Unregisters repository in the cluster

      This method can be only called on the master node. It removes repository information from cluster metadata.

      Parameters:
      projectId - project to look for the repository
      request - unregister repository request
      listener - unregister repository listener
    • verifyRepository

      public void verifyRepository(ProjectId projectId, String repositoryName, ActionListener<List<DiscoveryNode>> listener)
    • isDedicatedVotingOnlyNode

      public static boolean isDedicatedVotingOnlyNode(Set<DiscoveryNodeRole> roles)
    • applyClusterState

      public void applyClusterState(ClusterChangedEvent event)
      Checks if new repositories appeared in or disappeared from cluster metadata and updates current list of repositories accordingly.
      Specified by:
      applyClusterState in interface ClusterStateApplier
      Parameters:
      event - cluster changed event
    • getRepositoryData

      public void getRepositoryData(ProjectId projectId, String repositoryName, ActionListener<RepositoryData> listener)
      Gets the RepositoryData for the given repository.
      Parameters:
      projectId - project to look for the repository
      repositoryName - repository name
      listener - listener to pass RepositoryData to
    • repository

      @Deprecated(forRemoval=true) public Repository repository(String repositoryName)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns registered repository, either internal or external
      Parameters:
      repositoryName - repository name
      Returns:
      registered repository
      Throws:
      RepositoryMissingException - if repository with such name isn't registered
    • repository

      public Repository repository(ProjectId projectId, String repositoryName)
      Returns registered repository, either internal or external
      Parameters:
      projectId - the project to look for the repository
      repositoryName - repository name
      Returns:
      registered repository
      Throws:
      RepositoryMissingException - if repository with such name isn't registered
    • repositoryOrNull

      public Repository repositoryOrNull(ProjectId projectId, String repositoryName)
      Similar to repository(ProjectId, String), but returns null instead of throw if the repository is not found.
    • getRepositories

      public List<Repository> getRepositories()
      Returns:
      the current collection of registered repositories from all projects.
    • getProjectRepositories

      public Map<String,Repository> getProjectRepositories(ProjectId projectId)
      Returns:
      the current collection of registered repositories for the given project, keyed by name.
    • repositoriesStats

      public List<RepositoryStatsSnapshot> repositoriesStats()
    • getRepositoriesThrottlingStats

      public RepositoriesStats getRepositoriesThrottlingStats()
    • clearRepositoriesStatsArchive

      public List<RepositoryStatsSnapshot> clearRepositoriesStatsArchive(long maxVersionToClear)
    • registerInternalRepository

      public void registerInternalRepository(ProjectId projectId, String name, String type)
    • unregisterInternalRepository

      public void unregisterInternalRepository(ProjectId projectId, String name)
    • createRepository

      public Repository createRepository(ProjectId projectId, RepositoryMetadata repositoryMetadata)
      Creates a repository holder.

      WARNING: This method is intended for expert only usage mainly in plugins/modules. Please take note of the following:

      • This method does not register the repository (e.g., in the cluster state).
      • This method starts the repository. The repository should be closed after use.
      • The repository metadata should be associated to an already registered non-internal repository type and factory pair.
      Parameters:
      projectId - the project that the repository is associated with
      repositoryMetadata - the repository metadata
      Returns:
      the started repository
      Throws:
      RepositoryException - if repository type is not registered
    • createNonProjectRepository

      public Repository createNonProjectRepository(RepositoryMetadata repositoryMetadata)
      Similar to createRepository(ProjectId, RepositoryMetadata), but repository is not associated with a project, i.e. the repository is at the cluster level.
    • validateRepositoryName

      public static void validateRepositoryName(String repositoryName)
    • isReadOnly

      public static boolean isReadOnly(Settings repositorySettings)
    • getPreRestoreVersionChecks

      public List<BiConsumer<Snapshot,IndexVersion>> getPreRestoreVersionChecks()
    • getUsageStats

      public RepositoryUsageStats getUsageStats()
    • doStart

      protected void doStart()
      Description copied from class: AbstractLifecycleComponent
      Start this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.

      If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.

      Specified by:
      doStart in class AbstractLifecycleComponent
    • doStop

      protected void doStop()
      Description copied from class: AbstractLifecycleComponent
      Stop this component. Typically that means doing the reverse of whatever AbstractLifecycleComponent.doStart() does.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, after calling AbstractLifecycleComponent.doStart(), although it will not be called at all if this component did not successfully start.

      Specified by:
      doStop in class AbstractLifecycleComponent
    • doClose

      protected void doClose() throws IOException
      Description copied from class: AbstractLifecycleComponent
      Close this component. Typically that means doing the reverse of whatever happened during initialization, such as releasing resources acquired there.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is called once in the lifetime of a component. If the component was started then it will be stopped before it is closed, and once it is closed it will not be started or stopped.

      Specified by:
      doClose in class AbstractLifecycleComponent
      Throws:
      IOException