Skip to content

Commit 0510bdd

Browse files
authored
Merge branch 'main' into fix_semantic_recovery_test
2 parents e146cda + c7e7dbe commit 0510bdd

File tree

5 files changed

+53
-27
lines changed

5 files changed

+53
-27
lines changed

docs/changelog/123569.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123569
2+
summary: Abort pending deletion on `IndicesService` close
3+
area: Store
4+
type: enhancement
5+
issues: []

libs/core/src/main/java/org/elasticsearch/core/Releasables.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
package org.elasticsearch.core;
1111

12-
import java.io.IOException;
13-
import java.io.UncheckedIOException;
1412
import java.util.Arrays;
1513
import java.util.Iterator;
1614
import java.util.concurrent.atomic.AtomicReference;
@@ -21,11 +19,17 @@ public enum Releasables {
2119

2220
/** Release the provided {@link Releasable}s. */
2321
public static void close(Iterable<? extends Releasable> releasables) {
24-
try {
25-
// this does the right thing with respect to add suppressed and not wrapping errors etc.
26-
IOUtils.close(releasables);
27-
} catch (IOException e) {
28-
throw new UncheckedIOException(e);
22+
RuntimeException firstException = null;
23+
for (final Releasable releasable : releasables) {
24+
try {
25+
close(releasable);
26+
} catch (RuntimeException e) {
27+
firstException = useOrSuppress(firstException, e);
28+
}
29+
}
30+
31+
if (firstException != null) {
32+
throw firstException;
2933
}
3034
}
3135

@@ -38,7 +42,18 @@ public static void close(@Nullable Releasable releasable) {
3842

3943
/** Release the provided {@link Releasable}s. */
4044
public static void close(Releasable... releasables) {
41-
close(true, releasables);
45+
RuntimeException firstException = null;
46+
for (final Releasable releasable : releasables) {
47+
try {
48+
close(releasable);
49+
} catch (RuntimeException e) {
50+
firstException = useOrSuppress(firstException, e);
51+
}
52+
}
53+
54+
if (firstException != null) {
55+
throw firstException;
56+
}
4257
}
4358

4459
/** Release the provided {@link Releasable}s expecting no exception to by thrown by any of them. */
@@ -63,19 +78,21 @@ public static void closeExpectNoException(Releasable releasable) {
6378

6479
/** Release the provided {@link Releasable}s, ignoring exceptions. */
6580
public static void closeWhileHandlingException(Releasable... releasables) {
66-
close(false, releasables);
81+
for (final Releasable releasable : releasables) {
82+
try {
83+
close(releasable);
84+
} catch (RuntimeException e) {
85+
// ignored
86+
}
87+
}
6788
}
6889

69-
/** Release the provided {@link Releasable}s, ignoring exceptions if <code>success</code> is {@code false}. */
70-
private static void close(boolean success, Releasable... releasables) {
71-
try {
72-
// this does the right thing with respect to add suppressed and not wrapping errors etc.
73-
IOUtils.close(releasables);
74-
} catch (IOException e) {
75-
if (success) {
76-
throw new UncheckedIOException(e);
77-
}
90+
private static RuntimeException useOrSuppress(RuntimeException firstException, RuntimeException e) {
91+
if (firstException == null || firstException == e) {
92+
return e;
7893
}
94+
firstException.addSuppressed(e);
95+
return firstException;
7996
}
8097

8198
/** Wrap several releasables into a single one. This is typically useful for use with try-with-resources: for example let's assume

muted-tests.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ tests:
254254
- class: org.elasticsearch.test.rest.ClientYamlTestSuiteIT
255255
method: test {yaml=snapshot.delete/10_basic/Delete a snapshot asynchronously}
256256
issue: https://github.com/elastic/elasticsearch/issues/122102
257-
- class: org.elasticsearch.datastreams.TSDBPassthroughIndexingIT
258-
issue: https://github.com/elastic/elasticsearch/issues/121716
259257
- class: org.elasticsearch.smoketest.SmokeTestMonitoringWithSecurityIT
260258
method: testHTTPExporterWithSSL
261259
issue: https://github.com/elastic/elasticsearch/issues/122220
@@ -277,15 +275,9 @@ tests:
277275
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
278276
method: test {yaml=reference/snapshot-restore/apis/get-snapshot-api/line_408}
279277
issue: https://github.com/elastic/elasticsearch/issues/122681
280-
- class: org.elasticsearch.xpack.autoscaling.storage.ReactiveStorageIT
281-
method: testScaleWhileShrinking
282-
issue: https://github.com/elastic/elasticsearch/issues/122119
283278
- class: org.elasticsearch.search.basic.SearchWithRandomDisconnectsIT
284279
method: testSearchWithRandomDisconnects
285280
issue: https://github.com/elastic/elasticsearch/issues/122707
286-
- class: org.elasticsearch.snapshots.DedicatedClusterSnapshotRestoreIT
287-
method: testRestoreShrinkIndex
288-
issue: https://github.com/elastic/elasticsearch/issues/121717
289281
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
290282
method: test {yaml=reference/cat/allocation/cat-allocation-example}
291283
issue: https://github.com/elastic/elasticsearch/issues/121976

server/src/main/java/org/elasticsearch/indices/IndicesService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public class IndicesService extends AbstractLifecycleComponent
255255
private final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories;
256256
private final IndexStorePlugin.IndexFoldersDeletionListener indexFoldersDeletionListeners;
257257
final AbstractRefCounted indicesRefCount; // pkg-private for testing
258+
private final CountDownLatch stopLatch = new CountDownLatch(1);
258259
private final CountDownLatch closeLatch = new CountDownLatch(1);
259260
private volatile boolean idFieldDataEnabled;
260261
private volatile boolean allowExpensiveQueries;
@@ -403,6 +404,7 @@ public ClusterService clusterService() {
403404

404405
@Override
405406
protected void doStop() {
407+
stopLatch.countDown();
406408
clusterService.removeApplier(timestampFieldMapperService);
407409
timestampFieldMapperService.doStop();
408410

@@ -1440,7 +1442,15 @@ public void processPendingDeletes(Index index, IndexSettings indexSettings, Time
14401442
}
14411443
if (remove.isEmpty() == false) {
14421444
logger.warn("{} still pending deletes present for shards {} - retrying", index, remove.toString());
1443-
Thread.sleep(sleepTime);
1445+
if (stopLatch.await(sleepTime, TimeUnit.MILLISECONDS)) {
1446+
logger.info(
1447+
"Indices service stopped. {} aborting pending deletes after [{}] for shards {}",
1448+
index,
1449+
TimeValue.timeValueNanos(System.nanoTime() - startTimeNS),
1450+
remove.toString()
1451+
);
1452+
break;
1453+
}
14441454
sleepTime = Math.min(maxSleepTimeMs, sleepTime * 2); // increase the sleep time gradually
14451455
logger.debug("{} schedule pending delete retry after {} ms", index, sleepTime);
14461456
}

server/src/test/java/org/elasticsearch/reservedstate/service/FileSettingsServiceTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.logging.log4j.Level;
1313
import org.apache.logging.log4j.LogManager;
1414
import org.apache.logging.log4j.Logger;
15+
import org.apache.lucene.tests.util.LuceneTestCase;
1516
import org.elasticsearch.action.ActionListener;
1617
import org.elasticsearch.cluster.ClusterChangedEvent;
1718
import org.elasticsearch.cluster.ClusterName;
@@ -84,6 +85,7 @@
8485
import static org.mockito.Mockito.times;
8586
import static org.mockito.Mockito.verify;
8687

88+
@LuceneTestCase.SuppressFileSystems("ExtrasFS")
8789
public class FileSettingsServiceTests extends ESTestCase {
8890
private static final Logger logger = LogManager.getLogger(FileSettingsServiceTests.class);
8991
private Environment env;

0 commit comments

Comments
 (0)