Skip to content
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

Handle null retention leases in WaitForNoFollowersStep #40477

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;

/**
* A step that waits until the index it's used on is no longer a leader index.
Expand Down Expand Up @@ -57,8 +59,11 @@ public void evaluateCondition(IndexMetaData indexMetaData, Listener listener) {

boolean isCurrentlyLeaderIndex = Arrays.stream(indexStats.getShards())
.map(ShardStats::getRetentionLeaseStats)
.flatMap(retentionLeaseStats -> retentionLeaseStats.retentionLeases().leases().stream())
.anyMatch(lease -> CCR_LEASE_KEY.equals(lease.source()));
.map(Optional::ofNullable)
.map(o -> o.flatMap(stats -> Optional.ofNullable(stats.retentionLeases())))
.map(o -> o.flatMap(leases -> Optional.ofNullable(leases.leases())))
.map(o -> o.map(Collection::stream))
.anyMatch(lease -> lease.isPresent() && lease.get().anyMatch(l -> CCR_LEASE_KEY.equals(l.source())));

if (isCurrentlyLeaderIndex) {
listener.onResponse(false, new Info());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,42 @@ public void onFailure(Exception e) {
containsString("this index is a leader index; waiting for all following indices to cease following before proceeding"));
}

public void testNoShardStats() {
WaitForNoFollowersStep step = createRandomInstance();

String indexName = randomAlphaOfLengthBetween(5,10);

int numberOfShards = randomIntBetween(1, 100);
final IndexMetaData indexMetaData = IndexMetaData.builder(indexName)
.settings(settings(Version.CURRENT))
.numberOfShards(numberOfShards)
.numberOfReplicas(randomIntBetween(1, 10))
.build();

ShardStats sStats = new ShardStats(null, mockShardPath(), null, null, null, null);
ShardStats[] shardStats = new ShardStats[1];
shardStats[0] = sStats;
mockIndexStatsCall(step.getClient(), indexName, new IndexStats(indexName, "uuid", shardStats));

final SetOnce<Boolean> conditionMetHolder = new SetOnce<>();
final SetOnce<ToXContentObject> stepInfoHolder = new SetOnce<>();
step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject infomationContext) {
conditionMetHolder.set(conditionMet);
stepInfoHolder.set(infomationContext);
}

@Override
public void onFailure(Exception e) {
fail("onFailure should not be called in this test, called with exception: " + e.getMessage());
}
});

assertTrue(conditionMetHolder.get());
assertNull(stepInfoHolder.get());
}

public void testFailure() {
WaitForNoFollowersStep step = createRandomInstance();

Expand Down