嗨,我正在代码中实现dynamoDb锁定。我有一个包含2个ID的方法,并基于2个ID在dynamoDb的表中创建了几个条目。我已经实现了以下代码(样本代码):
Class Test {
public void testLocking() {
String pid;
String pid2;
//creating the lock and then using it as :
AcquireLockOptions optionsMain = AcquireLockOptions.builder(pid).build();
Optional<LockItem> lockItemMain = Optional.empty();
try {
lockItemMain = lockClient.tryAcquireLock(optionsMain);
if (lockItemMain.isPresent()) {
// do some operation and store the object in dynamodb:
dynamoDBMapper.save();
} catch (LockNotGrantedException e) {
//logging.
}
finally {
if (lockItemMain.isPresent()) {
logger.debug("Releasing the lock 1 :: ");
boolean status = lockClient.releaseLock(lockItemMain.get());
logger.info(LOCK_STATUS_STRING, status);
}
}
}
AcquireLockOptions optionsTemp = AcquireLockOptions.builder(pid2).build();
Optional<LockItem> lockItemTemp = Optional.empty();
try {
lockItemTemp = lockClient.tryAcquireLock(optionsTemp);
if (lockItemTemp.isPresent()) {
// do some operation and store the object in dynamodb:
dynamoDBMapper.save();
} catch (LockNotGrantedException e) {
//logging.
}
finally {
if (lockItemTemp.isPresent()) {
logger.debug("Releasing the lock 2 :: ");
boolean status = lockClient.releaseLock(lockItemTemp.get());
logger.info(LOCK_STATUS_STRING, status);
}
}
}
}
}
运行此代码后,我可以看到第一个锁已成功释放,并且该锁的条目已从锁表中删除。但是,当要释放第二个锁时,它会失败并显示以下异常:
com.amazonaws.AbortedException: 在com.amazonaws.internal.SdkFilterInputStream.abortIfNeeded(SdkFilterInputStream.java:53)〜[application.jar :?] 在com.amazonaws.internal.SdkFilterInputStream.markSupported(SdkFilterInputStream.java:117)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeHelper(AmazonHttpClient.java:1026)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.doExecute(AmazonHttpClient.java:745)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeWithTimer(AmazonHttpClient.java:719)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.execute(AmazonHttpClient.java:701)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.access $ 500(AmazonHttpClient.java:669)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient $ RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:651)〜[application.jar :?] 在com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:515)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:3609)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:3578)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:3567)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeDeleteItem(AmazonDynamoDBClient.java:1161)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.deleteItem(AmazonDynamoDBClient.java:1132)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBLockClient.releaseLock(AmazonDynamoDBLockClient.java:631)〜[application.jar :?] 在com.amazonaws.services.dynamodbv2.AmazonDynamoDBLockClient.releaseLock(AmazonDynamoDBLockClient.java:581)〜[application.jar:?]
无法找出原因。任何线索将不胜感激! 谢谢。