Search in sources :

Example 11 with KeyAlreadyExistsException

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

the class PaxosTransactionService method putUnlessExists.

@Override
public void putUnlessExists(long startTimestamp, long commitTimestamp) throws KeyAlreadyExistsException {
    try {
        byte[] finalValue = proposer.propose(startTimestamp, PtBytes.toBytes(commitTimestamp));
        long finalCommitTs = PtBytes.toLong(finalValue);
        try {
            // Make sure we do this put before we return because we want #get to succeed.
            kvStore.putAll(ImmutableMap.of(startTimestamp, finalCommitTs));
        } catch (KeyAlreadyExistsException e) {
        // this case isn't worrisome
        }
        if (commitTimestamp != finalCommitTs) {
            throw new KeyAlreadyExistsException("Key " + startTimestamp + " already exists and is mapped to " + finalCommitTs);
        }
    } catch (PaxosRoundFailureException e) {
        throw new ServiceNotAvailableException("Could not store trascaction");
    }
}
Also used : ServiceNotAvailableException(com.palantir.common.remoting.ServiceNotAvailableException) PaxosRoundFailureException(com.palantir.paxos.PaxosRoundFailureException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)

Aggregations

KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)11 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 CheckAndSetException (com.palantir.atlasdb.keyvalue.api.CheckAndSetException)2 PalantirSqlException (com.palantir.exception.PalantirSqlException)2 Entry (java.util.Map.Entry)2 ResultSet (com.datastax.driver.core.ResultSet)1 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)1 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)1 CheckAndSetRequest (com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest)1 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 Value (com.palantir.atlasdb.keyvalue.api.Value)1 MultiTimestampPutBatch (com.palantir.atlasdb.keyvalue.jdbc.impl.MultiTimestampPutBatch)1 PutBatch (com.palantir.atlasdb.keyvalue.jdbc.impl.PutBatch)1 SingleTimestampPutBatch (com.palantir.atlasdb.keyvalue.jdbc.impl.SingleTimestampPutBatch)1 TransactionFailedRetriableException (com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException)1 FunctionCheckedException (com.palantir.common.base.FunctionCheckedException)1 PalantirRuntimeException (com.palantir.common.exception.PalantirRuntimeException)1 ServiceNotAvailableException (com.palantir.common.remoting.ServiceNotAvailableException)1