osd: Make recovery_pg_switch switch to the next PG #195

Open
koolkhel wants to merge 1 commits from koolkhel/vitastor:osd-recovery-pg-switch into master
9 changed files with 100 additions and 22 deletions

View File

@@ -2093,6 +2093,25 @@ jobs:
echo ""
done
test_recovery_pg_switch:
runs-on: ubuntu-latest
needs: build
container: ${{env.TEST_IMAGE}}:${{github.sha}}
steps:
- name: Run test
id: test
timeout-minutes: 3
run: /root/vitastor/tests/test_recovery_pg_switch.sh
- name: Print logs
if: always() && steps.test.outcome == 'failure'
run: |
for i in /root/vitastor/testdata/*.log /root/vitastor/testdata/*.txt; do
echo "-------- $i --------"
cat $i
echo ""
done
test_scrub:
runs-on: ubuntu-latest
needs: build

View File

@@ -220,9 +220,10 @@ class osd_t
robin_hood::unordered_set<osd_op_t*> pending_owned_ops;
std::map<object_id, osd_op_t*> scrub_ops;
int recovery_pick = 0;
pool_pg_num_t recovery_last_pg = {};
object_id recovery_last_oid = {};
int recovery_pg_done = 0, recovery_done = 0;
pool_pg_num_t recovery_last_pg[OSD_REC_MAX] = {};
object_id recovery_last_oid[OSD_REC_MAX] = {};
int recovery_pg_done[OSD_REC_MAX] = {};
int recovery_done = 0;
int recovery_retry_timer_id = -1;
osd_op_t *autosync_op = NULL;
int autosync_copies_to_delete = 0;

View File

@@ -284,9 +284,13 @@ bool osd_t::pick_next_recovery(osd_recovery_op_t &op, uint64_t now_us)
kind == OSD_REC_MISPLACED ? (PG_ACTIVE | PG_DEGRADED | PG_HAS_MISPLACED) : (PG_ACTIVE | PG_HAS_TOMB);
auto check = kind == OSD_REC_DEGRADED ? (PG_ACTIVE | PG_HAS_DEGRADED) :
kind == OSD_REC_MISPLACED ? (PG_ACTIVE | PG_HAS_MISPLACED) : (PG_ACTIVE | PG_HAS_TOMB);
// Each kind keeps its own position, the kinds take turns after every pick
auto & last_pg = recovery_last_pg[kind];
auto & last_oid = recovery_last_oid[kind];
bool from_start = !last_pg.pool_id;
// Restart scanning from the same PG as the last time
restart:
for (auto pg_it = pgs.lower_bound(recovery_last_pg); pg_it != pgs.end(); pg_it++)
for (auto pg_it = pgs.lower_bound(last_pg); pg_it != pgs.end(); pg_it++)
{
auto & src = kind == OSD_REC_DEGRADED ? pg_it->second.degraded_objects :
kind == OSD_REC_MISPLACED ? pg_it->second.misplaced_objects : pg_it->second.tomb_objects;
@@ -297,11 +301,12 @@ bool osd_t::pick_next_recovery(osd_recovery_op_t &op, uint64_t now_us)
if (pool_it != st_cli->pool_config.end() && pool_it->second.backfillfull)
{
// Skip the pool
recovery_last_pg.pool_id++;
last_pg = { .pool_id = pg_it->first.pool_id+1, .pg_num = 0 };
last_oid = {};
goto restart;
}
// Restart scanning from the next object
for (auto obj_it = src.upper_bound(recovery_last_oid); obj_it != src.end(); obj_it++)
for (auto obj_it = src.upper_bound(last_oid); obj_it != src.end(); obj_it++)
{
if (kind == OSD_REC_TOMBSTONE)
{
@@ -315,24 +320,32 @@ bool osd_t::pick_next_recovery(osd_recovery_op_t &op, uint64_t now_us)
{
op.kind = kind;
recovery_pick = (kind + 1) % OSD_REC_MAX;
recovery_last_oid = op.oid = obj_it->first;
recovery_pg_done++;
last_pg = pg_it->first;
last_oid = op.oid = obj_it->first;
// Switch to another PG after recovery_pg_switch operations
// to always mix all PGs during recovery but still benefit
// from recovery queue depth greater than 1
if (recovery_pg_done >= recovery_pg_switch)
if (++recovery_pg_done[kind] >= recovery_pg_switch)
{
recovery_pg_done = 0;
recovery_last_pg.pg_num++;
recovery_last_oid = {};
recovery_pg_done[kind] = 0;
last_pg.pg_num++;
last_oid = {};
}
return true;
}
}
}
// The next PG is scanned from its beginning
last_oid = {};
}
last_pg = {};
last_oid = {};
if (!from_start)
{
// Rescan the PGs before the position
from_start = true;
goto restart;
}
recovery_last_pg = {};
recovery_last_oid = {};
}
return false;
}

View File

@@ -399,8 +399,8 @@ bool osd_t::continue_pg_peering(pg_t & pg)
{
// Restart recovery from degraded objects
this->recovery_pick = 0;
this->recovery_last_pg = {};
this->recovery_last_oid = {};
this->recovery_last_pg[OSD_REC_DEGRADED] = {};
this->recovery_last_oid[OSD_REC_DEGRADED] = {};
}
}
return true;

View File

@@ -792,8 +792,8 @@ pg_osd_set_state_t* osd_t::add_object_to_set(pg_t & pg, const object_id oid, con
{
// Restart recovery from degraded objects
recovery_pick = 0;
recovery_last_pg = {};
recovery_last_oid = {};
recovery_last_pg[OSD_REC_DEGRADED] = {};
recovery_last_oid[OSD_REC_DEGRADED] = {};
}
ringloop->wakeup();
}

View File

@@ -299,8 +299,8 @@ resume_6:
if (ready)
{
// Re-scan from the start: the cursor may sit past the covered oids
recovery_last_pg = {};
recovery_last_oid = {};
recovery_last_pg[OSD_REC_TOMBSTONE] = {};
recovery_last_oid[OSD_REC_TOMBSTONE] = {};
ringloop->set_immediate([this]() { continue_recovery(); });
}
}

View File

@@ -3997,8 +3997,8 @@ void chaos_t::run(uint64_t steps)
"peering_state=%x no_recovery=%d no_rebalance=%d\n",
pg.state, pg.dead_peers.size(), pg.tomb_objects.size(),
pg.copies_to_delete_after_sync.size(), f.osd->recovery_ops.size(),
f.osd->recovery_pick, f.osd->recovery_last_pg.pool_id, f.osd->recovery_last_pg.pg_num,
f.osd->recovery_last_oid.inode, f.osd->recovery_last_oid.stripe,
f.osd->recovery_pick, f.osd->recovery_last_pg[OSD_REC_TOMBSTONE].pool_id, f.osd->recovery_last_pg[OSD_REC_TOMBSTONE].pg_num,
f.osd->recovery_last_oid[OSD_REC_TOMBSTONE].inode, f.osd->recovery_last_oid[OSD_REC_TOMBSTONE].stripe,
f.osd->peering_state, (int)f.osd->no_recovery, (int)f.osd->no_rebalance);
for (auto & it: pg.tomb_objects)
{

View File

@@ -162,6 +162,7 @@ OLD=1 IMMEDIATE_COMMIT=1 ./test_enospc.sh
OLD=1 IMMEDIATE_COMMIT=1 SCHEME=xor ./test_enospc.sh
./test_recovery_enospc.sh
./test_recovery_pg_switch.sh
./test_scrub.sh
ZERO_OSD=2 ./test_scrub.sh

View File

@@ -0,0 +1,44 @@
#!/bin/bash -ex
# Recovery must switch to another PG after recovery_pg_switch operations instead of
# recovering PGs one by one
OSD_COUNT=4
PG_COUNT=16
PG_MINSIZE=1
IMMEDIATE_COMMIT=1
GLOBAL_CONFIG=',"client_enable_writeback":false,"osd_out_time":1,"recovery_pg_switch":32'
. `dirname $0`/run_3osds.sh
pool_clean()
{
$ETCDCTL get /vitastor/pg/state/1/ --prefix --print-value-only | jq -s -e '[ .[] | select(.state == ["active"] or .state == ["active", "left_on_dead"]) ] | length == '$PG_COUNT
}
# 128 objects of 128 KB in each PG
$VITASTOR_FIO -bs=1M -direct=1 -iodepth=4 -rw=write -pool=1 -inode=1 -size=256M
kill -9 $OSD4_PID
sleep 5
wait_condition 120 pool_clean "Recovery"
# Longest run of operations in one PG and the number of PGs, for each OSD and kind
for i in 1 2 3; do
for kind in degraded misplaced; do
perl -ne 'if (/Submitting recovery operation for [0-9a-f]+:([0-9a-f]+) \('$kind'\)/) {
$pg = int(hex($1) / 131072) % '$PG_COUNT'; if ($pg ne $last) { $last = $pg; $run = 0 }
$run++; $max = $run if $run > $max; $seen{$pg} = 1 }
END { print "$max ".scalar(keys %seen)."\n" if $max }' ./testdata/osd$i.log
done
done > ./testdata/pg_runs.txt
cat ./testdata/pg_runs.txt
if ! awk '$2 > 1 { n++ } END { exit !n }' ./testdata/pg_runs.txt; then
format_error "No OSD recovered more than one PG, the test didn't check anything"
fi
if awk '$2 > 1 && $1 > 32 { bad++ } END { exit !bad }' ./testdata/pg_runs.txt; then
format_error "Recovery didn't switch to another PG after recovery_pg_switch operations"
fi
format_green OK