fix infinite loop in test and correct logic in timeseries type
This commit is contained in:
parent
66af56320e
commit
6a47b4fa6e
|
@ -124,17 +124,21 @@ public class TimeseriesLifecycleType implements LifecycleType {
|
|||
case "warm":
|
||||
return (action) -> {
|
||||
ReplicasAction replicasAction = (ReplicasAction) actions.getOrDefault(ReplicasAction.NAME, null);
|
||||
boolean replicaActionFirst = replicasAction != null
|
||||
&& replicasAction.getNumberOfReplicas() <= context.getNumberOfReplicas();
|
||||
if (action == null) {
|
||||
if (replicasAction != null && replicasAction.getNumberOfReplicas() <= context.getNumberOfReplicas()) {
|
||||
if (replicaActionFirst) {
|
||||
return replicasAction;
|
||||
}
|
||||
return Stream.of(AllocateAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME, ReplicasAction.NAME)
|
||||
.map(a -> actions.getOrDefault(a, null))
|
||||
.filter(Objects::nonNull).findFirst().orElse(null);
|
||||
} else if (action instanceof ReplicasAction) {
|
||||
if (replicaActionFirst) {
|
||||
return Stream.of(AllocateAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME)
|
||||
.map(a -> actions.getOrDefault(a, null))
|
||||
.filter(Objects::nonNull).findFirst().orElse(null);
|
||||
}
|
||||
} else if (action instanceof AllocateAction) {
|
||||
return Stream.of(ShrinkAction.NAME, ForceMergeAction.NAME, ReplicasAction.NAME)
|
||||
.map(a -> actions.getOrDefault(a, null))
|
||||
|
|
|
@ -192,7 +192,6 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
|
|||
assertNull(provider.next(TEST_ROLLOVER_ACTION));
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "This gets into an infinite loop if there are other actions as well as the replicas action")
|
||||
public void testWarmActionProviderReplicasActionSortOrder() {
|
||||
String indexName = randomAlphaOfLengthBetween(1, 10);
|
||||
Map<String, LifecycleAction> actions = randomSubsetOf(VALID_WARM_ACTIONS)
|
||||
|
@ -222,20 +221,14 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
|
|||
};
|
||||
provider = policy.getActionProvider(context, warmPhase);
|
||||
if (actions.size() > 1) {
|
||||
int actionCount = 1;
|
||||
LifecycleAction current = provider.next(null);
|
||||
assertThat(current, not(equalTo(TEST_REPLICAS_ACTION)));
|
||||
while (true) {
|
||||
// NORELEASE This loop never exits as there is no break condition
|
||||
// also provider.next(current) never evaluates to null because
|
||||
// when called with the replicas action it always returns a
|
||||
// non-null action. We should avoid using while true here
|
||||
// because it means if there is a bug we will hang the build
|
||||
if (provider.next(current) == null) {
|
||||
assertThat(current, equalTo(TEST_REPLICAS_ACTION));
|
||||
} else {
|
||||
while (actionCount++ < actions.size()) {
|
||||
current = provider.next(current);
|
||||
}
|
||||
}
|
||||
assertNull(provider.next(current));
|
||||
assertThat(current, equalTo(TEST_REPLICAS_ACTION));
|
||||
} else {
|
||||
assertThat(provider.next(null), equalTo(TEST_REPLICAS_ACTION));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue