Skip to content

Commit

Permalink
Small cleanup in ShardGetService (elastic#89578)
Browse files Browse the repository at this point in the history
We can use try-with-resources here, and remove a null check because IndexShard.get
never returns null.
  • Loading branch information
romseygeek authored Aug 24, 2022
1 parent 0aa0477 commit 5422860
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,19 @@ private GetResult innerGet(
boolean forceSyntheticSource
) throws IOException {
fetchSourceContext = normalizeFetchSourceContent(fetchSourceContext, gFields);

Engine.GetResult get = indexShard.get(
new Engine.Get(realtime, realtime, id).version(version)
.versionType(versionType)
.setIfSeqNo(ifSeqNo)
.setIfPrimaryTerm(ifPrimaryTerm)
);
if (get.exists() == false) {
get.close();
}

if (get == null || get.exists() == false) {
return new GetResult(shardId.getIndexName(), id, UNASSIGNED_SEQ_NO, UNASSIGNED_PRIMARY_TERM, -1, false, null, null, null);
}

try {
try (
Engine.GetResult get = indexShard.get(
new Engine.Get(realtime, realtime, id).version(version)
.versionType(versionType)
.setIfSeqNo(ifSeqNo)
.setIfPrimaryTerm(ifPrimaryTerm)
)
) {
if (get.exists() == false) {
return new GetResult(shardId.getIndexName(), id, UNASSIGNED_SEQ_NO, UNASSIGNED_PRIMARY_TERM, -1, false, null, null, null);
}
// break between having loaded it from translog (so we only have _source), and having a document to load
return innerGetFetch(id, gFields, fetchSourceContext, get, forceSyntheticSource);
} finally {
get.close();
}
}

Expand Down

0 comments on commit 5422860

Please sign in to comment.