use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class Scrubber method scrubCells.
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());
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class StreamStoreRemappingSweepPriorityCalculator method adjustStreamStoreScores.
private void adjustStreamStoreScores(TableReference valueTable, @Output Map<TableReference, Double> scores, Map<TableReference, SweepPriority> tableToSweepPriority) {
TableReference indexTable = StreamTableType.getIndexTableFromValueTable(valueTable);
if (!scores.containsKey(indexTable)) {
// unlikely, but don't alter the score of something that hasn't been included as a candidate
return;
}
long lastSweptTimeOfValueTable = getLastSweptTime(valueTable, tableToSweepPriority);
long lastSweptTimeOfIndexTable = getLastSweptTime(indexTable, tableToSweepPriority);
if (lastSweptTimeOfValueTable >= lastSweptTimeOfIndexTable) {
// We want to sweep the value table but haven't yet done the index table. Do the index table first.
scores.put(indexTable, scores.get(valueTable));
doNotSweepTable(valueTable, scores);
} else if (System.currentTimeMillis() - lastSweptTimeOfIndexTable <= INDEX_TO_VALUE_TABLE_SLEEP_TIME) {
// We've done the index table recently:
// 1) wait a bit before we do the value table so that the unreadable timestamp has passed (wait > 1 hour).
// 2) ensure we don't sweep index table again as we could starve the value table if index sweeps too often
doNotSweepTable(valueTable, scores);
doNotSweepTable(indexTable, scores);
} else {
// The index table has been swept long enough ago that we can now sweep the value table
}
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class StreamStoreRemappingSweepPriorityCalculator method calculateSweepPriorityScores.
public Map<TableReference, Double> calculateSweepPriorityScores(Transaction tx, long conservativeSweepTs) {
Map<TableReference, Double> scores = delegate.calculateSweepPriorityScores(tx, conservativeSweepTs);
Map<TableReference, SweepPriority> tableToSweepPriority = getSweepPriorityMap(tx);
for (TableReference table : scores.keySet()) {
if (StreamTableType.isStreamStoreValueTable(table)) {
adjustStreamStoreScores(table, scores, tableToSweepPriority);
}
}
return scores;
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class SweepPriorityCalculator method getSweepScores.
private Map<TableReference, Double> getSweepScores(Transaction tx, Set<TableReference> allTables, List<SweepPriority> oldPriorities, List<SweepPriority> newPriorities) {
Set<TableReference> unsweptTables = Sets.difference(allTables, newPriorities.stream().map(SweepPriority::tableRef).collect(Collectors.toSet()));
if (!unsweptTables.isEmpty()) {
// Always sweep unswept tables first
logUnsweptTables(unsweptTables);
return unsweptTables.stream().collect(Collectors.toMap(Function.identity(), tableReference -> 100.0));
}
Map<TableReference, SweepPriority> newPrioritiesByTableName = newPriorities.stream().collect(Collectors.toMap(SweepPriority::tableRef, Function.identity()));
// Compute priority for tables that do have a priority table.
Map<TableReference, Double> scores = new HashMap<>(oldPriorities.size());
Collection<TableReference> toDelete = Lists.newArrayList();
for (SweepPriority oldPriority : oldPriorities) {
TableReference tableReference = oldPriority.tableRef();
if (allTables.contains(tableReference)) {
SweepPriority newPriority = newPrioritiesByTableName.get(tableReference);
scores.put(tableReference, getSweepPriorityScore(oldPriority, newPriority));
} else {
toDelete.add(tableReference);
}
}
// Clean up rows for tables that no longer exist.
sweepPriorityStore.delete(tx, toDelete);
return scores;
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class SerializableTransaction method verifyRanges.
private void verifyRanges(Transaction readOnlyTransaction) {
// verify each set of reads to ensure they are the same.
for (Entry<TableReference, ConcurrentMap<RangeRequest, byte[]>> tableAndRange : rangeEndByTable.entrySet()) {
TableReference table = tableAndRange.getKey();
Map<RangeRequest, byte[]> rangeEnds = tableAndRange.getValue();
for (Entry<RangeRequest, byte[]> rangeAndRangeEndEntry : rangeEnds.entrySet()) {
RangeRequest range = rangeAndRangeEndEntry.getKey();
byte[] rangeEnd = rangeAndRangeEndEntry.getValue();
if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(range.isReverse(), rangeEnd)) {
range = range.getBuilder().endRowExclusive(RangeRequests.getNextStartRow(range.isReverse(), rangeEnd)).build();
}
ConcurrentNavigableMap<Cell, byte[]> writes = writesByTable.get(table);
BatchingVisitableView<RowResult<byte[]>> bv = BatchingVisitableView.of(readOnlyTransaction.getRange(table, range));
NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInRange(table, range), ByteBuffer::wrap);
if (!bv.transformBatch(input -> filterWritesFromRows(input, writes)).isEqual(readsInRange.entrySet())) {
handleTransactionConflict(table);
}
}
}
}
Aggregations