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.nextPosition();
|
||||
if (!uid.isPayloadAvailable()) {
|
||||
uid.close();
|
||||
System.err.println("no payload...");
|
||||
break;
|
||||
}
|
||||
byte[] payload = uid.getPayload(new byte[8], 0);
|
||||
if (Numbers.bytesToLong(payload) != id) {
|
||||
uid.close();
|
||||
System.err.println("wrong id...");
|
||||
break;
|
||||
}
|
||||
uid.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -52,8 +52,9 @@ public class UidField extends AbstractField {
|
|||
|
||||
public static DocIdAndVersion loadDocIdAndVersion(IndexReader reader, Term term) {
|
||||
int docId = Lucene.NO_DOC;
|
||||
TermPositions uid = null;
|
||||
try {
|
||||
TermPositions uid = reader.termPositions(term);
|
||||
uid = reader.termPositions(term);
|
||||
if (!uid.next()) {
|
||||
return new DocIdAndVersion(Lucene.NO_DOC, -1);
|
||||
}
|
||||
|
@ -69,6 +70,14 @@ public class UidField extends AbstractField {
|
|||
return new DocIdAndVersion(docId, Numbers.bytesToLong(payload));
|
||||
} catch (Exception e) {
|
||||
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.)
|
||||
*/
|
||||
public static long loadVersion(IndexReader reader, Term term) {
|
||||
TermPositions uid = null;
|
||||
try {
|
||||
TermPositions uid = reader.termPositions(term);
|
||||
uid = reader.termPositions(term);
|
||||
if (!uid.next()) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -93,6 +103,14 @@ public class UidField extends AbstractField {
|
|||
return Numbers.bytesToLong(payload);
|
||||
} catch (Exception e) {
|
||||
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 {
|
||||
// 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)));
|
||||
if (version < 0) {
|
||||
version = -1;
|
||||
|
|
Loading…
Reference in New Issue