Search in sources :

Example 21 with RowResult

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

the class TransactionRangeMigrator method copyOneTransactionInternal.

private byte[] copyOneTransactionInternal(RangeRequest range, long rangeId, Transaction readT, Transaction writeT) {
    final long maxBytes = TransactionConstants.WARN_LEVEL_FOR_QUEUED_BYTES / 2;
    byte[] start = getCheckpoint(rangeId, writeT);
    if (start == null) {
        return null;
    }
    RangeRequest.Builder builder = range.getBuilder().startRowInclusive(start);
    if (builder.isInvalidRange()) {
        return null;
    }
    RangeRequest rangeToUse = builder.build();
    BatchingVisitable<RowResult<byte[]>> bv = readT.getRange(srcTable, rangeToUse);
    byte[] lastRow = internalCopyRange(bv, maxBytes, writeT);
    byte[] nextRow = getNextRowName(lastRow);
    checkpointer.checkpoint(srcTable.getQualifiedName(), rangeId, nextRow, writeT);
    return lastRow;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 22 with RowResult

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

the class TransactionRangeMigrator method internalCopyRange.

private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, final Transaction txn) {
    final Mutable<byte[]> lastRowName = Mutables.newMutable(null);
    final MutableLong bytesPut = new MutableLong(0L);
    bv.batchAccept(readBatchSize, AbortingVisitors.batching(// even though no exception can be thrown :-(
    new AbortingVisitor<RowResult<byte[]>, RuntimeException>() {

        @Override
        public boolean visit(RowResult<byte[]> rr) throws RuntimeException {
            return TransactionRangeMigrator.this.internalCopyRow(rr, maxBytes, txn, bytesPut, lastRowName);
        }
    }));
    return lastRowName.get();
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) MutableLong(org.apache.commons.lang3.mutable.MutableLong) AbortingVisitor(com.palantir.common.base.AbortingVisitor)

Example 23 with RowResult

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

the class TransactionGetBenchmarks method getRangeInner.

private List<RowResult<byte[]>> getRangeInner(ConsecutiveNarrowTable table) {
    final int rangeRequestSize = 1000;
    return table.getTransactionManager().runTaskThrowOnConflict(txn -> {
        RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, rangeRequestSize, false));
        List<RowResult<byte[]>> results = BatchingVisitables.copyToList(txn.getRange(table.getTableRef(), request));
        Preconditions.checkState(results.size() == rangeRequestSize, "Expected %s rows, found %s rows", rangeRequestSize, results.size());
        return results;
    });
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 24 with RowResult

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

the class CassandraKeyValueServiceImpl method getMetadataForTables.

/**
 * Gets the metadata for all non-hidden tables.
 * <p>
 * Does not require all Cassandra nodes to be up and available, works as long as quorum is achieved.
 *
 * @return a mapping of table names to their respective metadata in form of a byte array.  Consider
 * {@link TableMetadata#BYTES_HYDRATOR} for hydrating.
 */
@Override
public Map<TableReference, byte[]> getMetadataForTables() {
    Map<TableReference, byte[]> tableToMetadataContents = Maps.newHashMap();
    // we don't even have a metadata table yet. Return empty map.
    if (!getAllTableReferencesWithoutFiltering().contains(AtlasDbConstants.DEFAULT_METADATA_TABLE)) {
        log.trace("getMetadata called with no _metadata table present");
        return tableToMetadataContents;
    }
    try (ClosableIterator<RowResult<Value>> range = getRange(AtlasDbConstants.DEFAULT_METADATA_TABLE, RangeRequest.all(), Long.MAX_VALUE)) {
        while (range.hasNext()) {
            RowResult<Value> valueRow = range.next();
            Iterable<Entry<Cell, Value>> cells = valueRow.getCells();
            for (Entry<Cell, Value> entry : cells) {
                Value value = entry.getValue();
                TableReference tableRef = CassandraKeyValueServices.tableReferenceFromBytes(entry.getKey().getRowName());
                byte[] contents;
                if (value == null) {
                    contents = AtlasDbConstants.EMPTY_TABLE_METADATA;
                } else {
                    contents = value.getContents();
                }
                if (!HiddenTables.isHidden(tableRef)) {
                    tableToMetadataContents.put(tableRef, contents);
                }
            }
        }
    }
    return tableToMetadataContents;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Entry(java.util.Map.Entry) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 25 with RowResult

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

the class OneNodeDownGetTest method canGetRange.

@Test
public void canGetRange() {
    final RangeRequest range = RangeRequest.builder().endRowExclusive(OneNodeDownTestSuite.SECOND_ROW).build();
    ClosableIterator<RowResult<Value>> it = OneNodeDownTestSuite.kvs.getRange(OneNodeDownTestSuite.TEST_TABLE, range, Long.MAX_VALUE);
    ImmutableMap<byte[], Value> expectedColumns = ImmutableMap.of(OneNodeDownTestSuite.FIRST_COLUMN, OneNodeDownTestSuite.DEFAULT_VALUE, OneNodeDownTestSuite.SECOND_COLUMN, OneNodeDownTestSuite.DEFAULT_VALUE);
    RowResult<Value> expectedRowResult = RowResult.create(OneNodeDownTestSuite.FIRST_ROW, ImmutableSortedMap.copyOf(expectedColumns, UnsignedBytes.lexicographicalComparator()));
    assertThat(it).containsExactly(expectedRowResult);
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) Test(org.junit.Test)

Aggregations

RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)57 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)40 Test (org.junit.Test)23 Cell (com.palantir.atlasdb.keyvalue.api.Cell)17 Value (com.palantir.atlasdb.keyvalue.api.Value)16 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)10 Set (java.util.Set)8 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)7 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 SortedMap (java.util.SortedMap)7 Map (java.util.Map)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Lists (com.google.common.collect.Lists)5 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)5 Entry (java.util.Map.Entry)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 PtBytes (com.palantir.atlasdb.encoding.PtBytes)4 ClosableIterator (com.palantir.common.base.ClosableIterator)4