Search in sources :

Example 1 with BatchingVisitableView

use of com.palantir.common.base.BatchingVisitableView in project atlasdb by palantir.

the class SchemaApiTestImpl method getRangeSecondColumnOnlyFirstTwoResults.

@Override
protected Map<String, StringValue> getRangeSecondColumnOnlyFirstTwoResults(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).batchHint(2).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return BatchingVisitables.take(rangeRequestResult, 2).stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 2 with BatchingVisitableView

use of com.palantir.common.base.BatchingVisitableView in project atlasdb by palantir.

the class SchemaApiTestImpl method getRangeSecondColumn.

@Override
protected Map<String, StringValue> getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) {
    SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
    ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).build();
    BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
    return rangeRequestResult.immutableCopy().stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
Also used : StringValue(com.palantir.atlasdb.table.description.test.StringValue) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashComponentsTestTable(com.palantir.atlasdb.table.description.generated.HashComponentsTestTable) ApiTestTableFactory(com.palantir.atlasdb.table.description.generated.ApiTestTableFactory) Test(org.junit.Test) Hashing(com.google.common.hash.Hashing) Collectors(java.util.stream.Collectors) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestRow(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRow) List(java.util.List) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) Optional(java.util.Optional) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) SchemaApiTestTable(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable) SchemaApiTestRowResult(com.palantir.atlasdb.table.description.generated.SchemaApiTestTable.SchemaApiTestRowResult)

Example 3 with BatchingVisitableView

use of com.palantir.common.base.BatchingVisitableView 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)

Aggregations

PtBytes (com.palantir.atlasdb.encoding.PtBytes)3 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)3 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)3 Transaction (com.palantir.atlasdb.transaction.api.Transaction)3 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Hashing (com.google.common.hash.Hashing)2 EncodingUtils (com.palantir.atlasdb.ptobject.EncodingUtils)2 ApiTestTableFactory (com.palantir.atlasdb.table.description.generated.ApiTestTableFactory)2 HashComponentsTestTable (com.palantir.atlasdb.table.description.generated.HashComponentsTestTable)2 Meter (com.codahale.metrics.Meter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Functions (com.google.common.base.Functions)1 Predicate (com.google.common.base.Predicate)1 Predicates (com.google.common.base.Predicates)1 Supplier (com.google.common.base.Supplier)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1