Search in sources :

Example 56 with TableReference

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

the class SnapshotTransaction method getCellsToScrubByTable.

private Multimap<TableReference, Cell> getCellsToScrubByTable(State expectedState) {
    Multimap<TableReference, Cell> tableRefToCells = HashMultimap.create();
    State actualState = state.get();
    if (expectedState == actualState) {
        for (Entry<TableReference, ConcurrentNavigableMap<Cell, byte[]>> entry : writesByTable.entrySet()) {
            TableReference table = entry.getKey();
            Set<Cell> cells = entry.getValue().keySet();
            tableRefToCells.putAll(table, cells);
        }
    } else {
        AssertUtils.assertAndLog(log, false, "Expected state: " + expectedState + "; actual state: " + actualState);
    }
    return tableRefToCells;
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Cell(com.palantir.atlasdb.keyvalue.api.Cell) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap)

Example 57 with TableReference

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

the class SnapshotTransaction method getLocksForWrites.

protected Set<LockDescriptor> getLocksForWrites() {
    Set<LockDescriptor> result = Sets.newHashSet();
    Iterable<TableReference> allTables = IterableUtils.append(writesByTable.keySet(), TransactionConstants.TRANSACTION_TABLE);
    for (TableReference tableRef : allTables) {
        if (tableRef.equals(TransactionConstants.TRANSACTION_TABLE)) {
            result.add(AtlasRowLockDescriptor.of(TransactionConstants.TRANSACTION_TABLE.getQualifiedName(), TransactionConstants.getValueForTimestamp(getStartTimestamp())));
            continue;
        }
        ConflictHandler conflictHandler = getConflictHandlerForTable(tableRef);
        if (conflictHandler == ConflictHandler.RETRY_ON_WRITE_WRITE_CELL) {
            for (Cell cell : getLocalWrites(tableRef).keySet()) {
                result.add(AtlasCellLockDescriptor.of(tableRef.getQualifiedName(), cell.getRowName(), cell.getColumnName()));
            }
        } else if (conflictHandler != ConflictHandler.IGNORE_ALL) {
            Cell lastCell = null;
            for (Cell cell : getLocalWrites(tableRef).keySet()) {
                if (lastCell == null || !Arrays.equals(lastCell.getRowName(), cell.getRowName())) {
                    result.add(AtlasRowLockDescriptor.of(tableRef.getQualifiedName(), cell.getRowName()));
                }
                lastCell = cell;
            }
        }
    }
    return result;
}
Also used : ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 58 with TableReference

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

the class SnapshotTransaction method getCellsToScrubByCell.

private Multimap<Cell, TableReference> getCellsToScrubByCell(State expectedState) {
    Multimap<Cell, TableReference> cellToTableName = HashMultimap.create();
    State actualState = state.get();
    if (expectedState == actualState) {
        for (Entry<TableReference, ConcurrentNavigableMap<Cell, byte[]>> entry : writesByTable.entrySet()) {
            TableReference table = entry.getKey();
            Set<Cell> cells = entry.getValue().keySet();
            for (Cell c : cells) {
                cellToTableName.put(c, table);
            }
        }
    } else {
        AssertUtils.assertAndLog(log, false, "Expected state: " + expectedState + "; actual state: " + actualState);
    }
    return cellToTableName;
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Cell(com.palantir.atlasdb.keyvalue.api.Cell) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap)

Example 59 with TableReference

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

the class AbstractTableMappingService method getMappedTableName.

@Override
public TableReference getMappedTableName(TableReference tableRef) throws TableMappingNotFoundException {
    if (tableRef.getNamespace().isEmptyNamespace()) {
        return tableRef;
    }
    if (tableMap.get().containsKey(tableRef)) {
        TableReference shortName = tableMap.get().get(tableRef);
        validateShortName(tableRef, shortName);
        return tableMap.get().get(tableRef);
    } else {
        updateTableMap();
        TableReference shortTableName = tableMap.get().get(tableRef);
        if (shortTableName != null) {
            return shortTableName;
        }
        throw new TableMappingNotFoundException("Unable to resolve full name for table reference " + tableRef);
    }
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference)

Example 60 with TableReference

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

the class KvTableMappingService method readTableMap.

@Override
protected BiMap<TableReference, TableReference> readTableMap() {
    BiMap<TableReference, TableReference> ret = HashBiMap.create();
    ClosableIterator<RowResult<Value>> range = kv.getRange(AtlasDbConstants.NAMESPACE_TABLE, RangeRequest.builder().build(), Long.MAX_VALUE);
    try {
        while (range.hasNext()) {
            RowResult<Value> row = range.next();
            String shortName = PtBytes.toString(row.getColumns().get(AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES).getContents());
            TableReference ref = getTableRefFromBytes(row.getRowName());
            ret.put(ref, TableReference.createWithEmptyNamespace(shortName));
        }
    } finally {
        range.close();
    }
    return ret;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Value(com.palantir.atlasdb.keyvalue.api.Value)

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