Permalink
Browse files

Fixed suggestions for http://code.google.com/p/project-voldemort/sour…

  • Loading branch information...
1 parent eb04276 commit f0754d787abccc054338217685b5e25e72a6057e @bbansal bbansal committed Apr 7, 2009
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
+import junit.framework.Assert;
import voldemort.VoldemortException;
import voldemort.annotations.concurrency.Threadsafe;
import voldemort.annotations.jmx.JmxGetter;
@@ -110,4 +111,29 @@ public String toString() {
return builder.toString();
}
+ @Override
+ public boolean equals(Object second) {
+ Cluster secondCluster = (Cluster) second;
+ if(this.getNodes().size() != secondCluster.getNodes().size()) {
+ return false;
+ }
+
+ // cannot use ArrayList.equals() as order might be different
+ ArrayList<Node> nodeAList = new ArrayList<Node>(this.getNodes());
+ for(int i = 0; i < this.getNodes().size(); i++) {
+ Node nodeA = nodeAList.get(i);
+ Node nodeB = secondCluster.getNodeById(nodeA.getId());
+
+ if(nodeA.getNumberOfPartitions() != nodeB.getNumberOfPartitions()) {return false;}
+
+ for(int j = 0; j < nodeA.getNumberOfPartitions(); j++) {
+ if (nodeA.getPartitionIds() != nodeB.getPartitionIds())
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
}
@@ -14,16 +14,12 @@
* the License.
*/
-package voldemort.store.rebalancing;
+package voldemort.store;
import java.util.List;
import voldemort.VoldemortException;
import voldemort.routing.RoutingStrategy;
-import voldemort.store.DelegatingStore;
-import voldemort.store.InvalidMetadataException;
-import voldemort.store.Store;
-import voldemort.store.StoreUtils;
import voldemort.utils.ByteArray;
import voldemort.versioning.Version;
import voldemort.versioning.Versioned;
@@ -31,7 +31,6 @@
import java.util.SortedSet;
import java.util.TreeSet;
-import junit.framework.Assert;
import voldemort.client.RoutingTier;
import voldemort.cluster.Cluster;
import voldemort.cluster.Node;
@@ -305,29 +304,7 @@ public static RoutingStrategy getRoutingStrategy(int[][] partitionMap, int numRe
return nodes;
}
- public static void checkClusterMatch(Cluster A, Cluster B) {
- Assert.assertEquals("num nodes do not match.", A.getNodes().size(), B.getNodes().size());
-
- ArrayList<Node> nodeAList = new ArrayList<Node>(A.getNodes());
-
- for(int i = 0; i < A.getNodes().size(); i++) {
- Node nodeA = nodeAList.get(i);
- Node nodeB = B.getNodeById(nodeA.getId());
- Assert.assertEquals("NodeId do not match", nodeA.getId(), nodeB.getId());
- Assert.assertEquals("num partitions for Node:" + nodeA.getId() + " Do not match",
- nodeA.getNumberOfPartitions(),
- nodeB.getNumberOfPartitions());
-
- for(int j = 0; j < nodeA.getNumberOfPartitions(); j++) {
- Assert.assertEquals("partitionList do not match",
- nodeA.getPartitionIds(),
- nodeB.getPartitionIds());
- }
- }
-
- }
-
- public static int getPartitionsDiff(Cluster orig, Cluster updated) {
+ public static int getMissingPartitionsSize(Cluster orig, Cluster updated) {
int diffPartition = 0;
ArrayList<Node> nodeAList = new ArrayList<Node>(orig.getNodes());
@@ -342,12 +319,11 @@ public static int getPartitionsDiff(Cluster orig, Cluster updated) {
continue;
}
- SortedSet<Integer> BpartitonSet = new TreeSet<Integer>(nodeB.getPartitionIds());
+ SortedSet<Integer> bPartitonSet = new TreeSet<Integer>(nodeB.getPartitionIds());
for(int p: nodeA.getPartitionIds()) {
- if(!BpartitonSet.contains(new Integer(p))) {
+ if(!bPartitonSet.contains(new Integer(p))) {
diffPartition++;
}
-
}
}
return diffPartition;
@@ -23,6 +23,7 @@
import voldemort.cluster.Node;
import voldemort.routing.RoutingStrategy;
import voldemort.store.DoNothingStore;
+import voldemort.store.InvalidMetadataCheckingStore;
import voldemort.store.InvalidMetadataException;
import voldemort.store.Store;
import voldemort.utils.ByteArray;

0 comments on commit f0754d7

Please sign in to comment.