Skip to content

Commit

Permalink
Do not acquire lock in get_spot_instance_price(). (#19)
Browse files Browse the repository at this point in the history
The lock is already acquired.

Testing Done:

1. Without this change, the minion-manager hangs while switching from
on-demand to spot instances.
2. With this change, the switch happened successfully.

Closes #10
  • Loading branch information
shrinandj authored Aug 23, 2017
1 parent a43a55d commit 3e8f620
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,16 @@ def get_on_demand_price(self, instance_type):
def get_spot_instance_price(self, instance_type, zone):
"""
Returns the spot-instance price for the given instance_type and zone.
Caller is *required* to acquire the lock.
"""
assert self.lock.locked(), "BidAdvisor lock not acquired"

# The spot price list is sorted by time. Find the latest instance
# for the zone and instance_type and use that as the spot price.
with self.lock:
for price_info in self.spot_price_list:
if price_info["InstanceType"] == instance_type and \
price_info["AvailabilityZone"] == zone:
return float(price_info["SpotPrice"])
for price_info in self.spot_price_list:
if price_info["InstanceType"] == instance_type and \
price_info["AvailabilityZone"] == zone:
return float(price_info["SpotPrice"])
return None

def get_new_bid(self, zone, instance_type):
Expand Down

0 comments on commit 3e8f620

Please sign in to comment.