@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { return delegate1.getRows(tableRef, rows, columnSelection, timestamp); }
@Test public void checkpointTableOnSourceKvsIsIgnored() { fromKvs.createTables(TEST_AND_CHECKPOINT_TABLES); KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(migratorSpec); migrator.setup(); migrator.migrate(); verify(fromKvs, never()).get(eq(CHECKPOINT_TABLE), any()); verify(fromKvs, never()).getRange(eq(CHECKPOINT_TABLE), any(), anyLong()); verify(fromKvs, never()).getRows(eq(CHECKPOINT_TABLE), any(), any(), anyLong()); verify(fromKvs, never()).getRowsColumnRange(eq(CHECKPOINT_TABLE), any(), any(), anyLong()); verify(fromKvs, never()).getRowsColumnRange(eq(CHECKPOINT_TABLE), any(), any(), anyInt(), anyLong()); verify(fromKvs, never()).getFirstBatchForRanges(eq(CHECKPOINT_TABLE), any(), anyLong()); }
@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { if (Iterables.isEmpty(rows) || columnSelection.noColumnsSelected()) { return ImmutableMap.of(); } return delegate.getRows(tableRef, rows, columnSelection, timestamp); }
@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { return delegate().getRows(tableRef, rows, columnSelection, timestamp); }
@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { return getDelegate(tableRef).getRows(tableRef, rows, columnSelection, timestamp); }
@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { try { return delegate().getRows( tableMapper.getMappedTableName(tableRef), rows, columnSelection, timestamp); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }
private byte[] getRowsForCell(Cell cell) { return keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell.getRowName()), ColumnSelection.all(), TEST_TIMESTAMP + 3) .get(cell).getContents(); }
@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("getRows({}, {} rows, ts {})", LoggingArgs.safeTableOrPlaceholder(tableRef), Iterables.size(rows), timestamp)) { return delegate().getRows(tableRef, rows, columnSelection, timestamp); } }
@Benchmark @Threads(1) @Warmup(time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(time = 5, timeUnit = TimeUnit.SECONDS) public Object getFirstColumnExplicitlyGetRows(ModeratelyWideRowTable table) throws UnsupportedEncodingException { Map<Cell, Value> result = table.getKvs() .getRows(table.getTableRef(), Collections.singleton(Tables.ROW_BYTES.array()), ColumnSelection.create( table.getFirstCellAsSet().stream().map(Cell::getColumnName).collect(Collectors.toList()) ), Long.MAX_VALUE); Preconditions.checkState(result.size() == 1, "Should be %s column, but were: %s", 1, result.size()); int value = Ints.fromByteArray(Iterables.getOnlyElement(result.values()).getContents()); Preconditions.checkState(value == 0, "Value should be %s but is %s", 0, value); return result; }
@Override public SortedMap<byte[], RowResult<byte[]>> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection) { Timer.Context timer = getTimer("getRows").time(); checkGetPreconditions(tableRef); if (Iterables.isEmpty(rows)) { return AbstractTransaction.EMPTY_SORTED_ROWS; } hasReads = true; ImmutableMap.Builder<Cell, byte[]> result = ImmutableSortedMap.naturalOrder(); Map<Cell, Value> rawResults = Maps.newHashMap( keyValueService.getRows(tableRef, rows, columnSelection, getStartTimestamp())); SortedMap<Cell, byte[]> writes = writesByTable.get(tableRef); if (writes != null) { for (byte[] row : rows) { extractLocalWritesForRow(result, writes, row, columnSelection); } } // We don't need to do work postFiltering if we have a write locally. rawResults.keySet().removeAll(result.build().keySet()); SortedMap<byte[], RowResult<byte[]>> results = filterRowResults(tableRef, rawResults, result); long getRowsMillis = TimeUnit.NANOSECONDS.toMillis(timer.stop()); if (perfLogger.isDebugEnabled()) { perfLogger.debug("getRows({}, {} rows) found {} rows, took {} ms", tableRef, Iterables.size(rows), results.size(), getRowsMillis); } validatePreCommitRequirementsOnReadIfNecessary(tableRef, getStartTimestamp()); return results; }
@Benchmark @Threads(1) @Warmup(time = 6, timeUnit = TimeUnit.SECONDS) @Measurement(time = 60, timeUnit = TimeUnit.SECONDS) public Object getAllColumnsImplicitly(ModeratelyWideRowTable table) throws UnsupportedEncodingException { Map<Cell, Value> result = table.getKvs().getRows( table.getTableRef(), Collections.singleton(Tables.ROW_BYTES.array()), ColumnSelection.all(), Long.MAX_VALUE); Preconditions.checkState(result.size() == table.getNumCols(), "Should be %s columns, but were: %s", table.getNumCols(), result.size()); return result; }
@Override public SortedMap<byte[], RowResult<byte[]>> getRowsIgnoringLocalWrites( TableReference tableRef, Iterable<byte[]> rows) { checkGetPreconditions(tableRef); if (Iterables.isEmpty(rows)) { return AbstractTransaction.EMPTY_SORTED_ROWS; } hasReads = true; Map<Cell, Value> rawResults = Maps.newHashMap(keyValueService.getRows(tableRef, rows, ColumnSelection.all(), getStartTimestamp())); validatePreCommitRequirementsOnReadIfNecessary(tableRef, getStartTimestamp()); return filterRowResults(tableRef, rawResults, ImmutableMap.builderWithExpectedSize(rawResults.size())); }
@Test public void getRows() throws Exception { ImmutableList<byte[]> rows = ImmutableList.of(ROW_NAME); Map<Cell, Value> expectedResult = ImmutableMap.of(); when(delegate.getRows(TABLE_REF, rows, ColumnSelection.all(), TIMESTAMP)).thenReturn(expectedResult); Map<Cell, Value> result = kvs.getRows(TABLE_REF, rows, ColumnSelection.all(), TIMESTAMP); assertThat(result, equalTo(expectedResult)); checkSpan("atlasdb-kvs.getRows({table}, 1 rows, ts 1)"); verify(delegate).getRows(TABLE_REF, rows, ColumnSelection.all(), TIMESTAMP); verifyNoMoreInteractions(delegate); }
@Benchmark @Threads(1) @Warmup(time = 5) @Measurement(time = 40) public Object getManyRowsWithGetRows(ConsecutiveNarrowTable.CleanNarrowTable table) { Map<Cell, Value> result = table.getKvs().getRows( table.getTableRef(), table.getRowList(), ColumnSelection.all(), Long.MAX_VALUE ); Preconditions.checkState(result.size() == table.getRowList().size(), "Should be %s rows, but were: %s", table.getRowList().size(), result.size()); return result; } }
@Test public void testGetRowsWhenMultipleVersionsAndColumnsSelected() { putTestDataForMultipleTimestamps(); Map<Cell, Value> result = keyValueService.getRows( TEST_TABLE, ImmutableSet.of(row(0)), ColumnSelection.create(ImmutableSet.of(column(0))), TEST_TIMESTAMP + 1); assertEquals(1, result.size()); assertTrue(result.containsKey(TEST_CELL)); assertTrue(result.containsValue(Value.create(val(0, 5), TEST_TIMESTAMP))); result = keyValueService.getRows( TEST_TABLE, ImmutableSet.of(row(0)), ColumnSelection.create(ImmutableSet.of(column(0))), TEST_TIMESTAMP + 2); assertEquals(1, result.size()); assertTrue(result.containsKey(TEST_CELL)); assertTrue(result.containsValue(Value.create(val(0, 7), TEST_TIMESTAMP + 1))); }
@Test public void testGetRowsWhenMultipleVersions() { putTestDataForMultipleTimestamps(); Map<Cell, Value> result = keyValueService.getRows( TEST_TABLE, ImmutableSet.of(row(0)), ColumnSelection.all(), TEST_TIMESTAMP + 1); assertEquals(1, result.size()); assertTrue(result.containsKey(TEST_CELL)); assertTrue(result.containsValue(Value.create(val(0, 5), TEST_TIMESTAMP))); result = keyValueService.getRows( TEST_TABLE, ImmutableSet.of(row(0)), ColumnSelection.all(), TEST_TIMESTAMP + 2); assertEquals(1, result.size()); assertTrue(result.containsKey(TEST_CELL)); assertTrue(result.containsValue(Value.create(val(0, 7), TEST_TIMESTAMP + 1))); }
@Override public Map<Cell, Value> getRows(TableReference tableRef, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { long startTime = System.currentTimeMillis(); return KvsProfilingLogger.maybeLog(() -> delegate.getRows(tableRef, rows, columnSelection, timestamp), (logger, stopwatch) -> logger.log( "Call to KVS.getRows at time {}, on table {} requesting {} columns from {} rows took {} ms ", LoggingArgs.startTimeMillis(startTime), LoggingArgs.tableRef(tableRef), LoggingArgs.columnCount(columnSelection), LoggingArgs.rowCount(Iterables.size(rows)), LoggingArgs.durationMillis(stopwatch)), logCellResultSize(0L)); }
@Test public void shouldAllowRemovingAllCellsInDynamicColumns() { keyValueService.createTable(DynamicColumnTable.reference(), DynamicColumnTable.metadata()); byte[] row = PtBytes.toBytes(123L); byte[] value = PtBytes.toBytes(123L); long timestamp = 456L; Cell cell1 = Cell.create(row, dynamicColumn(1)); Cell cell2 = Cell.create(row, dynamicColumn(2)); Map<Cell, Long> valuesToDelete = ImmutableMap.of(cell1, timestamp, cell2, timestamp); Map<Cell, byte[]> valuesToPut = ImmutableMap.of(cell1, value, cell2, value); keyValueService.put(DynamicColumnTable.reference(), valuesToPut, timestamp); keyValueService.delete(DynamicColumnTable.reference(), Multimaps.forMap(valuesToDelete)); Map<Cell, Value> values = keyValueService.getRows( DynamicColumnTable.reference(), ImmutableList.of(row), ColumnSelection.all(), AtlasDbConstants.MAX_TS); assertThat(values, is(Collections.emptyMap())); }
@Test public void testGetRowsWithSelectedColumns() { putTestDataForSingleTimestamp(); ColumnSelection columns1and2 = ColumnSelection.create(Arrays.asList(column(1), column(2))); Map<Cell, Value> values = keyValueService.getRows(TEST_TABLE, Arrays.asList(row(1), row(2)), columns1and2, TEST_TIMESTAMP + 1); assertEquals(3, values.size()); assertNull(values.get(Cell.create(row(1), column(0)))); assertArrayEquals(val(1, 2), values.get(Cell.create(row(1), column(2))).getContents()); assertArrayEquals(val(2, 1), values.get(Cell.create(row(2), column(1))).getContents()); assertArrayEquals(val(2, 2), values.get(Cell.create(row(2), column(2))).getContents()); }
@Test public void testGetRowsAllColumns() { putTestDataForSingleTimestamp(); Map<Cell, Value> values = keyValueService.getRows(TEST_TABLE, Arrays.asList(row(1), row(2)), ColumnSelection.all(), TEST_TIMESTAMP + 1); assertEquals(4, values.size()); assertNull(values.get(Cell.create(row(1), column(1)))); assertArrayEquals(val(1, 0), values.get(Cell.create(row(1), column(0))).getContents()); assertArrayEquals(val(1, 2), values.get(Cell.create(row(1), column(2))).getContents()); assertArrayEquals(val(2, 1), values.get(Cell.create(row(2), column(1))).getContents()); assertArrayEquals(val(2, 2), values.get(Cell.create(row(2), column(2))).getContents()); }