Skip to content

Commit 5954354

Browse files
authored
Fix ShardFollowNodeTask.Status equals and hash code (#33189)
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.
1 parent d8a1b7c commit 5954354

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ public NavigableMap<Long, ElasticsearchException> fetchExceptions() {
687687
this.numberOfSuccessfulBulkOperations = numberOfSuccessfulBulkOperations;
688688
this.numberOfFailedBulkOperations = numberOfFailedBulkOperations;
689689
this.numberOfOperationsIndexed = numberOfOperationsIndexed;
690-
this.fetchExceptions = fetchExceptions;
690+
this.fetchExceptions = Objects.requireNonNull(fetchExceptions);
691691
}
692692

693693
public Status(final StreamInput in) throws IOException {
@@ -821,7 +821,15 @@ public boolean equals(final Object o) {
821821
operationsReceived == that.operationsReceived &&
822822
totalTransferredBytes == that.totalTransferredBytes &&
823823
numberOfSuccessfulBulkOperations == that.numberOfSuccessfulBulkOperations &&
824-
numberOfFailedBulkOperations == that.numberOfFailedBulkOperations;
824+
numberOfFailedBulkOperations == that.numberOfFailedBulkOperations &&
825+
numberOfOperationsIndexed == that.numberOfOperationsIndexed &&
826+
/*
827+
* ElasticsearchException does not implement equals so we will assume the fetch exceptions are equal if they are equal
828+
* up to the key set and their messages. Note that we are relying on the fact that the fetch exceptions are ordered by
829+
* keys.
830+
*/
831+
fetchExceptions.keySet().equals(that.fetchExceptions.keySet()) &&
832+
getFetchExceptionMessages(this).equals(getFetchExceptionMessages(that));
825833
}
826834

827835
@Override
@@ -843,8 +851,18 @@ public int hashCode() {
843851
operationsReceived,
844852
totalTransferredBytes,
845853
numberOfSuccessfulBulkOperations,
846-
numberOfFailedBulkOperations);
847-
854+
numberOfFailedBulkOperations,
855+
numberOfOperationsIndexed,
856+
/*
857+
* ElasticsearchException does not implement hash code so we will compute the hash code based on the key set and the
858+
* messages. Note that we are relying on the fact that the fetch exceptions are ordered by keys.
859+
*/
860+
fetchExceptions.keySet(),
861+
getFetchExceptionMessages(this));
862+
}
863+
864+
private static List<String> getFetchExceptionMessages(final Status status) {
865+
return status.fetchExceptions().values().stream().map(ElasticsearchException::getMessage).collect(Collectors.toList());
848866
}
849867

850868
public String toString() {

0 commit comments

Comments
 (0)