/** * Given a key, return the partition that it belongs to, or {@link #NO_PARTITION} if none matches. Mathematically, * partitions match (min, max]. */ public int findPartition(String keyObj) { if(keyObj == null) { throw new IllegalArgumentException("Key obj can't be null for findPartition()"); } for(PartitionEntry entry : partitionEntries) { // We assume (-Infinity, Infinity) matching since nulls represent Infinity for any type <T> boolean minMatches = true; boolean maxMatches = true; if(entry.getMin() != null) { if((entry.getMin()).compareTo(keyObj) >= 0) { minMatches = false; } } if(entry.getMax() != null) { if((entry.getMax()).compareTo(keyObj) < 0) { maxMatches = false; } } if(minMatches && maxMatches) { return entry.getShard(); } } return NO_PARTITION; }
/** * Given a key, return the partition that it belongs to, or {@link #NO_PARTITION} if none matches. Mathematically, * partitions match (min, max]. */ public int findPartition(String keyObj) { if (keyObj == null) { throw new IllegalArgumentException("Key obj can't be null for findPartition()"); } for (PartitionEntry entry : partitionEntries) { // We assume (-Infinity, Infinity) matching since nulls represent Infinity for any type <T> boolean minMatches = true; boolean maxMatches = true; if (entry.getMin() != null) { if ((entry.getMin()).compareTo(keyObj) >= 0) { minMatches = false; } } if (entry.getMax() != null) { if ((entry.getMax()).compareTo(keyObj) < 0) { maxMatches = false; } } if (minMatches && maxMatches) { return entry.getShard(); } } return NO_PARTITION; }
if (existingPartitionEntry.getMax() == null || myEntry.getMax() == null) { if (!(existingPartitionEntry.getMax() == null && myEntry.getMax() == null)) { throw new TablespaceVersionInfoException("Inconsistent partition metadata between nodes: " + existingPartitionEntry + " versus " + myEntry); if (!existingPartitionEntry.getMax().equals(myEntry.getMax())) { throw new TablespaceVersionInfoException("Inconsistent partition metadata between nodes: " + existingPartitionEntry + " versus " + myEntry);
metadata.setMaxKey(pEntry.getMax()); metadata.setNReplicas(rEntry.getNodes().size()); metadata.setDeploymentDate(deployDate);