Class CoreContainer

  • public class CoreContainer
    extends Object
    solr 1.3
    • Constructor Detail

      • CoreContainer

        public CoreContainer()
        Create a new CoreContainer using system properties to detect the solr home directory. The container's cores are not loaded.
        See Also:
      • CoreContainer

        public CoreContainer​(SolrResourceLoader loader)
        Create a new CoreContainer using the given SolrResourceLoader. The container's cores are not loaded.
        loader - the SolrResourceLoader
        See Also:
      • CoreContainer

        public CoreContainer​(String solrHome)
        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
        See Also:
      • CoreContainer

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

        public CoreContainer​(NodeConfig config,
                             Properties properties,
                             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

      • newBackupRepository

        public BackupRepository newBackupRepository​(Optional<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()
      • getReplayUpdatesExecutor

        public OrderedExecutor getReplayUpdatesExecutor()
      • 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
      • getCores

        public Collection<SolrCore> getCores()
        a Collection of registered SolrCores
      • getLoadedCoreNames

        public Collection<String> getLoadedCoreNames()
        Gets the 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.
      • getNamesForCore

        public Collection<String> getNamesForCore​(SolrCore core)
        This method is currently experimental.
        a Collection of the names that a specific core object is mapped to, there are more than one.
      • getAllCoreNames

        public Collection<String> getAllCoreNames()
        get a list of all the cores that are currently known, whether currently loaded or not
        a list of all the available core names in either permanent or transient cores
      • 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)
        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
      • 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()
      • getCore

        public SolrCore getCore​(String name)
        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)
      • 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
      • isLoadedNotPendingClose

        public boolean isLoadedNotPendingClose​(String name)
      • queueCoreToClose

        public void queueCoreToClose​(SolrCore coreToClose)
      • getUnloadedCoreDescriptor

        public CoreDescriptor getUnloadedCoreDescriptor​(String cname)
        Gets a solr core descriptor for a core that is not loaded. Note that if the caller calls this on a loaded core, the unloaded descriptor will be returned.
        cname - - name of the unloaded core descriptor to load. NOTE:
        a coreDescriptor. May return null
      • getSolrHome

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

        public boolean repairCoreProperty​(CoreDescriptor cd,
                                          String prop)
        cd - CoreDescriptor, presumably a deficient one
        prop - The property that needs to be repaired.
        true if we were able to successfuly perisist the repaired coreDescriptor, false otherwise. See SOLR-11503, This can be removed when there's no chance we'll need to upgrade a Solr installation created with legacyCloud=true from 6.6.1 through 7.1
      • 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