@Override public void returnIndexReaders(List<ZoieMultiReader<R>> readers) { for (ZoieMultiReader<R> r : readers) { r.decZoieRef(); } }
@Override public void returnIndexReaders(List<ZoieMultiReader<R>> readers) { for (ZoieMultiReader<R> r : readers) { r.decZoieRef(); } }
/** * Closes the index reader */ public void closeReader() { if (_currentReader != null) { _currentReader.decZoieRef(); int count = _currentReader.getInnerRefCount(); log.info("final closeReader in dispenser and current refCount: " + count); if (count > 0) { log.warn("final closeReader call with reference count == " + count + " greater than 0. Potentially, " + "the IndexReaders are not properly return to ZoieSystem."); } _currentReader = null; } } }
/** * Closes the index reader */ public void closeReader() { if (_currentReader != null) { _currentReader.decZoieRef(); int count = _currentReader.getInnerRefCount(); log.info("final closeReader in dispenser and current refCount: " + count); if (count > 0) { log.warn("final closeReader call with reference count == " + count + " greater than 0. Potentially, " + "the IndexReaders are not properly return to ZoieSystem."); } _currentReader = null; } } }
/** * swap the disk IndexReader cached in mem. In order to count the reference properly, * we need to lock the access to _mem so that it is safe to compare whether the old * and new disk IndexReader are different. decZoieRef the old IndexReader only when they * differ. * @param diskIndexReader the new disk IndexReader * @param oldDiskReader the old disk IndexReader from old mem * @param mem the new mem */ private void lockAndSwapMem(ZoieMultiReader<R> diskIndexReader, ZoieMultiReader<R> oldDiskReader, Mem<R> mem) { synchronized (_memLock) { if (oldDiskReader != diskIndexReader) { if (oldDiskReader != null) { oldDiskReader.decZoieRef(); } diskIndexReader.incZoieRef(); } _mem = mem; } }
/** * swap the disk IndexReader cached in mem. In order to count the reference properly, * we need to lock the access to _mem so that it is safe to compare whether the old * and new disk IndexReader are different. decZoieRef the old IndexReader only when they * differ. * @param diskIndexReader the new disk IndexReader * @param oldDiskReader the old disk IndexReader from old mem * @param mem the new mem */ private void lockAndSwapMem(ZoieMultiReader<R> diskIndexReader, ZoieMultiReader<R> oldDiskReader, Mem<R> mem) { synchronized (_memLock) { if (oldDiskReader != diskIndexReader) { if (oldDiskReader != null) { oldDiskReader.decZoieRef(); } diskIndexReader.incZoieRef(); } _mem = mem; } }
/** * The readers removed will also be decZoieRef(). But the readers to be added will NOT get incZoieRef(), * which means we assume the newly added ones have already been incRef(). * remove and add should be <b>disjoint</b> * @param remove the readers to be remove. This has to be disjoint from add. * @param add */ public synchronized void swapArchives(List<ZoieMultiReader<R>> remove, List<ZoieMultiReader<R>> add) { List<ZoieMultiReader<R>> archives = new LinkedList<ZoieMultiReader<R>>(add); if (!box._archives.containsAll(remove)) { log.error("swapArchives: potential sync issue. "); } archives.addAll(box._archives); archives.removeAll(remove); for (ZoieMultiReader<R> r : remove) { r.decZoieRef(); if (log.isDebugEnabled()) { log.debug("remove time " + r.directory() + " refCount: " + r.getInnerRefCount()); } } Box<R, D> newbox = new Box<R, D>(archives, box._archiveZoies, box._retiree, box._actives, _decorator); box = newbox; }
/** * The readers removed will also be decZoieRef(). But the readers to be added will NOT get incZoieRef(), * which means we assume the newly added ones have already been incRef(). * remove and add should be <b>disjoint</b> * @param remove the readers to be remove. This has to be disjoint from add. * @param add */ public synchronized void swapArchives(List<ZoieMultiReader<R>> remove, List<ZoieMultiReader<R>> add) { List<ZoieMultiReader<R>> archives = new LinkedList<ZoieMultiReader<R>>(add); if (!box._archives.containsAll(remove)) { log.error("swapArchives: potential sync issue. "); } archives.addAll(box._archives); archives.removeAll(remove); for (ZoieMultiReader<R> r : remove) { r.decZoieRef(); if (log.isDebugEnabled()) { log.debug("remove time " + r.directory() + " refCount: " + r.getInnerRefCount()); } } Box<R, D> newbox = new Box<R, D>(archives, box._archiveZoies, box._retiree, box._actives, _decorator); box = newbox; }
@Override public void close() { super.close(); if (_currentReader != null) { _currentReader.decZoieRef(); } if (_directory != null) { try { _directory.close(); if (_backingdir != null) FileUtil.rmDir(_backingdir); } catch (IOException e) { log.error(e); } } }
public void commitDeletes() throws IOException { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return; } reader.incZoieRef(); reader.commitDeletes(); reader.decZoieRef(); } }
@Override public void close() { super.close(); if (_currentReader != null) { _currentReader.decZoieRef(); } if (_directory != null) { try { _directory.close(); if (_backingdir != null) FileUtil.rmDir(_backingdir); } catch (IOException e) { log.error(e); } } }
public void commitDeletes() throws IOException { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return; } reader.incZoieRef(); reader.commitDeletes(); reader.decZoieRef(); } }
@Override public int getNumdocs() { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return 0; } reader.incZoieRef(); } int numDocs = reader.numDocs(); reader.decZoieRef(); return numDocs; }
@Override public int getNumdocs() { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return 0; } reader.incZoieRef(); } int numDocs = reader.numDocs(); reader.decZoieRef(); return numDocs; }
public void markDeletes(LongSet delDocs) throws IOException { if (delDocs != null && delDocs.size() > 0) { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return; } reader.incZoieRef(); reader.markDeletes(delDocs, _delDocs); reader.decZoieRef(); } } }
public void markDeletes(LongSet delDocs) throws IOException { if (delDocs != null && delDocs.size() > 0) { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return; } reader.incZoieRef(); reader.markDeletes(delDocs, _delDocs); reader.decZoieRef(); } } }
public void refreshDiskReader() throws IOException { log.info("refreshing disk reader ..."); ZoieMultiReader<R> diskIndexReader = null; try { // load a new reader, not in the lock because this should be done in the background // and should not contend with the readers diskIndexReader = _diskIndex.getNewReader(); } catch (IOException e) { ZoieHealth.setFatal(); log.error(e.getMessage(), e); throw e; } synchronized (_memLock) { Mem<R> oldMem = _mem; ZoieMultiReader<R> oldDiskIndexReader = oldMem.get_diskIndexReader(); if (diskIndexReader != oldDiskIndexReader) { Mem<R> mem = new Mem<R>(oldMem.get_memIndexA(), oldMem.get_memIndexB(), oldMem.get_currentWritable(), oldMem.get_currentReadOnly(), diskIndexReader); if (oldDiskIndexReader != null) { oldDiskIndexReader.decZoieRef(); } diskIndexReader.incZoieRef(); _mem = mem; } } log.info("disk reader refreshed"); }
@Override public void refresh() throws IOException { synchronized (this) { ZoieMultiReader<R> reader = null; if (_currentReader == null) { reader = openIndexReaderInternal(); } else { reader = _currentReader.reopen(); if (reader != _currentReader) { DocIDMapper mapper = _idxMgr._docIDMapperFactory.getDocIDMapper(reader); reader.setDocIDMapper(mapper); } } if (_currentReader != reader) { ZoieMultiReader<R> oldReader = _currentReader; _currentReader = reader; if (oldReader != null) { oldReader.decZoieRef(); } } LongSet delDocs = _delDocs; clearDeletes(); markDeletes(delDocs); // re-mark deletes commitDeletes(); } }
/** * Clean up * @throws IOException */ public void close() { Mem<R> mem = _mem; if (mem.get_memIndexA() != null) { mem.get_memIndexA().close(); } if (mem.get_memIndexB() != null) { mem.get_memIndexB().close(); } if (mem.get_diskIndexReader() != null) { mem.get_diskIndexReader().decZoieRef(); _diskIndex.close(); } }
/** * Clean up * @throws IOException */ public void close() { Mem<R> mem = _mem; if (mem.get_memIndexA() != null) { mem.get_memIndexA().close(); } if (mem.get_memIndexB() != null) { mem.get_memIndexB().close(); } if (mem.get_diskIndexReader() != null) { mem.get_diskIndexReader().decZoieRef(); _diskIndex.close(); } }