Skip to content

Commit 43fbbee

Browse files
committed
iter
1 parent e7e0f14 commit 43fbbee

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import org.elasticsearch.rest.RestStatus;
2828
import org.elasticsearch.xpack.core.XPackPlugin;
2929

30+
import java.util.Arrays;
3031
import java.util.Collections;
32+
import java.util.HashSet;
3133
import java.util.Locale;
3234
import java.util.Objects;
3335
import java.util.function.BiConsumer;
@@ -73,12 +75,12 @@ public boolean isCcrAllowed() {
7375
* If the remote cluster is not licensed for CCR, the {@code onFailure} consumer is is invoked. Otherwise,
7476
* the specified consumer is invoked with the leader index metadata fetched from the remote cluster.
7577
*
76-
* @param client the client
77-
* @param clusterAlias the remote cluster alias
78-
* @param leaderIndex the name of the leader index
79-
* @param onFailure the failure consumer
80-
* @param consumer the consumer for supplying the leader index metadata and historyUUIDs of all leader shards
81-
* @param <T> the type of response the listener is waiting for
78+
* @param client the client
79+
* @param clusterAlias the remote cluster alias
80+
* @param leaderIndex the name of the leader index
81+
* @param onFailure the failure consumer
82+
* @param consumer the consumer for supplying the leader index metadata and historyUUIDs of all leader shards
83+
* @param <T> the type of response the listener is waiting for
8284
*/
8385
public <T> void checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUUIDs(
8486
final Client client,
@@ -208,14 +210,24 @@ public void fetchLeaderHistoryUUIDs(
208210
for (IndexShardStats indexShardStats : indexStats) {
209211
for (ShardStats shardStats : indexShardStats) {
210212
CommitStats commitStats = shardStats.getCommitStats();
213+
if (commitStats == null) {
214+
onFailure.accept(new IllegalArgumentException("leader index's commit stats are missing"));
215+
return;
216+
}
211217
String historyUUID = commitStats.getUserData().get(Engine.HISTORY_UUID_KEY);
218+
if (historyUUID == null) {
219+
onFailure.accept(new IllegalArgumentException("leader index does not have an history uuid"));
220+
return;
221+
}
212222
ShardId shardId = shardStats.getShardRouting().shardId();
213223
historyUUIDs[shardId.id()] = historyUUID;
214224
}
215225
}
226+
assert new HashSet<>(Arrays.asList(historyUUIDs)).size() == leaderIndexMetaData.getNumberOfShards();
216227
historyUUIDConsumer.accept(historyUUIDs);
217228
};
218229
IndicesStatsRequest request = new IndicesStatsRequest();
230+
request.clear();
219231
request.indices(leaderIndex);
220232
leaderClient.admin().indices().stats(request, ActionListener.wrap(indicesStatsHandler, onFailure));
221233
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ static void validate(Request request,
546546
String recordedLeaderIndexHistoryUUID = recordedHistoryUUIDs[i];
547547
String actualLeaderIndexHistoryUUID = leaderIndexHistoryUUID[i];
548548
if (recordedLeaderIndexHistoryUUID.equals(actualLeaderIndexHistoryUUID) == false) {
549-
throw new IllegalArgumentException("follow index [" + request.followerIndex + "] should reference [" +
550-
recordedLeaderIndexHistoryUUID + "] as history uuid but instead reference [" +
551-
actualLeaderIndexHistoryUUID + "] as history uuid");
549+
throw new IllegalArgumentException("leader shard [" + request.followerIndex + "][" + i + "] should reference [" +
550+
recordedLeaderIndexHistoryUUID + "] as history uuid but instead reference [" + actualLeaderIndexHistoryUUID +
551+
"] as history uuid");
552552
}
553553
}
554554

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testValidation() throws IOException {
5252
IndexMetaData followIMD = createIMD("index2", 5, Settings.EMPTY, customMetaData);
5353
Exception e = expectThrows(IllegalArgumentException.class,
5454
() -> FollowIndexAction.validate(request, leaderIMD, followIMD, UUIDs, null));
55-
assertThat(e.getMessage(), equalTo("follow index [index2] should reference [another-uuid] as history uuid but " +
55+
assertThat(e.getMessage(), equalTo("leader shard [index2][0] should reference [another-uuid] as history uuid but " +
5656
"instead reference [uuid] as history uuid"));
5757
}
5858
{

0 commit comments

Comments
 (0)