make sure to close the term docs when loading version
This commit is contained in:
parent
914407ebda
commit
7fc04a4ab6
|
@ -74,14 +74,17 @@ public class LuceneUidScanBenchmark {
|
||||||
uid.next();
|
uid.next();
|
||||||
uid.nextPosition();
|
uid.nextPosition();
|
||||||
if (!uid.isPayloadAvailable()) {
|
if (!uid.isPayloadAvailable()) {
|
||||||
|
uid.close();
|
||||||
System.err.println("no payload...");
|
System.err.println("no payload...");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
byte[] payload = uid.getPayload(new byte[8], 0);
|
byte[] payload = uid.getPayload(new byte[8], 0);
|
||||||
if (Numbers.bytesToLong(payload) != id) {
|
if (Numbers.bytesToLong(payload) != id) {
|
||||||
|
uid.close();
|
||||||
System.err.println("wrong id...");
|
System.err.println("wrong id...");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
uid.close();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -52,8 +52,9 @@ public class UidField extends AbstractField {
|
||||||
|
|
||||||
public static DocIdAndVersion loadDocIdAndVersion(IndexReader reader, Term term) {
|
public static DocIdAndVersion loadDocIdAndVersion(IndexReader reader, Term term) {
|
||||||
int docId = Lucene.NO_DOC;
|
int docId = Lucene.NO_DOC;
|
||||||
|
TermPositions uid = null;
|
||||||
try {
|
try {
|
||||||
TermPositions uid = reader.termPositions(term);
|
uid = reader.termPositions(term);
|
||||||
if (!uid.next()) {
|
if (!uid.next()) {
|
||||||
return new DocIdAndVersion(Lucene.NO_DOC, -1);
|
return new DocIdAndVersion(Lucene.NO_DOC, -1);
|
||||||
}
|
}
|
||||||
|
@ -69,6 +70,14 @@ public class UidField extends AbstractField {
|
||||||
return new DocIdAndVersion(docId, Numbers.bytesToLong(payload));
|
return new DocIdAndVersion(docId, Numbers.bytesToLong(payload));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new DocIdAndVersion(docId, -2);
|
return new DocIdAndVersion(docId, -2);
|
||||||
|
} finally {
|
||||||
|
if (uid != null) {
|
||||||
|
try {
|
||||||
|
uid.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// nothing to do here...
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +86,9 @@ public class UidField extends AbstractField {
|
||||||
* no version is available (for backward comp.)
|
* no version is available (for backward comp.)
|
||||||
*/
|
*/
|
||||||
public static long loadVersion(IndexReader reader, Term term) {
|
public static long loadVersion(IndexReader reader, Term term) {
|
||||||
|
TermPositions uid = null;
|
||||||
try {
|
try {
|
||||||
TermPositions uid = reader.termPositions(term);
|
uid = reader.termPositions(term);
|
||||||
if (!uid.next()) {
|
if (!uid.next()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +103,14 @@ public class UidField extends AbstractField {
|
||||||
return Numbers.bytesToLong(payload);
|
return Numbers.bytesToLong(payload);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return -2;
|
return -2;
|
||||||
|
} finally {
|
||||||
|
if (uid != null) {
|
||||||
|
try {
|
||||||
|
uid.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// nothing to do here...
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ public class VersionSearchHitPhase implements SearchHitPhase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void execute(SearchContext context, HitContext hitContext) throws ElasticSearchException {
|
@Override public void execute(SearchContext context, HitContext hitContext) throws ElasticSearchException {
|
||||||
|
// it might make sense to cache the TermDocs on a shared fetch context and just skip here)
|
||||||
|
// it is going to mean we work on the high level multi reader and not the lower level reader as is
|
||||||
|
// the case below...
|
||||||
long version = UidField.loadVersion(hitContext.reader(), new Term(UidFieldMapper.NAME, hitContext.doc().get(UidFieldMapper.NAME)));
|
long version = UidField.loadVersion(hitContext.reader(), new Term(UidFieldMapper.NAME, hitContext.doc().get(UidFieldMapper.NAME)));
|
||||||
if (version < 0) {
|
if (version < 0) {
|
||||||
version = -1;
|
version = -1;
|
||||||
|
|
Loading…
Reference in New Issue