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()) { if (get.exists()) {
type = typeX; type = typeX;
break; 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); return new GetResponse(index, type, id, -1, false, null, null);
} }
} else { } else {
get = indexShard.get(new Engine.Get(realtime, UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(type, id))).loadSource(loadSource)); get = indexShard.get(new Engine.Get(realtime, UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(type, id))).loadSource(loadSource));
if (!get.exists()) { if (!get.exists()) {
get.release();
return new GetResponse(index, type, id, -1, false, null, null); return new GetResponse(index, type, id, -1, false, null, null);
} }
} }
DocumentMapper docMapper = indexService.mapperService().documentMapper(type); DocumentMapper docMapper = indexService.mapperService().documentMapper(type);
if (docMapper == null) { if (docMapper == null) {
get.release();
return new GetResponse(index, type, id, -1, false, null, null); 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); return new GetResponse(index, type, id, get.version(), get.exists(), sourceRequested ? source : null, fields);
} }
} finally { } finally {
if (get.searcher() != null) { get.release();
get.searcher().release();
}
} }
} }

View File

@ -666,6 +666,12 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
public UidField.DocIdAndVersion docIdAndVersion() { public UidField.DocIdAndVersion docIdAndVersion() {
return 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 //TODO: A better exception goes here
throw new EngineException(shardId(), "failed to load document", e); throw new EngineException(shardId(), "failed to load document", e);
} }
searcher.release();
return GetResult.NOT_EXISTS; return GetResult.NOT_EXISTS;
} finally { } finally {
rwl.readLock().unlock(); rwl.readLock().unlock();