|
11 | 11 | import org.elasticsearch.action.support.ActiveShardCount;
|
12 | 12 | import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
13 | 13 | import org.elasticsearch.cluster.ClusterState;
|
14 |
| -import org.elasticsearch.cluster.block.ClusterBlock; |
| 14 | +import org.elasticsearch.cluster.health.ClusterHealthStatus; |
| 15 | +import org.elasticsearch.cluster.metadata.IndexMetaData; |
15 | 16 | import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
16 | 17 | import org.elasticsearch.common.unit.ByteSizeValue;
|
17 | 18 | import org.elasticsearch.common.unit.TimeValue;
|
18 | 19 | import org.elasticsearch.common.xcontent.XContentType;
|
19 | 20 | import org.elasticsearch.index.IndexSettings;
|
| 21 | +import org.elasticsearch.index.engine.ReadOnlyEngine; |
20 | 22 | import org.elasticsearch.xpack.CcrIntegTestCase;
|
21 | 23 | import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
|
| 24 | +import org.junit.After; |
| 25 | +import org.junit.Before; |
22 | 26 |
|
23 |
| -import java.util.ArrayList; |
24 |
| -import java.util.List; |
| 27 | +import java.security.AccessController; |
| 28 | +import java.security.PrivilegedAction; |
25 | 29 | import java.util.concurrent.atomic.AtomicBoolean;
|
26 | 30 |
|
27 | 31 | import static java.util.Collections.singletonMap;
|
|
31 | 35 |
|
32 | 36 | public class CloseFollowerIndexIT extends CcrIntegTestCase {
|
33 | 37 |
|
34 |
| - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/38767") |
| 38 | + private Thread.UncaughtExceptionHandler uncaughtExceptionHandler; |
| 39 | + |
| 40 | + @Before |
| 41 | + public void wrapUncaughtExceptionHandler() { |
| 42 | + uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); |
| 43 | + AccessController.doPrivileged((PrivilegedAction<Void>) () -> { |
| 44 | + Thread.setDefaultUncaughtExceptionHandler((t, e) -> { |
| 45 | + if (t.getThreadGroup().getName().contains(getTestClass().getSimpleName())) { |
| 46 | + for (StackTraceElement element : e.getStackTrace()) { |
| 47 | + if (element.getClassName().equals(ReadOnlyEngine.class.getName())) { |
| 48 | + if (element.getMethodName().equals("assertMaxSeqNoEqualsToGlobalCheckpoint")) { |
| 49 | + return; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + uncaughtExceptionHandler.uncaughtException(t, e); |
| 55 | + }); |
| 56 | + return null; |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + @After |
| 61 | + public void restoreUncaughtExceptionHandler() { |
| 62 | + AccessController.doPrivileged((PrivilegedAction<Void>) () -> { |
| 63 | + Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler); |
| 64 | + return null; |
| 65 | + }); |
| 66 | + } |
| 67 | + |
35 | 68 | public void testCloseAndReopenFollowerIndex() throws Exception {
|
36 | 69 | final String leaderIndexSettings = getIndexSettings(1, 1, singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"));
|
37 | 70 | assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON));
|
@@ -67,16 +100,22 @@ public void testCloseAndReopenFollowerIndex() throws Exception {
|
67 | 100 | assertThat(response.isAcknowledged(), is(true));
|
68 | 101 |
|
69 | 102 | ClusterState clusterState = followerClient().admin().cluster().prepareState().get().getState();
|
70 |
| - List<ClusterBlock> blocks = new ArrayList<>(clusterState.getBlocks().indices().get("index2")); |
71 |
| - assertThat(blocks.size(), equalTo(1)); |
72 |
| - assertThat(blocks.get(0).id(), equalTo(MetaDataIndexStateService.INDEX_CLOSED_BLOCK_ID)); |
| 103 | + assertThat(clusterState.metaData().index("index2").getState(), is(IndexMetaData.State.CLOSE)); |
| 104 | + assertThat(clusterState.getBlocks().hasIndexBlock("index2", MetaDataIndexStateService.INDEX_CLOSED_BLOCK), is(true)); |
| 105 | + assertThat(followerClient().admin().cluster().prepareHealth("index2").get().getStatus(), equalTo(ClusterHealthStatus.RED)); |
73 | 106 |
|
74 | 107 | isRunning.set(false);
|
75 | 108 | for (Thread thread : threads) {
|
76 | 109 | thread.join();
|
77 | 110 | }
|
| 111 | + |
78 | 112 | assertAcked(followerClient().admin().indices().open(new OpenIndexRequest("index2")).get());
|
79 | 113 |
|
| 114 | + clusterState = followerClient().admin().cluster().prepareState().get().getState(); |
| 115 | + assertThat(clusterState.metaData().index("index2").getState(), is(IndexMetaData.State.OPEN)); |
| 116 | + assertThat(clusterState.getBlocks().hasIndexBlockWithId("index2", MetaDataIndexStateService.INDEX_CLOSED_BLOCK_ID), is(false)); |
| 117 | + ensureFollowerGreen("index2"); |
| 118 | + |
80 | 119 | refresh(leaderClient(), "index1");
|
81 | 120 | SearchRequest leaderSearchRequest = new SearchRequest("index1");
|
82 | 121 | leaderSearchRequest.source().trackTotalHits(true);
|
|
0 commit comments