From 46462da45e547fc5e0f92be87e32e18f013ed5cd Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 23 Apr 2023 01:50:30 +0300 Subject: [PATCH] Preload own PG history updates to fix PG state loop possibly applying the old metadata version --- src/osd_peering.cpp | 7 +++++++ tests/test_add_osd.sh | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/osd_peering.cpp b/src/osd_peering.cpp index b34963f7..6a021e32 100644 --- a/src/osd_peering.cpp +++ b/src/osd_peering.cpp @@ -483,6 +483,10 @@ void osd_t::report_pg_state(pg_t & pg) pg.all_peers = pg.target_set; std::sort(pg.all_peers.begin(), pg.all_peers.end()); pg.cur_peers = pg.target_set; + // Change pg_config at the same time, otherwise our PG reconciling loop may try to apply the old metadata + auto & pg_cfg = st_cli.pool_config[pg.pool_id].pg_config[pg.pg_num]; + pg_cfg.target_history = pg.target_history; + pg_cfg.all_peers = pg.all_peers; } else if (pg.state == (PG_ACTIVE|PG_LEFT_ON_DEAD)) { @@ -522,6 +526,9 @@ void osd_t::report_pg_state(pg_t & pg) pg.cur_peers.push_back(pg_osd); } } + auto & pg_cfg = st_cli.pool_config[pg.pool_id].pg_config[pg.pg_num]; + pg_cfg.target_history = pg.target_history; + pg_cfg.all_peers = pg.all_peers; } if (pg.state == PG_OFFLINE && !this->pg_config_applied) { diff --git a/tests/test_add_osd.sh b/tests/test_add_osd.sh index 2d0393d3..72a37695 100755 --- a/tests/test_add_osd.sh +++ b/tests/test_add_osd.sh @@ -28,9 +28,7 @@ if ! ($ETCDCTL get /vitastor/config/pgs --print-value-only |\ format_error "FAILED: OSD NOT ADDED INTO DISTRIBUTION" fi -if ! ($ETCDCTL get --prefix /vitastor/pg/state/ --print-value-only | jq -s -e '([ .[] | select(.state == ["active"]) ] | length) == '$PG_COUNT''); then - format_error "FAILED: $PG_COUNT PGS NOT ACTIVE" -fi +wait_finish_rebalance 10 sleep 1 kill -9 $OSD4_PID @@ -52,8 +50,6 @@ if ! ($ETCDCTL get /vitastor/config/pgs --print-value-only |\ format_error "FAILED: OSD NOT REMOVED FROM DISTRIBUTION" fi -if ! ($ETCDCTL get --prefix /vitastor/pg/state/ --print-value-only | jq -s -e '([ .[] | select(.state == ["active"] or .state == ["active", "left_on_dead"]) ] | length) == '$PG_COUNT''); then - format_error "FAILED: $PG_COUNT PGS NOT ACTIVE" -fi +wait_finish_rebalance 10 format_green OK