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,
boolean enablePriorityLeaseAssignment,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
long initialLeaseTableReadCapacity,
long initialLeaseTableWriteCapacity,
MetricsFactory metricsFactory,
LeaseManagementConfig.WorkerUtilizationAwareAssignmentConfig workerUtilizationAwareAssignmentConfig,
LeaseManagementConfig.GracefulLeaseHandoffConfig gracefulLeaseHandoffConfig,
ConcurrentMap<ShardInfo,ShardConsumer> shardInfoShardConsumerMap)
Constructor.
|
| 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)
Utility method to convert the basic lease or multistream lease to ShardInfo
|
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() |
LeaseStatsRecorder |
leaseStatsRecorder() |
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(MigrationAdaptiveLeaseAssignmentModeProvider leaseAssignmentModeProvider)
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 singleStreamShardId)
Updates application-specific lease values in DynamoDB.
|
String |
workerIdentifier() |
protected final MetricsFactory metricsFactory
public DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher, String workerIdentifier, long leaseDurationMillis, boolean enablePriorityLeaseAssignment, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, long initialLeaseTableReadCapacity, long initialLeaseTableWriteCapacity, MetricsFactory metricsFactory, LeaseManagementConfig.WorkerUtilizationAwareAssignmentConfig workerUtilizationAwareAssignmentConfig, LeaseManagementConfig.GracefulLeaseHandoffConfig gracefulLeaseHandoffConfig, ConcurrentMap<ShardInfo,ShardConsumer> shardInfoShardConsumerMap)
leaseRefresher - LeaseRefresher instance to useworkerIdentifier - Identifies the worker (e.g. useful to track lease ownership)leaseDurationMillis - Duration of a leaseenablePriorityLeaseAssignment - Whether to enable priority lease assignment for very expired leasesepsilonMillis - 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
LeaseCoordinatorinitialize in interface LeaseCoordinatorProvisionedThroughputExceptionDependencyExceptionIllegalStateExceptionpublic void start(MigrationAdaptiveLeaseAssignmentModeProvider leaseAssignmentModeProvider) throws DependencyException, InvalidStateException, ProvisionedThroughputException
LeaseCoordinatorstart in interface LeaseCoordinatorleaseAssignmentModeProvider - provider of Lease Assignment mode to determine whether to start components
for both V2 and V3 functionality or only V3 functionalityDependencyException - 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
LeaseCoordinatorrunLeaseTaker in interface LeaseCoordinatorDependencyExceptionInvalidStateExceptionpublic void runLeaseRenewer()
throws DependencyException,
InvalidStateException
LeaseCoordinatorrunLeaseRenewer in interface LeaseCoordinatorDependencyExceptionInvalidStateExceptionpublic Collection<Lease> getAssignments()
getAssignments in interface LeaseCoordinatorpublic List<Lease> allLeases()
LeaseCoordinatorallLeases in interface LeaseCoordinatorpublic Lease getCurrentlyHeldLease(String leaseKey)
getCurrentlyHeldLease in interface LeaseCoordinatorleaseKey - lease key to fetch currently held lease forpublic String workerIdentifier()
workerIdentifier in interface LeaseCoordinatorpublic LeaseRefresher leaseRefresher()
leaseRefresher in interface LeaseCoordinatorLeaseRefresherpublic void stop()
LeaseCoordinatorstop in interface LeaseCoordinatorpublic void stopLeaseTaker()
LeaseCoordinatorstopLeaseTaker in interface LeaseCoordinatorpublic void dropLease(Lease lease)
LeaseCoordinatordropLease in interface LeaseCoordinatorlease - the lease to stop renewing.public boolean isRunning()
isRunning in interface LeaseCoordinatorpublic boolean updateLease(Lease lease, UUID concurrencyToken, String operation, String singleStreamShardId) throws DependencyException, InvalidStateException, ProvisionedThroughputException
LeaseCoordinatorupdateLease in interface LeaseCoordinatorlease - lease object containing updated valuesconcurrencyToken - obtained by calling Lease.concurrencyToken for a currently held leaseoperation - that performs updateLeasesingleStreamShardId - for metrics emission in single stream mode. MultiStream mode will get the
shardId from the lease objectDependencyException - 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 LeaseCoordinatorpublic static ShardInfo convertLeaseToAssignment(Lease lease)
lease - @Deprecated public DynamoDBLeaseCoordinator initialLeaseTableReadCapacity(long readCapacity)
NOTE: This method is deprecated. Please set the initial capacity through the constructor.
This is a method of the public lease coordinator interface.initialLeaseTableReadCapacity in interface LeaseCoordinatorreadCapacity - 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.
This is a method of the public lease coordinator interface.initialLeaseTableWriteCapacity in interface LeaseCoordinatorwriteCapacity - The DynamoDB table used for tracking leases will be provisioned with the specified initial
write capacitypublic LeaseStatsRecorder leaseStatsRecorder()
leaseStatsRecorder in interface LeaseCoordinatorLeaseStatsRecorderCopyright © 2024. All rights reserved.