Skip to content

Commit

Permalink
Merge pull request LinkedInAttic#7 from jhartman/master
Browse files Browse the repository at this point in the history
Fixing reference counting issues Dmytro and Rahul reported.
  • Loading branch information
jhartman committed Jul 23, 2013
2 parents a503bc1 + 6f61697 commit b6b7ba7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
9 changes: 4 additions & 5 deletions zoie-core/src/main/java/proj/zoie/api/ZoieMultiReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ZoieMultiReader<R extends IndexReader> extends ZoieIndexReader<R>
private int[] _starts;
private List<R> _decoratedReaders;

public ZoieMultiReader(IndexReader in,IndexReaderDecorator<R> decorator) throws IOException
public ZoieMultiReader(IndexReader in, IndexReaderDecorator<R> decorator) throws IOException
{
super(in,decorator);
_readerMap = new HashMap<String,ZoieSegmentReader<R>>();
Expand All @@ -54,7 +54,7 @@ public ZoieMultiReader(IndexReader in,IndexReaderDecorator<R> decorator) throws
init(subReaders);
}

public ZoieMultiReader(IndexReader in,IndexReader[] subReaders,IndexReaderDecorator<R> decorator) throws IOException {
public ZoieMultiReader(IndexReader in,IndexReader[] subReaders, IndexReaderDecorator<R> decorator) throws IOException {
super(in,decorator);
_readerMap = new HashMap<String,ZoieSegmentReader<R>>();
_decoratedReaders = null;
Expand Down Expand Up @@ -109,7 +109,7 @@ else if (subReader instanceof SegmentReader){
for (ZoieSegmentReader<R> subReader : _subZoieReaders){
R decoratedReader = subReader.getDecoratedReader();
decoratedList.add(decoratedReader);
subReader.incSegmentRef();
subReader.incZoieRef();
}
_decoratedReaders = decoratedList;
}
Expand Down Expand Up @@ -262,8 +262,7 @@ protected void doClose() throws IOException {
}
finally{
for (ZoieSegmentReader<R> r : _subZoieReaders){
// r.decRef();
r.decSegmentRef();
r.decZoieRef();
}
}
}
Expand Down
20 changes: 1 addition & 19 deletions zoie-core/src/main/java/proj/zoie/api/ZoieSegmentReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ protected synchronized void doClose() throws IOException {
public void decRef() throws IOException {
// not synchronized, since it doesn't do anything anyway
}

@Override
public int numDocs() {
if (_currentDelDocIds != null) {
Expand All @@ -360,24 +361,5 @@ public ZoieSegmentReader<R> copy() throws IOException
{
return new ZoieSegmentReader<R>(this, this.in);
}
private AtomicLong zoieRefSegmentCounter = new AtomicLong(1);

public void incSegmentRef() {
zoieRefSegmentCounter.incrementAndGet();
}

public void decSegmentRef() {
long refCount = zoieRefSegmentCounter.decrementAndGet();
if (refCount < 0) {
throw new IllegalStateException("The segment ref count shouldn't be less than zero");
}
if (refCount == 0) {
try {
doClose();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

}
2 changes: 1 addition & 1 deletion zoie-core/src/test/java/proj/zoie/test/ZoieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public void testPurgeFilter() throws Exception {

log.info("new numdocs: "+numDocs);
//TODO for some reasons numdocs might be 6. I've put a temporary fix to avoid sporadical failures
TestCase.assertTrue("numdDocs should be 5" + numDocs, (numDocs == 5 || numDocs == 6));
TestCase.assertTrue("numdDocs should be 5 but is " + numDocs, (numDocs == 5 || numDocs == 6));

idxSystem.returnIndexReaders(readers);

Expand Down

0 comments on commit b6b7ba7

Please sign in to comment.