Skip to content

Commit cdf9bdc

Browse files
committed
Refactor
1 parent 69d757c commit cdf9bdc

File tree

5 files changed

+28
-41
lines changed

5 files changed

+28
-41
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrRetentionLeases.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,35 @@
66

77
package org.elasticsearch.xpack.ccr;
88

9+
import org.elasticsearch.index.Index;
10+
911
import java.util.Locale;
1012

1113
public class CcrRetentionLeases {
1214

1315
/**
1416
* The retention lease ID used by followers.
1517
*
16-
* @param followerUUID the follower index UUID
17-
* @param leaderUUID the leader index UUID
18+
* @param localClusterName the local cluster name
19+
* @param followerIndex the follower index
20+
* @param remoteClusterAlias the remote cluster alias
21+
* @param leaderIndex the leader index
1822
* @return the retention lease ID
1923
*/
2024
public static String retentionLeaseId(
2125
final String localClusterName,
22-
final String remoteClusterName,
23-
final String followerIndexName,
24-
final String followerUUID,
25-
final String leaderIndexName,
26-
final String leaderUUID) {
26+
final Index followerIndex,
27+
final String remoteClusterAlias,
28+
final Index leaderIndex) {
2729
return String.format(
2830
Locale.ROOT,
2931
"%s/%s/%s-following-%s/%s/%s",
3032
localClusterName,
31-
followerIndexName,
32-
followerUUID,
33-
remoteClusterName,
34-
leaderIndexName,
35-
leaderUUID);
33+
followerIndex.getName(),
34+
followerIndex.getUUID(),
35+
remoteClusterAlias,
36+
leaderIndex.getName(),
37+
leaderIndex.getUUID());
3638
}
3739

3840
}

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/repository/CcrRepository.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ public void restoreShard(IndexShard indexShard, SnapshotId snapshotId, Version v
307307
// TODO: Add timeouts to network calls / the restore process.
308308
createEmptyStore(indexShard, shardId);
309309

310-
final String followerIndexName = indexShard.shardId().getIndex().getName();
311-
final String followerUUID = indexShard.shardId().getIndex().getUUID();
312310
final Map<String, String> ccrMetaData = indexShard.indexSettings().getIndexMetaData().getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY);
313311
final String leaderIndexName = ccrMetaData.get(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_NAME_KEY);
314312
final String leaderUUID = ccrMetaData.get(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_UUID_KEY);
@@ -318,7 +316,7 @@ public void restoreShard(IndexShard indexShard, SnapshotId snapshotId, Version v
318316
final Client remoteClient = getRemoteClusterClient();
319317

320318
final String retentionLeaseId =
321-
retentionLeaseId(localClusterName, remoteClusterAlias, followerIndexName, followerUUID, leaderIndexName, leaderUUID);
319+
retentionLeaseId(localClusterName, indexShard.shardId().getIndex(), remoteClusterAlias, leaderIndex);
322320

323321
acquireRetentionLeaseOnLeader(shardId, retentionLeaseId, leaderShardId, remoteClient);
324322

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRetentionLeaseIT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.common.unit.ByteSizeValue;
2626
import org.elasticsearch.common.unit.TimeValue;
2727
import org.elasticsearch.common.xcontent.XContentType;
28+
import org.elasticsearch.index.Index;
2829
import org.elasticsearch.index.IndexService;
2930
import org.elasticsearch.index.IndexSettings;
3031
import org.elasticsearch.index.seqno.RetentionLease;
@@ -330,11 +331,9 @@ public void testRetentionLeasesAreNotBeingRenewedAfterRecoveryCompletes() throws
330331
currentRetentionLeases.leases().iterator().next();
331332
final String expectedRetentionLeaseId = retentionLeaseId(
332333
getFollowerCluster().getClusterName(),
334+
new Index(followerIndex, followerUUID),
333335
getLeaderCluster().getClusterName(),
334-
followerIndex,
335-
followerUUID,
336-
leaderIndex,
337-
leaderUUID);
336+
new Index(leaderIndex, leaderUUID));
338337
assertThat(retentionLease.id(), equalTo(expectedRetentionLeaseId));
339338
retentionLeases.add(currentRetentionLeases);
340339
}
@@ -393,11 +392,9 @@ private List<ShardStats> getShardStats(final IndicesStatsResponse stats) {
393392
private String getRetentionLeaseId(String followerIndex, String followerUUID, String leaderIndex, String leaderUUID) {
394393
return retentionLeaseId(
395394
getFollowerCluster().getClusterName(),
395+
new Index(followerIndex, followerUUID),
396396
getLeaderCluster().getClusterName(),
397-
followerIndex,
398-
followerUUID,
399-
leaderIndex,
400-
leaderUUID);
397+
new Index(leaderIndex, leaderUUID));
401398
}
402399

