From 49475f42b307cbcece005ecc44fd7829cc84d704 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 27 Aug 2018 21:16:28 -0400 Subject: [PATCH 1/3] Fix ShardFollowNodeTask.Status equals and hash code These were broken when fetch exceptions were introduced to the status object but equals and hash code were not updated then. This commit addresses that. --- .../elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java index f2b5b7b3772d2..06a69fd82e5c6 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java @@ -822,7 +822,8 @@ public boolean equals(final Object o) { operationsReceived == that.operationsReceived && totalTransferredBytes == that.totalTransferredBytes && numberOfSuccessfulBulkOperations == that.numberOfSuccessfulBulkOperations && - numberOfFailedBulkOperations == that.numberOfFailedBulkOperations; + numberOfFailedBulkOperations == that.numberOfFailedBulkOperations && + fetchExceptions.equals(that.fetchExceptions); } @Override @@ -844,7 +845,8 @@ public int hashCode() { operationsReceived, totalTransferredBytes, numberOfSuccessfulBulkOperations, - numberOfFailedBulkOperations); + numberOfFailedBulkOperations, + fetchExceptions); } From bb600a9a5bb6c344026e76e79cc4fd0265cc8a26 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 27 Aug 2018 21:25:17 -0400 Subject: [PATCH 2/3] Require non-null --- .../org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java index 06a69fd82e5c6..09f8dc27627d9 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java @@ -688,7 +688,7 @@ public NavigableMap fetchExceptions() { this.numberOfSuccessfulBulkOperations = numberOfSuccessfulBulkOperations; this.numberOfFailedBulkOperations = numberOfFailedBulkOperations; this.numberOfOperationsIndexed = numberOfOperationsIndexed; - this.fetchExceptions = fetchExceptions; + this.fetchExceptions = Objects.requireNonNull(fetchExceptions); } public Status(final StreamInput in) throws IOException { From eb9d7b67b8ed491509fbdef6550e7ae468cd7eb1 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 28 Aug 2018 06:30:37 -0400 Subject: [PATCH 3/3] A little trickier! --- .../xpack/ccr/action/ShardFollowNodeTask.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java index 6b7d9825e5601..80d6ed4cb4abf 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java @@ -822,7 +822,14 @@ public boolean equals(final Object o) { totalTransferredBytes == that.totalTransferredBytes && numberOfSuccessfulBulkOperations == that.numberOfSuccessfulBulkOperations && numberOfFailedBulkOperations == that.numberOfFailedBulkOperations && - fetchExceptions.equals(that.fetchExceptions); + numberOfOperationsIndexed == that.numberOfOperationsIndexed && + /* + * ElasticsearchException does not implement equals so we will assume the fetch exceptions are equal if they are equal + * up to the key set and their messages. Note that we are relying on the fact that the fetch exceptions are ordered by + * keys. + */ + fetchExceptions.keySet().equals(that.fetchExceptions.keySet()) && + getFetchExceptionMessages(this).equals(getFetchExceptionMessages(that)); } @Override @@ -845,8 +852,17 @@ public int hashCode() { totalTransferredBytes, numberOfSuccessfulBulkOperations, numberOfFailedBulkOperations, - fetchExceptions); + numberOfOperationsIndexed, + /* + * ElasticsearchException does not implement hash code so we will compute the hash code based on the key set and the + * messages. Note that we are relying on the fact that the fetch exceptions are ordered by keys. + */ + fetchExceptions.keySet(), + getFetchExceptionMessages(this)); + } + private static List getFetchExceptionMessages(final Status status) { + return status.fetchExceptions().values().stream().map(ElasticsearchException::getMessage).collect(Collectors.toList()); } public String toString() {