Skip to content

Commit

Permalink
Various Datastream Reindex Fixes (elastic#121376) (elastic#121599)
Browse files Browse the repository at this point in the history
* Fix incorrect value of reindex_required flag on ignored index warning
* Datastream reindex now uses unverified write block to allow retrying failed reindex
  • Loading branch information
lukewhiting authored Feb 3, 2025
1 parent 470e054 commit c558433
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterSta
+ "OK to remain read-only after upgrade",
false,
ofEntries(
entry("reindex_required", true),
entry("reindex_required", false),
entry("total_backing_indices", backingIndices.size()),
entry("ignored_indices_requiring_upgrade_count", ignoredIndices.size()),
entry("ignored_indices_requiring_upgrade", ignoredIndices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void testOldIndicesIgnoredWarningCheck() {
+ "OK to remain read-only after upgrade",
false,
ofEntries(
entry("reindex_required", true),
entry("reindex_required", false),
entry("total_backing_indices", oldIndexCount + newIndexCount),
entry("ignored_indices_requiring_upgrade_count", expectedIndices.size()),
entry("ignored_indices_requiring_upgrade", expectedIndices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
Expand All @@ -27,6 +28,7 @@
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -50,6 +52,7 @@
import java.util.Locale;
import java.util.Map;

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

// Assert that source index is now read-only but not verified read-only
GetSettingsResponse getSettingsResponse = admin().indices().getSettings(new GetSettingsRequest().indices(sourceIndex)).actionGet();
assertTrue(parseBoolean(getSettingsResponse.getSetting(sourceIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
assertFalse(
parseBoolean(getSettingsResponse.getSetting(sourceIndex, MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.getKey()))
);

// assert that write to source fails
var indexReq = new IndexRequest(sourceIndex).source(jsonBuilder().startObject().field("field", "1").endObject());
assertThrows(ClusterBlockException.class, () -> client().index(indexReq).actionGet());
Expand Down Expand Up @@ -253,9 +263,9 @@ public void testReadOnlyBlocksNotAddedBack() {
.getDestIndex();

var settingsResponse = indicesAdmin().getSettings(new GetSettingsRequest().indices(destIndex)).actionGet();
assertFalse(Boolean.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY)));
assertFalse(Boolean.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
assertFalse(Boolean.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
assertFalse(parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY)));
assertFalse(parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
assertFalse(parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));

cleanupMetadataBlocks(sourceIndex);
cleanupMetadataBlocks(destIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ private void addBlockToIndex(
TaskId parentTaskId
) {
AddIndexBlockRequest addIndexBlockRequest = new AddIndexBlockRequest(block, index);
addIndexBlockRequest.markVerified(false);
addIndexBlockRequest.setParentTask(parentTaskId);
client.admin().indices().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest, listener);
}
Expand Down

0 comments on commit c558433

Please sign in to comment.