Class SolrCore
- java.lang.Object
-
- org.apache.solr.core.SolrCore
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,SolrInfoBean
,SolrMetricProducer
public final class SolrCore extends Object implements SolrInfoBean, SolrMetricProducer, Closeable
SolrCore got its name because it represents the "core" of Solr -- one index and everything needed to make it work. When multi-core support was added to Solr way back in version 1.3, this class was required so that the core functionality could be re-used multiple times.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SolrCore.RawWriter
-
Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoBean
SolrInfoBean.Category, SolrInfoBean.Group
-
-
Field Summary
Fields Modifier and Type Field Description static Map<String,QueryResponseWriter>
DEFAULT_RESPONSE_WRITERS
boolean
indexEnabled
boolean
readOnly
boolean
searchEnabled
static boolean
VERBOSE
static String
version
-
Constructor Summary
Constructors Constructor Description SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet coreConfig)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCloseHook(CloseHook hook)
Add a close callback hookvoid
addConfListener(Runnable runnable)
Register to notify for any file change in the conf directory.void
addTransformerFactory(String name, TransformerFactory factory)
void
cleanupOldIndexDirectories(boolean reload)
void
close()
Close all resources allocated by the core if it is no longer in use...void
closeAndWait()
Close the core, if it is still in use waits until is no longer in use.void
closeSearcher()
<T> T
createInitInstance(PluginInfo info, Class<T> cast, String msg, String defClassName)
static <T> T
createInstance(String className, Class<T> cast, String msg, SolrCore core, org.apache.lucene.analysis.util.ResourceLoader resourceLoader)
Creates an instance by trying a constructor that accepts a SolrCore before trying the default (no arg) constructor.StatsCache
createStatsCache()
Create an instance ofStatsCache
using configured parameters.void
deleteNamedSnapshot(String commitName)
This method deletes the snapshot with the specified name.void
deleteNonSnapshotIndexFiles(String indexDirPath)
This method deletes the index files not associated with any named snapshot only if the specified indexDirPath is not the *current* index directory.static void
deleteUnloadedCore(CoreDescriptor cd, boolean deleteDataDir, boolean deleteInstanceDir)
void
execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
protected void
finalize()
SolrInfoBean.Category
getCategory()
Category of this componentorg.apache.lucene.codecs.Codec
getCodec()
String
getConfigResource()
Gets the configuration resource name used by this core instance.NamedList
getConfigSetProperties()
static Runnable
getConfListener(SolrCore core, ZkSolrResourceLoader zkSolrResourceLoader)
CoreContainer
getCoreContainer()
CoreDescriptor
getCoreDescriptor()
SolrCoreMetricManager
getCoreMetricManager()
Returns theSolrCoreMetricManager
for this core.String
getDataDir()
IndexDeletionPolicyWrapper
getDeletionPolicy()
String
getDescription()
Simple one or two line descriptionDirectoryFactory
getDirectoryFactory()
List<PluginInfo>
getImplicitHandlers()
String
getIndexDir()
IndexFingerprint
getIndexFingerprint(SolrIndexSearcher searcher, org.apache.lucene.index.LeafReaderContext ctx, long maxVersion)
Computes fingerprint of a segment and caches it only if all the version in segment are included in the fingerprint.IndexReaderFactory
getIndexReaderFactory()
long
getIndexSize()
Map<String,SolrInfoBean>
getInfoRegistry()
Returns a Map of name vs SolrInfoBean objects.Path
getInstancePath()
The core's instance directory (absolute).IndexSchema
getLatestSchema()
String
getLogId()
MemClassLoader
getMemClassLoader()
Set<String>
getMetricNames()
Modifiable set of metric names that this component reports (default is null, which means none).com.codahale.metrics.MetricRegistry
getMetricRegistry()
An instance ofMetricRegistry
that this component uses for metrics reporting (default is null, which means no registry).String
getMetricTag()
String
getName()
Simple common usage name, e.g.RefCounted<SolrIndexSearcher>
getNewestSearcher(boolean openNew)
Return the newest normalRefCounted
<SolrIndexSearcher
> with the reference count incremented.String
getNewIndexDir()
Returns the indexdir as given in index.properties.int
getOpenCount()
Current core usage count.PackageListeners
getPackageListeners()
QParserPlugin
getQueryPlugin(String parserName)
QueryResponseWriter
getQueryResponseWriter(String writerName)
Finds a writer by name, or returns the default writer if not found.QueryResponseWriter
getQueryResponseWriter(SolrQueryRequest request)
Returns the appropriate writer for a request.RefCounted<SolrIndexSearcher>
getRealtimeSearcher()
Gets the latest real-time searcher w/o forcing open a new searcher if one already exists.RefCounted<SolrIndexSearcher>
getRegisteredSearcher()
Returns the current registered searcher with its reference count incremented, or null if none are registered.SolrRequestHandler
getRequestHandler(String handlerName)
Get the request handler registered to a given name.PluginBag<SolrRequestHandler>
getRequestHandlers()
Returns an unmodifiable Map containing the registered handlersSolrResourceLoader
getResourceLoader()
The SolrResourceLoader used to load all resources for this core.SolrResourceLoader
getResourceLoader(String pkg)
Gets the SolrResourceLoader for a given packagePluginBag<QueryResponseWriter>
getResponseWriters()
RestManager
getRestManager()
ReentrantLock
getRuleExpiryLock()
String
getSchemaResource()
Gets the schema resource name used by this core instance.SearchComponent
getSearchComponent(String name)
PluginBag<SearchComponent>
getSearchComponents()
Accessor for all the Search ComponentsRefCounted<SolrIndexSearcher>
getSearcher()
Return a registeredRefCounted
<SolrIndexSearcher
> with the reference count incremented.RefCounted<SolrIndexSearcher>
getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher)
RefCounted<SolrIndexSearcher>
getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher, boolean updateHandlerReopens)
Get aSolrIndexSearcher
or start the process of creating a new one.SolrSnapshotMetaDataManager
getSnapshotMetaDataManager()
SolrConfig
getSolrConfig()
Gets the configuration object used by this core instance.SolrCoreState
getSolrCoreState()
SolrMetricsContext
getSolrMetricsContext()
Implementing classes should override this method to provide the context obtained inSolrMetricProducer.initializeMetrics(SolrMetricsContext, String)
to ensure proper cleanup of metrics at the end of the life-cycle of this component.long
getStartNanoTime()
Date
getStartTimeStamp()
TransformerFactory
getTransformerFactory(String name)
String
getUlogDir()
UpdateHandler
getUpdateHandler()
RequestHandlers need access to the updateHandler so they can all talk to the same RAM indexer.UpdateRequestProcessorChain
getUpdateProcessingChain(String name)
UpdateRequestProcessorChain
getUpdateProcessorChain(SolrParams params)
PluginBag<UpdateRequestProcessorFactory>
getUpdateProcessors()
long
getUptimeMs()
ValueSourceParser
getValueSourceParser(String parserName)
void
initDefaultPlugin(Object plugin, Class type)
void
initializeMetrics(SolrMetricsContext parentContext, String scope)
Initialize metrics specific to this producer.<T> List<T>
initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName)
For a given List of PluginInfo return the instances as a List<T> T
initPlugins(List<PluginInfo> pluginInfos, Map<String,T> registry, Class<T> type, String defClassName)
<T> T
initPlugins(Map<String,T> registry, Class<T> type)
protected RestManager
initRestManager()
Creates and initializes a RestManager based on configuration args in solrconfig.xml.boolean
isClosed()
Whether this core is closed.boolean
isReloaded()
BlobRepository.BlobContentRef
loadDecodeAndCacheBlob(String key, BlobRepository.Decoder<Object> decoder)
Convenience method to load a blob.static void
log(Throwable e)
boolean
modifyIndexProps(String tmpIdxDirName)
void
open()
expert: increments the core reference countRefCounted<SolrIndexSearcher>
openNewSearcher(boolean updateHandlerReopens, boolean realtime)
Opens a new searcher and returns a RefCounted<SolrIndexSearcher> with its reference incremented.static void
postDecorateResponse(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
Put status, QTime, and possibly request handler and params, in the response headerstatic void
preDecorateResponse(SolrQueryRequest req, SolrQueryResponse rsp)
void
registerFirstSearcherListener(SolrEventListener listener)
NOTE: this function is not thread safe.void
registerInfoBean(String name, SolrInfoBean solrInfoBean)
void
registerNewSearcherListener(SolrEventListener listener)
NOTE: this function is not thread safe.SolrRequestHandler
registerRequestHandler(String handlerName, SolrRequestHandler handler)
Registers a handler at the specified location.QueryResponseWriter
registerResponseWriter(String name, QueryResponseWriter responseWriter)
NOTE: this function is not thread safe.SolrCore
reload(ConfigSet coreConfig)
boolean
removeConfListener(Runnable runnable)
Remove a listenervoid
runAsync(Runnable r)
Run an arbitrary task in it's own thread.void
seedVersionBuckets()
void
setLatestSchema(IndexSchema replacementSchema)
Sets the latest schema snapshot to be used by this core instance.void
setName(String v)
void
unloadOnClose(CoreDescriptor desc, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir)
static void
verbose(Object... args)
<R> R
withSearcher(IOFunction<SolrIndexSearcher,R> lambda)
Executes the lambda with theSolrIndexSearcher
.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.solr.core.SolrInfoBean
getMetricsSnapshot, registerMetricName
-
Methods inherited from interface org.apache.solr.metrics.SolrMetricProducer
initializeMetrics
-
-
-
-
Field Detail
-
version
public static final String version
- See Also:
- Constant Field Values
-
searchEnabled
public volatile boolean searchEnabled
-
indexEnabled
public volatile boolean indexEnabled
-
readOnly
public volatile boolean readOnly
-
VERBOSE
public static boolean VERBOSE
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
- Debugging aid only. No non-test code should be released with uncommented verbose() calls.
-
DEFAULT_RESPONSE_WRITERS
public static final Map<String,QueryResponseWriter> DEFAULT_RESPONSE_WRITERS
-
-
Constructor Detail
-
SolrCore
public SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet coreConfig)
-
-
Method Detail
-
getMetricNames
public Set<String> getMetricNames()
Description copied from interface:SolrInfoBean
Modifiable set of metric names that this component reports (default is null, which means none). If not null then this set is used bySolrInfoBean.registerMetricName(String)
to capture what metrics names are reported from this component.NOTE: this set has to allow iteration under modifications.
- Specified by:
getMetricNames
in interfaceSolrInfoBean
-
getStartTimeStamp
public Date getStartTimeStamp()
-
getStartNanoTime
public long getStartNanoTime()
-
getUptimeMs
public long getUptimeMs()
-
getRestManager
public RestManager getRestManager()
-
getPackageListeners
public PackageListeners getPackageListeners()
-
getResourceLoader
public SolrResourceLoader getResourceLoader()
The SolrResourceLoader used to load all resources for this core.- Since:
- solr 1.3
-
getResourceLoader
public SolrResourceLoader getResourceLoader(String pkg)
Gets the SolrResourceLoader for a given package- Parameters:
pkg
- The package name
-
getConfigResource
public String getConfigResource()
Gets the configuration resource name used by this core instance.- Since:
- solr 1.3
-
getSolrConfig
public SolrConfig getSolrConfig()
Gets the configuration object used by this core instance.
-
getSchemaResource
public String getSchemaResource()
Gets the schema resource name used by this core instance.- Since:
- solr 1.3
-
getLatestSchema
public IndexSchema getLatestSchema()
- Returns:
- the latest snapshot of the schema used by this core instance.
- See Also:
setLatestSchema(org.apache.solr.schema.IndexSchema)
-
getInstancePath
public Path getInstancePath()
The core's instance directory (absolute).
-
setLatestSchema
public void setLatestSchema(IndexSchema replacementSchema)
Sets the latest schema snapshot to be used by this core instance. If the specifiedreplacementSchema
uses aSimilarityFactory
which isSolrCoreAware
then this method willSolrCoreAware.inform(org.apache.solr.core.SolrCore)
that factory about this SolrCore prior to using thereplacementSchema
- See Also:
getLatestSchema()
-
getConfigSetProperties
public NamedList getConfigSetProperties()
-
getDataDir
public String getDataDir()
-
getUlogDir
public String getUlogDir()
-
getIndexDir
public String getIndexDir()
-
getNewIndexDir
public String getNewIndexDir()
Returns the indexdir as given in index.properties. If index.properties exists in dataDir and there is a property index available and it points to a valid directory in dataDir that is returned. Else dataDir/index is returned. Only called for creating new indexSearchers and indexwriters. Use the getIndexDir() method to know the active index directory- Returns:
- the indexdir as given in index.properties
- Throws:
SolrException
- if for any reason the a reasonable index directory cannot be determined.
-
getDirectoryFactory
public DirectoryFactory getDirectoryFactory()
-
getIndexReaderFactory
public IndexReaderFactory getIndexReaderFactory()
-
getIndexSize
public long getIndexSize()
-
getName
public String getName()
Description copied from interface:SolrInfoBean
Simple common usage name, e.g. BasicQueryHandler, or fully qualified class name.- Specified by:
getName
in interfaceSolrInfoBean
-
setName
public void setName(String v)
-
getLogId
public String getLogId()
-
getCoreMetricManager
public SolrCoreMetricManager getCoreMetricManager()
Returns theSolrCoreMetricManager
for this core.- Returns:
- the
SolrCoreMetricManager
for this core
-
getInfoRegistry
public Map<String,SolrInfoBean> getInfoRegistry()
Returns a Map of name vs SolrInfoBean objects. The returned map is an instance of a ConcurrentHashMap and therefore no synchronization is needed for putting, removing or iterating over it.- Returns:
- the Info Registry map which contains SolrInfoBean objects keyed by name
- Since:
- solr 1.3
-
deleteNamedSnapshot
public void deleteNamedSnapshot(String commitName) throws IOException
This method deletes the snapshot with the specified name. If the directory storing the snapshot is not the same as the *current* core index directory, then delete the files corresponding to this snapshot. Otherwise we leave the index files related to snapshot as is (assuming the underlying Solr IndexDeletionPolicy will clean them up appropriately).- Parameters:
commitName
- The name of the snapshot to be deleted.- Throws:
IOException
- in case of I/O error.
-
deleteNonSnapshotIndexFiles
public void deleteNonSnapshotIndexFiles(String indexDirPath) throws IOException
This method deletes the index files not associated with any named snapshot only if the specified indexDirPath is not the *current* index directory.- Parameters:
indexDirPath
- The path of the directory- Throws:
IOException
- In case of I/O error.
-
registerFirstSearcherListener
public void registerFirstSearcherListener(SolrEventListener listener)
NOTE: this function is not thread safe. However, it is safe to call within theinform( SolrCore core )
function forSolrCoreAware
classes. Outsideinform
, this could potentially throw a ConcurrentModificationException- See Also:
SolrCoreAware
-
registerNewSearcherListener
public void registerNewSearcherListener(SolrEventListener listener)
NOTE: this function is not thread safe. However, it is safe to call within theinform( SolrCore core )
function forSolrCoreAware
classes. Outsideinform
, this could potentially throw a ConcurrentModificationException- See Also:
SolrCoreAware
-
registerResponseWriter
public QueryResponseWriter registerResponseWriter(String name, QueryResponseWriter responseWriter)
NOTE: this function is not thread safe. However, it is safe to call within theinform( SolrCore core )
function forSolrCoreAware
classes. Outsideinform
, this could potentially throw a ConcurrentModificationException- See Also:
SolrCoreAware
-
reload
public SolrCore reload(ConfigSet coreConfig) throws IOException
- Throws:
IOException
-
createInstance
public static <T> T createInstance(String className, Class<T> cast, String msg, SolrCore core, org.apache.lucene.analysis.util.ResourceLoader resourceLoader)
Creates an instance by trying a constructor that accepts a SolrCore before trying the default (no arg) constructor.- Parameters:
className
- the instance class to createcast
- the class or interface that the instance should extend or implementmsg
- a message helping compose the exception error if any occurs.core
- The SolrCore instance for which this object needs to be loaded- Returns:
- the desired instance
- Throws:
SolrException
- if the object could not be instantiated
-
createInitInstance
public <T> T createInitInstance(PluginInfo info, Class<T> cast, String msg, String defClassName)
-
getCoreContainer
public CoreContainer getCoreContainer()
-
seedVersionBuckets
public void seedVersionBuckets()
-
initializeMetrics
public void initializeMetrics(SolrMetricsContext parentContext, String scope)
Description copied from interface:SolrMetricProducer
Initialize metrics specific to this producer.- Specified by:
initializeMetrics
in interfaceSolrMetricProducer
- Parameters:
parentContext
- parent metrics context. If this component has the same life-cycle as the parent it can simply use the parent context, otherwise it should obtain a child context usingSolrMetricsContext.getChildContext(Object)
passingthis
as the child.scope
- component scope
-
getMetricTag
public String getMetricTag()
-
getSolrMetricsContext
public SolrMetricsContext getSolrMetricsContext()
Description copied from interface:SolrMetricProducer
Implementing classes should override this method to provide the context obtained inSolrMetricProducer.initializeMetrics(SolrMetricsContext, String)
to ensure proper cleanup of metrics at the end of the life-cycle of this component.- Specified by:
getSolrMetricsContext
in interfaceSolrMetricProducer
-
modifyIndexProps
public boolean modifyIndexProps(String tmpIdxDirName)
-
closeAndWait
public void closeAndWait()
Close the core, if it is still in use waits until is no longer in use.- See Also:
close()
,isClosed()
-
createStatsCache
public StatsCache createStatsCache()
Create an instance ofStatsCache
using configured parameters.
-
getSolrCoreState
public SolrCoreState getSolrCoreState()
-
getUpdateProcessingChain
public UpdateRequestProcessorChain getUpdateProcessingChain(String name)
- Returns:
- an update processor registered to the given name. Throw an exception if this chain is undefined
-
getUpdateProcessorChain
public UpdateRequestProcessorChain getUpdateProcessorChain(SolrParams params)
-
getUpdateProcessors
public PluginBag<UpdateRequestProcessorFactory> getUpdateProcessors()
-
open
public void open()
expert: increments the core reference count
-
close
public void close()
Close all resources allocated by the core if it is no longer in use...- searcher
- updateHandler
- all CloseHooks will be notified
- All MBeans will be unregistered from MBeanServer if JMX was enabled
The behavior of this method is determined by the result of decrementing the core's reference count (A core is created with a reference count of 1)...
- If reference count is > 0, the usage count is decreased by 1 and no resources are released.
- If reference count is == 0, the resources are released.
- If reference count is < 0, and error is logged and no further action is taken.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceSolrMetricProducer
- See Also:
isClosed()
-
getOpenCount
public int getOpenCount()
Current core usage count.
-
isClosed
public boolean isClosed()
Whether this core is closed.
-
finalize
protected void finalize() throws Throwable
-
addCloseHook
public void addCloseHook(CloseHook hook)
Add a close callback hook
-
verbose
public static void verbose(Object... args)
-
getRequestHandler
public SolrRequestHandler getRequestHandler(String handlerName)
Get the request handler registered to a given name.This function is thread safe.
-
getRequestHandlers
public PluginBag<SolrRequestHandler> getRequestHandlers()
Returns an unmodifiable Map containing the registered handlers
-
registerRequestHandler
public SolrRequestHandler registerRequestHandler(String handlerName, SolrRequestHandler handler)
Registers a handler at the specified location. If one exists there, it will be replaced. To remove a handler, registernull
at its pathOnce registered the handler can be accessed through:
http://${host}:${port}/${context}/${handlerName} or: http://${host}:${port}/${context}/select?qt=${handlerName}
Handlers must be initialized before getting registered. Registered handlers can immediately accept requests.
This call is thread safe.
- Returns:
- the previous
SolrRequestHandler
registered to this namenull
if none.
-
getSearchComponent
public SearchComponent getSearchComponent(String name)
- Returns:
- a Search Component registered to a given name. Throw an exception if the component is undefined
-
getSearchComponents
public PluginBag<SearchComponent> getSearchComponents()
Accessor for all the Search Components- Returns:
- An unmodifiable Map of Search Components
-
getUpdateHandler
public UpdateHandler getUpdateHandler()
RequestHandlers need access to the updateHandler so they can all talk to the same RAM indexer.
-
getSearcher
public RefCounted<SolrIndexSearcher> getSearcher()
Return a registeredRefCounted
<SolrIndexSearcher
> with the reference count incremented. It must be decremented when no longer needed. This method should not be called from SolrCoreAware.inform() since it can result in a deadlock if useColdSearcher==false. If handling a normal request, the searcher should be obtained fromSolrQueryRequest.getSearcher()
instead. If you still think you need to call this, considerwithSearcher(IOFunction)
instead which is easier to use.
-
withSearcher
public <R> R withSearcher(IOFunction<SolrIndexSearcher,R> lambda) throws IOException
Executes the lambda with theSolrIndexSearcher
. This is more convenient than usinggetSearcher()
since there is no ref-counting business to worry about. Example:IndexReader reader = h.getCore().withSearcher(SolrIndexSearcher::getIndexReader);
Warning: although a lambda is concise, it may be inappropriate to simply return the IndexReader because it might be closed soon after this method returns; it really depends.- Throws:
IOException
-
getIndexFingerprint
public IndexFingerprint getIndexFingerprint(SolrIndexSearcher searcher, org.apache.lucene.index.LeafReaderContext ctx, long maxVersion) throws IOException
Computes fingerprint of a segment and caches it only if all the version in segment are included in the fingerprint. We can't use computeIfAbsent as caching is conditional (as described above) There is chance that two threads may compute fingerprint on the same segment. It might be OK to do so rather than locking entire map.- Parameters:
searcher
- searcher that includes specified LeaderReaderContextctx
- LeafReaderContext of a segment to compute fingerprint ofmaxVersion
- maximum version number to consider for fingerprint computation- Returns:
- IndexFingerprint of the segment
- Throws:
IOException
- Can throw IOException
-
getRegisteredSearcher
public RefCounted<SolrIndexSearcher> getRegisteredSearcher()
Returns the current registered searcher with its reference count incremented, or null if none are registered.
-
getNewestSearcher
public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
Return the newest normalRefCounted
<SolrIndexSearcher
> with the reference count incremented. It must be decremented when no longer needed. If no searcher is currently open, then if openNew==true a new searcher will be opened, or null is returned if openNew==false.
-
getRealtimeSearcher
public RefCounted<SolrIndexSearcher> getRealtimeSearcher()
Gets the latest real-time searcher w/o forcing open a new searcher if one already exists. The reference count will be incremented.
-
getSearcher
public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher)
-
openNewSearcher
public RefCounted<SolrIndexSearcher> openNewSearcher(boolean updateHandlerReopens, boolean realtime)
Opens a new searcher and returns a RefCounted<SolrIndexSearcher> with its reference incremented."realtime" means that we need to open quickly for a realtime view of the index, hence don't do any autowarming and add to the _realtimeSearchers queue rather than the _searchers queue (so it won't be used for autowarming by a future normal searcher). A "realtime" searcher will currently never become "registered" (since it currently lacks caching).
realtimeSearcher is updated to the latest opened searcher, regardless of the value of "realtime".
This method acquires openSearcherLock - do not call with searchLock held!
-
getSearcher
public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher, boolean updateHandlerReopens)
Get aSolrIndexSearcher
or start the process of creating a new one.The registered searcher is the default searcher used to service queries. A searcher will normally be registered after all of the warming and event handlers (newSearcher or firstSearcher events) have run. In the case where there is no registered searcher, the newly created searcher will be registered before running the event handlers (a slow searcher is better than no searcher).
These searchers contain read-only IndexReaders. To access a non read-only IndexReader, see newSearcher(String name, boolean readOnly).
If forceNew==true then A new searcher will be opened and registered regardless of whether there is already a registered searcher or other searchers in the process of being created.
If forceNew==false then:
- If a searcher is already registered, that searcher will be returned
- If no searcher is currently registered, but at least one is in the process of being created, then this call will block until the first searcher is registered
- If no searcher is currently registered, and no searchers in the process of being registered, a new searcher will be created.
If returnSearcher==true then a
RefCounted
<SolrIndexSearcher
> will be returned with the reference count incremented. It must be decremented when no longer needed.If waitSearcher!=null and a new
SolrIndexSearcher
was created, then it is filled in with a Future that will return after the searcher is registered. The Future may be set to null in which case the SolrIndexSearcher created has already been registered at the time this method returned.- Parameters:
forceNew
- if true, force the open of a new index searcher regardless if there is already one open.returnSearcher
- if true, returns aSolrIndexSearcher
holder with the refcount already incremented.waitSearcher
- if non-null, will be filled in with aFuture
that will return after the new searcher is registered.updateHandlerReopens
- if true, the UpdateHandler will be used when reopening aSolrIndexSearcher
.
-
isReloaded
public boolean isReloaded()
-
closeSearcher
public void closeSearcher()
-
execute
public void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
-
preDecorateResponse
public static void preDecorateResponse(SolrQueryRequest req, SolrQueryResponse rsp)
-
postDecorateResponse
public static void postDecorateResponse(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
Put status, QTime, and possibly request handler and params, in the response header
-
log
public static final void log(Throwable e)
-
getResponseWriters
public PluginBag<QueryResponseWriter> getResponseWriters()
-
getMemClassLoader
public MemClassLoader getMemClassLoader()
-
getQueryResponseWriter
public final QueryResponseWriter getQueryResponseWriter(String writerName)
Finds a writer by name, or returns the default writer if not found.
-
getQueryResponseWriter
public final QueryResponseWriter getQueryResponseWriter(SolrQueryRequest request)
Returns the appropriate writer for a request. If the request specifies a writer via the 'wt' parameter, attempts to find that one; otherwise return the default writer.
-
getQueryPlugin
public QParserPlugin getQueryPlugin(String parserName)
-
getTransformerFactory
public TransformerFactory getTransformerFactory(String name)
-
addTransformerFactory
public void addTransformerFactory(String name, TransformerFactory factory)
-
initPlugins
public <T> T initPlugins(List<PluginInfo> pluginInfos, Map<String,T> registry, Class<T> type, String defClassName)
-
initPlugins
public <T> List<T> initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName)
For a given List of PluginInfo return the instances as a List- Parameters:
defClassName
- The default classname if PluginInfo#className == null- Returns:
- The instances initialized
-
initPlugins
public <T> T initPlugins(Map<String,T> registry, Class<T> type)
- Parameters:
registry
- The map to which the instance should be added to. The key is the name attributetype
- The type of the Plugin. These should be standard ones registered by type.getName() in SolrConfig- Returns:
- The default if any
-
getValueSourceParser
public ValueSourceParser getValueSourceParser(String parserName)
-
initRestManager
protected RestManager initRestManager() throws SolrException
Creates and initializes a RestManager based on configuration args in solrconfig.xml. RestManager provides basic storage support for managed resource data, such as to persist stopwords to ZooKeeper if running in SolrCloud mode.- Throws:
SolrException
-
getCoreDescriptor
public CoreDescriptor getCoreDescriptor()
-
getDeletionPolicy
public IndexDeletionPolicyWrapper getDeletionPolicy()
-
getSnapshotMetaDataManager
public SolrSnapshotMetaDataManager getSnapshotMetaDataManager()
- Returns:
- A reference of SolrSnapshotMetaDataManager managing the persistent snapshots for this Solr core.
-
getRuleExpiryLock
public ReentrantLock getRuleExpiryLock()
-
getDescription
public String getDescription()
Description copied from interface:SolrInfoBean
Simple one or two line description- Specified by:
getDescription
in interfaceSolrInfoBean
-
getCategory
public SolrInfoBean.Category getCategory()
Description copied from interface:SolrInfoBean
Category of this component- Specified by:
getCategory
in interfaceSolrInfoBean
-
getMetricRegistry
public com.codahale.metrics.MetricRegistry getMetricRegistry()
Description copied from interface:SolrInfoBean
An instance ofMetricRegistry
that this component uses for metrics reporting (default is null, which means no registry).- Specified by:
getMetricRegistry
in interfaceSolrInfoBean
-
getCodec
public org.apache.lucene.codecs.Codec getCodec()
-
unloadOnClose
public void unloadOnClose(CoreDescriptor desc, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir)
-
deleteUnloadedCore
public static void deleteUnloadedCore(CoreDescriptor cd, boolean deleteDataDir, boolean deleteInstanceDir)
-
addConfListener
public void addConfListener(Runnable runnable)
Register to notify for any file change in the conf directory. If the file change results in a core reload , then the listener is not fired
-
removeConfListener
public boolean removeConfListener(Runnable runnable)
Remove a listener
-
getConfListener
public static Runnable getConfListener(SolrCore core, ZkSolrResourceLoader zkSolrResourceLoader)
-
registerInfoBean
public void registerInfoBean(String name, SolrInfoBean solrInfoBean)
-
cleanupOldIndexDirectories
public void cleanupOldIndexDirectories(boolean reload)
-
getImplicitHandlers
public List<PluginInfo> getImplicitHandlers()
-
loadDecodeAndCacheBlob
public BlobRepository.BlobContentRef loadDecodeAndCacheBlob(String key, BlobRepository.Decoder<Object> decoder)
Convenience method to load a blob. This method minimizes the degree to which component and other code needs to depend on the structure of solr's object graph and ensures that a proper close hook is registered. This method should normally be called inSolrCoreAware.inform(SolrCore)
, and should never be called during request processing. The Decoder will only run on the first invocations, subsequent invocations will return the cached object.- Parameters:
key
- A key in the format of name/version for a blob stored in theCollectionAdminParams.SYSTEM_COLL
blob store via the Blob Store APIdecoder
- a decoder with which to convert the blob into a Java Object representation (first time only)- Returns:
- a reference to the blob that has already cached the decoded version.
-
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, 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.
- Parameters:
r
- the task to run
-
-