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");
}
}
Aggregations