Look through all nodes when downscaling
When looking to downscale instances, make sure you look though all nodes
for autoscaled node. This is needed since min_machines could have been
changed few times.
@@ -892,7 +892,8 @@ class Djinn
if Integer(@options['min_machines']) > @nodes.length
msg = 'min_machines is bigger than the number of nodes!'
Djinn.log_warn(msg)
- raise AppScaleException.new(msg)
+ # No exception raised here since we may be lowering the number
+ # of min_machines, just a warning in the logs will suffice.
end
if Integer(@options['max_machines']) < Integer(@options['min_machines'])
msg = 'min_machines is bigger than max_machines!'
@@ -2533,7 +2534,7 @@ class Djinn
def can_we_scale_down?(min_machines)
@state_change_lock.synchronize {
@nodes.drop(min_machines).each { |node|
- return false if node['jobs'] != ['compute']
+ return false if node.roles != ['compute']
}
}
return true
@@ -5057,7 +5058,6 @@ class Djinn
# any AppServers and the minimum number of user specified machines are still
# running in the deployment.
def scale_down_instances
- num_scaled_down = 0
# If we are already at the minimum number of machines that the user specified,
# then we do not have the capacity to scale down.
max_scale_down_capacity = @nodes.length - Integer(@options['min_machines'])
@@ -5082,18 +5082,19 @@ class Djinn
Thread.new {
SCALE_LOCK.synchronize {
- # Look through an array of autoscaled nodes and check if any of the
- # machines are not running any AppServers and need to be downscaled.
- get_autoscaled_nodes.reverse_each { |node|
- break if num_scaled_down == max_scale_down_capacity
+ # Look through the nodes and check if any of the machines was
+ # autoscaled (compute role only)a and are not running any
+ # AppServers and need to be downscaled.
+ nodes_to_remove = []
+ @state_change_lock.synchronize {
+ @nodes.reverse_each { |node|
+ break if nodes_to_remove.length == max_scale_down_capacity
hosted_apps = []
@versions_loaded.each { |version_key|
@app_info_map[version_key]['appservers'].each { |location|
host, port = location.split(":")
- if host == node.private_ip
- hosted_apps << "#{version_key}:#{port}"
- end
+ hosted_apps << "#{version_key}:#{port}" if host == node.private_ip
}
}
@@ -5106,14 +5107,14 @@ class Djinn
# Right now, only the autoscaled machines are started with just the
# compute role, so we check specifically for that during downscaling
# to make sure we only downscale the new machines added.
- node_to_remove = nil
- if node.roles == ['compute']
- Djinn.log_info("Removing node #{node}")
- node_to_remove = node
- end
+ nodes_to_remove << node if node.roles == ['compute']
+ }
+ }
- num_terminated = terminate_node_from_deployment(node_to_remove)
- num_scaled_down += num_terminated
+ # Now we remove the nodes marked for deletion.
+ nodes_to_remove.each { |node|
+ Djinn.log_info("Removing node #{node}.")
+ APPS_LOCK.synchronize { terminate_node_from_deployment(node) }
}
}
