Class CoreContainer

  • public class CoreContainer
    extends Object
    solr 1.3
    • Constructor Detail

      • CoreContainer

        public CoreContainer​(Path solrHome,
                             Properties properties)
        Create a new CoreContainer using the given solr home directory. The container's cores are not loaded.
        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.
        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.
        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.
        testConstructor - pass (Object)null.
        WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Method Detail

      • getJerseyApplicationHandler

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

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

        public ExecutorService getCoreZkRegisterExecutorService()
      • createAndLoad

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

        public Properties getContainerProperties()
      • getTracer

        public io.opentracing.Tracer getTracer()
        Never null but may implement NoopTracer.
      • getReplayUpdatesExecutor

        public OrderedExecutor getReplayUpdatesExecutor()
      • getObjectCache

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

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

        public void securityNodeChanged()
      • isShutDown

        public boolean isShutDown()
      • shutdown

        public void shutdown()
      • cancelCoreRecoveries

        public void cancelCoreRecoveries()
      • create

        public SolrCore create​(String coreName,
                               Map<String,​String> parameters)
        Creates a new core, publishing the core state to the cluster
        coreName - the core name
        parameters - the core parameters
        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
        coreName - the core name
        instancePath - the instance directory
        parameters - the core parameters
        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)
        pathToAssert - path to check
        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.
      • getCores

        public List<SolrCore> getCores()
        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.

        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 permanent and transient cores that are currently loaded, i.e. cores that have 1: loadOnStartup=true and are either not-transient or, if transient, have been loaded and have not been aged out 2: loadOnStartup=false and have been loaded but are either non-transient or have not been aged out.

        Put another way, this will not return any names of cores that are lazily loaded but have not been called for yet or are transient and either not loaded or have been swapped out.

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

        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, permanent and transient, that are currently known, whether they are loaded or not.

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

        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 permanent and transient cores, loaded and unloaded cores. Faster equivalent for 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,
                           UUID coreId)
        Recreates a SolrCore. While the new core is loading, requests will continue to be dispatched to and processed by the old core
        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
        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
        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
        a List of CoreDescriptors
      • getCoreRootDirectory

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

        public SolrCore getCore​(String name,
                                UUID id)
        Gets a core by name and increase its refcount.
        name - the core name
        the core if found, null if a SolrCore by this name does not exist
        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.
        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)
      • setCoreConfigService

        public void setCoreConfigService​(ConfigSetService configSetService)
      • getHostName

        public String getHostName()
      • getManagementPath

        public String getManagementPath()
        Gets the alternate path for multicore handling: This is used in case there is a registered unnamed core (aka name is "") to declare an alternate way of accessing named cores. This can also be used in a pseudo single-core environment so admins can prepare a new version before swapping.
      • isLoaded

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

        public String 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()
      • getShardHandlerFactory

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

        public boolean isCoreLoading​(String name)
      • getNodeConfig

        public NodeConfig getNodeConfig()
      • getStatus

        public long getStatus()
      • getAliases

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

        public boolean checkTragicException​(SolrCore solrCore)
        solrCore - the core against which we check if there has been a tragic exception
        whether this Solr core has tragic exception
        See Also:
      • runAsync

        public void runAsync​(Runnable r)
        Run an arbitrary task in it's 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 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.

        r - the task to run
      • setWeakStringInterner

        public static void setWeakStringInterner()