Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Fixes #167 (Unsafe concurrent access to unknown lease collection in A…
Browse files Browse the repository at this point in the history
…ssignableVMs class) (#168)

Fixes #167 (Unsafe concurrent access to unknown lease collection in AssignableVMs class)
  • Loading branch information
tbak authored Jan 8, 2018
1 parent 6eccfa7 commit 30b1874
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions fenzo-core/src/main/java/com/netflix/fenzo/AssignableVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void assignResult(TaskAssignmentResult result) {
};
private final ActiveVmGroups activeVmGroups;
private String activeVmGroupAttributeName=null;
private final List<String> unknownLeaseIdsToExpire = new ArrayList<>();
private final BlockingQueue<String> unknownLeaseIdsToExpire = new LinkedBlockingQueue<>();

AssignableVMs(TaskTracker taskTracker, Action1<VirtualMachineLease> leaseRejectAction,
long leaseOfferExpirySecs, int maxOffersToReject,
Expand Down Expand Up @@ -181,7 +181,8 @@ private int addLeases(List<VirtualMachineLease> leases) {
void expireLease(String leaseId) {
final String hostname = leaseIdToHostnameMap.get(leaseId);
if(hostname==null) {
unknownLeaseIdsToExpire.add(leaseId);
logger.debug("Received expiry request for an unknown lease: {}", leaseId);
unknownLeaseIdsToExpire.offer(leaseId);
return;
}
internalExpireLease(leaseId, hostname);
Expand Down Expand Up @@ -253,13 +254,12 @@ private boolean isInActiveVmGroup(String attrValue) {
}

private void expireAnyUnknownLeaseIds() {
if(!unknownLeaseIdsToExpire.isEmpty()) {
for(String leaseId: unknownLeaseIdsToExpire) {
final String hostname = leaseIdToHostnameMap.get(leaseId);
if(hostname!=null)
internalExpireLease(leaseId, hostname);
}
unknownLeaseIdsToExpire.clear();
List<String> unknownExpiredLeases = new ArrayList<>();
unknownLeaseIdsToExpire.drainTo(unknownExpiredLeases);
for(String leaseId: unknownExpiredLeases) {
final String hostname = leaseIdToHostnameMap.get(leaseId);
if(hostname!=null)
internalExpireLease(leaseId, hostname);
}
}

Expand Down

0 comments on commit 30b1874

Please sign in to comment.