Class CoreContainer
- java.lang.Object
-
- org.apache.solr.core.CoreContainer
-
public class CoreContainer extends Object
- Since:
- solr 1.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CoreContainer.CoreLoadFailure
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
CoreContainer(Object testConstructor)
This method allows subclasses to construct a CoreContainer without any default init behavior.CoreContainer(Path solrHome, Properties properties)
Create a new CoreContainer using the given solr home directory.CoreContainer(NodeConfig config)
Create a new CoreContainer using the given configuration.CoreContainer(NodeConfig config, boolean asyncSolrCoreLoad)
CoreContainer(NodeConfig config, CoresLocator locator)
Create a new CoreContainer using the given configuration and locator.CoreContainer(NodeConfig config, CoresLocator locator, boolean asyncSolrCoreLoad)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
assertPathAllowed(Path pathToAssert)
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.void
cancelCoreRecoveries()
boolean
checkTragicException(SolrCore solrCore)
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 clusterSolrCore
create(String coreName, Map<String,String> parameters)
Creates a new core, publishing the core state to the clusterstatic CoreContainer
createAndLoad(Path solrHome)
static CoreContainer
createAndLoad(Path solrHome, Path configFile)
Create a new CoreContainer and load its coresprotected <T> T
createHandler(String path, String handlerClass, Class<T> clazz)
org.apache.solr.common.cloud.Aliases
getAliases()
Retrieve the aliases from zookeeper.List<String>
getAllCoreNames()
Gets a collection of all the cores, permanent and transient, that are currently known, whether they are loaded or not.AllowListUrlChecker
getAllowListUrlChecker()
Gets the URLs checker based on theallowUrls
configuration of solr.xml.Set<Path>
getAllowPaths()
Return the file system paths that should be allowed for various API requests.AuditLoggerPlugin
getAuditLoggerPlugin()
AuthenticationPlugin
getAuthenticationPlugin()
AuthorizationPlugin
getAuthorizationPlugin()
BlobRepository
getBlobRepository()
SolrCache<?,?>
getCache(String name)
ClusterEventProducer
getClusterEventProducer()
ClusterSingletons
getClusterSingletons()
CollectionsHandler
getCollectionsHandler()
NodeConfig
getConfig()
ConfigSetService
getConfigSetService()
ConfigSetsHandler
getConfigSetsHandler()
ContainerPluginsRegistry
getContainerPluginsRegistry()
Properties
getContainerProperties()
SolrCore
getCore(String name)
SolrCore
getCore(String name, UUID id)
Gets a core by name and increase its refcount.CoreDescriptor
getCoreDescriptor(String coreName)
List<CoreDescriptor>
getCoreDescriptors()
Get the CoreDescriptors for all cores managed by this containerMap<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.Path
getCoreRootDirectory()
Where cores are created (absolute).List<SolrCore>
getCores()
Deprecated.CoresLocator
getCoresLocator()
CoreSorter
getCoreSorter()
ExecutorService
getCoreZkRegisterExecutorService()
Optional<DistributedCollectionConfigSetCommandRunner>
getDistributedCollectionCommandRunner()
FileStoreAPI
getFileStoreAPI()
HealthCheckHandler
getHealthCheckHandler()
String
getHostName()
InfoHandler
getInfoHandler()
JerseyAppHandlerCache
getJerseyAppHandlerCache()
org.glassfish.jersey.server.ApplicationHandler
getJerseyApplicationHandler()
List<String>
getLoadedCoreNames()
Gets the permanent and transient cores that are currently loaded, i.e.LogWatcher<?>
getLogging()
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.SolrMetricManager
getMetricManager()
MetricsHandler
getMetricsHandler()
CoreAdminHandler
getMultiCoreHandler()
NodeConfig
getNodeConfig()
int
getNumAllCores()
Gets the total number of cores, including permanent and transient cores, loaded and unloaded cores.org.apache.solr.common.util.ObjectCache
getObjectCache()
SolrPackageLoader
getPackageLoader()
PKIAuthenticationPlugin
getPkiAuthenticationSecurityBuilder()
PlacementPluginFactory<? extends PlacementPluginConfig>
getPlacementPluginFactory()
OrderedExecutor
getReplayUpdatesExecutor()
SolrRequestHandler
getRequestHandler(String path)
PluginBag<SolrRequestHandler>
getRequestHandlers()
SolrResourceLoader
getResourceLoader()
ShardHandlerFactory
getShardHandlerFactory()
The default ShardHandlerFactory used to communicate with other solr instancesSolrClientCache
getSolrClientCache()
String
getSolrHome()
The primary path of a Solr server's config, cores, and misc things.long
getStatus()
io.opentracing.Tracer
getTracer()
Never null but may implementNoopTracer
.UpdateShardHandler
getUpdateShardHandler()
Path
getUserFilesPath()
A path where Solr users can retrieve arbitrary files from.ZkController
getZkController()
boolean
hideStackTrace()
boolean
isCoreLoading(String name)
boolean
isLoaded(String name)
Determines whether the core is already loaded or not but does NOT load the coreboolean
isSharedFs(CoreDescriptor cd)
boolean
isShutDown()
boolean
isStatusLoadComplete()
boolean
isZooKeeperAware()
void
load()
Load the cores defined for this CoreContainerBackupRepository
newBackupRepository(String repositoryName)
This method instantiates a new instance of BackupRepository.protected SolrCore
registerCore(CoreDescriptor cd, SolrCore core, boolean registerInZk, boolean skipRecovery)
void
reload(String name)
reloads a core referreload(String, UUID)
for detailsvoid
reload(String name, UUID coreId)
Recreates a SolrCore.void
rename(String name, String toName)
void
runAsync(Runnable r)
Run an arbitrary task in its own thread.void
securityNodeChanged()
void
setCoreConfigService(ConfigSetService configSetService)
static void
setWeakStringInterner()
void
shutdown()
void
swap(String n0, String n1)
Swaps two SolrCore descriptors.void
unload(String name)
Unload a core from this container, leaving all files on diskvoid
unload(String name, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir)
Unload a core from this container, optionally removing the core's data and configurationvoid
waitForLoadingCore(String name, long timeoutMs)
void
waitForLoadingCoresToFinish(long timeoutMs)
If using asyncSolrCoreLoad=true, calling this afterload()
will not return until all cores have finished loading.
-
-
-
Field Detail
-
zkClientSupplier
public final Supplier<org.apache.solr.common.cloud.SolrZkClient> zkClientSupplier
Minimize exposure to CoreContainer. Mostly only ZK interface is required
-
coreInitFailures
protected final Map<String,CoreContainer.CoreLoadFailure> coreInitFailures
-
coreAdminHandler
protected volatile CoreAdminHandler coreAdminHandler
-
collectionsHandler
protected volatile CollectionsHandler collectionsHandler
-
healthCheckHandler
protected volatile HealthCheckHandler healthCheckHandler
-
configSetsHandler
protected volatile ConfigSetsHandler configSetsHandler
-
containerProperties
protected volatile Properties containerProperties
-
zkSys
protected final ZkContainer zkSys
-
shardHandlerFactory
protected volatile ShardHandlerFactory shardHandlerFactory
-
logging
protected volatile LogWatcher<?> logging
-
cfg
protected final NodeConfig cfg
-
loader
protected final SolrResourceLoader loader
-
solrHome
protected final Path solrHome
-
nodeKeyPair
protected final SolrNodeKeyPair nodeKeyPair
-
coresLocator
protected final CoresLocator coresLocator
-
securityConfHandler
protected volatile SecurityConfHandler securityConfHandler
-
metricManager
protected volatile SolrMetricManager metricManager
-
metricTag
protected volatile String metricTag
-
solrMetricsContext
protected volatile SolrMetricsContext solrMetricsContext
-
tracer
protected volatile io.opentracing.Tracer tracer
-
metricsHandler
protected MetricsHandler metricsHandler
-
nodeRoles
public final NodeRoles nodeRoles
-
LOAD_COMPLETE
public static final long LOAD_COMPLETE
- See Also:
- Constant Field Values
-
CORE_DISCOVERY_COMPLETE
public static final long CORE_DISCOVERY_COMPLETE
- See Also:
- Constant Field Values
-
INITIAL_CORE_LOAD_COMPLETE
public static final long INITIAL_CORE_LOAD_COMPLETE
- See Also:
- Constant Field Values
-
-
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.- Parameters:
solrHome
- a String containing the path to the solr home directoryproperties
- substitutable properties (alternative to Sys props)- See Also:
load()
-
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:
load()
-
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 configurationlocator
- a CoresLocator- See Also:
load()
-
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 Detail
-
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 directoryconfigFile
- 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.opentracing.Tracer getTracer()
Never null but may implementNoopTracer
.
-
getReplayUpdatesExecutor
public OrderedExecutor getReplayUpdatesExecutor()
-
getPackageLoader
public SolrPackageLoader getPackageLoader()
-
getFileStoreAPI
public FileStoreAPI getFileStoreAPI()
-
getSolrClientCache
public SolrClientCache getSolrClientCache()
-
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()
-
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 nameparameters
- 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 nameinstancePath
- the instance directoryparameters
- 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 toSolrPaths.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 theallowPaths
configuration of solr.xml. These paths are used by theassertPathAllowed(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 theallowUrls
configuration of solr.xml.
-
isSharedFs
public boolean isSharedFs(CoreDescriptor cd)
-
getCores
@Deprecated public List<SolrCore> getCores()
Deprecated.Gets all loaded cores, consistent withgetLoadedCoreNames()
. 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 callgetCore(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 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 ofgetLoadedCoreNames()
.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, permanent and transient, that are currently known, whether they are loaded or not.For efficiency, prefer to check
getCoreDescriptor(String)
!= null instead ofgetAllCoreNames()
.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 permanent and transient cores, loaded and unloaded cores. Faster equivalent forgetAllCoreNames()
.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 referreload(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 reloadcoreId
- The unique Id of the coreSolrCore.uniqueId
. If this is null, it's reloaded anyway. If the current core has a different id, this is a no-op
-
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 unloaddeleteIndexDir
- if true, delete the core's index on closedeleteDataDir
- if true, delete the core's data directory on closedeleteInstanceDir
- if true, delete the core's instance directory on close
-
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, 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:
SolrCore.close()
-
getBlobRepository
public BlobRepository getBlobRepository()
-
waitForLoadingCoresToFinish
public void waitForLoadingCoresToFinish(long timeoutMs)
If using asyncSolrCoreLoad=true, calling this afterload()
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)
-
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()
-
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.
-
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 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()
-
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 aCoreContainer
whereisZooKeeperAware()
returns false
-
checkTragicException
public boolean checkTragicException(SolrCore solrCore)
- 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()
-
getDistributedCollectionCommandRunner
public Optional<DistributedCollectionConfigSetCommandRunner> getDistributedCollectionCommandRunner()
-
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 usesSolrCore.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()
-
-