Skip to content

Commit

Permalink
Removing index alias creation for deprecated transforms notification …
Browse files Browse the repository at this point in the history
…index (elastic#117583)

* Removing index alias creation for deprecated transforms notification index

* Update docs/changelog/117583.yaml

* Updating changelog

* Updating deprecation area to Transform

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
dan-rubinstein and elasticmachine authored Dec 11, 2024
1 parent c792595 commit d839205
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 91 deletions.
17 changes: 17 additions & 0 deletions docs/changelog/117583.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pr: 117583
summary: Removing index alias creation for deprecated transforms notification index
area: Machine Learning
type: deprecation
issues: []
deprecation:
title: Removing index alias creation for deprecated transforms notification index
area: Transform
details: >-
As part of the migration from 7.x to 8.x, the `.data-frame-notifications-1` index
was deprecated and replaced with the `.transform-notifications-000002` index.
The index is no longer created by default, all writes are directed to the new index,
and any clusters with the deprecated index will have an alias created to ensure that
reads are still retrieving data that was written to the index before the migration to 8.x.
This change removes the alias from the deprecated index in 9.x. Any clusters with the alias present
will retain it, but it will not be created on new clusters.
impact: No known end user impact.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public final class TransformInternalIndexConstants {
public static final String AUDIT_TEMPLATE_VERSION = "000002";
public static final String AUDIT_INDEX_PREFIX = TRANSFORM_PREFIX + "notifications-";
public static final String AUDIT_INDEX_PATTERN = AUDIT_INDEX_PREFIX + "*";
public static final String AUDIT_INDEX_DEPRECATED = TRANSFORM_PREFIX_DEPRECATED + "notifications-1";
public static final String AUDIT_INDEX_PATTERN_DEPRECATED = TRANSFORM_PREFIX_DEPRECATED + "notifications-*";

public static final String AUDIT_INDEX_READ_ALIAS = TRANSFORM_PREFIX + "notifications-read";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
package org.elasticsearch.xpack.transform.integration;

import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
import org.junit.Before;

Expand Down Expand Up @@ -92,28 +89,4 @@ public void testAuditorWritesAudits() throws Exception {
});

}

public void testAliasCreatedforBWCIndexes() throws Exception {
Settings.Builder settings = indexSettings(1, 0);

// These indices should only exist if created in previous versions, ignore the deprecation warning for this test
RequestOptions options = expectWarnings(
"index name ["
+ TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED
+ "] starts "
+ "with a dot '.', in the next major version, index names starting with a dot are reserved for hidden indices "
+ "and system indices"
).toBuilder().addHeader("X-elastic-product-origin", "elastic").build();
Request request = new Request("PUT", "/" + TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED);
String entity = "{\"settings\": " + Strings.toString(settings.build()) + "}";
request.setJsonEntity(entity);
request.setOptions(options);
client().performRequest(request);

assertBusy(
() -> assertTrue(
aliasExists(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED, TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,18 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import static org.elasticsearch.xpack.core.ClientHelper.TRANSFORM_ORIGIN;
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;

class TransformClusterStateListener implements ClusterStateListener, Supplier<Optional<ClusterState>> {

private static final Logger logger = LogManager.getLogger(TransformClusterStateListener.class);
Expand All @@ -51,61 +43,6 @@ public void clusterChanged(ClusterChangedEvent event) {
}

clusterState.set(event.state());

// The atomic flag prevents multiple simultaneous attempts to run alias creation
// if there is a flurry of cluster state updates in quick succession
if (event.localNodeMaster() && isIndexCreationInProgress.compareAndSet(false, true)) {
createAuditAliasForDataFrameBWC(event.state(), client, ActionListener.wrap(r -> {
isIndexCreationInProgress.set(false);
if (r) {
logger.info("Created alias for deprecated data frame notifications index");
} else {
logger.debug("Skipped creating alias for deprecated data frame notifications index");
}
}, e -> {
isIndexCreationInProgress.set(false);
logger.error("Error creating alias for deprecated data frame notifications index", e);
}));
}
}

private static void createAuditAliasForDataFrameBWC(ClusterState state, Client client, final ActionListener<Boolean> finalListener) {

// check if old audit index exists, no need to create the alias if it does not
if (state.getMetadata().hasIndexAbstraction(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) == false) {
finalListener.onResponse(false);
return;
}

Metadata metadata = state.metadata();
if (state.getMetadata()
.getIndicesLookup()
.get(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED)
.getIndices()
.stream()
.anyMatch(name -> metadata.index(name).getAliases().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS))) {
finalListener.onResponse(false);
return;
}

final IndicesAliasesRequest request = client.admin()
.indices()
.prepareAliases()
.addAliasAction(
IndicesAliasesRequest.AliasActions.add()
.index(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED)
.alias(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)
.isHidden(true)
)
.request();

executeAsyncWithOrigin(
client.threadPool().getThreadContext(),
TRANSFORM_ORIGIN,
request,
ActionListener.<IndicesAliasesResponse>wrap(r -> finalListener.onResponse(r.isAcknowledged()), finalListener::onFailure),
client.admin().indices()::aliases
);
}

/**
Expand Down

0 comments on commit d839205

Please sign in to comment.