Search in sources :

Example 71 with TableReference

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());
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) HashMultimap(com.google.common.collect.HashMultimap) Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Collection(java.util.Collection) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 72 with TableReference

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
    }
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference)

Example 73 with TableReference

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;
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference)

Example 74 with TableReference

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;
}
Also used : StreamTableType(com.palantir.atlasdb.schema.stream.StreamTableType) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Lists(com.google.common.collect.Lists) Transaction(com.palantir.atlasdb.transaction.api.Transaction) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Duration(java.time.Duration) Map(java.util.Map) LoggingArgs(com.palantir.atlasdb.logging.LoggingArgs) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) HashMap(java.util.HashMap)

Example 75 with TableReference

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);
            }
        }
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) ByteBuffer(java.nio.ByteBuffer) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)112 Cell (com.palantir.atlasdb.keyvalue.api.Cell)41 Test (org.junit.Test)41 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 Multimap (com.google.common.collect.Multimap)13 Entry (java.util.Map.Entry)13 Set (java.util.Set)13 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)12 Value (com.palantir.atlasdb.keyvalue.api.Value)12 Collection (java.util.Collection)12 List (java.util.List)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)11 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)11 SortedMap (java.util.SortedMap)11 Lists (com.google.common.collect.Lists)10 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)10 Sets (com.google.common.collect.Sets)9 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)9