From 69b51b5f198eba477c05dc01c22a04c0b676dd59 Mon Sep 17 00:00:00 2001 From: Dimitri Savineau Date: Mon, 26 Oct 2020 17:33:45 -0400 Subject: [PATCH] monitor: use quorum_status instead of ceph status The ceph status command returns a lot of information stored in variables and/or facts which could consume resources for nothing. When checking the quorum status, we're only using the quorum_names structure in the ceph status output. To optimize this, we could use the ceph quorum_status command which contains the same needed information. This command returns less information. $ ceph status -f json | wc -c 2001 $ ceph quorum_status -f json | wc -c 957 $ time ceph status -f json > /dev/null real 0m0.577s user 0m0.538s sys 0m0.029s $ time ceph quorum_status -f json > /dev/null real 0m0.544s user 0m0.527s sys 0m0.016s Signed-off-by: Dimitri Savineau (cherry picked from commit 88f91d8c12169e08fc299dbd2fcaecc9d42dedca) --- infrastructure-playbooks/rolling_update.yml | 4 ++-- infrastructure-playbooks/shrink-mon.yml | 2 +- ...h-from-non-containerized-to-containerized-ceph-daemons.yml | 2 +- roles/ceph-handler/templates/restart_mon_daemon.sh.j2 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/infrastructure-playbooks/rolling_update.yml b/infrastructure-playbooks/rolling_update.yml index d60a21a26..a5318505c 100644 --- a/infrastructure-playbooks/rolling_update.yml +++ b/infrastructure-playbooks/rolling_update.yml @@ -233,7 +233,7 @@ ignore_errors: True # if no mgr collocated with mons - name: non container | waiting for the monitor to join the quorum... - command: ceph --cluster "{{ cluster }}" -m "{{ hostvars[groups[mon_group_name][0]]['_current_monitor_address'] }}" -s --format json + command: ceph --cluster "{{ cluster }}" -m "{{ hostvars[groups[mon_group_name][0]]['_current_monitor_address'] }}" quorum_status --format json register: ceph_health_raw until: - ceph_health_raw.rc == 0 @@ -245,7 +245,7 @@ - name: container | waiting for the containerized monitor to join the quorum... command: > - {{ container_binary }} exec ceph-mon-{{ ansible_hostname }} ceph --cluster "{{ cluster }}" -m "{{ hostvars[groups[mon_group_name][0]]['_current_monitor_address'] }}" -s --format json + {{ container_binary }} exec ceph-mon-{{ ansible_hostname }} ceph --cluster "{{ cluster }}" -m "{{ hostvars[groups[mon_group_name][0]]['_current_monitor_address'] }}" quorum_status --format json register: ceph_health_raw until: - ceph_health_raw.rc == 0 diff --git a/infrastructure-playbooks/shrink-mon.yml b/infrastructure-playbooks/shrink-mon.yml index 54e95dcb3..868559be3 100644 --- a/infrastructure-playbooks/shrink-mon.yml +++ b/infrastructure-playbooks/shrink-mon.yml @@ -112,7 +112,7 @@ post_tasks: - name: verify the monitor is out of the cluster - command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} -s -f json" + command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} quorum_status -f json" delegate_to: "{{ mon_host }}" failed_when: false register: result diff --git a/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml b/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml index 921e44bae..7e9249a59 100644 --- a/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml +++ b/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml @@ -135,7 +135,7 @@ post_tasks: - name: waiting for the monitor to join the quorum... - command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} -s --format json" + command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} quorum_status --format json" register: ceph_health_raw until: > hostvars[mon_host]['ansible_hostname'] in (ceph_health_raw.stdout | from_json)["quorum_names"] diff --git a/roles/ceph-handler/templates/restart_mon_daemon.sh.j2 b/roles/ceph-handler/templates/restart_mon_daemon.sh.j2 index e8344cbef..06383eae1 100644 --- a/roles/ceph-handler/templates/restart_mon_daemon.sh.j2 +++ b/roles/ceph-handler/templates/restart_mon_daemon.sh.j2 @@ -19,7 +19,7 @@ $DOCKER_EXEC test -S /var/run/ceph/{{ cluster }}-mon.{{ ansible_hostname }}.asok check_quorum() { while [ $RETRIES -ne 0 ]; do - $DOCKER_EXEC ceph --cluster {{ cluster }} -s --format json | "{{ discovered_interpreter_python }}" -c 'import sys, json; exit(0) if "{{ monitor_name }}" in json.load(sys.stdin)["quorum_names"] else exit(1)' && exit 0 + $DOCKER_EXEC ceph --cluster {{ cluster }} quorum_status --format json | "{{ discovered_interpreter_python }}" -c 'import sys, json; exit(0) if "{{ monitor_name }}" in json.load(sys.stdin)["quorum_names"] else exit(1)' && exit 0 sleep $DELAY let RETRIES=RETRIES-1 done