MCPcopy Create free account
hub / github.com/apache/solr / openNewSearcher

Method openNewSearcher

solr/core/src/java/org/apache/solr/core/SolrCore.java:2319–2488  ·  view source on GitHub ↗

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 wo

(
      boolean updateHandlerReopens, boolean realtime)

Source from the content-addressed store, hash-verified

2317 * currently never become "registered" (since it currently lacks caching).
2318 *
2319 * <p>realtimeSearcher is updated to the latest opened searcher, regardless of the value of
2320 * "realtime".
2321 *
2322 * <p>This method acquires openSearcherLock - do not call with searchLock held!
2323 */
2324 public RefCounted<SolrIndexSearcher> openNewSearcher(
2325 boolean updateHandlerReopens, boolean realtime) {
2326 if (isClosed()) { // catch some errors quicker
2327 throw new SolrCoreState.CoreIsClosedException();
2328 }
2329
2330 SolrIndexSearcher tmp;
2331 RefCounted<SolrIndexSearcher> newestSearcher = null;
2332
2333 openSearcherLock.lock();
2334 try {
2335 String newIndexDir = getNewIndexDir();
2336 String indexDirFile = null;
2337 String newIndexDirFile = null;
2338
2339 // if it's not a normal near-realtime update, check that paths haven't changed.
2340 if (!updateHandlerReopens) {
2341 indexDirFile = getDirectoryFactory().normalize(getIndexDir());
2342 newIndexDirFile = getDirectoryFactory().normalize(newIndexDir);
2343 }
2344
2345 synchronized (searcherLock) {
2346 newestSearcher = realtimeSearcher;
2347 if (newestSearcher != null) {
2348 newestSearcher.incref(); // the matching decref is in the finally block
2349 }
2350 }
2351
2352 if (newestSearcher != null
2353 && (updateHandlerReopens || indexDirFile.equals(newIndexDirFile))) {
2354
2355 DirectoryReader newReader;
2356 DirectoryReader currentReader = newestSearcher.get().getRawReader();
2357
2358 // SolrCore.verbose("start reopen from",previousSearcher,"writer=",writer);
2359
2360 RefCounted<IndexWriter> writer = getSolrCoreState().getIndexWriter(null);
2361
2362 try {
2363 if (writer != null) {
2364 // if in NRT mode, open from the writer
2365 newReader = DirectoryReader.openIfChanged(currentReader, writer.get(), true);
2366 } else {
2367 // verbose("start reopen without writer, reader=", currentReader);
2368 newReader = DirectoryReader.openIfChanged(currentReader);
2369 // verbose("reopen result", newReader);
2370 }
2371 } finally {
2372 if (writer != null) {
2373 writer.decref();
2374 }
2375 }
2376

Callers 5

getRealtimeSearcherMethod · 0.95
getSearcherMethod · 0.95
runMethod · 0.45
testDocValuesMethod · 0.45
testDocValuesMethod · 0.45

Calls 15

isClosedMethod · 0.95
getNewIndexDirMethod · 0.95
getDirectoryFactoryMethod · 0.95
getIndexDirMethod · 0.95
getSolrCoreStateMethod · 0.95
getLatestSchemaMethod · 0.95
newHolderMethod · 0.95
getRawReaderMethod · 0.80
isCachingEnabledMethod · 0.80
debugMethod · 0.80
getMethod · 0.65
getSchemaMethod · 0.65

Tested by 3

runMethod · 0.36
testDocValuesMethod · 0.36
testDocValuesMethod · 0.36