-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathrocksdb-resharding.yml
133 lines (116 loc) · 5.03 KB
/
rocksdb-resharding.yml
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
# Copyright Red Hat
# SPDX-License-Identifier: Apache-2.0
# Author: Guillaume Abrioux <[email protected]>
#
# This playbook reshards the rocksDB database for a given OSD
#
# Usage:
#
# ansible-playbook -i <inventory host file> rocksdb-resharding.yml -e osd_id=0 -e admin_node=ceph-mon0
#
# Required run-time variables
# ------------------
# osd_id : the id of the OSD where you want to reshard its corresponding rocksdb database.
# admin_node : the name of a node with enough privileges to stop/start
# daemons via `cephadm shell ceph orch daemon` command.
# (usually the bootstrap node).
#
# Optional run-time variables
# ------------------
# fsid : the fsid of the cluster.
# rocksdb_sharding_parameters : the rocksdb sharding parameter to set. Default is 'm(3) p(3,0-12) O(3,0-13) L P'.
# docker : bool to be set in order to use docker engine instead. Default is False.
- name: Rocksdb-resharding
hosts: all
become: true
gather_facts: false
strategy: linear
tasks:
- name: Check prerequisites
run_once: true # noqa: run-once[task]
delegate_to: localhost
block:
- name: Fail if osd_id is not defined
ansible.builtin.fail:
msg: "you must provide 'osd_id' variable"
when: osd_id is undefined
- name: Fail if admin_node is not defined
ansible.builtin.fail:
msg: "you must pass 'admin_node' variable"
when: admin_node is not defined
- name: Fail if osd_id isn't an id
ansible.builtin.fail:
msg: "osd_id must be an id"
when: not osd_id is regex('^\d+$')
- name: Set_fact cephadm_cmd
ansible.builtin.set_fact:
cephadm_cmd: "cephadm {{ '--docker' if docker | default(False) | bool else '' }} shell ceph"
- name: Test connectivity to admin node
ansible.builtin.ping:
delegate_to: "{{ admin_node }}"
run_once: true # noqa: run-once[task]
- name: Get details about the osd daemon
delegate_to: "{{ admin_node }}"
block:
- name: Get cluster fsid
ansible.builtin.command: "{{ cephadm_cmd }} fsid"
register: fsid
changed_when: false
when: fsid is not defined
- name: Set_fact fsid
ansible.builtin.set_fact:
fsid: "{{ fsid.stdout }}"
when: fsid.stdout is defined
- name: Get container image currently used by osd container
ansible.builtin.command: "{{ cephadm_cmd }} orch ps --daemon_type osd --daemon_id {{ osd_id }} --format json"
changed_when: false
register: ceph_orch_ps
retries: 120
delay: 1
until: (ceph_orch_ps.stdout | from_json)[0]['status_desc'] == 'running'
- name: Set_fact container_image, container_host
ansible.builtin.set_fact:
container_image: "{{ (ceph_orch_ps.stdout | from_json)[0]['container_image_name'] }}"
container_host: "{{ (ceph_orch_ps.stdout | from_json)[0]['hostname'] }}"
- name: Stop the osd
ceph_orch_daemon:
fsid: "{{ fsid }}"
state: stopped
daemon_id: "{{ osd_id }}"
daemon_type: osd
- name: Set_fact ceph_cmd
ansible.builtin.set_fact:
ceph_bluestore_tool_cmd: >
{{ container_binary | default('podman') }} run --rm --privileged --entrypoint=ceph-bluestore-tool
-v /var/run/ceph/{{ fsid }}:/var/run/ceph:z -v /var/log/ceph/{{ fsid }}:/var/log/ceph:z
-v /var/lib/ceph/{{ fsid }}/crash:/var/lib/ceph/crash:z
-v /var/lib/ceph/{{ fsid }}/osd.{{ osd_id }}:/var/lib/ceph/osd/ceph-{{ osd_id }}:z
-v /var/lib/ceph/{{ fsid }}/osd.{{ osd_id }}/config:/etc/ceph/ceph.conf:z -v /dev:/dev
-v /run/udev:/run/udev -v /sys:/sys
-v /var/lib/ceph/{{ fsid }}/selinux:/sys/fs/selinux:ro
-v /run/lvm:/run/lvm -v /run/lock/lvm:/run/lock/lvm {{ container_image }}
--path /var/lib/ceph/osd/ceph-{{ osd_id }}
- name: Resharding operations
delegate_to: "{{ container_host }}"
run_once: true # noqa: run-once[task]
block:
- name: Check fs consistency with fsck before resharding
ansible.builtin.command: "{{ ceph_bluestore_tool_cmd }} fsck"
changed_when: false
- name: Show current sharding
ansible.builtin.command: "{{ ceph_bluestore_tool_cmd }} show-sharding"
changed_when: false
- name: Reshard
ansible.builtin.command: "{{ ceph_bluestore_tool_cmd }} --sharding=\"{{ rocksdb_sharding_parameters | default('m(3) p(3,0-12) O(3,0-13) L P') }}\" reshard" # noqa: yaml[line-length]
changed_when: false
- name: Check fs consistency with fsck after resharding
ansible.builtin.command: "{{ ceph_bluestore_tool_cmd }} fsck"
changed_when: false
- name: Restart the osd
ceph_orch_daemon:
fsid: "{{ fsid }}"
state: started
daemon_id: "{{ osd_id }}"
daemon_type: osd
delegate_to: "{{ admin_node }}"