protected static void waitForWarming(SolrCore core) throws InterruptedException { RefCounted<SolrIndexSearcher> registeredSearcher = core.getRegisteredSearcher(); RefCounted<SolrIndexSearcher> newestSearcher = core.getNewestSearcher(false); while (registeredSearcher == null || registeredSearcher.get() != newestSearcher.get()) { if (registeredSearcher != null) { registeredSearcher.decref(); } newestSearcher.decref(); Thread.sleep(50); registeredSearcher = core.getRegisteredSearcher(); newestSearcher = core.getNewestSearcher(false); } registeredSearcher.decref(); newestSearcher.decref(); }
private RefCounted<SolrIndexSearcher> newHolder(SolrIndexSearcher newSearcher) { RefCounted<SolrIndexSearcher> holder = new RefCounted<SolrIndexSearcher>(newSearcher) { public void close() { try { synchronized(searcherLock) { // it's possible for someone to get a reference via the _searchers queue // and increment the refcount while RefCounted.close() is being called. // we check the refcount again to see if this has happened and abort the close. // This relies on the RefCounted class allowing close() to be called every // time the counter hits zero. if (refcount.get() > 0) return; _searchers.remove(this); } resource.close(); } catch (IOException e) { log.error("Error closing searcher:" + SolrException.toStr(e)); } } }; holder.incref(); // set ref count to 1 to account for this._searcher return holder; }
public void decref() { if (refcount.decrementAndGet() == 0) { close(); } }
@Override public void close() { lock.writeLock().lock(); try { if(current != null){ Object version = log.isDebugEnabled() ? current.get().getVersion() : null; current.decref(); log.debug(" > close EntityCache for version {} (remaining refCount: {})", version , current.getRefcount()); current = null; } } finally{ lock.writeLock().unlock(); } }
@Override public void decref() { super.decref(); if(log.isDebugEnabled()){ log.debug(" > decrease RefCount for EntityCache for version {} to {}", get().getVersion(), current.getRefcount()); } } /**
/** * Getter for the EntityCache * @return the cache or <code>null</code> if no one is configured */ public EntityCache getDocumentCache(){ return documentCacheRef != null ? documentCacheRef.get() : null; } /**
lock.readLock().lock(); try { if(current != null && current.get().getVersion().equals(version)){ current.incref(); //this increase is for the holder of the returned instance log.debug(" > increase RefCount for EntityCache for version {} to {}", version, current.getRefcount()); return current; if(current == null || !current.get().getVersion().equals(version)){ if(current != null){ log.debug(" > invalidate EntityCache for version {}", current.get().getVersion()); current.decref(); log.debug(" ... {} remaining users for invalidated Cache", current.getRefcount()); current = null; current.incref(); current.incref(); //this increase is for the holder of the returned instance log.debug(" > increase RefCount for EntityCache for version {} to {}", version, current.getRefcount()); return current; } finally {
_searcher.incref(); return _searcher; } else { _searcher.incref(); return _searcher; } else { IndexReader currentReader = newestSearcher.get().getReader(); IndexReader newReader = currentReader.reopen(); } finally { if (newestSearcher != null) { newestSearcher.decref(); final RefCounted<SolrIndexSearcher> newSearchHolder=newHolder(newSearcher); if (returnSearcher) newSearchHolder.incref(); currSearcherHolder.incref(); final SolrIndexSearcher currSearcher = currSearcherHolder==null ? null : currSearcherHolder.get(); if (currSearcherHolder != null) currSearcherHolder.decref();
/** * Frees resources associated with this request, this method <b>must</b> * be called when the object is no longer in use. */ public void close() { if (searcherHolder!=null) { searcherHolder.decref(); searcherHolder = null; } }
public SolrIndexSearcher getSearcher() { return searcherRef.get(); }
public SolrIndexSearcher getSearcher() { if(core == null) return null;//a request for a core admin will no have a core // should this reach out and get a searcher from the core singleton, or // should the core populate one in a factory method to create requests? // or there could be a setSearcher() method that Solr calls if (searcherHolder==null) { searcherHolder = core.getSearcher(); } return searcherHolder.get(); }
public void closeSearcher() { log.info(logid+"Closing main searcher on request."); synchronized (searcherLock) { if (_searcher != null) { _searcher.decref(); // dec refcount for this._searcher _searcher=null; // isClosed() does check this infoRegistry.remove("currentSearcher"); } } }
/** * Return the newest {@link RefCounted}<{@link SolrIndexSearcher}> with * the reference count incremented. It <b>must</b> 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> getNewestSearcher(boolean openNew) { synchronized (searcherLock) { if (_searchers.isEmpty()) { if (!openNew) return null; // Not currently implemented since simply calling getSearcher during inform() // can result in a deadlock. Right now, solr always opens a searcher first // before calling inform() anyway, so this should never happen. throw new UnsupportedOperationException(); } RefCounted<SolrIndexSearcher> newest = _searchers.getLast(); newest.incref(); return newest; } }
/** * Updates the configuration based on the current version of the * {@link #getIndex()}. If the SolrCore was not updated this will do * nothing. */ public void update(){ RefCounted<SolrIndexSearcher> searcherRef = index.getSearcher(); try { update(getIndexVersion(searcherRef.get()), searcherRef.get()); } finally { searcherRef.decref(); //decrease the count on the searcher } } /**
public FieldLoaderImpl(IndexReader reader) { this.reader = reader; loadedFieldsFields = new ArrayList<Field>(solrDocfields.size()); for(String loadedFieldName : solrDocfields){ loadedFieldsFields.add(new StringField(LOADED_FIELDS_FIELD_NAME, loadedFieldName, Store.NO)); } if(documentCacheRef != null){ this.cache = documentCacheRef.get(); } else { this.cache = null; } }
public Object call() throws Exception { try { // signal that we no longer need to decrement // the count *before* registering the searcher since // registerSearcher will decrement even if it errors. decrementOnDeckCount[0]=false; registerSearcher(newSearchHolder); } catch (Throwable e) { SolrException.logOnce(log,null,e); } finally { // we are all done with the old searcher we used // for warming... if (currSearcherHolderF!=null) currSearcherHolderF.decref(); } return null; } }
private void registerSearcher(RefCounted<SolrIndexSearcher> newSearcherHolder) throws IOException { synchronized (searcherLock) { try { if (_searcher != null) { _searcher.decref(); // dec refcount for this._searcher _searcher=null; } _searcher = newSearcherHolder; SolrIndexSearcher newSearcher = newSearcherHolder.get(); newSearcher.register(); // register subitems (caches) log.info(logid+"Registered new searcher " + newSearcher); } catch (Throwable e) { log(e); } finally { // wake up anyone waiting for a searcher // even in the face of errors. onDeckSearchers--; searcherLock.notifyAll(); } } }
/** * closes the {@link SolrEntityCache} */ protected void close(){ if(log.isDebugEnabled()){ log.debug(" > close EntityCache for version {}", current.get().getVersion()); } ((SolrEntityCache)get()).close(); }