public class DynamoDBLockBasedLeaderDecider extends Object implements LeaderDecider
The lock client is obtained from CoordinatorStateDAO.getDDBLockClient() on each
isLeader() call, which routes to the appropriate table based on the current
TableMigrationStatus. When migration
completes (PENDING → COMPLETE), the DAO transparently switches from the legacy table lock
client to the lease table lock client.
METRIC_OPERATION_LEADER_DECIDER, METRIC_OPERATION_LEADER_DECIDER_IS_LEADER| Constructor and Description |
|---|
DynamoDBLockBasedLeaderDecider() |
| Modifier and Type | Method and Description |
|---|---|
static DynamoDBLockBasedLeaderDecider |
create(CoordinatorStateDAO coordinatorStateDao,
String workerId,
MetricsFactory metricsFactory,
long leaseDurationInMillis,
long heartbeatPeriodInMillis,
TableMigrationStateMachine tableMigrationStateMachine) |
void |
initialize()
Performs initialization tasks for decider if any.
|
Boolean |
isLeader(String workerId)
Check the lockItem in storage and if the current worker is not leader worker, then tries to acquire lock and
returns true if it was able to acquire lock else false.
|
void |
releaseLeadershipIfHeld()
If the current worker is the leader, then releases the leadership else does nothing.
|
void |
shutdown()
Shuts down the leader decider, releasing any held lock and closing all lock clients.
|
public static DynamoDBLockBasedLeaderDecider create(CoordinatorStateDAO coordinatorStateDao, String workerId, MetricsFactory metricsFactory, long leaseDurationInMillis, long heartbeatPeriodInMillis, TableMigrationStateMachine tableMigrationStateMachine)
public void initialize()
LeaderDeciderinitialize in interface LeaderDeciderpublic Boolean isLeader(String workerId)
isLeader in interface LeaderDeciderworkerId - ID of the workerpublic void shutdown()
This method releases the leadership lock if held and then closes the underlying DynamoDB lock clients (both legacy and lease table) via the DAO to stop their background heartbeat threads. This ensures that no locks are kept alive after shutdown.
shutdown in interface LeaderDeciderpublic void releaseLeadershipIfHeld()
LeaderDeciderreleaseLeadershipIfHeld in interface LeaderDeciderCopyright © 2026. All rights reserved.