Search in sources :

Example 1 with ConflictHandler

use of com.palantir.atlasdb.transaction.api.ConflictHandler in project atlasdb by palantir.

the class SnapshotTransaction method throwIfConflictOnCommit.

/**
 * Make sure we have all the rows we are checking already locked before calling this.
 */
protected void throwIfConflictOnCommit(LockToken commitLocksToken, TransactionService transactionService) throws TransactionConflictException {
    for (Entry<TableReference, ConcurrentNavigableMap<Cell, byte[]>> write : writesByTable.entrySet()) {
        ConflictHandler conflictHandler = getConflictHandlerForTable(write.getKey());
        throwIfWriteAlreadyCommitted(write.getKey(), write.getValue(), conflictHandler, commitLocksToken, transactionService);
    }
}
Also used : ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap)

Example 2 with ConflictHandler

use of com.palantir.atlasdb.transaction.api.ConflictHandler 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)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)2 ConflictHandler (com.palantir.atlasdb.transaction.api.ConflictHandler)2 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockDescriptor (com.palantir.lock.LockDescriptor)1 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)1