Get API: a get for a document that does not exists can cause open file handles leak, closes #1167.

This commit is contained in:
Shay Banon 2011-07-26 22:57:34 +03:00
parent cbde265ab8
commit 8dff55c79e
3 changed files with 17 additions and 5 deletions

View File

@ -133,20 +133,28 @@ public class TransportGetAction extends TransportShardSingleOperationAction<GetR
if (get.exists()) {
type = typeX;
break;
} else {
get.release();
}
}
if (get == null || !get.exists()) {
if (get == null) {
return new GetResponse(index, type, id, -1, false, null, null);
}
if (!get.exists()) {
// no need to release here as well..., we release in the for loop for non exists
return new GetResponse(index, type, id, -1, false, null, null);
}
} else {
get = indexShard.get(new Engine.Get(realtime, UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(type, id))).loadSource(loadSource));
if (!get.exists()) {
get.release();
return new GetResponse(index, type, id, -1, false, null, null);
}
}
DocumentMapper docMapper = indexService.mapperService().documentMapper(type);
if (docMapper == null) {
get.release();
return new GetResponse(index, type, id, -1, false, null, null);
}
@ -307,9 +315,7 @@ public class TransportGetAction extends TransportShardSingleOperationAction<GetR
return new GetResponse(index, type, id, get.version(), get.exists(), sourceRequested ? source : null, fields);
}
} finally {
if (get.searcher() != null) {
get.searcher().release();
}
get.release();
}
}

View File

@ -666,6 +666,12 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
public UidField.DocIdAndVersion docIdAndVersion() {
return docIdAndVersion;
}
public void release() {
if (searcher != null) {
searcher.release();
}
}
}
}

View File

@ -340,7 +340,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
//TODO: A better exception goes here
throw new EngineException(shardId(), "failed to load document", e);
}
searcher.release();
return GetResult.NOT_EXISTS;
} finally {
rwl.readLock().unlock();