close DV producers on exception

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1619609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-08-21 22:15:01 +00:00
parent 75ed12e0c7
commit 999f7ab30d
1 changed files with 63 additions and 47 deletions

View File

@ -48,11 +48,15 @@ class SegmentDocValuesProducer extends DocValuesProducer {
final List<Long> dvGens = new ArrayList<>();
SegmentDocValuesProducer(SegmentCommitInfo si, Directory dir, FieldInfos fieldInfos, SegmentDocValues segDocValues, DocValuesFormat dvFormat) throws IOException {
boolean success = false;
try {
Version ver = si.info.getVersion();
if (ver != null && ver.onOrAfter(Version.LUCENE_4_9_0)) {
DocValuesProducer baseProducer = null;
for (FieldInfo fi : fieldInfos) {
if (!fi.hasDocValues()) continue;
if (!fi.hasDocValues()) {
continue;
}
long docValuesGen = fi.getDocValuesGen();
if (docValuesGen == -1) {
if (baseProducer == null) {
@ -76,7 +80,9 @@ class SegmentDocValuesProducer extends DocValuesProducer {
// we initialize each DocValuesProducer once per gen.
Map<Long,List<FieldInfo>> genInfos = new HashMap<>();
for (FieldInfo fi : fieldInfos) {
if (!fi.hasDocValues()) continue;
if (!fi.hasDocValues()) {
continue;
}
List<FieldInfo> genFieldInfos = genInfos.get(fi.getDocValuesGen());
if (genFieldInfos == null) {
genFieldInfos = new ArrayList<>();
@ -103,6 +109,16 @@ class SegmentDocValuesProducer extends DocValuesProducer {
}
}
}
success = true;
} finally {
if (success == false) {
try {
segDocValues.decRef(dvGens);
} catch (Throwable t) {
// Ignore so we keep throwing first exception
}
}
}
}
@Override