From aaf52acc278fb179b9fd88bb14d2188192eeb70b Mon Sep 17 00:00:00 2001 From: Stephen Taylor Date: Fri, 17 Jul 2020 19:30:46 +0000 Subject: [PATCH] [ceph-client] Add back a new version of reweight_osds() https://review.opendev.org/733193 removed the reweight_osds() function from the ceph-client and weighted OSDs as they are added in the ceph-osd chart instead. Since then some situations have come up where OSDs were already deployed with incorrect weights and this function is needed in order to weight them properly later on. This new version calculates an expected weight for each OSD, compares it to the OSD's actual weight, and makes an adjustment if necessary. Change-Id: I58bc16fc03b9234a08847d29aa14067bec05f1f1 --- ceph-client/templates/bin/pool/_init.sh.tpl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ceph-client/templates/bin/pool/_init.sh.tpl b/ceph-client/templates/bin/pool/_init.sh.tpl index 6ce3d23cf..550dbcbe9 100644 --- a/ceph-client/templates/bin/pool/_init.sh.tpl +++ b/ceph-client/templates/bin/pool/_init.sh.tpl @@ -67,6 +67,17 @@ create_crushrule {{ .name }} {{ .crush_rule }} {{ .failure_domain }} {{ .device_ {{- end }} {{- end }} +function reweight_osds () { + OSD_DF_OUTPUT=$(ceph --cluster "${CLUSTER}" osd df --format json-pretty) + for OSD_ID in $(ceph --cluster "${CLUSTER}" osd ls); do + OSD_EXPECTED_WEIGHT=$(echo "${OSD_DF_OUTPUT}" | grep -A7 "\bosd.${OSD_ID}\b" | awk '/"kb"/{ gsub(",",""); d= $2/1073741824 ; r = sprintf("%.2f", d); print r }'); + OSD_WEIGHT=$(echo "${OSD_DF_OUTPUT}" | grep -A3 "\bosd.${OSD_ID}\b" | awk '/crush_weight/{print $2}' | cut -d',' -f1) + if [[ "${OSD_WEIGHT}" != "${OSD_EXPECTED_WEIGHT}" ]]; then + ceph --cluster "${CLUSTER}" osd crush reweight osd.${OSD_ID} ${OSD_EXPECTED_WEIGHT}; + fi + done +} + function enable_autoscaling () { if [[ "${ENABLE_AUTOSCALER}" == "true" ]]; then ceph mgr module enable pg_autoscaler @@ -171,6 +182,8 @@ function manage_pool () { ceph --cluster "${CLUSTER}" osd pool set-quota "${POOL_NAME}" max_bytes $POOL_QUOTA } +reweight_osds + {{ $targetPGperOSD := .Values.conf.pool.target.pg_per_osd }} {{ $crushRuleDefault := .Values.conf.pool.default.crush_rule }} {{ $targetQuota := .Values.conf.pool.target.quota | default 100 }}