This commit makes the TransportRolloverAction more resilient, by having it execute only one cluster state update that creates the new (rollover index), rolls over the alias from the source to the target index and set the RolloverInfo on the source index. Before these 3 steps were represented as 3 chained cluster state updates, which would've seen the user manually intervene if, say, the alias rollover cluster state update (second in the chain) failed but the creation of the rollover index (first in the chain) update succeeded * Rename innerExecute to applyAliasActions (cherry picked from commit 1ba4339a0c73ef3354b8c8b44b628fc55f1dbc78) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
This commit is contained in:
parent
975cc99516
commit
a3cdbda7c6
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.action.admin.indices.rollover;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
|
||||
|
@ -150,56 +149,44 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
|||
new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false, false, false));
|
||||
return;
|
||||
}
|
||||
List<Condition<?>> metConditions = rolloverRequest.getConditions().values().stream()
|
||||
List<Condition<?>> metConditions = rolloverRequest.getConditions().values().stream()
|
||||
.filter(condition -> conditionResults.get(condition.toString())).collect(Collectors.toList());
|
||||
if (conditionResults.size() == 0 || metConditions.size() > 0) {
|
||||
CreateIndexClusterStateUpdateRequest updateRequest = prepareCreateIndexRequest(unresolvedName, rolloverIndexName,
|
||||
rolloverRequest);
|
||||
createIndexService.createIndex(updateRequest, ActionListener.wrap(createIndexClusterStateUpdateResponse -> {
|
||||
final IndicesAliasesClusterStateUpdateRequest aliasesUpdateRequest;
|
||||
if (explicitWriteIndex) {
|
||||
aliasesUpdateRequest = prepareRolloverAliasesWriteIndexUpdateRequest(sourceIndexName,
|
||||
rolloverIndexName, rolloverRequest);
|
||||
} else {
|
||||
aliasesUpdateRequest = prepareRolloverAliasesUpdateRequest(sourceIndexName,
|
||||
rolloverIndexName, rolloverRequest);
|
||||
CreateIndexClusterStateUpdateRequest createIndexRequest = prepareCreateIndexRequest(unresolvedName,
|
||||
rolloverIndexName, rolloverRequest);
|
||||
clusterService.submitStateUpdateTask("rollover_index source [" + sourceIndexName + "] to target ["
|
||||
+ rolloverIndexName + "]", new ClusterStateUpdateTask() {
|
||||
@Override
|
||||
public ClusterState execute(ClusterState currentState) throws Exception {
|
||||
ClusterState newState = createIndexService.applyCreateIndexRequest(currentState, createIndexRequest);
|
||||
newState = indexAliasesService.applyAliasActions(newState,
|
||||
rolloverAliasToNewIndex(sourceIndexName, rolloverIndexName, rolloverRequest, explicitWriteIndex));
|
||||
RolloverInfo rolloverInfo = new RolloverInfo(rolloverRequest.getAlias(), metConditions,
|
||||
threadPool.absoluteTimeInMillis());
|
||||
return ClusterState.builder(newState)
|
||||
.metaData(MetaData.builder(newState.metaData())
|
||||
.put(IndexMetaData.builder(newState.metaData().index(sourceIndexName))
|
||||
.putRolloverInfo(rolloverInfo))).build();
|
||||
}
|
||||
indexAliasesService.indicesAliases(aliasesUpdateRequest,
|
||||
ActionListener.wrap(aliasClusterStateUpdateResponse -> {
|
||||
if (aliasClusterStateUpdateResponse.isAcknowledged()) {
|
||||
clusterService.submitStateUpdateTask("update_rollover_info", new ClusterStateUpdateTask() {
|
||||
@Override
|
||||
public ClusterState execute(ClusterState currentState) {
|
||||
RolloverInfo rolloverInfo = new RolloverInfo(rolloverRequest.getAlias(), metConditions,
|
||||
threadPool.absoluteTimeInMillis());
|
||||
return ClusterState.builder(currentState)
|
||||
.metaData(MetaData.builder(currentState.metaData())
|
||||
.put(IndexMetaData.builder(currentState.metaData().index(sourceIndexName))
|
||||
.putRolloverInfo(rolloverInfo))).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String source, Exception e) {
|
||||
listener.onFailure(e);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(String source, Exception e) {
|
||||
listener.onFailure(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
|
||||
activeShardsObserver.waitForActiveShards(new String[]{rolloverIndexName},
|
||||
rolloverRequest.getCreateIndexRequest().waitForActiveShards(),
|
||||
rolloverRequest.masterNodeTimeout(),
|
||||
isShardsAcknowledged -> listener.onResponse(new RolloverResponse(
|
||||
sourceIndexName, rolloverIndexName, conditionResults, false, true, true,
|
||||
isShardsAcknowledged)),
|
||||
listener::onFailure);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults,
|
||||
false, true, false, false));
|
||||
}
|
||||
}, listener::onFailure));
|
||||
}, listener::onFailure));
|
||||
@Override
|
||||
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
|
||||
if (newState.equals(oldState) == false) {
|
||||
activeShardsObserver.waitForActiveShards(new String[]{rolloverIndexName},
|
||||
rolloverRequest.getCreateIndexRequest().waitForActiveShards(),
|
||||
rolloverRequest.masterNodeTimeout(),
|
||||
isShardsAcknowledged -> listener.onResponse(new RolloverResponse(
|
||||
sourceIndexName, rolloverIndexName, conditionResults, false, true, true,
|
||||
isShardsAcknowledged)),
|
||||
listener::onFailure);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// conditions not met
|
||||
listener.onResponse(
|
||||
|
@ -216,29 +203,24 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
|
|||
);
|
||||
}
|
||||
|
||||
static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesUpdateRequest(String oldIndex, String newIndex,
|
||||
RolloverRequest request) {
|
||||
List<AliasAction> actions = unmodifiableList(Arrays.asList(
|
||||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, null),
|
||||
new AliasAction.Remove(oldIndex, request.getAlias())));
|
||||
final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest(actions)
|
||||
.ackTimeout(request.ackTimeout())
|
||||
.masterNodeTimeout(request.masterNodeTimeout());
|
||||
return updateRequest;
|
||||
/**
|
||||
* Creates the alias actions to reflect the alias rollover from the old (source) index to the new (target/rolled over) index. An
|
||||
* alias pointing to multiple indices will have to be an explicit write index (ie. the old index alias has is_write_index set to true)
|
||||
* in which case, after the rollover, the new index will need to be the explicit write index.
|
||||
*/
|
||||
static List<AliasAction> rolloverAliasToNewIndex(String oldIndex, String newIndex, RolloverRequest request,
|
||||
boolean explicitWriteIndex) {
|
||||
if (explicitWriteIndex) {
|
||||
return unmodifiableList(Arrays.asList(
|
||||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, true),
|
||||
new AliasAction.Add(oldIndex, request.getAlias(), null, null, null, false)));
|
||||
} else {
|
||||
return unmodifiableList(Arrays.asList(
|
||||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, null),
|
||||
new AliasAction.Remove(oldIndex, request.getAlias())));
|
||||
}
|
||||
}
|
||||
|
||||
static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesWriteIndexUpdateRequest(String oldIndex, String newIndex,
|
||||
RolloverRequest request) {
|
||||
List<AliasAction> actions = unmodifiableList(Arrays.asList(
|
||||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, true),
|
||||
new AliasAction.Add(oldIndex, request.getAlias(), null, null, null, false)));
|
||||
final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest(actions)
|
||||
.ackTimeout(request.ackTimeout())
|
||||
.masterNodeTimeout(request.masterNodeTimeout());
|
||||
return updateRequest;
|
||||
}
|
||||
|
||||
|
||||
static String generateRolloverIndexName(String sourceIndexName, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
String resolvedName = indexNameExpressionResolver.resolveDateMathExpression(sourceIndexName);
|
||||
final boolean isDateMath = sourceIndexName.equals(resolvedName) == false;
|
||||
|
|
|
@ -258,7 +258,7 @@ public class MetaDataCreateIndexService {
|
|||
* Handles the cluster state transition to a version that reflects the {@link CreateIndexClusterStateUpdateRequest}.
|
||||
* All the requested changes are firstly validated before mutating the {@link ClusterState}.
|
||||
*/
|
||||
ClusterState applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request) throws Exception {
|
||||
public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateIndexClusterStateUpdateRequest request) throws Exception {
|
||||
logger.trace("executing IndexCreationTask for [{}] against cluster state version [{}]", request, currentState.version());
|
||||
Index createdIndex = null;
|
||||
String removalExtraInfo = null;
|
||||
|
|
|
@ -85,12 +85,15 @@ public class MetaDataIndexAliasesService {
|
|||
|
||||
@Override
|
||||
public ClusterState execute(ClusterState currentState) {
|
||||
return innerExecute(currentState, request.actions());
|
||||
return applyAliasActions(currentState, request.actions());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ClusterState innerExecute(ClusterState currentState, Iterable<AliasAction> actions) {
|
||||
/**
|
||||
* Handles the cluster state transition to a version that reflects the provided {@link AliasAction}s.
|
||||
*/
|
||||
public ClusterState applyAliasActions(ClusterState currentState, Iterable<AliasAction> actions) {
|
||||
List<Index> indicesToClose = new ArrayList<>();
|
||||
Map<String, IndexService> indices = new HashMap<>();
|
||||
try {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.indices.rollover;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
|
||||
import org.elasticsearch.action.admin.indices.stats.CommonStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndexStats;
|
||||
|
@ -219,15 +218,13 @@ public class TransportRolloverActionTests extends ESTestCase {
|
|||
results2.forEach((k, v) -> assertFalse(v));
|
||||
}
|
||||
|
||||
public void testCreateUpdateAliasRequest() {
|
||||
public void testRolloverAliasActions() {
|
||||
String sourceAlias = randomAlphaOfLength(10);
|
||||
String sourceIndex = randomAlphaOfLength(10);
|
||||
String targetIndex = randomAlphaOfLength(10);
|
||||
final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, targetIndex);
|
||||
final IndicesAliasesClusterStateUpdateRequest updateRequest =
|
||||
TransportRolloverAction.prepareRolloverAliasesUpdateRequest(sourceIndex, targetIndex, rolloverRequest);
|
||||
|
||||
List<AliasAction> actions = updateRequest.actions();
|
||||
List<AliasAction> actions = TransportRolloverAction.rolloverAliasToNewIndex(sourceIndex, targetIndex, rolloverRequest, false);
|
||||
assertThat(actions, hasSize(2));
|
||||
boolean foundAdd = false;
|
||||
boolean foundRemove = false;
|
||||
|
@ -246,15 +243,13 @@ public class TransportRolloverActionTests extends ESTestCase {
|
|||
assertTrue(foundRemove);
|
||||
}
|
||||
|
||||
public void testCreateUpdateAliasRequestWithExplicitWriteIndex() {
|
||||
public void testRolloverAliasActionsWithExplicitWriteIndex() {
|
||||
String sourceAlias = randomAlphaOfLength(10);
|
||||
String sourceIndex = randomAlphaOfLength(10);
|
||||
String targetIndex = randomAlphaOfLength(10);
|
||||
final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, targetIndex);
|
||||
final IndicesAliasesClusterStateUpdateRequest updateRequest =
|
||||
TransportRolloverAction.prepareRolloverAliasesWriteIndexUpdateRequest(sourceIndex, targetIndex, rolloverRequest);
|
||||
List<AliasAction> actions = TransportRolloverAction.rolloverAliasToNewIndex(sourceIndex, targetIndex, rolloverRequest, true);
|
||||
|
||||
List<AliasAction> actions = updateRequest.actions();
|
||||
assertThat(actions, hasSize(2));
|
||||
boolean foundAddWrite = false;
|
||||
boolean foundRemoveWrite = false;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), index);
|
||||
|
||||
// Add an alias to it
|
||||
ClusterState after = service.innerExecute(before, singletonList(new AliasAction.Add(index, "test", null, null, null, null)));
|
||||
ClusterState after = service.applyAliasActions(before, singletonList(new AliasAction.Add(index, "test", null, null, null, null)));
|
||||
AliasOrIndex alias = after.metaData().getAliasAndIndexLookup().get("test");
|
||||
assertNotNull(alias);
|
||||
assertTrue(alias.isAlias());
|
||||
|
@ -82,7 +82,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
|
||||
// Remove the alias from it while adding another one
|
||||
before = after;
|
||||
after = service.innerExecute(before, Arrays.asList(
|
||||
after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Remove(index, "test"),
|
||||
new AliasAction.Add(index, "test_2", null, null, null, null)));
|
||||
assertNull(after.metaData().getAliasAndIndexLookup().get("test"));
|
||||
|
@ -94,7 +94,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
|
||||
// Now just remove on its own
|
||||
before = after;
|
||||
after = service.innerExecute(before, singletonList(new AliasAction.Remove(index, "test_2")));
|
||||
after = service.applyAliasActions(before, singletonList(new AliasAction.Remove(index, "test_2")));
|
||||
assertNull(after.metaData().getAliasAndIndexLookup().get("test"));
|
||||
assertNull(after.metaData().getAliasAndIndexLookup().get("test_2"));
|
||||
assertAliasesVersionIncreased(index, before, after);
|
||||
|
@ -110,7 +110,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
before = createIndex(before, index);
|
||||
addActions.add(new AliasAction.Add(index, "alias-" + index, null, null, null, null));
|
||||
}
|
||||
final ClusterState afterAddingAliasesToAll = service.innerExecute(before, addActions);
|
||||
final ClusterState afterAddingAliasesToAll = service.applyAliasActions(before, addActions);
|
||||
assertAliasesVersionIncreased(indices.toArray(new String[0]), before, afterAddingAliasesToAll);
|
||||
|
||||
// now add some aliases randomly
|
||||
|
@ -122,7 +122,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
randomIndices.add(index);
|
||||
}
|
||||
}
|
||||
final ClusterState afterAddingRandomAliases = service.innerExecute(afterAddingAliasesToAll, randomAddActions);
|
||||
final ClusterState afterAddingRandomAliases = service.applyAliasActions(afterAddingAliasesToAll, randomAddActions);
|
||||
assertAliasesVersionIncreased(randomIndices.toArray(new String[0]), afterAddingAliasesToAll, afterAddingRandomAliases);
|
||||
assertAliasesVersionUnchanged(
|
||||
Sets.difference(indices, randomIndices).toArray(new String[0]),
|
||||
|
@ -135,15 +135,15 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
final ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), index);
|
||||
|
||||
final ClusterState afterAddWriteAlias =
|
||||
service.innerExecute(before, singletonList(new AliasAction.Add(index, "test", null, null, null, true)));
|
||||
service.applyAliasActions(before, singletonList(new AliasAction.Add(index, "test", null, null, null, true)));
|
||||
assertAliasesVersionIncreased(index, before, afterAddWriteAlias);
|
||||
|
||||
final ClusterState afterChangeWriteAliasToNonWriteAlias =
|
||||
service.innerExecute(afterAddWriteAlias, singletonList(new AliasAction.Add(index, "test", null, null, null, false)));
|
||||
service.applyAliasActions(afterAddWriteAlias, singletonList(new AliasAction.Add(index, "test", null, null, null, false)));
|
||||
assertAliasesVersionIncreased(index, afterAddWriteAlias, afterChangeWriteAliasToNonWriteAlias);
|
||||
|
||||
final ClusterState afterChangeNonWriteAliasToWriteAlias =
|
||||
service.innerExecute(
|
||||
service.applyAliasActions(
|
||||
afterChangeWriteAliasToNonWriteAlias,
|
||||
singletonList(new AliasAction.Add(index, "test", null, null, null, true)));
|
||||
assertAliasesVersionIncreased(index, afterChangeWriteAliasToNonWriteAlias, afterChangeNonWriteAliasToWriteAlias);
|
||||
|
@ -159,7 +159,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
for (int i = 0; i < length; i++) {
|
||||
addActions.add(new AliasAction.Add(index, "test", null, null, null, null));
|
||||
}
|
||||
final ClusterState afterAddingAliases = service.innerExecute(before, addActions);
|
||||
final ClusterState afterAddingAliases = service.applyAliasActions(before, addActions);
|
||||
|
||||
assertAliasesVersionIncreased(index, before, afterAddingAliases);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
final String aliasName = randomValueOtherThanMany(v -> aliasNames.add(v) == false, () -> randomAlphaOfLength(8));
|
||||
addActions.add(new AliasAction.Add(index, aliasName, null, null, null, null));
|
||||
}
|
||||
final ClusterState afterAddingAlias = service.innerExecute(before, addActions);
|
||||
final ClusterState afterAddingAlias = service.applyAliasActions(before, addActions);
|
||||
|
||||
// now perform a remove and add for each alias which is idempotent, the resulting aliases are unchanged
|
||||
final List<AliasAction> removeAndAddActions = new ArrayList<>(2 * length);
|
||||
|
@ -184,7 +184,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
removeAndAddActions.add(new AliasAction.Remove(index, aliasName));
|
||||
removeAndAddActions.add(new AliasAction.Add(index, aliasName, null, null, null, null));
|
||||
}
|
||||
final ClusterState afterRemoveAndAddAlias = service.innerExecute(afterAddingAlias, removeAndAddActions);
|
||||
final ClusterState afterRemoveAndAddAlias = service.applyAliasActions(afterAddingAlias, removeAndAddActions);
|
||||
assertAliasesVersionUnchanged(index, afterAddingAlias, afterRemoveAndAddAlias);
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
before = createIndex(before, "test_2");
|
||||
|
||||
// Now remove "test" and add an alias to "test" to "test_2" in one go
|
||||
ClusterState after = service.innerExecute(before, Arrays.asList(
|
||||
ClusterState after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test_2", "test", null, null, null, null),
|
||||
new AliasAction.RemoveIndex("test")));
|
||||
AliasOrIndex alias = after.metaData().getAliasAndIndexLookup().get("test");
|
||||
|
@ -209,7 +209,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), "test");
|
||||
|
||||
// Attempt to add an alias to "test" at the same time as we remove it
|
||||
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.innerExecute(before, Arrays.asList(
|
||||
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, null),
|
||||
new AliasAction.RemoveIndex("test"))));
|
||||
assertEquals("test", e.getIndex().getName());
|
||||
|
@ -220,7 +220,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), "test");
|
||||
|
||||
// Try to remove an index twice. This should just remove the index once....
|
||||
ClusterState after = service.innerExecute(before, Arrays.asList(
|
||||
ClusterState after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.RemoveIndex("test"),
|
||||
new AliasAction.RemoveIndex("test")));
|
||||
assertNull(after.metaData().getAliasAndIndexLookup().get("test"));
|
||||
|
@ -229,20 +229,20 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
public void testAddWriteOnlyWithNoExistingAliases() {
|
||||
ClusterState before = createIndex(ClusterState.builder(ClusterName.DEFAULT).build(), "test");
|
||||
|
||||
ClusterState after = service.innerExecute(before, Arrays.asList(
|
||||
ClusterState after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, false)));
|
||||
assertFalse(after.metaData().index("test").getAliases().get("alias").writeIndex());
|
||||
assertNull(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex());
|
||||
assertAliasesVersionIncreased("test", before, after);
|
||||
|
||||
after = service.innerExecute(before, Arrays.asList(
|
||||
after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, null)));
|
||||
assertNull(after.metaData().index("test").getAliases().get("alias").writeIndex());
|
||||
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
|
||||
equalTo(after.metaData().index("test")));
|
||||
assertAliasesVersionIncreased("test", before, after);
|
||||
|
||||
after = service.innerExecute(before, Arrays.asList(
|
||||
after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, true)));
|
||||
assertTrue(after.metaData().index("test").getAliases().get("alias").writeIndex());
|
||||
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
|
||||
|
@ -259,7 +259,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
ClusterState before = ClusterState.builder(ClusterName.DEFAULT)
|
||||
.metaData(MetaData.builder().put(indexMetaData).put(indexMetaData2)).build();
|
||||
|
||||
ClusterState after = service.innerExecute(before, Arrays.asList(
|
||||
ClusterState after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, null)));
|
||||
assertNull(after.metaData().index("test").getAliases().get("alias").writeIndex());
|
||||
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
|
||||
|
@ -267,7 +267,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
assertAliasesVersionIncreased("test", before, after);
|
||||
assertAliasesVersionUnchanged("test2", before, after);
|
||||
|
||||
Exception exception = expectThrows(IllegalStateException.class, () -> service.innerExecute(before, Arrays.asList(
|
||||
Exception exception = expectThrows(IllegalStateException.class, () -> service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, true))));
|
||||
assertThat(exception.getMessage(), startsWith("alias [alias] has more than one write index ["));
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
new AliasAction.Add("test2", "alias", null, null, null, true)
|
||||
);
|
||||
Collections.shuffle(swapActions, random());
|
||||
ClusterState after = service.innerExecute(before, swapActions);
|
||||
ClusterState after = service.applyAliasActions(before, swapActions);
|
||||
assertThat(after.metaData().index("test").getAliases().get("alias").writeIndex(), equalTo(unsetValue));
|
||||
assertTrue(after.metaData().index("test2").getAliases().get("alias").writeIndex());
|
||||
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
|
||||
|
@ -310,7 +310,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
|
||||
assertNull(((AliasOrIndex.Alias) before.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex());
|
||||
|
||||
ClusterState after = service.innerExecute(before, Arrays.asList(
|
||||
ClusterState after = service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test3", "alias", null, null, null, true)));
|
||||
assertTrue(after.metaData().index("test3").getAliases().get("alias").writeIndex());
|
||||
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
|
||||
|
@ -334,7 +334,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
assertNull(before.metaData().index("test2").getAliases().get("alias").writeIndex());
|
||||
assertNull(((AliasOrIndex.Alias) before.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex());
|
||||
|
||||
ClusterState after = service.innerExecute(before, Collections.singletonList(new AliasAction.RemoveIndex("test")));
|
||||
ClusterState after = service.applyAliasActions(before, Collections.singletonList(new AliasAction.RemoveIndex("test")));
|
||||
assertNull(after.metaData().index("test2").getAliases().get("alias").writeIndex());
|
||||
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
|
||||
equalTo(after.metaData().index("test2")));
|
||||
|
@ -349,7 +349,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
|
|||
ClusterState before = ClusterState.builder(ClusterName.DEFAULT)
|
||||
.metaData(MetaData.builder().put(indexMetaData).put(indexMetaData2)).build();
|
||||
|
||||
Exception exception = expectThrows(IllegalStateException.class, () -> service.innerExecute(before, Arrays.asList(
|
||||
Exception exception = expectThrows(IllegalStateException.class, () -> service.applyAliasActions(before, Arrays.asList(
|
||||
new AliasAction.Add("test", "alias", null, null, null, true),
|
||||
new AliasAction.Add("test2", "alias", null, null, null, true)
|
||||
)));
|
||||
|
|
Loading…
Reference in New Issue