Handle only LockNotGrantedException for heartbeat

If we don't have a connection to AWS or our thread is interrupted
for some reason, we should just re-throw that exception as is.

* Only catch a `LockNotGrantedException` which really indicates
that the state of the lock record has been changed.
Therefore we also have to reset local state and try again
This commit is contained in:
Artem Bilan
2021-01-07 10:34:49 -05:00
parent 6b0933c7b7
commit 696472037f

View File

@@ -56,6 +56,7 @@ import com.amazonaws.services.dynamodbv2.model.BillingMode;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.LockNotGrantedException;
import com.amazonaws.services.dynamodbv2.model.LockTableDoesNotExistException;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ResourceInUseException;
@@ -532,7 +533,7 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
this.lockItem.sendHeartBeat();
acquired = true;
}
catch (Exception e) {
catch (LockNotGrantedException ex) {
// May be no lock record in the DB - discard local holder and try to lock again
this.lockItem = null;
}