Skip to content

Commit 0684a27

Browse files
committed
ES-10711 Datastream reindex now uses unverified write block to allow retrying failed reindex
1 parent 8392bab commit 0684a27

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/ReindexDatastreamIndexTransportActionIT.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
1717
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
1818
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
19+
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
1920
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
2021
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
2122
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
@@ -27,6 +28,7 @@
2728
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
2829
import org.elasticsearch.cluster.metadata.IndexMetadata;
2930
import org.elasticsearch.cluster.metadata.MappingMetadata;
31+
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
3032
import org.elasticsearch.cluster.metadata.Template;
3133
import org.elasticsearch.common.compress.CompressedXContent;
3234
import org.elasticsearch.common.settings.Settings;
@@ -50,6 +52,7 @@
5052
import java.util.Locale;
5153
import java.util.Map;
5254

55+
import static java.lang.Boolean.parseBoolean;
5356
import static org.elasticsearch.cluster.metadata.MetadataIndexTemplateService.DEFAULT_TIMESTAMP_FIELD;
5457
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5558
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
@@ -147,6 +150,13 @@ public void testSetSourceToBlockWrites() throws Exception {
147150
// call reindex
148151
client().execute(ReindexDataStreamIndexAction.INSTANCE, new ReindexDataStreamIndexAction.Request(sourceIndex)).actionGet();
149152

153+
// Assert that source index is now read-only but not verified read-only
154+
GetSettingsResponse getSettingsResponse = admin().indices().getSettings(new GetSettingsRequest().indices(sourceIndex)).actionGet();
155+
assertTrue(parseBoolean(getSettingsResponse.getSetting(sourceIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
156+
assertFalse(
157+
parseBoolean(getSettingsResponse.getSetting(sourceIndex, MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.getKey()))
158+
);
159+
150160
// assert that write to source fails
151161
var indexReq = new IndexRequest(sourceIndex).source(jsonBuilder().startObject().field("field", "1").endObject());
152162
assertThrows(ClusterBlockException.class, () -> client().index(indexReq).actionGet());
@@ -253,9 +263,9 @@ public void testReadOnlyBlocksNotAddedBack() {
253263
.getDestIndex();
254264

255265
var settingsResponse = indicesAdmin().getSettings(new GetSettingsRequest().indices(destIndex)).actionGet();
256-
assertFalse(Boolean.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY)));
257-
assertFalse(Boolean.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
258-
assertFalse(Boolean.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
266+
assertFalse(parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY)));
267+
assertFalse(parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
268+
assertFalse(parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
259269

260270
cleanupMetadataBlocks(sourceIndex);
261271
cleanupMetadataBlocks(destIndex);

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/ReindexDataStreamIndexTransportAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ private void addBlockToIndex(
341341
TaskId parentTaskId
342342
) {
343343
AddIndexBlockRequest addIndexBlockRequest = new AddIndexBlockRequest(block, index);
344+
addIndexBlockRequest.markVerified(false);
344345
addIndexBlockRequest.setParentTask(parentTaskId);
345346
client.admin().indices().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest, listener);
346347
}

0 commit comments

Comments
 (0)