Skip to content

Commit

Permalink
Go back to the previous intent of these tests
Browse files Browse the repository at this point in the history
by setting the tier preference back to null after the index has been
created
  • Loading branch information
joegallo committed Oct 25, 2021
1 parent bb799ed commit 72dee11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public void testScaleFromEmptyLegacy() {
putAutoscalingPolicy("hot", DataTier.DATA_HOT);
putAutoscalingPolicy("warm", DataTier.DATA_WARM);
putAutoscalingPolicy("cold", DataTier.DATA_COLD);
putAutoscalingPolicy("content", DataTier.DATA_CONTENT);

// add an index using `_id` allocation to check that it does not trigger spinning up the tier.
assertAcked(
Expand All @@ -181,6 +180,10 @@ public void testScaleFromEmptyLegacy() {
.build()
)
);

// the tier preference will have defaulted to data_content, set it back to null
updateIndexSettings(indexName, Settings.builder().putNull(DataTier.TIER_PREFERENCE));

refresh(indexName);
assertThat(capacity().results().get("warm").requiredCapacity().total().storage().getBytes(), Matchers.equalTo(0L));
assertThat(capacity().results().get("cold").requiredCapacity().total().storage().getBytes(), Matchers.equalTo(0L));
Expand All @@ -196,12 +199,9 @@ public void testScaleFromEmptyLegacy() {
.actionGet()
);

// since we always enforce a default tier preference, this index wants to be on data_content, regardless of `data_tier: warm` above
assertThat(capacity().results().get("content").requiredCapacity().total().storage().getBytes(), Matchers.greaterThan(0L));

// and doesn't care about warm or cold
assertThat(capacity().results().get("warm").requiredCapacity().total().storage().getBytes(), Matchers.equalTo(0L));
assertThat(capacity().results().get("cold").requiredCapacity().total().storage().getBytes(), Matchers.equalTo(0L));
assertThat(capacity().results().get("warm").requiredCapacity().total().storage().getBytes(), Matchers.greaterThan(0L));
// this is not desirable, but one of the caveats of not using data tiers in the ILM policy.
assertThat(capacity().results().get("cold").requiredCapacity().total().storage().getBytes(), Matchers.greaterThan(0L));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ public void testMigrateToDataTiersAction() throws Exception {
for (int i = 1; i <= 2; i++) {
// assign the rollover-only policy to a few other indices - these indices will end up getting caught by the catch-all
// tier preference migration
createIndexWithSettings(client(), rolloverIndexPrefix + "-00000" + i, alias + i, Settings.builder()
String rolloverIndex = rolloverIndexPrefix + "-00000" + i;
createIndexWithSettings(client(), rolloverIndex, alias + i, Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.putNull(DataTier.TIER_PREFERENCE) // since we always enforce a tier preference, this will be ignored (i.e. data_content)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias + i)
);

// the tier preference will have defaulted to data_content, set it back to null
updateIndexSettings(rolloverIndex, Settings.builder().putNull(DataTier.TIER_PREFERENCE));
}

// let's stop ILM so we can perform the migration
Expand All @@ -159,6 +163,9 @@ public void testMigrateToDataTiersAction() throws Exception {
.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "data", "warm");
createIndex(indexWithDataWarmRouting, settings.build());

// the tier preference will have defaulted to data_content, set it back to null
updateIndexSettings(indexWithDataWarmRouting, Settings.builder().putNull(DataTier.TIER_PREFERENCE));

Request migrateRequest = new Request("POST", "_ilm/migrate_to_data_tiers");
migrateRequest.setJsonEntity(
"{\"legacy_template_to_delete\": \"" + templateName + "\", \"node_attribute\": \"data\"}"
Expand All @@ -170,18 +177,18 @@ public void testMigrateToDataTiersAction() throws Exception {
assertThat((List<String>) migrateResponseAsMap.get(MigrateToDataTiersResponse.MIGRATED_ILM_POLICIES.getPreferredName()),
contains(policy));
assertThat((List<String>) migrateResponseAsMap.get(MigrateToDataTiersResponse.MIGRATED_INDICES.getPreferredName()),
containsInAnyOrder(index, indexWithDataWarmRouting));
containsInAnyOrder(index, indexWithDataWarmRouting, rolloverIndexPrefix + "-000001", rolloverIndexPrefix + "-000002"));
assertThat(migrateResponseAsMap.get(MigrateToDataTiersResponse.REMOVED_LEGACY_TEMPLATE.getPreferredName()),
is(templateName));

// let's verify the legacy template doesn't exist anymore
Request getTemplateRequest = new Request("HEAD", "_template/" + templateName);
assertThat(client().performRequest(getTemplateRequest).getStatusLine().getStatusCode(), is(RestStatus.NOT_FOUND.getStatus()));

// regardless of require.data:warm configuration the "indexWithDataWarmRouting", we enforced a default tier preference,
// so this is data_content
// let's assert the require.data:warm configuration the "indexWithDataWarmRouting" had was migrated to
// _tier_preference:data_warm,data_hot
Map<String, Object> indexSettings = getOnlyIndexSettings(client(), indexWithDataWarmRouting);
assertThat(indexSettings.get(DataTier.TIER_PREFERENCE), is(DataTier.DATA_CONTENT));
assertThat(indexSettings.get(DataTier.TIER_PREFERENCE), is("data_warm,data_hot"));

// let's retrieve the migrated policy and check it was migrated correctly - namely the warm phase should not contain any allocate
// action anymore and the cold phase should contain an allocate action that only configures the number of replicas
Expand Down Expand Up @@ -271,6 +278,9 @@ public void testMigrationDryRun() throws Exception {
.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "data", "warm");
createIndex(indexWithDataWarmRouting, settings.build());

// the tier preference will have defaulted to data_content, set it back to null
updateIndexSettings(indexWithDataWarmRouting, Settings.builder().putNull(DataTier.TIER_PREFERENCE));

Request migrateRequest = new Request("POST", "_ilm/migrate_to_data_tiers");
migrateRequest.addParameter("dry_run", "true");
migrateRequest.setJsonEntity(
Expand All @@ -293,10 +303,9 @@ public void testMigrationDryRun() throws Exception {
Request getTemplateRequest = new Request("HEAD", "_template/" + templateName);
assertThat(client().performRequest(getTemplateRequest).getStatusLine().getStatusCode(), is(RestStatus.OK.getStatus()));

// the index settings will contain a tier preference, regardless of this being a dry run,
// because we always enforce a tier preference being set (so the null above is overridden when the index is created)
// the index settings should not contain the _tier_preference
Map<String, Object> indexSettings = getOnlyIndexSettings(client(), indexWithDataWarmRouting);
assertThat(indexSettings.get(DataTier.TIER_PREFERENCE), is(DataTier.DATA_CONTENT));
assertThat(indexSettings.get(DataTier.TIER_PREFERENCE), nullValue());

// let's check the ILM policy was not migrated - ie. the warm phase still contains the allocate action
Request getPolicy = new Request("GET", "/_ilm/policy/" + policy);
Expand Down

0 comments on commit 72dee11

Please sign in to comment.