public final class SolrCore extends Object implements SolrInfoBean, SolrMetricProducer, Closeable
Modifier and Type | Class and Description |
---|---|
static interface |
SolrCore.RawWriter |
SolrInfoBean.Category, SolrInfoBean.Group
Modifier and Type | Field and Description |
---|---|
static Map<String,QueryResponseWriter> |
DEFAULT_RESPONSE_WRITERS |
boolean |
indexEnabled |
boolean |
readOnly |
boolean |
searchEnabled |
UUID |
uniqueId
A unique id to differentiate multiple instances of the same core
If we reload a core, the name remains same , but the id will be new
|
static boolean |
VERBOSE |
static String |
version |
Constructor and Description |
---|
SolrCore(CoreContainer coreContainer,
CoreDescriptor cd,
ConfigSet configSet) |
Modifier and Type | Method and Description |
---|---|
void |
addCloseHook(CloseHook hook)
Add a close callback hook
|
void |
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,
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 of
StatsCache 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) |
void |
fetchLatestSchema() |
protected void |
finalize() |
SolrInfoBean.Category |
getCategory()
Category of this component
|
CircuitBreakerManager |
getCircuitBreakerManager() |
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 the
SolrCoreMetricManager for this core. |
String |
getDataDir() |
IndexDeletionPolicyWrapper |
getDeletionPolicy() |
String |
getDescription()
Simple one or two line description
|
DirectoryFactory |
getDirectoryFactory() |
List<PluginInfo> |
getImplicitHandlers() |
String |
getIndexDir() |
IndexFingerprint |
getIndexFingerprint(SolrIndexSearcher searcher,
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() |
com.codahale.metrics.MetricRegistry |
getMetricRegistry()
An instance of
MetricRegistry 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 normal
RefCounted <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(SolrQueryRequest request)
Returns the appropriate writer for a request.
|
QueryResponseWriter |
getQueryResponseWriter(String writerName)
Finds a writer by name, or returns the default writer if not found.
|
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 handlers
|
SolrResourceLoader |
getResourceLoader()
The SolrResourceLoader used to load all resources for this core.
|
SolrResourceLoader |
getResourceLoader(String pkg)
Gets the SolrResourceLoader for a given package
|
PluginBag<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 Components
|
RefCounted<SolrIndexSearcher> |
getSearcher()
Return a registered
RefCounted <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 a
SolrIndexSearcher 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 in
SolrMetricProducer.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.
|
static <T> T |
initPlugin(PluginInfo info,
T o) |
<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 count
|
RefCounted<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 header
|
static 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 listener
|
void |
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 the
SolrIndexSearcher . |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMetricNames, getMetricsSnapshot, registerMetricName
getUniqueMetricTag, initializeMetrics
public static final String version
public final UUID uniqueId
public volatile boolean searchEnabled
public volatile boolean indexEnabled
public volatile boolean readOnly
public static boolean VERBOSE
public static final Map<String,QueryResponseWriter> DEFAULT_RESPONSE_WRITERS
public SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet configSet)
public Date getStartTimeStamp()
public long getStartNanoTime()
public long getUptimeMs()
public RestManager getRestManager()
public PackageListeners getPackageListeners()
public SolrResourceLoader getResourceLoader()
public SolrResourceLoader getResourceLoader(String pkg)
pkg
- The package namepublic String getConfigResource()
public SolrConfig getSolrConfig()
public String getSchemaResource()
public IndexSchema getLatestSchema()
setLatestSchema(org.apache.solr.schema.IndexSchema)
public Path getInstancePath()
public void setLatestSchema(IndexSchema replacementSchema)
replacementSchema
uses a SimilarityFactory
which is
SolrCoreAware
then this method will SolrCoreAware.inform(org.apache.solr.core.SolrCore)
that factory about
this SolrCore prior to using the replacementSchema
getLatestSchema()
public NamedList getConfigSetProperties()
public String getDataDir()
public String getUlogDir()
public String getIndexDir()
public String getNewIndexDir()
SolrException
- if for any reason the a reasonable index directory cannot be determined.public DirectoryFactory getDirectoryFactory()
public IndexReaderFactory getIndexReaderFactory()
public long getIndexSize()
public String getName()
SolrInfoBean
getName
in interface SolrInfoBean
public void setName(String v)
public String getLogId()
public SolrCoreMetricManager getCoreMetricManager()
SolrCoreMetricManager
for this core.SolrCoreMetricManager
for this corepublic Map<String,SolrInfoBean> getInfoRegistry()
public void deleteNamedSnapshot(String commitName) throws IOException
commitName
- The name of the snapshot to be deleted.IOException
- in case of I/O error.public void deleteNonSnapshotIndexFiles(String indexDirPath) throws IOException
indexDirPath
- The path of the directoryIOException
- In case of I/O error.public void registerFirstSearcherListener(SolrEventListener listener)
inform( SolrCore core )
function for SolrCoreAware
classes.
Outside inform
, this could potentially throw a ConcurrentModificationExceptionSolrCoreAware
public void registerNewSearcherListener(SolrEventListener listener)
inform( SolrCore core )
function for SolrCoreAware
classes.
Outside inform
, this could potentially throw a ConcurrentModificationExceptionSolrCoreAware
public QueryResponseWriter registerResponseWriter(String name, QueryResponseWriter responseWriter)
inform( SolrCore core )
function for SolrCoreAware
classes.
Outside inform
, this could potentially throw a ConcurrentModificationExceptionSolrCoreAware
public SolrCore reload(ConfigSet coreConfig) throws IOException
IOException
public static <T> T createInstance(String className, Class<T> cast, String msg, SolrCore core, ResourceLoader resourceLoader)
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 loadedSolrException
- if the object could not be instantiatedpublic <T> T createInitInstance(PluginInfo info, Class<T> cast, String msg, String defClassName)
public static <T> T initPlugin(PluginInfo info, T o)
public CoreContainer getCoreContainer()
public void seedVersionBuckets()
public void initializeMetrics(SolrMetricsContext parentContext, String scope)
SolrMetricProducer
initializeMetrics
in interface SolrMetricProducer
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
using SolrMetricsContext.getChildContext(Object)
passing this
as the child.scope
- component scopepublic String getMetricTag()
public SolrMetricsContext getSolrMetricsContext()
SolrMetricProducer
SolrMetricProducer.initializeMetrics(SolrMetricsContext, String)
to ensure proper cleanup of metrics
at the end of the life-cycle of this component.getSolrMetricsContext
in interface SolrMetricProducer
public boolean modifyIndexProps(String tmpIdxDirName)
public void closeAndWait()
close()
,
isClosed()
public StatsCache createStatsCache()
StatsCache
using configured parameters.public SolrCoreState getSolrCoreState()
public UpdateRequestProcessorChain getUpdateProcessingChain(String name)
public UpdateRequestProcessorChain getUpdateProcessorChain(SolrParams params)
public PluginBag<UpdateRequestProcessorFactory> getUpdateProcessors()
public CircuitBreakerManager getCircuitBreakerManager()
public void open()
public void close()
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)...
close
in interface Closeable
close
in interface AutoCloseable
close
in interface SolrMetricProducer
isClosed()
public int getOpenCount()
public boolean isClosed()
protected void finalize() throws Throwable
public void addCloseHook(CloseHook hook)
public static void verbose(Object... args)
public SolrRequestHandler getRequestHandler(String handlerName)
This function is thread safe.
public PluginBag<SolrRequestHandler> getRequestHandlers()
public SolrRequestHandler registerRequestHandler(String handlerName, SolrRequestHandler handler)
null
at its path
Once 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.
SolrRequestHandler
registered to this name null
if none.public SearchComponent getSearchComponent(String name)
public PluginBag<SearchComponent> getSearchComponents()
public UpdateHandler getUpdateHandler()
public RefCounted<SolrIndexSearcher> getSearcher()
RefCounted
<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 from
SolrQueryRequest.getSearcher()
instead.
If you still think you need to call this, consider withSearcher(IOFunction)
instead which is easier to
use.public <R> R withSearcher(IOFunction<SolrIndexSearcher,R> lambda) throws IOException
SolrIndexSearcher
. This is more convenient than using
getSearcher()
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.
IOException
public IndexFingerprint getIndexFingerprint(SolrIndexSearcher searcher, LeafReaderContext ctx, long maxVersion) throws IOException
searcher
- searcher that includes specified LeaderReaderContextctx
- LeafReaderContext of a segment to compute fingerprint ofmaxVersion
- maximum version number to consider for fingerprint computationIOException
- Can throw IOExceptionpublic RefCounted<SolrIndexSearcher> getRegisteredSearcher()
public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
RefCounted
<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.public RefCounted<SolrIndexSearcher> getRealtimeSearcher()
public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher)
public RefCounted<SolrIndexSearcher> openNewSearcher(boolean updateHandlerReopens, boolean realtime)
"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!
public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher, boolean updateHandlerReopens)
SolrIndexSearcher
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 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.
forceNew
- if true, force the open of a new index searcher regardless if there is already one open.returnSearcher
- if true, returns a SolrIndexSearcher
holder with the refcount already incremented.waitSearcher
- if non-null, will be filled in with a Future
that will return after the new searcher is registered.updateHandlerReopens
- if true, the UpdateHandler will be used when reopening a SolrIndexSearcher
.public boolean isReloaded()
public void closeSearcher()
public void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
public static void preDecorateResponse(SolrQueryRequest req, SolrQueryResponse rsp)
public static void postDecorateResponse(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
public static final void log(Throwable e)
public PluginBag<QueryResponseWriter> getResponseWriters()
public MemClassLoader getMemClassLoader()
public void fetchLatestSchema()
public final QueryResponseWriter getQueryResponseWriter(String writerName)
public final QueryResponseWriter getQueryResponseWriter(SolrQueryRequest request)
public QParserPlugin getQueryPlugin(String parserName)
public TransformerFactory getTransformerFactory(String name)
public void addTransformerFactory(String name, TransformerFactory factory)
public <T> T initPlugins(List<PluginInfo> pluginInfos, Map<String,T> registry, Class<T> type, String defClassName)
public <T> List<T> initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName)
defClassName
- The default classname if PluginInfo#className == nullpublic <T> T initPlugins(Map<String,T> registry, Class<T> type)
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 SolrConfigpublic ValueSourceParser getValueSourceParser(String parserName)
protected RestManager initRestManager() throws SolrException
SolrException
public CoreDescriptor getCoreDescriptor()
public IndexDeletionPolicyWrapper getDeletionPolicy()
public SolrSnapshotMetaDataManager getSnapshotMetaDataManager()
public ReentrantLock getRuleExpiryLock()
public String getDescription()
SolrInfoBean
getDescription
in interface SolrInfoBean
public SolrInfoBean.Category getCategory()
SolrInfoBean
getCategory
in interface SolrInfoBean
public com.codahale.metrics.MetricRegistry getMetricRegistry()
SolrInfoBean
MetricRegistry
that this component uses for metrics reporting
(default is null, which means no registry).getMetricRegistry
in interface SolrInfoBean
public Codec getCodec()
public void unloadOnClose(CoreDescriptor desc, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir)
public static void deleteUnloadedCore(CoreDescriptor cd, boolean deleteDataDir, boolean deleteInstanceDir)
public void addConfListener(Runnable runnable)
public boolean removeConfListener(Runnable runnable)
public static Runnable getConfListener(SolrCore core, ZkSolrResourceLoader zkSolrResourceLoader)
public void registerInfoBean(String name, SolrInfoBean solrInfoBean)
public void cleanupOldIndexDirectories(boolean reload)
public List<PluginInfo> getImplicitHandlers()
public BlobRepository.BlobContentRef loadDecodeAndCacheBlob(String key, BlobRepository.Decoder<Object> decoder)
SolrCoreAware.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.key
- A key in the format of name/version for a blob stored in the
CollectionAdminParams.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)public void runAsync(Runnable r)
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.
r
- the task to runCopyright © 2000-2020 Apache Software Foundation. All Rights Reserved.