@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> cells, long timestamp) { return delegate1.getAllTimestamps(tableRef, cells, timestamp); }
private Multimap<Cell, Long> getTestTimestamps() { return keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(TEST_CELL), AtlasDbConstants.MAX_TS); }
private Collection<Long> getAllTimestampsForTestCell() { return keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(TEST_CELL), Long.MAX_VALUE) .asMap().get(TEST_CELL); }
@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> cells, long timestamp) { return getDelegate(tableRef).getAllTimestamps(tableRef, cells, timestamp); }
@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> cells, long timestamp) { if (cells.isEmpty()) { return ImmutableSetMultimap.of(); } else { return delegate.getAllTimestamps(tableRef, cells, timestamp); } }
@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> keys, long timestamp) { return delegate().getAllTimestamps(tableRef, keys, timestamp); }
private Set<Long> getAllTs(String row, String column) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), column.getBytes(StandardCharsets.UTF_8)); return ImmutableSet.copyOf(kvs.getAllTimestamps(TABLE_NAME, ImmutableSet.of(cell), Long.MAX_VALUE).get(cell)); }
public static void deleteAllTimestampsDefaultImpl(KeyValueService kvs, TableReference tableRef, Map<Cell, Long> maxTimestampByCell, boolean deleteSentinel) { if (maxTimestampByCell.isEmpty()) { return; } long maxTimestampExclusive = maxTimestampByCell.values().stream().max(Long::compare).get(); Multimap<Cell, Long> timestampsByCell = kvs.getAllTimestamps(tableRef, maxTimestampByCell.keySet(), maxTimestampExclusive); Multimap<Cell, Long> timestampsByCellExcludingSentinels = Multimaps.filterEntries(timestampsByCell, entry -> { long maxTimestampForCell = maxTimestampByCell.get(entry.getKey()); long timestamp = entry.getValue(); return timestamp < maxTimestampForCell && (deleteSentinel || timestamp != Value.INVALID_VALUE_TIMESTAMP); }); kvs.delete(tableRef, timestampsByCellExcludingSentinels); }
@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> cells, long timestamp) { return maybeLog(() -> delegate.getAllTimestamps(tableRef, cells, timestamp), logCellsAndSize("getAllTimestamps", tableRef, cells.size(), cells.size() * Longs.BYTES)); }
@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> keys, long timestamp) { try { return delegate().getAllTimestamps(tableMapper.getMappedTableName(tableRef), keys, timestamp); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }
private void scrubCells(TransactionManager txManager, Multimap<TableReference, Cell> tableNameToCells, long scrubTimestamp, Transaction.TransactionType transactionType) { Map<TableReference, Multimap<Cell, Long>> allCellsToMarkScrubbed = Maps.newHashMapWithExpectedSize(tableNameToCells.keySet().size()); for (Entry<TableReference, Collection<Cell>> entry : tableNameToCells.asMap().entrySet()) { TableReference tableRef = entry.getKey(); log.debug("Attempting to immediately scrub {} cells from table {}", entry.getValue().size(), tableRef); for (List<Cell> cells : Iterables.partition(entry.getValue(), batchSizeSupplier.get())) { Multimap<Cell, Long> allTimestamps = keyValueService.getAllTimestamps( tableRef, ImmutableSet.copyOf(cells), scrubTimestamp); Multimap<Cell, Long> timestampsToDelete = Multimaps.filterValues( allTimestamps, v -> !v.equals(Value.INVALID_VALUE_TIMESTAMP)); // If transactionType == TransactionType.AGGRESSIVE_HARD_DELETE this might // force other transactions to abort or retry deleteCellsAtTimestamps(txManager, tableRef, timestampsToDelete, transactionType); Multimap<Cell, Long> cellsToMarkScrubbed = HashMultimap.create(allTimestamps); for (Cell cell : cells) { cellsToMarkScrubbed.put(cell, scrubTimestamp); } allCellsToMarkScrubbed.put(tableRef, cellsToMarkScrubbed); } log.debug("Immediately scrubbed {} cells from table {}", entry.getValue().size(), tableRef); } scrubberStore.markCellsAsScrubbed(allCellsToMarkScrubbed, batchSizeSupplier.get()); }
@Override public Multimap<Cell, Long> getAllTimestamps(TableReference tableRef, Set<Cell> keys, long timestamp) { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("getAllTimestamps({}, {} keys, ts {})", LoggingArgs.safeTableOrPlaceholder(tableRef), keys.size(), timestamp)) { return delegate().getAllTimestamps(tableRef, keys, timestamp); } }
@Test public void getAllTimestamps() throws Exception { Set<Cell> cells = ImmutableSet.of(CELL); kvs.getAllTimestamps(TABLE_REF, cells, 1L); checkSpan("atlasdb-kvs.getAllTimestamps({table}, 1 keys, ts 1)"); verify(delegate).getAllTimestamps(TABLE_REF, cells, 1L); verifyNoMoreInteractions(delegate); }
private Set<Long> getAllTs(KeyValueService kvs, TableReference table, String row) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), COL.getBytes(StandardCharsets.UTF_8)); return ImmutableSet.copyOf(kvs.getAllTimestamps(table, ImmutableSet.of(cell), Long.MAX_VALUE).get(cell)); }
@Test public void testGetAllTimestamps() { putTestDataForMultipleTimestamps(); final Set<Cell> cellSet = ImmutableSet.of(TEST_CELL); Multimap<Cell, Long> timestamps = keyValueService.getAllTimestamps( TEST_TABLE, cellSet, TEST_TIMESTAMP); assertEquals(0, timestamps.size()); timestamps = keyValueService.getAllTimestamps(TEST_TABLE, cellSet, TEST_TIMESTAMP + 1); assertEquals(1, timestamps.size()); assertTrue(timestamps.containsEntry(TEST_CELL, TEST_TIMESTAMP)); timestamps = keyValueService.getAllTimestamps(TEST_TABLE, cellSet, TEST_TIMESTAMP + 2); assertEquals(2, timestamps.size()); assertTrue(timestamps.containsEntry(TEST_CELL, TEST_TIMESTAMP)); assertTrue(timestamps.containsEntry(TEST_CELL, TEST_TIMESTAMP + 1)); assertEquals( timestamps, keyValueService.getAllTimestamps(TEST_TABLE, cellSet, TEST_TIMESTAMP + 3)); }
private static int getAmountOfGarbageInMetadataTable(KeyValueService keyValueService, TableReference tableRef) { return keyValueService.getAllTimestamps( AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableSet.of(Cell.create( tableRef.getQualifiedName().getBytes(StandardCharsets.UTF_8), "m".getBytes(StandardCharsets.UTF_8))), AtlasDbConstants.MAX_TS).size(); }
private void verifyCheckAndSet(Cell key, byte[] expectedValue) { Multimap<Cell, Long> timestamps = keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(key), 1L); assertEquals(1, timestamps.size()); assertTrue(timestamps.containsEntry(key, AtlasDbConstants.TRANSACTION_TS)); ClosableIterator<RowResult<Value>> result = keyValueService.getRange(TEST_TABLE, RangeRequest.all(), AtlasDbConstants.TRANSACTION_TS + 1); // Check result is right byte[] actual = result.next().getColumns().get(key.getColumnName()).getContents(); assertArrayEquals(String.format("Value \"%s\" different from expected \"%s\"", new String(actual, StandardCharsets.UTF_8), new String(expectedValue, StandardCharsets.UTF_8)), expectedValue, actual); // Check no more results assertFalse(result.hasNext()); }
row1col0, latestTsCol0), false); assertThat(keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(row0col0), Long.MAX_VALUE).asMap().get( row0col0), contains(latestTsCol0)); assertThat(keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(row0col1), Long.MAX_VALUE).asMap().get( row0col1), contains(latestTsCol1)); assertThat(keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(row1col0), Long.MAX_VALUE).asMap().get( row1col0), contains(latestTsCol0));
@Test public void testNegativeTimestamps() { Cell k = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("col1")); keyValueService.addGarbageCollectionSentinelValues(TEST_TABLE, ImmutableSet.of(k)); putDirect("row1", "col1", "v3", 3); Pair<String, Long> pair = getDirect("row1", "col1", Long.MAX_VALUE); assertEquals("v3", pair.getLhSide()); pair = getDirect("row1", "col1", 0); assertEquals("", pair.getLhSide()); assertEquals(-1L, (long)pair.getRhSide()); keyValueService.delete(TEST_TABLE, ImmutableMultimap.of(k, 3L)); pair = getDirect("row1", "col1", Long.MAX_VALUE); assertEquals("", pair.getLhSide()); assertEquals(-1L, (long)pair.getRhSide()); Multimap<Cell, Long> allTimestamps = keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(k), 0); assertEquals(1, allTimestamps.size()); allTimestamps = keyValueService.getAllTimestamps(TEST_TABLE, ImmutableSet.of(k), Long.MAX_VALUE); assertEquals(1, allTimestamps.size()); }
@Test public void migrateOnlyMigratesMostRecentVersions() { fromKvs.createTables(TEST_AND_CHECKPOINT_TABLES); fromTxManager.runTaskWithRetry(tx -> { tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE1)); tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL2, TEST_VALUE1)); return tx.getTimestamp(); }); fromTxManager.runTaskWithRetry(tx -> { tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE2)); return tx.getTimestamp(); }); KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(migratorSpec); migrator.setup(); migrator.migrate(); toTxManager.runTaskThrowOnConflict(tx -> { Map<Cell, byte[]> values = tx.get(TEST_TABLE, ImmutableSet.of(TEST_CELL, TEST_CELL2)); assertThat(values.get(TEST_CELL)).isEqualTo(TEST_VALUE2); assertThat(values.get(TEST_CELL2)).isEqualTo(TEST_VALUE1); return null; }); assertThat(toKvs.getAllTimestamps(TEST_TABLE, ImmutableSet.of(TEST_CELL), Long.MAX_VALUE).size()).isEqualTo(1); }