protected ZoieMultiReader<R> newInstance(IndexReader inner,IndexReader[] subReaders) throws IOException{ return new ZoieMultiReader<R>(inner, subReaders ,_decorator); }
@SuppressWarnings("unchecked") private ZoieMultiReader(DirectoryReader in, IndexReaderDecorator<R> decorator, ZoieSubReaderWrapper<R> wrapper) throws IOException { super(in, wrapper); _subZoieReaders = (List<ZoieSegmentReader<R>>) getSequentialSubReaders(); _decorator = decorator; _readerMap = new HashMap<String, ZoieSegmentReader<R>>(); _decoratedReaders = null; init(); }
public UIDFilter(long[] filteredIDs, ZoieMultiReader<?> reader) { _filteredIDs = filteredIDs; _subZoieReaders = reader.getSubReaders(); }
public void commitDeletes() throws IOException { ZoieMultiReader<R> reader = null; synchronized (this) { reader = openIndexReader(); if (reader == null) { return; } reader.incZoieRef(); reader.commitDeletes(); reader.decZoieRef(); } }
/** * 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; } }
protected List<ZoieMultiReader<R>> loadArchives() { List<ZoieMultiReader<R>> archives = new ArrayList<ZoieMultiReader<R>>(); long t0 = System.currentTimeMillis(); List<Directory> dirs = _dirMgrFactory.getAllArchivedDirectories(); for (Directory dir : dirs) { DirectoryReader reader; try { reader = DirectoryReader.open(dir); ZoieMultiReader<R> zoiereader = new ZoieMultiReader<R>(reader, _decorator); // Initialize docIdMapper DocIDMapper mapper = _zConfig.getDocidMapperFactory().getDocIDMapper(zoiereader); zoiereader.setDocIDMapper(mapper); archives.add(zoiereader); } catch (CorruptIndexException e) { log.error("corruptedIndex", e); } catch (IOException e) { log.error("IOException", e); } } log.info("load " + dirs.size() + " archived indices of " + getSizeBytes() + " bytes in " + (System.currentTimeMillis() - t0) + "ms"); return archives; }
@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(); } }
/** * 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; }
public boolean isDeleted(int docid) { int idx = readerIndex(docid); ZoieSegmentReader<R> subReader = _subZoieReaders.get(idx); return subReader.isDeleted(docid - readerBase(idx)); }
int docCount = reader.maxDoc(); final ZoieSegmentReader<?>[] subreaders = (ZoieSegmentReader<?>[]) (reader .getSequentialSubReaders()); final int[] starts = reader.getStarts();
@Override public void setDelDocIds() { ZoieIndexReader<R>[] subReaders = getSequentialSubReaders(); for(ZoieIndexReader<R> subReader : subReaders) { subReader.setDelDocIds(); } }
@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(); } } }
@Override public byte[] getStoredValue(long uid) throws IOException { int docid = this.getDocIDMaper().getDocID(uid); if (docid < 0) return null; int idx = readerIndex(docid); if (idx < 0) return null; ZoieIndexReader<R> subReader = _subZoieReaders.get(idx); return subReader.getStoredValue(uid); }
private int readerIndex(int n){ return readerIndex(n,_starts,_starts.length); }
public DocIDMapper<?> getDocIDMapper(ZoieMultiReader<?> multireader) { final ZoieSegmentReader<?>[] subreaders =(ZoieSegmentReader<?>[])(multireader.getSequentialSubReaders()); final int[] starts = multireader.getStarts(); for (int i = 0; i < subreaders.length; ++i){ ZoieSegmentReader<?> subReader = subreaders[i]; DocIDMapper<?> mapper = subReader.getDocIDMaper(); if (mapper == null){ mapper = new DocIDMapperImpl(subReader.getUIDArray()); } subReader.setDocIDMapper(mapper); } final DocIDMapper[] mappers = new DocIDMapper[subreaders.length]; for(int i=0; i< subreaders.length; i++) { mappers[i] = subreaders[i].getDocIDMaper(); } final int bound = subreaders.length-1; return new DefaultDocIDMapper(bound, mappers, starts); }
public ZoieMultiReader(IndexReader in,IndexReader[] subReaders,IndexReaderDecorator<R> decorator) throws IOException { super(in,decorator); _readerMap = new HashMap<String,ZoieSegmentReader<R>>(); _decoratedReaders = null; init(subReaders); }
/** * 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; } } }
@Override public void returnIndexReaders(List<ZoieMultiReader<R>> readers) { for (ZoieMultiReader<R> r : readers) { r.decZoieRef(); } }