Skip to content

Commit

Permalink
Simplify CcrRetentionLeaseIT#testForgetFollower
Browse files Browse the repository at this point in the history
This test was more complicated than necessary, where we were capturing
requests to prevent removal of retention leases, so that our forget
follower request could remove the retention leases instead. Instead, a
pause is enough to ensure that the retention leases are not re-added
after we remove them by the forget follower request. This commit
simplifies this test, and should remove some spurious failures.

Closes #39850
  • Loading branch information
jasontedor committed Mar 8, 2019
1 parent 4f5ca36 commit 833474e
Showing 1 changed file with 20 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -937,60 +937,29 @@ public void testForgetFollower() throws Exception {
pauseFollow(followerIndex);
followerClient().admin().indices().close(new CloseIndexRequest(followerIndex)).actionGet();

final ClusterStateResponse followerClusterState = followerClient().admin().cluster().prepareState().clear().setNodes(true).get();
try {
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
final MockTransportService senderTransportService =
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
senderTransportService.addSendBehavior(
(connection, requestId, action, request, options) -> {
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)
|| TransportActionProxy.getProxyAction(RetentionLeaseActions.Remove.ACTION_NAME).equals(action)) {
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
if (randomBoolean()) {
throw new ConnectTransportException(connection.getNode(), "connection failed");
} else {
throw new IndexShardClosedException(removeRequest.getShardId());
}
}
connection.sendRequest(requestId, action, request, options);
});
}

expectThrows(
ElasticsearchException.class,
() -> followerClient().execute(UnfollowAction.INSTANCE, new UnfollowAction.Request(followerIndex)).actionGet());

final ClusterStateResponse followerIndexClusterState =
followerClient().admin().cluster().prepareState().clear().setMetaData(true).setIndices(followerIndex).get();
final String followerUUID = followerIndexClusterState.getState().metaData().index(followerIndex).getIndexUUID();
final ClusterStateResponse followerIndexClusterState =
followerClient().admin().cluster().prepareState().clear().setMetaData(true).setIndices(followerIndex).get();
final String followerUUID = followerIndexClusterState.getState().metaData().index(followerIndex).getIndexUUID();

final BroadcastResponse forgetFollowerResponse = leaderClient().execute(
ForgetFollowerAction.INSTANCE,
new ForgetFollowerAction.Request(
getFollowerCluster().getClusterName(),
followerIndex,
followerUUID,
"leader_cluster",
leaderIndex)).actionGet();
final BroadcastResponse forgetFollowerResponse = leaderClient().execute(
ForgetFollowerAction.INSTANCE,
new ForgetFollowerAction.Request(
getFollowerCluster().getClusterName(),
followerIndex,
followerUUID,
"leader_cluster",
leaderIndex)).actionGet();

assertThat(forgetFollowerResponse.getTotalShards(), equalTo(numberOfShards));
assertThat(forgetFollowerResponse.getSuccessfulShards(), equalTo(numberOfShards));
assertThat(forgetFollowerResponse.getFailedShards(), equalTo(0));
assertThat(forgetFollowerResponse.getShardFailures(), emptyArray());
assertThat(forgetFollowerResponse.getTotalShards(), equalTo(numberOfShards));
assertThat(forgetFollowerResponse.getSuccessfulShards(), equalTo(numberOfShards));
assertThat(forgetFollowerResponse.getFailedShards(), equalTo(0));
assertThat(forgetFollowerResponse.getShardFailures(), emptyArray());

final IndicesStatsResponse afterForgetFollowerStats =
leaderClient().admin().indices().stats(new IndicesStatsRequest().clear().indices(leaderIndex)).actionGet();
final List<ShardStats> afterForgetFollowerShardsStats = getShardsStats(afterForgetFollowerStats);
for (final ShardStats shardStats : afterForgetFollowerShardsStats) {
assertThat(shardStats.getRetentionLeaseStats().retentionLeases().leases(), empty());
}
} finally {
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getDataNodes().values()) {
final MockTransportService senderTransportService =
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
senderTransportService.clearAllRules();
}
final IndicesStatsResponse afterForgetFollowerStats =
leaderClient().admin().indices().stats(new IndicesStatsRequest().clear().indices(leaderIndex)).actionGet();
final List<ShardStats> afterForgetFollowerShardsStats = getShardsStats(afterForgetFollowerStats);
for (final ShardStats shardStats : afterForgetFollowerShardsStats) {
assertThat(shardStats.getRetentionLeaseStats().retentionLeases().leases(), empty());
}
}

Expand Down

0 comments on commit 833474e

Please sign in to comment.