in src/main/java/com/amazonaws/services/dynamodbv2/transactions/Transaction.java [801:835]
protected static void releaseReadLock(String txId, TransactionManager txManager, String tableName, Map<String, AttributeValue> key) {
Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>();
expected.put(AttributeName.TXID.toString(), new ExpectedAttributeValue().withValue(new AttributeValue(txId)));
expected.put(AttributeName.TRANSIENT.toString(), new ExpectedAttributeValue().withExists(false));
expected.put(AttributeName.APPLIED.toString(), new ExpectedAttributeValue().withExists(false));
try {
Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(1);
updates.put(AttributeName.TXID.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
updates.put(AttributeName.DATE.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
UpdateItemRequest update = new UpdateItemRequest()
.withTableName(tableName)
.withAttributeUpdates(updates)
.withKey(key)
.withExpected(expected);
txManager.getClient().updateItem(update);
} catch (ConditionalCheckFailedException e) {
try {
expected.put(AttributeName.TRANSIENT.toString(), new ExpectedAttributeValue().withValue(new AttributeValue().withS(BOOLEAN_TRUE_ATTR_VAL)));
DeleteItemRequest delete = new DeleteItemRequest()
.withTableName(tableName)
.withKey(key)
.withExpected(expected);
txManager.getClient().deleteItem(delete);
} catch (ConditionalCheckFailedException e1) {
// Ignore, means it was definitely rolled back
// Re-read to ensure that it wasn't applied
Map<String, AttributeValue> item = getItem(txManager, tableName, key);
txAssert(! (item != null && txId.equals(getOwner(item)) && item.containsKey(AttributeName.APPLIED.toString())),
"Item should not have been applied. Unable to release lock", "item", item);
}
}
}