/** * Intended to extract this to separate method since only pendingPrepare uses ConcurrentNavigableMap. */ private ConcurrentNavigableMap<byte[], byte[]> createPendingPrepareMap() { return new ConcurrentSkipListMap<>(UnsignedBytes.lexicographicalComparator()); } }
public void testLexicographicalComparatorChoice() throws Exception { Comparator<byte[]> defaultComparator = UnsignedBytes.lexicographicalComparator(); assertNotNull(defaultComparator); assertSame(defaultComparator, UnsignedBytes.lexicographicalComparator()); if (unsafeComparatorAvailable()) { assertSame(defaultComparator.getClass(), Class.forName(unsafeComparatorClassName())); } else { assertSame(defaultComparator, UnsignedBytes.lexicographicalComparatorJavaImpl()); } }
private ConcurrentNavigableMap<byte[], byte[]> createPendingPrepareMap() { return new ConcurrentSkipListMap<>(UnsignedBytes.lexicographicalComparator()); } }
@SuppressWarnings("unchecked") public void testLexicographicalComparatorLongInputs() { Random rnd = new Random(); for (Comparator<byte[]> comparator : Arrays.asList( UnsignedBytes.lexicographicalComparator(), UnsignedBytes.lexicographicalComparatorJavaImpl())) { for (int trials = 10; trials-- > 0; ) { byte[] left = new byte[1 + rnd.nextInt(32)]; rnd.nextBytes(left); byte[] right = left.clone(); assertTrue(comparator.compare(left, right) == 0); int i = rnd.nextInt(left.length); left[i] ^= (byte) (1 + rnd.nextInt(255)); assertTrue(comparator.compare(left, right) != 0); assertEquals( comparator.compare(left, right) > 0, UnsignedBytes.compare(left[i], right[i]) > 0); } } }
@Override public int compareTo(Timestamp<GTID> o) { return UnsignedBytes.lexicographicalComparator().compare(this.gtid, ((GTID) o).gtid); }
public void testLexicographicalComparator() { List<byte[]> ordered = Arrays.asList( new byte[] {}, new byte[] {LEAST}, new byte[] {LEAST, LEAST}, new byte[] {LEAST, (byte) 1}, new byte[] {(byte) 1}, new byte[] {(byte) 1, LEAST}, new byte[] {GREATEST, GREATEST - (byte) 1}, new byte[] {GREATEST, GREATEST}, new byte[] {GREATEST, GREATEST, GREATEST}); // The Unsafe implementation if it's available. Otherwise, the Java implementation. Comparator<byte[]> comparator = UnsignedBytes.lexicographicalComparator(); Helpers.testComparator(comparator, ordered); assertSame(comparator, SerializableTester.reserialize(comparator)); // The Java implementation. Comparator<byte[]> javaImpl = UnsignedBytes.lexicographicalComparatorJavaImpl(); Helpers.testComparator(javaImpl, ordered); assertSame(javaImpl, SerializableTester.reserialize(javaImpl)); }
@Override public int compare(String s, String s2) { return UnsignedBytes.lexicographicalComparator().compare( StringUtils.toUtf8(s), StringUtils.toUtf8(s2)); } }).nullsFirst();
Collections.sort(byteArrayList, UnsignedBytes.lexicographicalComparator());
private void loadChunkFromHBase() { Map<byte[], byte[]> chunk = new TreeMap<>(UnsignedBytes.lexicographicalComparator()); try { ResultScanner resultScanner = hbaseClient.scan(cursorKey, endScanKey); Result[] results = resultScanner.next(chunkSize); for (Result result : results) { byte[] columnKey = extractStateKeyFromRowKey(result.getRow()); byte[] columnValue = result.getValue(columnFamily, STATE_QUALIFIER); chunk.put(columnKey, columnValue); } if (results.length > 0) { byte[] lastRow = results[results.length - 1].getRow(); cursorKey = advanceRow(lastRow); } cachedResultIterator = chunk.entrySet().iterator(); } catch (Exception e) { throw new RuntimeException("Fail to scan from HBase state storage.", e); } }
private void initTxids() { HBaseProjectionCriteria criteria = new HBaseProjectionCriteria(); criteria.addColumnFamily(columnFamily); Get get = hbaseClient.constructGetRequests(txidNamespace, criteria); try { Result[] results = hbaseClient.batchGet(Collections.singletonList(get)); Result result = results[0]; if (!result.isEmpty()) { NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(columnFamily); txIds = new TreeMap<>(familyMap); } else { txIds = new TreeMap<>(UnsignedBytes.lexicographicalComparator()); } LOG.debug("initTxids, txIds {}", txIds); } catch (Exception e) { throw new RuntimeException(e); } }
private void initPendingCommit() { RedisCommands commands = null; try { commands = container.getInstance(); if (commands.exists(prepareNamespace)) { LOG.debug("Loading previously prepared commit from {}", prepareNamespace); NavigableMap<byte[], byte[]> pendingCommitMap = new TreeMap<>(UnsignedBytes.lexicographicalComparator()); pendingCommitMap.putAll(commands.hgetAll(prepareNamespace)); pendingCommit = Maps.unmodifiableNavigableMap(pendingCommitMap); } else { LOG.debug("No previously prepared commits."); pendingCommit = EMPTY_PENDING_COMMIT_MAP; } } finally { container.returnInstance(commands); } }
@Test public void testEqualsPerformance() { boolean testEnabled = false; if (testEnabled) { final int ITERATIONS = 10000000; long start1 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { Comparator<byte[]> comparator = UnsignedBytes .lexicographicalComparator(); comparator.compare(wrapper1.getData(), wrapper2.getData()); } System.out.println(System.currentTimeMillis() - start1 + "ms"); long start2 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { Arrays.equals(wrapper1.getData(), wrapper2.getData()); } System.out.println(System.currentTimeMillis() - start2 + "ms"); long start3 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { FastByteComparisons.compareTo(wrapper1.getData(), 0, wrapper1.getData().length, wrapper2.getData(), 0, wrapper1.getData().length); } System.out.println(System.currentTimeMillis() - start3 + "ms"); } } }
@Override public int compareTo(CookiesIdxColumn o) { return ComparisonChain.start() .compare(this.rowName, o.rowName, UnsignedBytes.lexicographicalComparator()) .compare(this.columnName, o.columnName, UnsignedBytes.lexicographicalComparator()) .compare(this.id, o.id) .result(); } }
@Override public int compareTo(CreatedIdxColumn o) { return ComparisonChain.start() .compare(this.rowName, o.rowName, UnsignedBytes.lexicographicalComparator()) .compare(this.columnName, o.columnName, UnsignedBytes.lexicographicalComparator()) .compare(this.id, o.id) .result(); } }
@Override public int compareTo(ValueStreamIdxColumn o) { return ComparisonChain.start() .compare(this.reference, o.reference, UnsignedBytes.lexicographicalComparator()) .result(); } }
@Override public int compareTo(SweepableTimestampsRow o) { return ComparisonChain.start() .compare(this.hashOfRowComponents, o.hashOfRowComponents) .compare(this.shard, o.shard) .compare(this.timestampPartition, o.timestampPartition) .compare(this.sweepConservative, o.sweepConservative, UnsignedBytes.lexicographicalComparator()) .result(); } }
public static <T> NavigableMap<byte[], SortedMap<byte[], T>> breakCellsUpByRow(Iterable<Map.Entry<Cell, T>> map) { NavigableMap<byte[], SortedMap<byte[], T>> ret = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()); for (Map.Entry<Cell, T> e : map) { byte[] row = e.getKey().getRowName(); SortedMap<byte[], T> sortedMap = ret.computeIfAbsent(row, rowName -> Maps.newTreeMap(UnsignedBytes.lexicographicalComparator())); sortedMap.put(e.getKey().getColumnName(), e.getValue()); } return ret; }
public static SortedSet<byte[]> getRows(Iterable<Cell> cells) { if (Iterables.isEmpty(cells)) { return ImmutableSortedSet.orderedBy(UnsignedBytes.lexicographicalComparator()).build(); } return FluentIterable.from(cells).transform(Cell::getRowName) .toSortedSet(UnsignedBytes.lexicographicalComparator()); }
private RowResult(byte[] row, SortedMap<byte[], T> columns) { Preconditions.checkArgument(Cell.isNameValid(row)); Preconditions.checkArgument(UnsignedBytes.lexicographicalComparator().equals(columns.comparator()), "comparator for the map must be the bytes comparator"); for (byte[] colName : columns.keySet()) { Preconditions.checkArgument(Cell.isNameValid(colName)); } this.row = row.clone(); this.columns = ImmutableSortedMap.copyOf(columns, UnsignedBytes.lexicographicalComparator()); }
@Test public void canGetRange() { RangeRequest range = RangeRequest.builder().endRowExclusive(SECOND_ROW).build(); ClosableIterator<RowResult<Value>> resultIterator = getTestKvs().getRange(TEST_TABLE, range, Long.MAX_VALUE); Map<byte[], Value> expectedColumns = ImmutableMap.of(FIRST_COLUMN, VALUE, SECOND_COLUMN, VALUE); RowResult<Value> expectedRowResult = RowResult.create(FIRST_ROW, ImmutableSortedMap.copyOf(expectedColumns, UnsignedBytes.lexicographicalComparator())); assertThat(resultIterator).containsExactlyElementsOf(ImmutableList.of(expectedRowResult)); }