-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeep-scrub.sh
executable file
·108 lines (99 loc) · 3.31 KB
/
deep-scrub.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#
# Manual deep-scrub management script for Ceph 18.x
#
# by: Michael J. Kidd <[email protected]>
# version: 1.0
# https://github.com/linuxkidd/ceph-misc/blob/main/deep-scrub.sh
#
#
# Usage:
# ./deep-scrub.sh <concurrency> <osd_scrub_sleep> <scrub_chunk>
#
# Where:
# <concurrency>: Is the number of concurrent deep-scrubs to schedule
# (Required)
#
# <osd_scrub_sleep>: Fractional seconds to set for sleep between scrub
# chunk reads during deep-scrub
# (Optional, default: no change)
#
# <scrub_chunk>: How many objects to read at a time for deep-scrub
# (Optional, default: no change)
#
# NOTE:
# Automatic deep-scrub scheduling should be disabled in the cluster when
# using this tool for deep-scrub management.
# # ceph osd set nodeep-scrub
#
usage() {
echo
echo Usage:
echo " $0 <concurrency> <osd_scrub_sleep> <scrub_chunk>"
echo
echo Where:
echo " <concurrency>: Is the number of concurrent deep-scrubs to schedule"
echo " (Required)"
echo
echo " <osd_scrub_sleep>: Fractional seconds to set for sleep between scrub "
echo " chunk reads during deep-scrub"
echo " (Optional, default: no change)"
echo
echo " <scrub_chunk>: How many objects to read at a time for deep-scrub"
echo " (Optional, default: no change)"
echo
echo NOTE:
echo " Automatic deep-scrub scheduling should be disabled in the cluster when"
echo " using this tool for deep-scrub management."
echo " # ceph osd set nodeep-scrub"
echo
echo
exit 1
}
logline() {
echo $(date +%F\ %T) $1
}
if [ $# -eq 3 ]; then
if [ $(echo $3 | grep -c '^[0-9][0-9]*$') -eq 1 ]; then
CHUNK=$3
logline "Setting osd_scrub_chunk_min and max to $CHUNK"
ceph config set osd osd_scrub_chunk_max $CHUNK
ceph config set osd osd_scrub_chunk_min $CHUNK
else
echo ERROR: 3rd parameter \(osd_scrub_chunk_max\) must be a positive whole number.
usage
fi
fi
if [ $# -ge 2 ]; then
if [ $(echo $2 | grep -c '^[0-9\.][0-9\.]*$') -eq 1 ]; then
SLEEP=$2
logline "Setting osd_scrub_sleep to $SLEEP"
ceph config set osd osd_scrub_sleep $SLEEP
else
echo ERROR: 2nd parameter \(osd_scrub_sleep\) must be a positive decimal number.
usage
fi
fi
if [ $# -ge 1 ]; then
if [ $(echo $1 | grep -c '^[0-9][0-9]*$') -eq 1 ]; then
CONCUR=$1
else
echo ERROR: 1st parameter \(concurrency\) must be a positive whole number.
usage
fi
else
usage
fi
queuedscrub=$(ceph pg dump 2> /dev/null | grep -c 'queued for deep scrub')
activescrub=$(ceph pg dump 2> /dev/null | grep -c 'scrubbing+deep')
takenslots=$((queuedscrub + activescrub))
openslots=$((CONCUR - takenslots))
logline "$activescrub actively deep-scrubbing."
logline "$queuedscrub queued for deep-scrub."
logline "$openslots open scrub slots."
if [ $openslots -gt 0 ]; then
oldestnotscrub=$(ceph pg dump 2> /dev/null | grep -v scrubbing+deep | grep -v 'queued for deep scrub' | awk '$1 ~ /[0-9a-f]+\.[0-9a-f]+/ {print $22, $1}' | sort | head -n $openslots | awk '{print $2}')
for i in $oldestnotscrub; do
logline "$(ceph pg deep-scrub $i 2>&1)"
done
fi