/** * Returns a new <code>Pair</code> instance * with the given left-side and right-side objects. */ public static <V, W> Pair<V, W> create(V v, W w) { return new Pair<V, W>(v, w); }
/** * Returns a textual summary of the top numQueries queries ordered by total time. */ @Override public synchronized String getTopQueriesByTotalTime(int numQueries) { List<Pair<Long, SqlCallStats>> entries = new ArrayList<Pair<Long, SqlCallStats>>(); for (SqlCallStats stats : statsByName.values()) { entries.add(new Pair<Long, SqlCallStats>(stats.getTotalTime(), stats)); } entries.sort(Pair.compareLhSide()); Collections.reverse(entries); StringBuilder sb = new StringBuilder(); for (int i = 0; i < Math.min(entries.size(), numQueries); ++i) { long totalTimeMs = entries.get(i).lhSide; SqlCallStats stats = entries.get(i).rhSide; String line = String.format( "total_time_ms=%-15d total_calls=%-10d query=%s%n", //$NON-NLS-1$ totalTimeMs, stats.getTotalCalls(), stats.getQueryName()); sb.append(line); } return sb.toString(); }
private void verifyLockCorrectness() { for (Pair<InvokeEvent, OkEvent> eventPair : locksAtSomePoint) { InvokeEvent invokeEvent = eventPair.getLhSide(); OkEvent okEvent = eventPair.getRhSide(); if (intervalCovered(invokeEvent, okEvent)) { log.error("Lock {} granted to process {} between {} and {}, but lock was already held by " + "another process.", lockName, invokeEvent.process(), invokeEvent.time(), okEvent.time()); errors.add(invokeEvent); errors.add(okEvent); } } }
/** * Returns a new <code>Pair</code> with the right hand side set to the passed value. */ public <T> Pair<V, T> withRhSide(T newRhSide) { return Pair.create(lhSide, newRhSide); }
public String convertToString(byte[] value) { return convertToString(value, 0).getLhSide(); }
@Test public void testMinMax() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L)); assertEquals("BatchingVisitables.getMin was wrong", 0L, (long) BatchingVisitables.getMin(visitor)); assertEquals("BatchingVisitables.getMax was wrong", 3L, (long) BatchingVisitables.getMax(visitor)); BatchingVisitable<Pair<Long, Long>> pairedVisitable = ListVisitor.create(Lists.newArrayList( Pair.create(0L, 0L), Pair.create(1L, 0L), Pair.create(0L, 1L), Pair.create(1L, 1L))); Ordering<Pair<Long, Long>> ordering = Pair.compareLhSide(); assertEquals("BatchingVisitables.getMin was wrong", Pair.create(0L, 0L), BatchingVisitables.getMin(pairedVisitable, ordering, null)); assertEquals("BatchingVisitables.getMax was wrong", Pair.create(1L, 0L), BatchingVisitables.getMax(pairedVisitable, ordering, null)); }
private static Set<Incongruency> getIncongruencies(CqlResult casResult, Map<String, Pair<byte[], byte[]>> casMap) { Map<String, byte[]> relevantCassandraState = getRelevantCassandraState(casResult, casMap); return casMap.entrySet().stream() .filter(entry -> !Arrays.equals(relevantCassandraState.get(entry.getKey()), entry.getValue().getRhSide())) .map(entry -> createIncongruency(relevantCassandraState, entry.getKey(), entry.getValue().getRhSide())) .collect(Collectors.toSet()); }
private void testBigValue(int i) { byte[] bytes = new byte[64 * 1024]; new Random().nextBytes(bytes); String encodeHexString = BaseEncoding.base16().lowerCase().encode(bytes); putDirect("row" + i, "col" + i, encodeHexString, 0); Pair<String, Long> pair = getDirect("row" + i, "col" + i, 1); assertEquals(0L, (long) pair.getRhSide()); assertEquals(encodeHexString, pair.getLhSide()); }
/** * Returns a pair with the left and right reversed. * @return */ public Pair<W, V> getReversed() { return create(rhSide, lhSide); }
public String convertToJson(byte[] value) { return convertToJson(value, 0).getLhSide(); }
private static Set<Incongruency> getIncongruencies(CqlResult casResult, Map<String, Pair<byte[], byte[]>> casMap) { Map<String, byte[]> relevantCassandraState = getRelevantCassandraState(casResult, casMap); return casMap.entrySet().stream() .filter(entry -> !Arrays.equals(relevantCassandraState.get(entry.getKey()), entry.getValue().getRhSide())) .map(entry -> createIncongruency(relevantCassandraState, entry.getKey(), entry.getValue().getRhSide())) .collect(Collectors.toSet()); }
public static CqlQuery constructCheckAndSetMultipleQuery(Map<String, Pair<byte[], byte[]>> checkAndSetRequest) { StringBuilder builder = new StringBuilder(); builder.append("BEGIN UNLOGGED BATCH\n"); // Safe, because all updates are on the same partition key // Safe, because ordering does not apply in batches checkAndSetRequest.forEach((columnName, value) -> { byte[] expected = value.getLhSide(); byte[] target = value.getRhSide(); builder.append(constructCheckAndSetQuery(columnName, expected, target)); }); builder.append("APPLY BATCH;"); // This looks awkward. However, we know that all expressions in this String pertain to timestamps and known // table references, hence this is actually safe. Doing this quickly owing to priority. // TODO (jkong): Build up a query by passing around legitimate formats and args. return CqlQuery.builder() .safeQueryFormat(builder.toString()) .build(); }
/** * Return a new <code>Pair</code> with the left hand side set to the passed value. */ public <T> Pair<T, W> withLhSide(T newLhSide) { return Pair.create(newLhSide, rhSide); }
@Test(timeout = 50000) public void testSweepBatchesDownToDeleteBatchSize() { CellsSweeper cellsSweeper = Mockito.mock(CellsSweeper.class); SweepTaskRunner spiedSweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper); putTwoValuesInEachCell(SMALL_LIST_OF_CELLS); int deleteBatchSize = 1; Pair<List<List<Cell>>, SweepResults> sweptCellsAndSweepResults = runSweep(cellsSweeper, spiedSweepRunner, 8, 8, deleteBatchSize); List<List<Cell>> sweptCells = sweptCellsAndSweepResults.getLhSide(); assertThat(sweptCells).allMatch(list -> list.size() <= 2 * deleteBatchSize); assertThat(Iterables.concat(sweptCells)).containsExactlyElementsOf(SMALL_LIST_OF_CELLS); }
@SuppressWarnings("unchecked") private Pair<List<List<Cell>>, SweepResults> runSweep(CellsSweeper cellsSweeper, SweepTaskRunner spiedSweepRunner, int maxCellTsPairsToExamine, int candidateBatchSize, int deleteBatchSize) { sweepTimestamp.set(Long.MAX_VALUE); List<List<Cell>> sweptCells = Lists.newArrayList(); doAnswer((invocationOnMock) -> { Object[] arguments = invocationOnMock.getArguments(); Collection<Cell> sentinelsToAdd = (Collection<Cell>) arguments[2]; sweptCells.add(new ArrayList(sentinelsToAdd)); return null; }).when(cellsSweeper).sweepCells(eq(TABLE_NAME), any(), any()); SweepResults sweepResults = spiedSweepRunner.run(TABLE_NAME, ImmutableSweepBatchConfig.builder() .maxCellTsPairsToExamine(maxCellTsPairsToExamine) .candidateBatchSize(candidateBatchSize) .deleteBatchSize(deleteBatchSize) .build(), PtBytes.EMPTY_BYTE_ARRAY); return new Pair(sweptCells, sweepResults); }
/** * Returns a textual summary of the top numQueries queries ordered by total time. */ @Override public synchronized String getTopQueriesByTotalTime(int numQueries) { List<Pair<Long, SqlCallStats>> entries = new ArrayList<Pair<Long, SqlCallStats>>(); for (SqlCallStats stats : statsByName.values()) { entries.add(new Pair<Long, SqlCallStats>(stats.getTotalTime(), stats)); } entries.sort(Pair.compareLhSide()); Collections.reverse(entries); StringBuilder sb = new StringBuilder(); for (int i = 0; i < Math.min(entries.size(), numQueries); ++i) { long totalTimeMs = entries.get(i).lhSide; SqlCallStats stats = entries.get(i).rhSide; String line = String.format( "total_time_ms=%-15d total_calls=%-10d query=%s%n", //$NON-NLS-1$ totalTimeMs, stats.getTotalCalls(), stats.getQueryName()); sb.append(line); } return sb.toString(); }
@Test public void testEmptyValue() { putDirect("row1", "col1", "v1", 0); Pair<String, Long> pair = getDirect("row1", "col1", 1); assertEquals(0L, (long)pair.getRhSide()); assertEquals("v1", pair.getLhSide()); putDirect("row1", "col1", "", 2); pair = getDirect("row1", "col1", 2); assertEquals(0L, (long)pair.getRhSide()); assertEquals("v1", pair.getLhSide()); pair = getDirect("row1", "col1", 3); assertEquals(2L, (long)pair.getRhSide()); assertEquals("", pair.getLhSide()); }