public void checkRegionBoundaries() { try { ByteArrayComparator comparator = new ByteArrayComparator(); List<RegionInfo> regions = MetaTableAccessor.getAllRegions(connection, true); final RegionBoundariesInformation currentRegionBoundariesInformation = CacheConfig.DISABLED, true, getConf()); if ((reader.getFirstKey() != null) && ((storeFirstKey == null) || (comparator.compare(storeFirstKey, ((KeyValue.KeyOnlyKeyValue) reader.getFirstKey().get()).getKey()) > 0))) { storeFirstKey = ((KeyValue.KeyOnlyKeyValue)reader.getFirstKey().get()).getKey(); && ((storeLastKey == null) || (comparator.compare(storeLastKey, ((KeyValue.KeyOnlyKeyValue)reader.getLastKey().get()).getKey())) < 0)) { storeLastKey = ((KeyValue.KeyOnlyKeyValue)reader.getLastKey().get()).getKey(); && (currentRegionBoundariesInformation.metaFirstKey != null)) { valid = valid && comparator.compare(currentRegionBoundariesInformation.storesFirstKey, currentRegionBoundariesInformation.metaFirstKey) >= 0; && (currentRegionBoundariesInformation.metaLastKey != null)) { valid = valid && comparator.compare(currentRegionBoundariesInformation.storesLastKey, currentRegionBoundariesInformation.metaLastKey) < 0;
public void checkRegionBoundaries() { try { ByteArrayComparator comparator = new ByteArrayComparator(); List<HRegionInfo> regions = MetaScanner.listAllRegions(getConf(), connection, false); final RegionBoundariesInformation currentRegionBoundariesInformation = getConf()), getConf()); if ((reader.getFirstKey() != null) && ((storeFirstKey == null) || (comparator.compare(storeFirstKey, reader.getFirstKey()) > 0))) { storeFirstKey = reader.getFirstKey(); && ((storeLastKey == null) || (comparator.compare(storeLastKey, reader.getLastKey())) < 0)) { storeLastKey = reader.getLastKey(); && (currentRegionBoundariesInformation.metaFirstKey != null)) { valid = valid && comparator.compare(currentRegionBoundariesInformation.storesFirstKey, currentRegionBoundariesInformation.metaFirstKey) >= 0; && (currentRegionBoundariesInformation.metaLastKey != null)) { valid = valid && comparator.compare(currentRegionBoundariesInformation.storesLastKey, currentRegionBoundariesInformation.metaLastKey) < 0;
int sizeOfMap = Bytes.toInt(payload, 9); data = new TreeMap<byte[], LinkedList<byte[]>>(new Bytes.ByteArrayComparator());
int sizeOfMap = Bytes.toInt(payload, 9); data = new TreeMap<byte[], LinkedList<byte[]>>(new Bytes.ByteArrayComparator());
ByteArrayComparator bac = new ByteArrayComparator(); Entry<String, String> entry = mapIter.next(); assertEquals(0, bac.compare(key, iter.getKey())); assertEquals(0, bac.compare(key, entry.getKey().getBytes())); assertEquals(0, bac.compare(iter.getValue(), entry.getValue().getBytes())); count--;
return 1; } else { return new Bytes.ByteArrayComparator().compare( Util.UUIDToBytes(uuid), Util.UUIDToBytes(row2.uuid));
ByteArrayComparator bac = new ByteArrayComparator(); Entry<String, String> entry = mapIter.next(); assertEquals(0, bac.compare(key, iter.getKey())); assertEquals(0, bac.compare(key, entry.getKey().getBytes())); assertEquals(0, bac.compare(iter.getValue(), entry.getValue().getBytes()));
private static int recordsCompare(List<byte[]> records1, List<byte[]> records2, int nullOrder) { byte[] value1, value2; int compare; for (int i = 0; i < Math.min(records1.size(), records2.size()); i++) { value1 = records1.get(i); value2 = records2.get(i); if (value1 == value2) { continue; } if (value1 == null) { return nullOrder; } if (value2 == null) { return nullOrder * -1; } compare = new Bytes.ByteArrayComparator().compare(value1, value2); if (compare != 0) { return compare; } } return records2.size() - records1.size(); } }
/** * Tests whether sortedoplog supports duplicate keys, required when conflation is disabled */ public void testFromToIterator() throws IOException { ByteArrayComparator bac = new ByteArrayComparator(); String hoplogName = getRandomHoplogName(); HFileSortedOplog hoplog = new HFileSortedOplog(hdfsStore, new Path(testDataDir, hoplogName), blockCache, stats, storeStats); int count = 5; HoplogWriter writer = hoplog.createWriter(5); for (int i = 0; i < count; i++) { String value = "value-" + (i * 2); // even keys key-[0 2 4 6 8] writer.append(("key-" + (i * 2)).getBytes(), value.getBytes()); } writer.close(); HoplogReader reader = hoplog.getReader(); HoplogIterator<byte[], byte[]> iter = reader.scan("key-1".getBytes(), true, "key-7".getBytes(), true); for (int i = 2; i < 7; i += 2) { assertTrue(iter.hasNext()); iter.next(); assertEquals(0, bac.compare(("key-" + i).getBytes(), iter.getKey())); assertEquals(0, bac.compare(("value-" + i).getBytes(), iter.getValue())); System.out.println(new String(iter.getKey())); } assertFalse(iter.hasNext()); }
@Override public boolean next(List<Cell> result, ScannerContext scannerContext) throws IOException { boolean ret = scanner.next(result, scannerContext); for (int i = 0; i < result.size(); i++) { Cell c = result.get(i); // Replace the Cell if the value is the one we're replacing if (CellUtil.isPut(c) && comparator.compare(CellUtil.cloneValue(c), sourceValue) == 0) { try { cellBuilder.setRow(CellUtil.copyRow(c)); cellBuilder.setFamily(CellUtil.cloneFamily(c)); cellBuilder.setQualifier(CellUtil.cloneQualifier(c)); cellBuilder.setTimestamp(c.getTimestamp()); cellBuilder.setType(Cell.Type.Put); // Make sure each cell gets a unique value byte[] clonedValue = new byte[replacedValue.length]; System.arraycopy(replacedValue, 0, clonedValue, 0, replacedValue.length); cellBuilder.setValue(clonedValue); result.set(i, cellBuilder.build()); } finally { cellBuilder.clear(); } } } return ret; }
/** * Tests full iteration on a hoplog. Ensures all inserted keys are returned and no key is missing */ public void testIterator() throws IOException { int count = 10; ByteArrayComparator bac = new ByteArrayComparator(); String hoplogName = getRandomHoplogName(); TreeMap<String, String> sortedMap = createHoplog(hoplogName, count); HFileSortedOplog testHoplog = new HFileSortedOplog(hdfsStore, new Path(testDataDir, hoplogName), blockCache, stats, storeStats); HoplogReader reader = testHoplog.getReader(); Iterator<Entry<String, String>> mapIter = sortedMap.entrySet().iterator(); HoplogIterator<byte[], byte[]> iter = reader.scan(); for (; iter.hasNext();) { byte[] key = iter.next(); Entry<String, String> entry = mapIter.next(); assertEquals(0, bac.compare(key, iter.getKey())); assertEquals(0, bac.compare(key, entry.getKey().getBytes())); assertEquals(0, bac.compare(iter.getValue(), entry.getValue().getBytes())); count--; } assertEquals(0, count); }
@Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { if (b1 == b2 && s1 == s2 && l1 == l2) { return 0; } if (l1 == 0) { return l2; //0 or positive } if (l2 == 0) { return -1; } return super.compare(b1, s1, l1, b2, s2, l2); } }
@Override public int compareTo(RowKey o) { int typeCompare = getPrefix() - o.getPrefix(); if (typeCompare != 0) { return typeCompare; } DataRowKey row2 = (DataRowKey) o; return ComparisonChain.start() .compare(getTableId(), row2.getTableId()) .compare(Util.UUIDToBytes(getUuid()), Util.UUIDToBytes(row2.getUuid()), new Bytes.ByteArrayComparator()) .result(); } }
@Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { if (b1 == b2 && s1 == s2 && l1 == l2) { return 0; } if (l1 == 0) { return l2; //0 or positive } if (l2 == 0) { return -1; } return super.compare(b1, s1, l1, b2, s2, l2); } }
@Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { if (b1 == b2 && s1 == s2 && l1 == l2) { return 0; } if (l1 == 0) { return l2; //0 or positive } if (l2 == 0) { return -1; } return super.compare(b1, s1, l1, b2, s2, l2); } }
@Override public int compare(byte[] l, byte[] r) { if (l == null && r == null) return 0; if (l == null) return 1; if (r == null) return -1; return super.compare(l, r); } };
@Override public int compare(SchemaId schemaId1, SchemaId schemaId2) { return byteArrayComparator.compare(schemaId1.getBytes(), schemaId2.getBytes()); } };
@Override public void start( @SuppressWarnings("rawtypes") CoprocessorEnvironment env) throws IOException { RegionCoprocessorEnvironment renv = (RegionCoprocessorEnvironment) env; sourceValue = Bytes.toBytes(renv.getConfiguration().get(ORIGINAL_VALUE_KEY)); replacedValue = Bytes.toBytes(renv.getConfiguration().get(REPLACED_VALUE_KEY)); comparator = new Bytes.ByteArrayComparator(); cellBuilder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); }
@Override public int compare(byte[] l, byte[] r) { if (l == null && r == null) return 0; if (l == null) return 1; if (r == null) return -1; return super.compare(l, r); } };
int sizeOfMap = Bytes.toInt(payload, 9); data = new TreeMap<byte[], LinkedList<byte[]>>(new Bytes.ByteArrayComparator());