Three steps when updating cluster state:
1) get cluster state from redis.
2) update cluster state.
3) rewrite to redis.
Before: write to redis one job info once.
After: write to redis more job infos once.
It will save time when writing more than one job info once.
Signed-off-by: Ren Wen <15991987063(a)163.com>
---
src/lib/sched.cr | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr
index a4b12b4..72f4e0b 100644
--- a/src/lib/sched.cr
+++ b/src/lib/sched.cr
@@ -58,11 +58,11 @@ class Sched
return cluster_state
end
- # get -> modify -> set
- def update_cluster_state(cluster_id, job_id, property, value)
+ # Update job's infos according to cluster id.
+ def update_cluster_state(cluster_id, job_id, job_infos : Hash(String, String))
cluster_state = get_cluster_state(cluster_id)
if cluster_state[job_id]?
- cluster_state[job_id].merge!({property => value})
+ cluster_state[job_id].merge!(job_infos)
@redis.hash_set("sched/cluster_state", cluster_id, cluster_state.to_json)
end
end
@@ -86,9 +86,9 @@ class Sched
case request_state
when "abort", "finished", "failed"
# update node state only
- update_cluster_state(cluster_id, job_id, "state", states[request_state])
+ update_cluster_state(cluster_id, job_id, {"state" => states[request_state]})
when "wait_ready"
- update_cluster_state(cluster_id, job_id, "state", states[request_state])
+ update_cluster_state(cluster_id, job_id, {"state" => states[request_state]})
@block_helper.block_until_finished(cluster_id) {
cluster_state = sync_cluster_state(cluster_id, job_id, states[request_state])
cluster_state == "ready" || cluster_state == "abort"
@@ -96,7 +96,7 @@ class Sched
return cluster_state
when "wait_finish"
- update_cluster_state(cluster_id, job_id, "state", states[request_state])
+ update_cluster_state(cluster_id, job_id, {"state" => states[request_state]})
while 1
sleep(10)
cluster_state = sync_cluster_state(cluster_id, job_id, states[request_state])
@@ -110,10 +110,11 @@ class Sched
direct_ips = env.params.query["direct_ips"]
direct_macs = env.params.query["direct_macs"]
- update_cluster_state(cluster_id, job_id, "roles", node_roles)
- update_cluster_state(cluster_id, job_id, "ip", node_ip)
- update_cluster_state(cluster_id, job_id, "direct_ips", direct_ips)
- update_cluster_state(cluster_id, job_id, "direct_macs", direct_macs)
+ job_infos = {"roles" => node_roles,
+ "ip" => node_ip,
+ "direct_ips" => direct_ips,
+ "direct_macs" => direct_macs}
+ update_cluster_state(cluster_id, job_id, job_infos)
when "roles_ip"
role = "server"
role_state = get_role_state(cluster_id, role)
--
2.23.0