public class DynamoDBLeaseCoordinator extends Object implements LeaseCoordinator
Modifier and Type | Field and Description |
---|---|
protected MetricsFactory |
metricsFactory |
Constructor and Description |
---|
DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
long initialLeaseTableReadCapacity,
long initialLeaseTableWriteCapacity,
MetricsFactory metricsFactory)
Constructor.
|
DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
MetricsFactory metricsFactory)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
List<Lease> |
allLeases()
Default implementation returns an empty list and concrete implementation is expected to return all leases
for the application that are in the lease table.
|
static ShardInfo |
convertLeaseToAssignment(Lease lease) |
void |
dropLease(Lease lease)
Requests that renewals for the given lease are stopped.
|
Collection<Lease> |
getAssignments() |
List<ShardInfo> |
getCurrentAssignments() |
Lease |
getCurrentlyHeldLease(String leaseKey) |
void |
initialize()
Initialize the lease coordinator (create the lease table if needed).
|
DynamoDBLeaseCoordinator |
initialLeaseTableReadCapacity(long readCapacity)
Deprecated.
|
DynamoDBLeaseCoordinator |
initialLeaseTableWriteCapacity(long writeCapacity)
Deprecated.
|
boolean |
isRunning() |
LeaseRefresher |
leaseRefresher() |
void |
runLeaseRenewer()
Runs a single iteration of the lease renewer - used by integration tests.
|
void |
runLeaseTaker()
Runs a single iteration of the lease taker - used by integration tests.
|
void |
start()
Start background LeaseHolder and LeaseTaker threads.
|
void |
stop()
Stops background threads and waits for specific amount of time for all background tasks to complete.
|
void |
stopLeaseTaker()
Requests the cancellation of the lease taker.
|
boolean |
updateLease(Lease lease,
UUID concurrencyToken,
String operation,
String shardId)
Updates application-specific lease values in DynamoDB.
|
String |
workerIdentifier() |
protected final MetricsFactory metricsFactory
@Deprecated public DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, MetricsFactory metricsFactory)
NOTE: This constructor is deprecated and will be removed in a future release.
leaseRefresher
- LeaseRefresher instance to useworkerIdentifier
- Identifies the worker (e.g. useful to track lease ownership)leaseDurationMillis
- Duration of a leaseepsilonMillis
- Allow for some variance when calculating lease expirationsmaxLeasesForWorker
- Max leases this Worker can handle at a timemaxLeasesToStealAtOneTime
- Steal up to these many leases at a time (for load balancing)metricsFactory
- Used to publish metrics about lease operationspublic DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, long initialLeaseTableReadCapacity, long initialLeaseTableWriteCapacity, MetricsFactory metricsFactory)
leaseRefresher
- LeaseRefresher instance to useworkerIdentifier
- Identifies the worker (e.g. useful to track lease ownership)leaseDurationMillis
- Duration of a leaseepsilonMillis
- Allow for some variance when calculating lease expirationsmaxLeasesForWorker
- Max leases this Worker can handle at a timemaxLeasesToStealAtOneTime
- Steal up to these many leases at a time (for load balancing)initialLeaseTableReadCapacity
- Initial dynamodb lease table read iops if creating the lease tableinitialLeaseTableWriteCapacity
- Initial dynamodb lease table write iops if creating the lease tablemetricsFactory
- Used to publish metrics about lease operationspublic void initialize() throws ProvisionedThroughputException, DependencyException, IllegalStateException
LeaseCoordinator
initialize
in interface LeaseCoordinator
ProvisionedThroughputException
DependencyException
IllegalStateException
public void start() throws DependencyException, InvalidStateException, ProvisionedThroughputException
LeaseCoordinator
start
in interface LeaseCoordinator
DependencyException
- If we encountered exception taking to DynamoDBInvalidStateException
- If the lease table doesn't existProvisionedThroughputException
- If we can't talk to DynamoDB due to insufficient capacity.public void runLeaseTaker() throws DependencyException, InvalidStateException
LeaseCoordinator
runLeaseTaker
in interface LeaseCoordinator
DependencyException
InvalidStateException
public void runLeaseRenewer() throws DependencyException, InvalidStateException
LeaseCoordinator
runLeaseRenewer
in interface LeaseCoordinator
DependencyException
InvalidStateException
public Collection<Lease> getAssignments()
getAssignments
in interface LeaseCoordinator
public List<Lease> allLeases()
LeaseCoordinator
allLeases
in interface LeaseCoordinator
public Lease getCurrentlyHeldLease(String leaseKey)
getCurrentlyHeldLease
in interface LeaseCoordinator
leaseKey
- lease key to fetch currently held lease forpublic String workerIdentifier()
workerIdentifier
in interface LeaseCoordinator
public LeaseRefresher leaseRefresher()
leaseRefresher
in interface LeaseCoordinator
LeaseRefresher
public void stop()
LeaseCoordinator
stop
in interface LeaseCoordinator
public void stopLeaseTaker()
LeaseCoordinator
stopLeaseTaker
in interface LeaseCoordinator
public void dropLease(Lease lease)
LeaseCoordinator
dropLease
in interface LeaseCoordinator
lease
- the lease to stop renewing.public boolean isRunning()
isRunning
in interface LeaseCoordinator
public boolean updateLease(Lease lease, UUID concurrencyToken, String operation, String shardId) throws DependencyException, InvalidStateException, ProvisionedThroughputException
LeaseCoordinator
updateLease
in interface LeaseCoordinator
lease
- lease object containing updated valuesconcurrencyToken
- obtained by calling Lease.concurrencyToken for a currently held leaseDependencyException
- if DynamoDB update fails in an unexpected wayInvalidStateException
- if lease table does not existProvisionedThroughputException
- if DynamoDB update fails due to lack of capacitypublic List<ShardInfo> getCurrentAssignments()
getCurrentAssignments
in interface LeaseCoordinator
@Deprecated public DynamoDBLeaseCoordinator initialLeaseTableReadCapacity(long readCapacity)
NOTE: This method is deprecated. Please set the initial capacity through the constructor.
initialLeaseTableReadCapacity
in interface LeaseCoordinator
readCapacity
- The DynamoDB table used for tracking leases will be provisioned with the specified initial
read capacity@Deprecated public DynamoDBLeaseCoordinator initialLeaseTableWriteCapacity(long writeCapacity)
NOTE: This method is deprecated. Please set the initial capacity through the constructor.
initialLeaseTableWriteCapacity
in interface LeaseCoordinator
writeCapacity
- The DynamoDB table used for tracking leases will be provisioned with the specified initial
write capacityCopyright © 2019. All rights reserved.