Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.admin.indices.shrink.TransportResizeAction;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
Expand Down Expand Up @@ -44,6 +45,7 @@
import java.util.List;
import java.util.Map;

import static org.elasticsearch.action.admin.indices.ResizeIndexTestUtils.resizeRequest;
import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.MapMatcher.matchesMap;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
Expand Down Expand Up @@ -267,12 +269,10 @@ public void testIndexingGettingAndSearchingShrunkIndex() throws Exception {
assertThat(updateSettingsResponse.isAcknowledged(), is(true));

String shrunkenTarget = "k8s-shrunken";
var shrinkIndexResponse = client().admin()
.indices()
.prepareResizeIndex(sourceIndex, shrunkenTarget)
.setResizeType(ResizeType.SHRINK)
.setSettings(indexSettings(2, 0).build())
.get();
final var shrinkIndexResponse = client().execute(
TransportResizeAction.TYPE,
resizeRequest(ResizeType.SHRINK, sourceIndex, shrunkenTarget, indexSettings(2, 0))
).actionGet();
assertThat(shrinkIndexResponse.isAcknowledged(), is(true));
assertThat(shrinkIndexResponse.index(), equalTo(shrunkenTarget));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.List;

import static org.elasticsearch.action.admin.indices.ResizeIndexTestUtils.executeResize;
import static org.elasticsearch.action.admin.indices.create.ShrinkIndexIT.assertNoResizeSourceIndexSettings;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
Expand Down Expand Up @@ -67,11 +68,12 @@ public void testCreateCloneIndex() {

final boolean createWithReplicas = randomBoolean();
assertAcked(
indicesAdmin().prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
.setSettings(
Settings.builder().put("index.number_of_replicas", createWithReplicas ? 1 : 0).putNull("index.blocks.write").build()
)
executeResize(
ResizeType.CLONE,
"source",
"target",
Settings.builder().put("index.number_of_replicas", createWithReplicas ? 1 : 0).putNull("index.blocks.write")
)
);
ensureGreen();
assertNoResizeSourceIndexSettings("target");
Expand Down Expand Up @@ -125,9 +127,10 @@ public void testResizeChangeIndexMode() {
Settings.builder().put("index.mode", "lookup").build()
);
for (Settings settings : indexSettings) {
IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> {
indicesAdmin().prepareResizeIndex("source", "target").setResizeType(ResizeType.CLONE).setSettings(settings).get();
});
IllegalArgumentException error = expectThrows(
IllegalArgumentException.class,
() -> executeResize(ResizeType.CLONE, "source", "target", Settings.builder().put(settings)).actionGet()
);
assertThat(error.getMessage(), equalTo("can't change setting [index.mode] during resize"));
}
}
Expand All @@ -137,12 +140,15 @@ public void testResizeChangeSyntheticSource() {
.setMapping("@timestamp", "type=date", "host.name", "type=keyword")
.get();
updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source");
IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> {
indicesAdmin().prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
.setSettings(Settings.builder().put("index.mapping.source.mode", "synthetic").putNull("index.blocks.write").build())
.get();
});
IllegalArgumentException error = expectThrows(
IllegalArgumentException.class,
() -> executeResize(
ResizeType.CLONE,
"source",
"target",
Settings.builder().put("index.mapping.source.mode", "synthetic").putNull("index.blocks.write")
).actionGet()
);
assertThat(error.getMessage(), containsString("can't change setting [index.mapping.source.mode] during resize"));
}

Expand All @@ -159,26 +165,26 @@ public void testResizeChangeRecoveryUseSyntheticSource() {
)
).setMapping("@timestamp", "type=date", "host.name", "type=keyword").get();
updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source");
IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> {
indicesAdmin().prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
.setSettings(
Settings.builder()
.put(
"index.version.created",
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.USE_SYNTHETIC_SOURCE_FOR_RECOVERY,
IndexVersion.current()
)
IllegalArgumentException error = expectThrows(
IllegalArgumentException.class,
() -> executeResize(
ResizeType.CLONE,
"source",
"target",
Settings.builder()
.put(
"index.version.created",
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.USE_SYNTHETIC_SOURCE_FOR_RECOVERY,
IndexVersion.current()
)
.put("index.recovery.use_synthetic_source", true)
.put("index.mode", "logsdb")
.putNull("index.blocks.write")
.build()
)
.get();
});
)
.put("index.recovery.use_synthetic_source", true)
.put("index.mode", "logsdb")
.putNull("index.blocks.write")
).actionGet()
);
// The index.recovery.use_synthetic_source setting requires either index.mode or index.mapping.source.mode
// to be present in the settings. Since these are all unmodifiable settings with a non-deterministic evaluation
// order, any of them may trigger a failure first.
Expand All @@ -196,12 +202,11 @@ public void testResizeChangeIndexSorts() {
.setMapping("@timestamp", "type=date", "host.name", "type=keyword")
.get();
updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source");
ValidationException error = expectThrows(ValidationException.class, () -> {
indicesAdmin().prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
.setSettings(Settings.builder().putList("index.sort.field", List.of("@timestamp")).build())
.get();
});
ValidationException error = expectThrows(
ValidationException.class,
() -> executeResize(ResizeType.CLONE, "source", "target", Settings.builder().putList("index.sort.field", List.of("@timestamp")))
.actionGet()
);
assertThat(error.getMessage(), containsString("can't override index sort when resizing an index"));
}

Expand All @@ -216,11 +221,13 @@ public void testCloneLogsdbIndexWithNonDefaultTimestamp() {
ensureGreen();

// Clone the index
indicesAdmin().prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
executeResize(
ResizeType.CLONE,
"source",
"target",
// We need to explicitly set the number of replicas in case the source has 0 replicas and the cluster has only 1 data node
.setSettings(Settings.builder().put("index.number_of_replicas", numberOfReplicas).build())
.get();
Settings.builder().put("index.number_of_replicas", numberOfReplicas)
).actionGet();

// Verify that the target index has the correct @timestamp mapping
final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get();
Expand All @@ -246,11 +253,13 @@ public void testCloneTimeSeriesIndexWithNonDefaultTimestamp() {
ensureGreen();

// Clone the index
indicesAdmin().prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
executeResize(
ResizeType.CLONE,
"source",
"target",
// We need to explicitly set the number of replicas in case the source has 0 replicas and the cluster has only 1 data node
.setSettings(Settings.builder().put("index.number_of_replicas", numberOfReplicas).build())
.get();
Settings.builder().put("index.number_of_replicas", numberOfReplicas)
).actionGet();

// Verify that the target index has the correct @timestamp mapping
final var targetMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "target").get();
Expand Down
Loading