|
78 | 78 | import org.elasticsearch.test.ESIntegTestCase.Scope; |
79 | 79 | import org.elasticsearch.test.InternalTestCluster; |
80 | 80 | import org.elasticsearch.test.TestCustomMetaData; |
| 81 | +import org.elasticsearch.test.disruption.BusyMasterServiceDisruption; |
| 82 | +import org.elasticsearch.test.disruption.ServiceDisruptionScheme; |
81 | 83 | import org.elasticsearch.test.rest.FakeRestRequest; |
82 | 84 |
|
83 | 85 | import java.io.IOException; |
@@ -1151,6 +1153,50 @@ public void testSnapshotTotalAndIncrementalSizes() throws IOException { |
1151 | 1153 | assertThat(anotherStats.getTotalSize(), is(snapshot1FileSize)); |
1152 | 1154 | } |
1153 | 1155 |
|
| 1156 | + public void testDataNodeRestartWithBusyMasterDuringSnapshot() throws Exception { |
| 1157 | + logger.info("--> starting a master node and two data nodes"); |
| 1158 | + internalCluster().startMasterOnlyNode(); |
| 1159 | + internalCluster().startDataOnlyNodes(2); |
| 1160 | + logger.info("--> creating repository"); |
| 1161 | + assertAcked(client().admin().cluster().preparePutRepository("test-repo") |
| 1162 | + .setType("mock").setSettings(Settings.builder() |
| 1163 | + .put("location", randomRepoPath()) |
| 1164 | + .put("compress", randomBoolean()) |
| 1165 | + .put("max_snapshot_bytes_per_sec", "1000b") |
| 1166 | + .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES))); |
| 1167 | + assertAcked(prepareCreate("test-idx", 0, Settings.builder() |
| 1168 | + .put("number_of_shards", 5).put("number_of_replicas", 0))); |
| 1169 | + ensureGreen(); |
| 1170 | + logger.info("--> indexing some data"); |
| 1171 | + final int numdocs = randomIntBetween(50, 100); |
| 1172 | + IndexRequestBuilder[] builders = new IndexRequestBuilder[numdocs]; |
| 1173 | + for (int i = 0; i < builders.length; i++) { |
| 1174 | + builders[i] = client().prepareIndex("test-idx", "type1", |
| 1175 | + Integer.toString(i)).setSource("field1", "bar " + i); |
| 1176 | + } |
| 1177 | + indexRandom(true, builders); |
| 1178 | + flushAndRefresh(); |
| 1179 | + final String dataNode = blockNodeWithIndex("test-repo", "test-idx"); |
| 1180 | + logger.info("--> snapshot"); |
| 1181 | + client(internalCluster().getMasterName()).admin().cluster() |
| 1182 | + .prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(false).setIndices("test-idx").get(); |
| 1183 | + ServiceDisruptionScheme disruption = new BusyMasterServiceDisruption(random(), Priority.HIGH); |
| 1184 | + setDisruptionScheme(disruption); |
| 1185 | + disruption.startDisrupting(); |
| 1186 | + logger.info("--> restarting data node, which should cause primary shards to be failed"); |
| 1187 | + internalCluster().restartNode(dataNode, InternalTestCluster.EMPTY_CALLBACK); |
| 1188 | + unblockNode("test-repo", dataNode); |
| 1189 | + disruption.stopDisrupting(); |
| 1190 | + // check that snapshot completes |
| 1191 | + assertBusy(() -> { |
| 1192 | + GetSnapshotsResponse snapshotsStatusResponse = client().admin().cluster() |
| 1193 | + .prepareGetSnapshots("test-repo").setSnapshots("test-snap").setIgnoreUnavailable(true).get(); |
| 1194 | + assertEquals(1, snapshotsStatusResponse.getSnapshots().size()); |
| 1195 | + SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0); |
| 1196 | + assertTrue(snapshotInfo.state().toString(), snapshotInfo.state().completed()); |
| 1197 | + }, 30, TimeUnit.SECONDS); |
| 1198 | + } |
| 1199 | + |
1154 | 1200 | private long calculateTotalFilesSize(List<Path> files) { |
1155 | 1201 | return files.stream().mapToLong(f -> { |
1156 | 1202 | try { |
|
0 commit comments