Skip to content

Commit

Permalink
DynamoDB leadership election: return leadership success status (#687)
Browse files Browse the repository at this point in the history
* DynamoDB leadership election: return leadership success status

* dynamo db - fix delete tablename
  • Loading branch information
sarahwada-stripe authored Jul 9, 2024
1 parent e11c26d commit 985c5e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ public boolean isLeaderElectorRunning() {
/**
* This function will attempt to become the leader at the heartbeat interval of the lockClient. If
* it becomes the leader it will update the leader data and the thread will stop running.
* Returns true if leader election succeeded, false otherwise.
*/
private void tryToBecomeLeader() {
protected boolean tryToBecomeLeader() {
final MasterDescription me = leadershipManager.getDescription();
try {
log.info("requesting leadership from {}", me.getHostname());
Expand All @@ -135,9 +136,12 @@ private void tryToBecomeLeader() {
leaderLock = optionalLock.get();
shouldLeaderElectorBeRunning.set(false);
leadershipManager.becomeLeader();
return true;
}
return false;
} catch (RuntimeException | InterruptedException | JsonProcessingException e) {
log.error("leader elector task has failed it will restart, if this error is frequent there is likely a problem with DynamoDB based leader election", e);
return false;
} finally {
isLeaderElectorRunning.set(false);
if (shouldLeaderElectorBeRunning.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean delete(String tableName, String partitionKey, String secondaryKey
expressionAttributeValues.put(PK, AttributeValue.builder().s(tableName).build());
expressionAttributeValues.put(SK, AttributeValue.builder().s(String.format("%s#%s", partitionKey, secondaryKey)).build());
final DeleteItemRequest request = DeleteItemRequest.builder()
.tableName(tableName)
.tableName(this.mantisTable)
.key(expressionAttributeValues)
.build();
final DeleteItemResponse response = this.client.deleteItem(request);
Expand Down

0 comments on commit 985c5e9

Please sign in to comment.