diff --git a/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java b/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java index 1608489e39eec..2bc517745f7e2 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java +++ b/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java @@ -114,8 +114,7 @@ protected Translog.Operation nextOperation() throws IOException { private void loadNextBatch() throws IOException { List documentsToLoad = new ArrayList<>(); long accumulatedSize = 0; - boolean reachedMemoryLimit = false; - while (reachedMemoryLimit == false) { + while (accumulatedSize < maxMemorySizeInBytes) { if (pendingDocs.isEmpty()) { ScoreDoc[] topDocs = nextTopDocs().scoreDocs; if (topDocs.length == 0) { @@ -127,9 +126,6 @@ private void loadNextBatch() throws IOException { document.doc().shardIndex = documentsToLoad.size(); documentsToLoad.add(document); accumulatedSize += document.size(); - if (accumulatedSize > maxMemorySizeInBytes) { - reachedMemoryLimit = true; - } } for (var op : loadDocuments(documentsToLoad)) {