Class CoreContainer

java.lang.Object
org.apache.solr.core.CoreContainer

public class CoreContainer extends Object
Since:
solr 1.3
  • Field Details

  • Constructor Details

    • CoreContainer

      public CoreContainer(Path solrHome, Properties properties)
      Create a new CoreContainer using the given solr home directory. The container's cores are not loaded.
      Parameters:
      solrHome - a String containing the path to the solr home directory
      properties - substitutable properties (alternative to Sys props)
      See Also:
    • CoreContainer

      public CoreContainer(NodeConfig config)
      Create a new CoreContainer using the given configuration. The container's cores are not loaded.
      Parameters:
      config - a ConfigSolr representation of this container's configuration
      See Also:
    • CoreContainer

      public CoreContainer(NodeConfig config, boolean asyncSolrCoreLoad)
    • CoreContainer

      public CoreContainer(NodeConfig config, CoresLocator locator)
      Create a new CoreContainer using the given configuration and locator.

      The container's cores are not loaded. This constructor should be used only in tests, as it overrides CoresLocator's instantiation process.

      Parameters:
      config - a ConfigSolr representation of this container's configuration
      locator - a CoresLocator
      See Also:
    • CoreContainer

      public CoreContainer(NodeConfig config, CoresLocator locator, boolean asyncSolrCoreLoad)
    • CoreContainer

      protected CoreContainer(Object testConstructor)
      This method allows subclasses to construct a CoreContainer without any default init behavior.
      Parameters:
      testConstructor - pass (Object)null.
      WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Method Details

    • getIndexSearcherExecutor

      public Executor getIndexSearcherExecutor()
    • getIndexFingerprintExecutor

      public ExecutorService getIndexFingerprintExecutor()
    • getJerseyApplicationHandler

      public org.glassfish.jersey.server.ApplicationHandler getJerseyApplicationHandler()
    • getJerseyAppHandlerCache

      public JerseyAppHandlerCache getJerseyAppHandlerCache()
    • newBackupRepository

      public BackupRepository newBackupRepository(String repositoryName)
      This method instantiates a new instance of BackupRepository.
      Parameters:
      repositoryName - The name of the backup repository (Optional). If not specified, a default implementation is used.
      Returns:
      a new instance of BackupRepository.
    • getCoreZkRegisterExecutorService

      public ExecutorService getCoreZkRegisterExecutorService()
    • getRequestHandler

      public SolrRequestHandler getRequestHandler(String path)
    • getRequestHandlers

      public PluginBag<SolrRequestHandler> getRequestHandlers()
    • createAndLoad

      public static CoreContainer createAndLoad(Path solrHome)
    • createAndLoad

      public static CoreContainer createAndLoad(Path solrHome, Path configFile)
      Create a new CoreContainer and load its cores
      Parameters:
      solrHome - the solr home directory
      configFile - the file containing this container's configuration
      Returns:
      a loaded CoreContainer
    • getContainerProperties

      public Properties getContainerProperties()
    • getPkiAuthenticationSecurityBuilder

      public PKIAuthenticationPlugin getPkiAuthenticationSecurityBuilder()
    • getMetricManager

      public SolrMetricManager getMetricManager()
    • getMetricsHandler

      public MetricsHandler getMetricsHandler()
    • getTracer

      public io.opentelemetry.api.trace.Tracer getTracer()
      Never null
    • getReplayUpdatesExecutor

      public OrderedExecutor<org.apache.lucene.util.BytesRef> getReplayUpdatesExecutor()
    • getPackageLoader

      public SolrPackageLoader getPackageLoader()
    • getFileStore

      public FileStore getFileStore()
    • getCache

      public SolrCache<?,?> getCache(String name)
    • getSolrClientCache

      @Deprecated public SolrClientCache getSolrClientCache()
      Deprecated.
      likely to simply be moved to the ObjectCache so as to not be used
      The SolrClientCache is mostly for streaming expressions. Prefer other clients for other use-cases.
      See Also:
    • getObjectCache

      public org.apache.solr.common.util.ObjectCache getObjectCache()
    • load

      public void load()
      Load the cores defined for this CoreContainer
    • securityNodeChanged

      public void securityNodeChanged()
    • getGpuMetricsProvider

      public GpuMetricsProvider getGpuMetricsProvider()
    • isShutDown

      public boolean isShutDown()
    • shutdown

      public void shutdown()
      Close / shut down. Only called by CoreContainerProvider.
    • cancelCoreRecoveries

      public void cancelCoreRecoveries()
    • getCoresLocator

      public CoresLocator getCoresLocator()
    • getCoreSorter

      public CoreSorter getCoreSorter()
    • registerCore

      protected SolrCore registerCore(CoreDescriptor cd, SolrCore core, boolean registerInZk, boolean skipRecovery)
    • create

      public SolrCore create(String coreName, Map<String,String> parameters)
      Creates a new core, publishing the core state to the cluster
      Parameters:
      coreName - the core name
      parameters - the core parameters
      Returns:
      the newly created core
    • create

      public SolrCore create(String coreName, Path instancePath, Map<String,String> parameters, boolean newCollection)
      Creates a new core in a specified instance directory, publishing the core state to the cluster
      Parameters:
      coreName - the core name
      instancePath - the instance directory
      parameters - the core parameters
      Returns:
      the newly created core
    • assertPathAllowed

      public void assertPathAllowed(Path pathToAssert) throws org.apache.solr.common.SolrException
      Checks that the given path is relative to SOLR_HOME, SOLR_DATA_HOME, coreRootDirectory or one of the paths specified in solr.xml's allowPaths element. Delegates to SolrPaths.assertPathAllowed(Path, Set)
      Parameters:
      pathToAssert - path to check
      Throws:
      org.apache.solr.common.SolrException - if path is outside allowed paths
    • getAllowPaths

      public Set<Path> getAllowPaths()
      Return the file system paths that should be allowed for various API requests. This list is compiled at startup from SOLR_HOME, SOLR_DATA_HOME and the allowPaths configuration of solr.xml. These paths are used by the assertPathAllowed(Path) method call.

      NOTE: This method is currently only in use in tests in order to modify the mutable Set directly. Please treat this as a private method.

    • getAllowListUrlChecker

      public AllowListUrlChecker getAllowListUrlChecker()
      Gets the URLs checker based on the allowUrls configuration of solr.xml.
    • isSharedFs

      public boolean isSharedFs(CoreDescriptor cd)
    • getCores

      @Deprecated public List<SolrCore> getCores()
      Deprecated.
      Gets all loaded cores, consistent with getLoadedCoreNames(). Caller doesn't need to close.

      NOTE: rather dangerous API because each core is not reserved (could in theory be closed). Prefer getLoadedCoreNames() and then call getCore(String) then close it.

      Returns:
      An unsorted list. This list is a new copy, it can be modified by the caller (e.g. it can be sorted). Don't need to close them.
    • getLoadedCoreNames

      public List<String> getLoadedCoreNames()
      Gets the cores that are currently loaded, i.e. cores that have 1: loadOnStartup=true and have been loaded and 2: loadOnStartup=false and have been subsequently loaded.

      For efficiency, prefer to check isLoaded(String) instead of getLoadedCoreNames().contains(coreName).

      Returns:
      An unsorted list. This list is a new copy, it can be modified by the caller (e.g. it can be sorted).
    • getAllCoreNames

      public List<String> getAllCoreNames()
      Gets a collection of all the cores that are currently known, whether they are loaded or not.

      For efficiency, prefer to check getCoreDescriptor(String) != null instead of getAllCoreNames().contains(coreName).

      Returns:
      An unsorted list. This list is a new copy, it can be modified by the caller (e.g. it can be sorted).
    • getNumAllCores

      public int getNumAllCores()
      Gets the total number of cores, including both loaded and unloaded cores. Faster equivalent to getAllCoreNames().size().
    • getCoreInitFailures

      public Map<String,CoreContainer.CoreLoadFailure> getCoreInitFailures()
      Returns an immutable Map of Exceptions that occurred when initializing SolrCores (either at startup, or do to runtime requests to create cores) keyed off of the name (String) of the SolrCore that had the Exception during initialization.

      While the Map returned by this method is immutable and will not change once returned to the client, the source data used to generate this Map can be changed as various SolrCore operations are performed:

      • Failed attempts to create new SolrCores will add new Exceptions.
      • Failed attempts to re-create a SolrCore using a name already contained in this Map will replace the Exception.
      • Failed attempts to reload a SolrCore will cause an Exception to be added to this list -- even though the existing SolrCore with that name will continue to be available.
      • Successful attempts to re-created a SolrCore using a name already contained in this Map will remove the Exception.
      • Registering an existing SolrCore with a name already contained in this Map (ie: ALIAS or SWAP) will remove the Exception.
    • reload

      public void reload(String name)
      reloads a core refer reload(String, UUID) for details
    • reload

      public void reload(String name, UUID coreId)
      Recreates a SolrCore. While the new core is loading, requests will continue to be dispatched to and processed by the old core
      Parameters:
      name - the name of the SolrCore to reload
      coreId - The unique Id of the core SolrCore.uniqueId. If this is null, it's reloaded anyway. If the current core has a different id, this is a no-op
    • swap

      public void swap(String n0, String n1)
      Swaps two SolrCore descriptors.
    • unload

      public void unload(String name)
      Unload a core from this container, leaving all files on disk
      Parameters:
      name - the name of the core to unload
    • unload

      public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir)
      Unload a core from this container, optionally removing the core's data and configuration
      Parameters:
      name - the name of the core to unload
      deleteIndexDir - if true, delete the core's index on close
      deleteDataDir - if true, delete the core's data directory on close
      deleteInstanceDir - if true, delete the core's instance directory on close
    • rename

      public void rename(String name, String toName)
    • getCoreDescriptors

      public List<CoreDescriptor> getCoreDescriptors()
      Get the CoreDescriptors for all cores managed by this container
      Returns:
      a List of CoreDescriptors
    • getCoreDescriptor

      public CoreDescriptor getCoreDescriptor(String coreName)
    • getCoreRootDirectory

      public Path getCoreRootDirectory()
      Where cores are created (absolute).
    • getCore

      public SolrCore getCore(String name)
    • getCore

      public SolrCore getCore(String name, UUID id)
      Gets a core by name and increase its refcount.
      Parameters:
      name - the core name
      Returns:
      the core if found, null if a SolrCore by this name does not exist
      Throws:
      SolrCoreInitializationException - if a SolrCore with this name failed to be initialized
      See Also:
    • waitForLoadingCoresToFinish

      public void waitForLoadingCoresToFinish(long timeoutMs)
      If using asyncSolrCoreLoad=true, calling this after load() will not return until all cores have finished loading.
      Parameters:
      timeoutMs - timeout, upon which method simply returns
    • waitForLoadingCore

      public void waitForLoadingCore(String name, long timeoutMs)
    • createHandler

      protected <T> T createHandler(String path, String handlerClass, Class<T> clazz)
    • getMultiCoreHandler

      public CoreAdminHandler getMultiCoreHandler()
    • getCollectionsHandler

      public CollectionsHandler getCollectionsHandler()
    • getHealthCheckHandler

      public HealthCheckHandler getHealthCheckHandler()
    • getInfoHandler

      public InfoHandler getInfoHandler()
    • getConfigSetsHandler

      public ConfigSetsHandler getConfigSetsHandler()
    • getConfigSetService

      public ConfigSetService getConfigSetService()
    • setCoreConfigService

      public void setCoreConfigService(ConfigSetService configSetService)
    • getHostName

      public String getHostName()
    • getLogging

      public LogWatcher<?> getLogging()
    • isLoaded

      public boolean isLoaded(String name)
      Determines whether the core is already loaded or not but does NOT load the core
    • getSolrHome

      public Path getSolrHome()
      The primary path of a Solr server's config, cores, and misc things. Absolute.
    • getUserFilesPath

      public Path getUserFilesPath()
      A path where Solr users can retrieve arbitrary files from. Absolute.

      Files located in this directory can be manipulated using select Solr features (e.g. streaming expressions).

    • isZooKeeperAware

      public boolean isZooKeeperAware()
    • getZkController

      public ZkController getZkController()
    • getConfig

      public NodeConfig getConfig()
    • getShardHandlerFactory

      public ShardHandlerFactory getShardHandlerFactory()
      The default ShardHandlerFactory used to communicate with other solr instances
    • getUpdateShardHandler

      public UpdateShardHandler getUpdateShardHandler()
    • getResourceLoader

      public SolrResourceLoader getResourceLoader()
    • isCoreLoading

      public boolean isCoreLoading(String name)
    • getAuthorizationPlugin

      public AuthorizationPlugin getAuthorizationPlugin()
    • getAuthenticationPlugin

      public AuthenticationPlugin getAuthenticationPlugin()
    • getAuditLoggerPlugin

      public AuditLoggerPlugin getAuditLoggerPlugin()
    • getNodeConfig

      public NodeConfig getNodeConfig()
    • getStatus

      public long getStatus()
    • isStatusLoadComplete

      public boolean isStatusLoadComplete()
    • hideStackTrace

      public boolean hideStackTrace()
    • getAliases

      public org.apache.solr.common.cloud.Aliases getAliases()
      Retrieve the aliases from zookeeper. This is typically cached and does not hit zookeeper after the first use.
      Returns:
      an immutable instance of Aliases accurate as of at the time this method is invoked, less any zookeeper update lag.
      Throws:
      RuntimeException - if invoked on a CoreContainer where isZooKeeperAware() returns false
    • checkTragicException

      public boolean checkTragicException(SolrCore solrCore)
      Checks whether a tragic exception was thrown during update (including update log).
      Parameters:
      solrCore - the core against which we check if there has been a tragic exception
      Returns:
      whether this Solr core has tragic exception
      See Also:
      • IndexWriter.getTragicException()
    • getContainerPluginsRegistry

      public ContainerPluginsRegistry getContainerPluginsRegistry()
    • getClusterSingletons

      public ClusterSingletons getClusterSingletons()
    • getClusterEventProducer

      public ClusterEventProducer getClusterEventProducer()
    • getPlacementPluginFactory

      public PlacementPluginFactory<? extends PlacementPluginConfig> getPlacementPluginFactory()
    • getDefaultHttpSolrClient

      public HttpJettySolrClient getDefaultHttpSolrClient()
      A general-purpose HTTP/2 Solr client.

      The caller does not need to close the client.

      Returns:
      the existing HttpJettySolrClient
      See Also:
      • HttpSolrClientBase.requestWithBaseUrl(String, SolrRequest, String)
    • runAsync

      public void runAsync(Runnable r)
      Run an arbitrary task in its own thread. This is an expert option and is a method you should use with great care. It would be bad to run something that never stopped or run something that took a very long time. Typically this is intended for actions that take a few seconds, and therefore would be bad to wait for within a request, or actions that need to happen when a core has zero references, but would not pose a significant hindrance to server shut down times. It is not intended for long-running tasks and if you are using a Runnable with a loop in it, you are almost certainly doing it wrong.


      WARNING: Solr wil not be able to shut down gracefully until this task completes!


      A significant upside of using this method vs creating your own ExecutorService is that your code does not have to properly shutdown executors which typically is risky from a unit testing perspective since the test framework will complain if you don't carefully ensure the executor shuts down before the end of the test. Also the threads running this task are sure to have a proper MDC for logging.


      Normally, one uses SolrCore.runAsync(Runnable) if possible, but in some cases you might need to execute a task asynchronously when you could be running on a node with no cores, and then use of this method is indicated.

      Parameters:
      r - the task to run
    • setWeakStringInterner

      public static void setWeakStringInterner()