Merge pull request #57 from Renjuju/cherry-pick-leases-list-to-set

[Cherry-pick] Convert expiredLeases to set (#56)
This commit is contained in:
ashwing 2020-06-16 10:19:45 -07:00 committed by GitHub
commit a24e7dcf03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -499,10 +499,13 @@ public class DynamoDBLeaseTaker implements LeaseTaker {
*/
private Map<String, Integer> computeLeaseCounts(List<Lease> expiredLeases) {
Map<String, Integer> leaseCounts = new HashMap<>();
// The set will give much faster lookup than the original list, an
// important optimization when the list is large
Set<Lease> expiredLeasesSet = new HashSet<>(expiredLeases);
// Compute the number of leases per worker by looking through allLeases and ignoring leases that have expired.
for (Lease lease : allLeases.values()) {
if (!expiredLeases.contains(lease)) {
if (!expiredLeasesSet.contains(lease)) {
String leaseOwner = lease.leaseOwner();
Integer oldCount = leaseCounts.get(leaseOwner);
if (oldCount == null) {