Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions src/rebuild/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,12 @@ rebuild_obj_scan_cb(daos_handle_t ch, vos_iter_entry_t *ent,
int i;
int rc = 0;

if (rpt->rt_abort || arg->cont_child->sc_stopping) {
/* Check rt_finishing to allow rebuild_scan_leader to exit quickly when
* rebuild_tgt_fini() is waiting for the refcount to drop. Without this,
* a stale scan_leader continues scanning all VOS objects indefinitely,
* blocking TLS cleanup and causing retries to fail with -DER_BUSY.
*/
if (rpt->rt_abort || rpt->rt_finishing || arg->cont_child->sc_stopping) {
D_DEBUG(DB_REBUILD, "rebuild is aborted\n");
return 1;
}
Expand Down Expand Up @@ -1206,6 +1211,7 @@ rebuild_tgt_scan_handler(crt_rpc_t *rpc)
struct rebuild_tgt_pool_tracker *rpt = NULL;
struct ds_pool *pool = NULL;
bool checker = false;
uint64_t ts_start, ts_now;
int rc;

rsi = crt_req_get(rpc);
Expand All @@ -1216,6 +1222,7 @@ rebuild_tgt_scan_handler(crt_rpc_t *rpc)
rsi->rsi_rebuild_ver, rsi->rsi_rebuild_gen, rsi->rsi_master_rank,
rsi->rsi_leader_term, RB_OP_STR(rsi->rsi_rebuild_op));

ts_start = daos_gettime_coarse();
rc = ds_pool_lookup(rsi->rsi_pool_uuid, &pool);
if (rc) {
D_ERROR("Can not find pool " DF_UUID ": %d\n", DP_UUID(rsi->rsi_pool_uuid), rc);
Expand Down Expand Up @@ -1251,14 +1258,26 @@ rebuild_tgt_scan_handler(crt_rpc_t *rpc)
}
}

