From bcc8e697f9e1c0d6102cd5eabbc6c5cca5436130 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 1 Dec 2020 14:13:24 +0300 Subject: [PATCH] Delete PGs when deleting pools (All OSD crash with "Online PG count change not allowed" if you try to delete an active pool though) --- mon/mon.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/mon/mon.js b/mon/mon.js index 0d676e5fe..ba271fa3d 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -565,19 +565,15 @@ class Mon { requestPut: { key: b64(this.etcd_prefix+'/config/pgs'), value: b64(JSON.stringify(new_cfg)) } }, ], }, this.config.etcd_mon_timeout, 0); - if (!res.succeeded) - { - return false; - } - this.state.config.pgs = new_cfg; + return false; } return !has_online; } save_new_pgs_txn(request, pool_id, up_osds, prev_pgs, new_pgs, pg_history) { - const replicated = this.state.config.pools[pool_id].scheme === 'replicated'; - const pg_minsize = this.state.config.pools[pool_id].pg_minsize; + const replicated = new_pgs.length && this.state.config.pools[pool_id].scheme === 'replicated'; + const pg_minsize = new_pgs.length && this.state.config.pools[pool_id].pg_minsize; const pg_items = {}; new_pgs.map((osd_set, i) => { @@ -632,7 +628,14 @@ class Mon } } this.state.config.pgs.items = this.state.config.pgs.items || {}; - this.state.config.pgs.items[pool_id] = pg_items; + if (!new_pgs.length) + { + delete this.state.config.pgs.items[pool_id]; + } + else + { + this.state.config.pgs.items[pool_id] = pg_items; + } } validate_pool_cfg(pool_id, pool_cfg, warn) @@ -756,6 +759,24 @@ class Mon { // Something has changed const etcd_request = { compare: [], success: [] }; + for (const pool_id in (this.state.config.pgs||{}).items||{}) + { + if (!this.state.config.pools[pool_id]) + { + // Pool deleted. Delete all PGs, but first stop them. + if (!await this.stop_all_pgs(pool_id)) + { + this.schedule_recheck(); + return; + } + const prev_pgs = []; + for (const pg in this.state.config.pgs.items[pool_id]||{}) + { + prev_pgs[pg-1] = this.state.config.pgs.items[pool_id][pg].osd_set; + } + this.save_new_pgs_txn(etcd_request, pool_id, up_osds, prev_pgs, [], []); + } + } for (const pool_id in this.state.config.pools) { const pool_cfg = this.state.config.pools[pool_id];