Skip to content

Commit e779602

Browse files
Cleanup
1 parent 75c5a7f commit e779602

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

server/src/main/java/org/elasticsearch/index/engine/ThreadPoolMergeScheduler.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import org.elasticsearch.index.merge.OnGoingMerge;
3131
import org.elasticsearch.index.shard.ShardId;
3232

33-
import java.io.FileNotFoundException;
3433
import java.io.IOException;
35-
import java.nio.file.NoSuchFileException;
3634
import java.util.Comparator;
3735
import java.util.HashMap;
3836
import java.util.Locale;
@@ -541,17 +539,14 @@ public OnGoingMerge getOnGoingMerge() {
541539
private static long getNewSegmentSize(MergePolicy.OneMerge currentMerge) {
542540
try {
543541
return currentMerge.getMergeInfo() != null ? currentMerge.getMergeInfo().sizeInBytes() : currentMerge.estimatedMergeBytes;
544-
} catch (FileNotFoundException | NoSuchFileException e) {
545-
// It is (rarely) possible that the merged segment could be merged away by the IndexWriter prior to reaching this point.
546-
// Once the IW creates the new segment, it could be exposed to be included in a new merge. That merge can be executed
547-
// concurrently if more than 1 merge threads are configured. That new merge allows this IW to delete segment created by
548-
// this merge. Although the files may still be available in the object store for executing searches, the IndexDirectory
549-
// will no longer have references to the underlying segment files and will throw file not found if we try to read them.
550-
// In this case, we will ignore that exception (which would otherwise fail the shard) and use the originally estimated
551-
// merge size for metrics.
552-
return currentMerge.estimatedMergeBytes;
553542
} catch (IOException e) {
554-
// TODO how to handle?
543+
// For stateless only: It is (rarely) possible that the merged segment could be merged away by the IndexWriter prior to
544+
// reaching this point. Once the IW creates the new segment, it could be exposed to be included in a new merge. That
545+
// merge can be executed concurrently if more than 1 merge threads are configured. That new merge allows this IW to
546+
// delete segment created by this merge. Although the files may still be available in the object store for executing
547+
// searches, the IndexDirectory will no longer have references to the underlying segment files and will throw file not
548+
// found if we try to read them. In this case, we will ignore that exception (which would otherwise fail the shard) and
549+
// use the originally estimated merge size for metrics.
555550
return currentMerge.estimatedMergeBytes;
556551
}
557552
}

server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeSchedulerTests.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public void testSchedulerCloseWaitsForRunningMerge() throws Exception {
516516
IndexSettingsModule.newIndexSettings("index", settings),
517517
threadPoolMergeExecutorService,
518518
merge -> 0,
519-
mock(MergeMetrics.class)
519+
MergeMetrics.NOOP
520520
)
521521
) {
522522
CountDownLatch mergeDoneLatch = new CountDownLatch(1);
@@ -580,7 +580,6 @@ public void testAutoIOThrottleForMergeTasksWhenSchedulerDisablesIt() throws Exce
580580
ThreadPoolMergeExecutorService threadPoolMergeExecutorService = mock(ThreadPoolMergeExecutorService.class);
581581
MergePolicy.OneMergeProgress oneMergeProgress = new MergePolicy.OneMergeProgress();
582582
OneMerge oneMerge = mock(OneMerge.class);
583-
MergeMetrics mergeMetrics = mock(MergeMetrics.class);
584583
when(oneMerge.getStoreMergeInfo()).thenReturn(getNewMergeInfo(randomNonNegativeLong()));
585584
when(oneMerge.getMergeProgress()).thenReturn(oneMergeProgress);
586585
MergeSource mergeSource = mock(MergeSource.class);
@@ -591,7 +590,7 @@ public void testAutoIOThrottleForMergeTasksWhenSchedulerDisablesIt() throws Exce
591590
indexSettings,
592591
threadPoolMergeExecutorService,
593592
merge -> 0,
594-
mergeMetrics
593+
MergeMetrics.NOOP
595594
)
596595
) {
597596
threadPoolMergeScheduler.merge(mergeSource, randomFrom(MergeTrigger.values()));
@@ -610,7 +609,6 @@ public void testAutoIOThrottleForMergeTasks() throws Exception {
610609
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index", settingsBuilder.build());
611610
MergePolicy.OneMergeProgress oneMergeProgress = new MergePolicy.OneMergeProgress();
612611
OneMerge oneMerge = mock(OneMerge.class);
613-
MergeMetrics mergeMetrics = mock(MergeMetrics.class);
614612
// forced merge with a set number of segments
615613
when(oneMerge.getStoreMergeInfo()).thenReturn(getNewMergeInfo(randomNonNegativeLong(), randomNonNegativeInt()));
616614
when(oneMerge.getMergeProgress()).thenReturn(oneMergeProgress);
@@ -623,7 +621,7 @@ public void testAutoIOThrottleForMergeTasks() throws Exception {
623621
indexSettings,
624622
threadPoolMergeExecutorService,
625623
merge -> 0,
626-
mergeMetrics
624+
MergeMetrics.NOOP
627625
)
628626
) {
629627
threadPoolMergeScheduler.merge(mergeSource, randomFrom(MergeTrigger.values()));
@@ -641,7 +639,7 @@ public void testAutoIOThrottleForMergeTasks() throws Exception {
641639
indexSettings,
642640
threadPoolMergeExecutorService,
643641
merge -> 0,
644-
mergeMetrics
642+
MergeMetrics.NOOP
645643
)
646644
) {
647645
// merge submitted upon closing
@@ -659,7 +657,7 @@ public void testAutoIOThrottleForMergeTasks() throws Exception {
659657
indexSettings,
660658
threadPoolMergeExecutorService,
661659
merge -> 0,
662-
mergeMetrics
660+
MergeMetrics.NOOP
663661
)
664662
) {
665663
// merge submitted upon closing
@@ -676,14 +674,13 @@ public void testAutoIOThrottleForMergeTasks() throws Exception {
676674

677675
public void testMergeSchedulerAbortsMergeWhenShouldSkipMergeIsTrue() {
678676
ThreadPoolMergeExecutorService threadPoolMergeExecutorService = mock(ThreadPoolMergeExecutorService.class);
679-
MergeMetrics mergeMetrics = mock(MergeMetrics.class);
680677
// build a scheduler that always returns true for shouldSkipMerge
681678
ThreadPoolMergeScheduler threadPoolMergeScheduler = new ThreadPoolMergeScheduler(
682679
new ShardId("index", "_na_", 1),
683680
IndexSettingsModule.newIndexSettings("index", Settings.builder().build()),
684681
threadPoolMergeExecutorService,
685682
merge -> 0,
686-
mergeMetrics
683+
MergeMetrics.NOOP
687684
) {
688685
@Override
689686
protected boolean shouldSkipMerge() {

0 commit comments

Comments
 (0)