/** * Use this method for creating a PartitionMap that has only one shard (0) and whose range is -Infinity, +Infinity */ public static PartitionMap oneShardOpenedMap() { // For convenience, we create a 1-shard opened map here (shard = 0) List<PartitionEntry> partitionMap = new ArrayList<PartitionEntry>(); PartitionEntry openedEntry = new PartitionEntry(); openedEntry.setMin(null); openedEntry.setMax(null); openedEntry.setShard(0); partitionMap.add(openedEntry); return new PartitionMap(partitionMap); }
/** * 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 min and a max key, return all the partitions that impact this range, min and max inclusive. * <p> * Note that (null, null) is a valid input to this method and will be interpreted as the whole key range, regardless * of the key type (that's why we use null for representing opened ranges). */ public List<Integer> findPartitions(String minKey, String maxKey) { List<Integer> partitions = new ArrayList<Integer>(); int minPartitionIndex = 0, maxPartitionIndex = partitionEntries.size() - 1; if(minKey != null) { minPartitionIndex = findPartition(minKey); } if(maxKey != null) { maxPartitionIndex = findPartition(maxKey); } for(int i = minPartitionIndex; i <= maxPartitionIndex; i++) { partitions.add(partitionEntries.get(i).getShard()); } return partitions; }
/** * Given a min and a max key, return all the partitions that impact this range, min and max inclusive. * <p/> * Note that (null, null) is a valid input to this method and will be interpreted as the whole key range, regardless * of the key type (that's why we use null for representing opened ranges). */ public List<Integer> findPartitions(String minKey, String maxKey) { List<Integer> partitions = new ArrayList<Integer>(); int minPartitionIndex = 0, maxPartitionIndex = partitionEntries.size() - 1; if (minKey != null) { minPartitionIndex = findPartition(minKey); } if (maxKey != null) { maxPartitionIndex = findPartition(maxKey); } for (int i = minPartitionIndex; i <= maxPartitionIndex; i++) { partitions.add(partitionEntries.get(i).getShard()); } return partitions; }
/** * Use this method for creating a PartitionMap that has only one shard (0) and whose range is -Infinity, +Infinity */ public static PartitionMap oneShardOpenedMap() { // For convenience, we create a 1-shard opened map here (shard = 0) List<PartitionEntry> partitionMap = new ArrayList<PartitionEntry>(); PartitionEntry openedEntry = new PartitionEntry(); openedEntry.setMin(null); openedEntry.setMax(null); openedEntry.setShard(0); partitionMap.add(openedEntry); return new PartitionMap(partitionMap); }
/** * 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; }
boolean foundDistinctKey = false; for (int i = 1; i <= nPartitions; i++) { PartitionEntry entry = new PartitionEntry(); if (min != null) { entry.setMin(min); candidateToLastPartitionMin = previousKey; entry.setMax(key.toString()); min = key.toString(); entry.setShard(i - 1); // Shard are 0-indexed partitionEntries.add(entry); partitionEntries.get(generatedPartitions - 1).setMax(null); if (compareWithNulls(previous.getMin(), candidateToLastPartitionMin) < 0) { previous.setMax(candidateToLastPartitionMin); latest.setMin(candidateToLastPartitionMin); } else { previous.setMax(null); partitionEntries.remove(generatedPartitions - 1);
PartitionEntry pEntry = null; for (PartitionEntry partEntry : req.getPartitionMap()) { if (partEntry.getShard().equals(rEntry.getShard())) { pEntry = partEntry; metadata.setMinKey(pEntry.getMin()); metadata.setMaxKey(pEntry.getMax()); metadata.setNReplicas(rEntry.getNodes().size()); metadata.setDeploymentDate(deployDate);
int thisMax = (i + 1) * eachPartition; HadoopUtils.stringToFile(inFs, new Path(input, i + ".txt"), i + "\t" + thisMin + ":" + thisMax); PartitionEntry entry = new PartitionEntry(); entry.setMin(String.format(paddingExp, thisMin)); entry.setMax(String.format(paddingExp, thisMax)); entry.setShard(i); partitionEntries.add(entry); partitionEntries.get(0).setMin(null); partitionEntries.get(partitionEntries.size() - 1).setMax(null);
PartitionEntry pEntry = new PartitionEntry(); pEntry.setShard(entry.getShard()); tablespace.getPartitionMap().getPartitionEntries().remove(pEntry); PartitionEntry myEntry = new PartitionEntry(); myEntry.setMax(metadata.getMaxKey()); myEntry.setMin(metadata.getMinKey()); myEntry.setShard(shard); PartitionEntry existingPartitionEntry = null; 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); if (existingPartitionEntry.getMin() == null || myEntry.getMin() == null) { if (!(existingPartitionEntry.getMin() == null && myEntry.getMin() == null)) { throw new TablespaceVersionInfoException("Inconsistent partition metadata between nodes: " + existingPartitionEntry + " versus " + myEntry); if (!existingPartitionEntry.getMin().equals(myEntry.getMin())) { throw new TablespaceVersionInfoException("Inconsistent partition metadata between nodes: " + existingPartitionEntry + " versus " + myEntry);