403400
private void assertExpectedDocument(final String followerIndex, final int value) {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.elasticsearch.common.xcontent.XContentBuilder;
5858
import org.elasticsearch.common.xcontent.XContentType;
5959
import org.elasticsearch.common.xcontent.support.XContentMapValues;
60+
import org.elasticsearch.index.Index;
6061
import org.elasticsearch.index.IndexNotFoundException;
6162
import org.elasticsearch.index.IndexSettings;
6263
import org.elasticsearch.index.seqno.RetentionLeaseActions;
@@ -1011,11 +1012,9 @@ public void testIndexFallBehind() throws Exception {
10111012

10121013
final String retentionLeaseId = retentionLeaseId(
10131014
getFollowerCluster().getClusterName(),
1015+
new Index("index2", followerUUID),
10141016
getLeaderCluster().getClusterName(),
1015-
"index2",
1016-
followerUUID,
1017-
"index1",
1018-
leaderUUID);
1017+
new Index("index1", leaderUUID));
10191018

10201019
for (final ObjectCursor<IndexShardRoutingTable> shardRoutingTable
10211020
: leaderRoutingTable.index("index1").shards().values()) {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/repository/CcrRepositoryRetentionLeaseTests.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.stream.Stream;
3030

3131
import static org.elasticsearch.index.seqno.RetentionLeaseActions.RETAIN_ALL;
32+
import static org.elasticsearch.xpack.ccr.CcrRetentionLeases.retentionLeaseId;
3233
import static org.hamcrest.Matchers.equalTo;
3334
import static org.mockito.Matchers.any;
3435
import static org.mockito.Matchers.same;
@@ -60,13 +61,8 @@ public void testWhenRetentionLeaseAlreadyExistsWeTryToRenewIt() {
6061
final ShardId followerShardId = new ShardId(new Index("follower-index-name", "follower-index-uuid"), 0);
6162
final ShardId leaderShardId = new ShardId(new Index("leader-index-name", "leader-index-uuid"), 0);
6263

63-
final String retentionLeaseId = CcrRetentionLeases.retentionLeaseId(
64-
"local-cluster",
65-
"remote-cluster",
66-
followerShardId.getIndex().getName(),
67-
followerShardId.getIndex().getUUID(),
68-
leaderShardId.getIndex().getName(),
69-
leaderShardId.getIndex().getUUID());
64+
final String retentionLeaseId =
65+
retentionLeaseId("local-cluster", followerShardId.getIndex(), "remote-cluster", leaderShardId.getIndex());
7066

7167
// simulate that the the retention lease already exists on the leader, and verify that we attempt to renew it
7268
final Client remoteClient = mock(Client.class);
@@ -118,13 +114,8 @@ public void testWhenRetentionLeaseExpiresBeforeWeCanRenewIt() {
118114
final ShardId followerShardId = new ShardId(new Index("follower-index-name", "follower-index-uuid"), 0);
119115
final ShardId leaderShardId = new ShardId(new Index("leader-index-name", "leader-index-uuid"), 0);
120116

121-
final String retentionLeaseId = CcrRetentionLeases.retentionLeaseId(
122-
"local-cluster",
123-
"remote-cluster",
124-
followerShardId.getIndex().getName(),
125-
followerShardId.getIndex().getUUID(),
126-
leaderShardId.getIndex().getName(),
127-
leaderShardId.getIndex().getUUID());
117+
final String retentionLeaseId =
118+
retentionLeaseId("local-cluster", followerShardId.getIndex(), "remote-cluster", leaderShardId.getIndex());
128119

129120
// simulate that the the retention lease already exists on the leader, expires before we renew, and verify that we attempt to add it
130121
final Client remoteClient = mock(Client.class);

0 commit comments

Comments
 (0)