This is an automated email from the ASF dual-hosted git repository.

samt pushed a commit to branch cassandra-4.1
in repository https://gitbox.apache.org/repos/asf/cassandra.git

commit 9ff31e806070873449ceb6e47aaa5e25118b466f
Author: Sam Tunnicliffe <[email protected]>
AuthorDate: Wed Sep 18 13:21:39 2024 +0100

    Equality check for Paxos.Electorate should not depend on collection types
    
    Patch by Sam Tunnicliffe; reviewed by Marcus Eriksson for CASSANDRA-19935
---
 CHANGES.txt                                        |  1 +
 .../org/apache/cassandra/service/paxos/Paxos.java  |  5 +-
 .../service/paxos/PaxosElectorateTest.java         | 55 ++++++++++++++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index f27d82f87b..6d6da13c10 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.1.8
+ * Equality check for Paxos.Electorate should not depend on collection types 
(CASSANDRA-19935)
  * Fix race condition in DecayingEstimatedHistogramReservoir during rescale 
(CASSANDRA-19365)
 Merged from 4.0:
  * Add configurable batchlog endpoint strategies: random_remote, prefer_local, 
dynamic_remote, and dynamic (CASSANDRA-18120)
diff --git a/src/java/org/apache/cassandra/service/paxos/Paxos.java 
b/src/java/org/apache/cassandra/service/paxos/Paxos.java
index 36968d8160..1e6f0c813c 100644
--- a/src/java/org/apache/cassandra/service/paxos/Paxos.java
+++ b/src/java/org/apache/cassandra/service/paxos/Paxos.java
@@ -273,7 +273,10 @@ public class Paxos
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
             Electorate that = (Electorate) o;
-            return natural.equals(that.natural) && 
pending.equals(that.pending);
+            return natural.size() == that.natural.size() &&
+                   pending.size() == that.pending.size() &&
+                   natural.containsAll(that.natural)  &&
+                   pending.containsAll(that.pending);
         }
 
         public int hashCode()
diff --git 
a/test/unit/org/apache/cassandra/service/paxos/PaxosElectorateTest.java 
b/test/unit/org/apache/cassandra/service/paxos/PaxosElectorateTest.java
new file mode 100644
index 0000000000..67756d9635
--- /dev/null
+++ b/test/unit/org/apache/cassandra/service/paxos/PaxosElectorateTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service.paxos;
+
+import java.net.UnknownHostException;
+import java.util.HashSet;
+
+import org.junit.Test;
+
+import org.apache.cassandra.dht.Murmur3Partitioner;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.locator.EndpointsForToken;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.locator.Replica;
+import org.apache.cassandra.service.paxos.Paxos.Electorate;
+
+import static org.junit.Assert.assertEquals;
+
+public class PaxosElectorateTest
+{
+
+    @Test
+    public void compareElectoratesWithDifferentCollectionTypes() throws 
UnknownHostException
+    {
+        Token t = new Murmur3Partitioner.LongToken(0L);
+        EndpointsForToken natural = EndpointsForToken.of(t, 
replica(1),replica(2), replica(3));
+        EndpointsForToken pending = EndpointsForToken.of(t, replica(4));
+        Electorate first = new Electorate(natural.endpointList(), 
pending.endpointList());
+        Electorate second = new Electorate(new HashSet<>(natural.endpoints()), 
new HashSet<>(pending.endpoints()));
+        assertEquals(first, second);
+    }
+
+    private static Replica replica(int i) throws UnknownHostException
+    {
+        return Replica.fullReplica(InetAddressAndPort.getByName("127.0.0." + 
i),
+                                   
Murmur3Partitioner.instance.getMinimumToken(),
+                                   
Murmur3Partitioner.instance.getMinimumToken());
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to