redo_rpt_lookup:
/* check if the rebuild with different leader is already started */
rpt = rpt_lookup(rsi->rsi_pool_uuid, -1, rsi->rsi_rebuild_ver, -1);
if (rpt != NULL && rpt->rt_rebuild_op == rsi->rsi_rebuild_op) {
if (rpt->rt_global_done) {
D_WARN("the previous rebuild "DF_UUID"/%d/"DF_U64"/%p is not cleanup yet\n",
DP_UUID(rsi->rsi_pool_uuid), rsi->rsi_rebuild_ver,
rsi->rsi_leader_term, rpt);
D_GOTO(out_put, rc = -DER_BUSY);
ts_now = daos_gettime_coarse();
if (ts_now > ts_start + 30) {
D_WARN(DF_UUID " %s ver %d/gen %u waited previous rebuild "
"finishing more than 30 seconds\n",
DP_UUID(rsi->rsi_pool_uuid), RB_OP_STR(rpt->rt_rebuild_op),
rsi->rsi_rebuild_ver, rpt->rt_rebuild_gen);
D_GOTO(out_put, rc = -DER_BUSY);
} else {
rpt_put(rpt);
dss_sleep(1000);
goto redo_rpt_lookup;
}
}

/* Rebuild should never skip the version */
Expand Down Expand Up @@ -1322,6 +1341,36 @@ rebuild_tgt_scan_handler(crt_rpc_t *rpc)
tls = rebuild_pool_tls_lookup(rsi->rsi_pool_uuid, rsi->rsi_rebuild_ver,
rsi->rsi_rebuild_gen);
if (tls != NULL) {
struct rebuild_tgt_pool_tracker *tmp;

/* Check whether the TLS belongs to an rpt that is finishing
* (rt_finishing == 1). rpt_lookup() skips such rpts, so the
* scan handler arrives here with a NULL rpt but a live TLS.
* This is a transient window between rebuild_tgt_fini() setting
* rt_finishing and the subsequent rebuild_pool_tls_destroy().
* Yield to let the finishing rpt's scan_leader exit and drop
* its refcount so TLS cleanup can proceed, then retry.
*/
d_list_for_each_entry(tmp, &rebuild_gst.rg_tgt_tracker_list, rt_list) {
if (uuid_compare(tmp->rt_pool_uuid, rsi->rsi_pool_uuid) == 0 &&
tmp->rt_rebuild_ver == rsi->rsi_rebuild_ver &&
tmp->rt_rebuild_gen == rsi->rsi_rebuild_gen &&
(tmp->rt_finishing || tmp->rt_abort)) {
ts_now = daos_gettime_coarse();
if (ts_now > ts_start + 30) {
D_WARN(DF_UUID " %s ver %d/gen %u waited previous rebuild "
"finishing more than 30 seconds\n",
DP_UUID(rsi->rsi_pool_uuid),
RB_OP_STR(tmp->rt_rebuild_op), rsi->rsi_rebuild_ver,
rsi->rsi_rebuild_gen);
break;
} else {
dss_sleep(1000);
goto tls_lookup;
}
}
}

D_WARN("the previous rebuild "DF_UUID"/%d is not cleanup yet\n",
DP_UUID(rsi->rsi_pool_uuid), rsi->rsi_rebuild_ver);
D_GOTO(out_delete, rc = -DER_BUSY);
Expand Down
42 changes: 33 additions & 9 deletions src/rebuild/srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,10 @@ rebuild_tgt_query(struct rebuild_tgt_pool_tracker *rpt,
return rc;
}

void
ds_rebuild_running_query(uuid_t pool_uuid, uint32_t opc, uint32_t *upper_ver,
daos_epoch_t *stable_eph, uint32_t *generation)
static void
ds_rebuild_running_query_adv(uuid_t pool_uuid, uint32_t opc, uint32_t *upper_ver,
daos_epoch_t *stable_eph, uint32_t *generation, uint32_t *leader_rank,
uint64_t *leader_term)
{
struct rebuild_tgt_pool_tracker *rpt;

Expand All @@ -539,6 +540,10 @@ ds_rebuild_running_query(uuid_t pool_uuid, uint32_t opc, uint32_t *upper_ver,
*stable_eph = 0;
if (generation)
*generation = -1;
if (leader_rank)
*leader_rank = -1;
if (leader_term)
*leader_term = -1;
rpt = rpt_lookup(pool_uuid, opc, -1, -1);
if (rpt != NULL && !rpt->rt_global_done && !rpt->rt_abort) {
D_DEBUG(DB_REBUILD, DF_UUID" rebuild %p running eph/ver/gen "DF_X64"/%u/%u\n",
Expand All @@ -550,11 +555,22 @@ ds_rebuild_running_query(uuid_t pool_uuid, uint32_t opc, uint32_t *upper_ver,
*upper_ver = rpt->rt_rebuild_ver;
if (generation)
*generation = rpt->rt_rebuild_gen;
if (leader_rank)
*leader_rank = rpt->rt_leader_rank;
if (leader_term)
*leader_term = rpt->rt_leader_term;
}
if (rpt)
rpt_put(rpt);
}

void
ds_rebuild_running_query(uuid_t pool_uuid, uint32_t opc, uint32_t *upper_ver,
daos_epoch_t *stable_eph, uint32_t *generation)
{
ds_rebuild_running_query_adv(pool_uuid, opc, upper_ver, stable_eph, generation, NULL, NULL);
}

/*
* Restart rebuild if \a rank's rebuild not finished.
* Only used for massive failure recovery case, see pool_restart_rebuild_if_rank_wip().
Expand Down Expand Up @@ -1423,7 +1439,8 @@ static int
rebuild_leader_start(struct ds_pool *pool, struct rebuild_task *task,
struct rebuild_global_pool_tracker **p_rgt)
{
uint64_t leader_term;
uint64_t leader_term, rebuild_leader_term;
uint32_t leader_rank, rebuild_leader_rank;
uint32_t version;
uint32_t generation;
int rc;
Expand All @@ -1434,12 +1451,17 @@ rebuild_leader_start(struct ds_pool *pool, struct rebuild_task *task,
DP_RC(rc));
return rc;
}
leader_rank = dss_self_rank();

/* If this happened due to leader switch, then do not need update
* generation.
/* If this happened due to leader switch, then do not need update generation.
* If on the same PS leader, it retry the rebuild/reclaim on same version, should bump
* the generation.
*/
ds_rebuild_running_query(pool->sp_uuid, -1, &version, NULL, &generation);
if (version < task->dst_map_ver)
ds_rebuild_running_query_adv(pool->sp_uuid, -1, &version, NULL, &generation,
&rebuild_leader_rank, &rebuild_leader_term);
if ((version < task->dst_map_ver) ||
(version == task->dst_map_ver && leader_rank == rebuild_leader_rank &&
leader_term == rebuild_leader_term))
generation = ++pool->sp_rebuild_gen;

rc = rebuild_prepare(pool, task->dst_map_ver, generation,
Expand All @@ -1457,7 +1479,9 @@ rebuild_leader_start(struct ds_pool *pool, struct rebuild_task *task,
rc = rebuild_scan_broadcast(pool, *p_rgt, &task->dst_tgts,
task->dst_new_layout_version, task->dst_rebuild_op);
if (rc)
D_ERROR("object scan failed: "DF_RC"\n", DP_RC(rc));
DL_ERROR(rc, "pool " DF_UUID ": %s, ver %d, object scan broadcast failed.",
DP_UUID(pool->sp_uuid), RB_OP_STR(task->dst_rebuild_op),
task->dst_map_ver);
else
rc = 1;

Expand Down
Loading