-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Transform] Rename internal indexes for transform plugin #47788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hendrikmuhs
merged 10 commits into
elastic:master
from
hendrikmuhs:rename-to-transform-index
Oct 11, 2019
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
73587b3
rename audit index and create an alias for accessing it
00da79b
rename internal index and search on old name pattern
124d3ee
use old and new indexes in rolling upgrade IT
bde0d3e
update index name
517fae7
improve doc strings
6f6717c
fix alias creation for old notification index
c5862fd
use new role for auditor IT
986ac27
improve code doc
3419d55
use proper pattern
3645d5d
add an integration test for testing alias creation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...nsform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.transform; | ||
|
|
||
| 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.support.master.AcknowledgedResponse; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.cluster.ClusterChangedEvent; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.ClusterStateListener; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.gateway.GatewayService; | ||
| import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import static org.elasticsearch.xpack.core.ClientHelper.TRANSFORM_ORIGIN; | ||
| import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; | ||
|
|
||
| class TransformClusterStateListener implements ClusterStateListener { | ||
|
|
||
| private static final Logger logger = LogManager.getLogger(TransformClusterStateListener.class); | ||
|
|
||
| private final Client client; | ||
| private final AtomicBoolean isIndexCreationInProgress = new AtomicBoolean(false); | ||
|
|
||
| TransformClusterStateListener(ClusterService clusterService, Client client) { | ||
| this.client = client; | ||
| clusterService.addListener(this); | ||
| logger.debug("Created TransformClusterStateListener"); | ||
| } | ||
|
|
||
| @Override | ||
| public void clusterChanged(ClusterChangedEvent event) { | ||
| if (event.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { | ||
| // Wait until the gateway has recovered from disk. | ||
| return; | ||
| } | ||
|
|
||
| // 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); | ||
hendrikmuhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
hendrikmuhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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().getAliasAndIndexLookup().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) == false) { | ||
| finalListener.onResponse(false); | ||
| return; | ||
| } | ||
|
|
||
| if (state.getMetaData().getAliasAndIndexLookup().get(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED).getIndices().stream() | ||
| .anyMatch(metaData -> metaData.getAliases().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS))) { | ||
| finalListener.onResponse(false); | ||
| return; | ||
| } | ||
|
|
||
| final IndicesAliasesRequest request = client.admin().indices().prepareAliases() | ||
| .addAlias(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED, TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS) | ||
| .request(); | ||
|
|
||
| executeAsyncWithOrigin(client.threadPool().getThreadContext(), TRANSFORM_ORIGIN, request, | ||
| ActionListener.<AcknowledgedResponse>wrap(r -> finalListener.onResponse(r.isAcknowledged()), finalListener::onFailure), | ||
| client.admin().indices()::aliases); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.