Search in sources :

Example 76 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class SerializableTransaction method verifyCells.

private void verifyCells(Transaction readOnlyTransaction) {
    for (Entry<TableReference, Set<Cell>> tableAndCellsEntry : cellsRead.entrySet()) {
        TableReference table = tableAndCellsEntry.getKey();
        Set<Cell> cells = tableAndCellsEntry.getValue();
        final ConcurrentNavigableMap<Cell, byte[]> readsForTable = getReadsForTable(table);
        for (Iterable<Cell> batch : Iterables.partition(cells, BATCH_SIZE)) {
            // We don't want to verify any reads that we wrote to cause we will just read our own values.
            // NB: If the value has changed between read and write, our normal SI checking handles this case
            Iterable<Cell> batchWithoutWrites = writesByTable.get(table) != null ? Iterables.filter(batch, Predicates.not(Predicates.in(writesByTable.get(table).keySet()))) : batch;
            ImmutableSet<Cell> batchWithoutWritesSet = ImmutableSet.copyOf(batchWithoutWrites);
            Map<Cell, byte[]> currentBatch = readOnlyTransaction.get(table, batchWithoutWritesSet);
            ImmutableMap<Cell, byte[]> originalReads = Maps.toMap(Sets.intersection(batchWithoutWritesSet, readsForTable.keySet()), Functions.forMap(readsForTable));
            if (!areMapsEqual(currentBatch, originalReads)) {
                handleTransactionConflict(table);
            }
        }
    }
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 77 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class SerializableTransaction method verifyColumnRanges.

private void verifyColumnRanges(Transaction readOnlyTransaction) {
    // verify each set of reads to ensure they are the same.
    for (Entry<TableReference, ConcurrentMap<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>>> tableAndRange : columnRangeEndsByTable.entrySet()) {
        TableReference table = tableAndRange.getKey();
        Map<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>> columnRangeEnds = tableAndRange.getValue();
        Map<Cell, byte[]> writes = writesByTable.get(table);
        Map<BatchColumnRangeSelection, List<byte[]>> rangesToRows = Maps.newHashMap();
        for (Entry<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>> rowAndRangeEnds : columnRangeEnds.entrySet()) {
            byte[] row = rowAndRangeEnds.getKey();
            Map<BatchColumnRangeSelection, byte[]> rangeEnds = columnRangeEnds.get(row);
            for (Entry<BatchColumnRangeSelection, byte[]> e : rangeEnds.entrySet()) {
                BatchColumnRangeSelection range = e.getKey();
                byte[] rangeEnd = e.getValue();
                if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(false, rangeEnd)) {
                    range = BatchColumnRangeSelection.create(range.getStartCol(), RangeRequests.getNextStartRow(false, rangeEnd), range.getBatchHint());
                }
                if (rangesToRows.get(range) != null) {
                    rangesToRows.get(range).add(row);
                } else {
                    rangesToRows.put(range, ImmutableList.of(row));
                }
            }
        }
        for (Entry<BatchColumnRangeSelection, List<byte[]>> e : rangesToRows.entrySet()) {
            BatchColumnRangeSelection range = e.getKey();
            List<byte[]> rows = e.getValue();
            Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> result = readOnlyTransaction.getRowsColumnRange(table, rows, range);
            for (Entry<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> res : result.entrySet()) {
                byte[] row = res.getKey();
                BatchingVisitableView<Entry<Cell, byte[]>> bv = BatchingVisitableView.of(res.getValue());
                NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInColumnRange(table, row, range), input -> ByteBuffer.wrap(input));
                boolean isEqual = bv.transformBatch(input -> filterWritesFromCells(input, writes)).isEqual(readsInRange.entrySet());
                if (!isEqual) {
                    handleTransactionConflict(table);
                }
            }
        }
    }
}
Also used : TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) LoggerFactory(org.slf4j.LoggerFactory) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ByteBuffer(java.nio.ByteBuffer) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Set(java.util.Set) Cleaner(com.palantir.atlasdb.cleaner.Cleaner) Maps2(com.palantir.common.collect.Maps2) NavigableMap(java.util.NavigableMap) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) List(java.util.List) Predicate(com.google.common.base.Predicate) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Entry(java.util.Map.Entry) Optional(java.util.Optional) Cells(com.palantir.atlasdb.keyvalue.impl.Cells) SortedMap(java.util.SortedMap) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) AtlasDbMetrics(com.palantir.atlasdb.util.AtlasDbMetrics) Supplier(com.google.common.base.Supplier) Multimap(com.google.common.collect.Multimap) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ConcurrentMap(java.util.concurrent.ConcurrentMap) Multimaps(com.google.common.collect.Multimaps) Meter(com.codahale.metrics.Meter) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) ExecutorService(java.util.concurrent.ExecutorService) Functions(com.google.common.base.Functions) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Logger(org.slf4j.Logger) MetricRegistry(com.codahale.metrics.MetricRegistry) PreCommitCondition(com.palantir.atlasdb.transaction.api.PreCommitCondition) LockToken(com.palantir.lock.v2.LockToken) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) TimelockService(com.palantir.lock.v2.TimelockService) Maps(com.google.common.collect.Maps) IterableUtils(com.palantir.common.collect.IterableUtils) Pair(com.palantir.util.Pair) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Validate(org.apache.commons.lang3.Validate) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) Idempotent(com.palantir.common.annotation.Idempotent) AbortingVisitor(com.palantir.common.base.AbortingVisitor) BatchingVisitable(com.palantir.common.base.BatchingVisitable) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Entry(java.util.Map.Entry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Cell(com.palantir.atlasdb.keyvalue.api.Cell) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ConcurrentMap(java.util.concurrent.ConcurrentMap) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 78 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class KeyValueServiceMigratorsTest method skipsTheOldScrubTable.

@Test
public void skipsTheOldScrubTable() {
    TableReference tableToMigrate = TableReference.create(Namespace.DEFAULT_NAMESPACE, "can-be-migrated");
    KeyValueService fromKvs = mock(KeyValueService.class);
    when(fromKvs.getAllTableNames()).thenReturn(ImmutableSet.of(AtlasDbConstants.OLD_SCRUB_TABLE, tableToMigrate));
    Set<TableReference> creatableTableNames = KeyValueServiceMigrators.getMigratableTableNames(fromKvs, ImmutableSet.of());
    assertThat(creatableTableNames).containsExactly(tableToMigrate);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Test(org.junit.Test)

Example 79 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class ScrubberTest method testScrubQueueIsCleared.

@Test
public void testScrubQueueIsCleared() {
    Cell cell1 = Cell.create(new byte[] { 1 }, new byte[] { 2 });
    Cell cell2 = Cell.create(new byte[] { 2 }, new byte[] { 3 });
    Cell cell3 = Cell.create(new byte[] { 3 }, new byte[] { 4 });
    TableReference tableRef = TableReference.createFromFullyQualifiedName("foo.bar");
    kvs.createTable(tableRef, new byte[] {});
    kvs.putWithTimestamps(tableRef, ImmutableMultimap.<Cell, Value>builder().put(cell1, Value.create(new byte[] { 3 }, 10)).put(cell1, Value.create(new byte[] { 4 }, 20)).put(cell2, Value.create(new byte[] { 4 }, 30)).put(cell2, Value.create(new byte[] { 5 }, 40)).put(cell2, Value.create(new byte[] { 6 }, 50)).put(cell3, Value.create(new byte[] { 7 }, 60)).build());
    transactions.putUnlessExists(10, 15);
    transactions.putUnlessExists(20, 25);
    transactions.putUnlessExists(30, 35);
    transactions.putUnlessExists(50, 55);
    transactions.putUnlessExists(60, 65);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell1, tableRef), 10, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell1, tableRef), 20, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell2, tableRef), 40, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell2, tableRef), 50, 100);
    scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell3, tableRef), 60, 100);
    scrubber.runBackgroundScrubTask(null);
    List<SortedMap<Long, Multimap<TableReference, Cell>>> scrubQueue = BatchingVisitables.copyToList(scrubStore.getBatchingVisitableScrubQueue(Long.MAX_VALUE, null, null));
    Assert.assertEquals(ImmutableList.of(), scrubQueue);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SortedMap(java.util.SortedMap) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 80 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class Benchmarks method createStreamingTable.

private static void createStreamingTable(KeyValueService kvs, TableReference parentTable, String columnName) {
    StreamStoreDefinition ssd = new StreamStoreDefinitionBuilder(columnName, "Value", ValueType.VAR_LONG).inMemoryThreshold(1024 * 1024).build();
    ssd.getTables().forEach((tableName, tableDefinition) -> {
        TableReference streamingTable = TableReference.create(parentTable.getNamespace(), tableName);
        kvs.createTable(streamingTable, tableDefinition.toTableMetadata().persistToBytes());
    });
}
Also used : StreamStoreDefinition(com.palantir.atlasdb.schema.stream.StreamStoreDefinition) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) StreamStoreDefinitionBuilder(com.palantir.atlasdb.schema.stream.StreamStoreDefinitionBuilder)

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