-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get unassigned leases in leasesToTake #1320
Conversation
* @param asOfNanos time in nanoseconds to check expiration as-of | ||
* @return true if lease lease is ready te taken | ||
*/ | ||
public boolean isAvailable(long leaseDurationNanos, long asOfNanos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer a Duration type instead of long nanos
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have this all the way up I'm not going to change it right now.
List<Lease> availableLeases = new ArrayList<>(); | ||
|
||
for (Lease lease : allLeases.values()) { | ||
if (lease.isExpired(leaseDurationNanos, lastScanTimeNanos)) { | ||
expiredLeases.add(lease); | ||
if (lease.isAvailable(leaseDurationNanos, lastScanTimeNanos)) { | ||
availableLeases.add(lease); | ||
} | ||
} | ||
|
||
return expiredLeases; | ||
return availableLeases; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return allLeases.values().stream()
.filter(lease->lease.isAvailable(...))
.collect(toList())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in next commit
/** | ||
* @param leaseDurationNanos duration of lease in nanoseconds | ||
* @param asOfNanos time in nanoseconds to check expiration as-of | ||
* @return true if lease lease is ready te taken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in next commit
Currently when considering leases to take we only consider leases that are expired. This creates a delay for leases that have no owner unnecessarily. We should instead consider all unassigned leases as a potential lease to take
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.