On Fri, Nov 06, 2020 at 10:42:31AM +0800, Li Ping wrote:
On Fri, Nov 06, 2020 at 09:10:06AM +0800, Ren Wen wrote:
There are three steps when updating cluster state:
- get cluster state from redis.
- update cluster state.
- rewrite to redis.
Before: write to redis one job info once. After: write to redis more than one job info once.
==> more job info
Got it.
Thanks, RenWen
It will save time when writing more than one job info once.
Signed-off-by: Ren Wen 15991987063@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..bff6090 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 info according to cluster id.
- def update_cluster_state(cluster_id, job_id, job_info : Hash(String, String)) cluster_state = get_cluster_state(cluster_id) if cluster_state[job_id]?
cluster_state[job_id].merge!({property => value})
end endcluster_state[job_id].merge!(job_info) @redis.hash_set("sched/cluster_state", cluster_id, cluster_state.to_json)
@@ -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])
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])
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_info = {"roles" => node_roles,
"ip" => node_ip,
"direct_ips" => direct_ips,
"direct_macs" => direct_macs}
when "roles_ip" role = "server" role_state = get_role_state(cluster_id, role)update_cluster_state(cluster_id, job_id, job_info)
-- 2.23.0