updateLeaseWithMetaInfo with expectation

This commit is contained in:
Chunxue Yang 2020-07-28 13:32:04 -07:00
parent f713017528
commit 6738087a8f
4 changed files with 23 additions and 1 deletions

View file

@ -120,6 +120,11 @@ public class KinesisClientLeaseSerializer implements ILeaseSerializer<KinesisCli
return baseSerializer.getDynamoNonexistantExpectation();
}
@Override
public Map<String, ExpectedAttributeValue> getDynamoExistantExpectation(final String leaseKey) {
return baseSerializer.getDynamoExistantExpectation(leaseKey);
}
@Override
public Map<String, AttributeValueUpdate> getDynamoLeaseCounterUpdate(KinesisClientLease lease) {
return baseSerializer.getDynamoLeaseCounterUpdate(lease);

View file

@ -620,7 +620,7 @@ public class LeaseManager<T extends Lease> implements ILeaseManager<T> {
UpdateItemRequest request = new UpdateItemRequest();
request.setTableName(table);
request.setKey(serializer.getDynamoHashKey(lease));
request.setExpected(serializer.getDynamoLeaseCounterExpectation(lease));
request.setExpected(serializer.getDynamoExistantExpectation(lease.getLeaseKey()));
Map<String, AttributeValueUpdate> updates = serializer.getDynamoUpdateLeaseUpdate(lease, updateField);
updates.putAll(serializer.getDynamoUpdateLeaseUpdate(lease));

View file

@ -137,6 +137,16 @@ public class LeaseSerializer implements ILeaseSerializer<Lease> {
return result;
}
@Override
public Map<String, ExpectedAttributeValue> getDynamoExistantExpectation(final String leaseKey) {
Map<String, ExpectedAttributeValue> result = new HashMap<>();
ExpectedAttributeValue expectedAV = new ExpectedAttributeValue(DynamoUtils.createAttributeValue(leaseKey));
result.put(LEASE_KEY_KEY, expectedAV);
return result;
}
@Override
public Map<String, AttributeValueUpdate> getDynamoLeaseCounterUpdate(Lease lease) {
return getDynamoLeaseCounterUpdate(lease.getLeaseCounter());

View file

@ -79,6 +79,13 @@ public interface ILeaseSerializer<T extends Lease> {
*/
public Map<String, ExpectedAttributeValue> getDynamoNonexistantExpectation();
/**
* @return the attribute value map asserting that a lease does exist.
*/
default Map<String, ExpectedAttributeValue> getDynamoExistantExpectation(final String leaseKey) {
throw new UnsupportedOperationException("DynamoExistantExpectation is not implemented");
}
/**
* @param lease
* @return the attribute value map that increments a lease counter