From 07fc778bce5959805176f43bb0e75aaa2f96904d Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Mon, 9 Nov 2026 02:31:40 +0000 Subject: [PATCH] DAOS-19937 object: fix convert cond TX restart A sub-task failing with -DER_TX_RESTART is retried by the convert TX, but its error code still propagates to the parent task and fails the retried operation. Reset it once handled, as dc_tx_convert_cb() does. The per-akey path also registered its callback on the parent, which may complete the parent inside its own completion callback and corrupt its callback list. Move the callback to a body-less aggregation task. Also fix error paths of the condition check tasks that could close the TX twice, and hold a TX reference across dc_tx_convert_post(). Add test IO58 with a dedicated DAOS_FAIL_TX_CONVERT_RESTART fail loc injecting the restart. Signed-off-by: Wang Shilong --- src/include/daos/common.h | 2 + src/object/cli_obj.c | 2 +- src/object/obj_tx.c | 76 +++++++++++++++++++++++++++++++---- src/tests/suite/daos_obj.c | 81 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 8 deletions(-) diff --git a/src/include/daos/common.h b/src/include/daos/common.h index 2a484b4b203..8b0c46fca8b 100644 --- a/src/include/daos/common.h +++ b/src/include/daos/common.h @@ -930,6 +930,8 @@ enum { #define DAOS_CONT_EC_BOUNDARY_FREEZE (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0xa5) /* cap the EC aggregation upper bound at the epoch given by fail_value */ #define DAOS_CONT_EC_AGG_EPOCH_MAX (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0xa6) +/* Convert update to internal TX, then restart the convert TX via stale pool map check */ +#define DAOS_FAIL_TX_CONVERT_RESTART (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0xab) #define DAOS_CHK_CONT_ORPHAN (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0xb0) #define DAOS_CHK_CONT_BAD_LABEL (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0xb1) diff --git a/src/object/cli_obj.c b/src/object/cli_obj.c index 8e980c41a62..1da30687f21 100644 --- a/src/object/cli_obj.c +++ b/src/object/cli_obj.c @@ -6573,7 +6573,7 @@ dc_obj_update(tse_task_t *task, struct dtx_epoch *epoch, uint32_t map_ver, if (rc != 0) D_GOTO(out_task, rc); - if (daos_fail_check(DAOS_FAIL_TX_CONVERT)) + if (daos_fail_check(DAOS_FAIL_TX_CONVERT) || daos_fail_check(DAOS_FAIL_TX_CONVERT_RESTART)) D_GOTO(out_task, rc = -DER_NEED_TX); /* For update, based on re-assembled sgl for csum calculate (to match with iod). diff --git a/src/object/obj_tx.c b/src/object/obj_tx.c index 3db33e1ab9e..a29f75584f4 100644 --- a/src/object/obj_tx.c +++ b/src/object/obj_tx.c @@ -685,8 +685,8 @@ dc_tx_check_pmv_internal(daos_handle_t th, struct dc_tx **ptx) pm_ver = dc_pool_get_version(tx->tx_pool); - if (tx->tx_pm_ver != pm_ver || - DAOS_FAIL_CHECK(DAOS_DTX_STALE_PM)) { + if (tx->tx_pm_ver != pm_ver || DAOS_FAIL_CHECK(DAOS_DTX_STALE_PM) || + (tx->tx_for_convert && DAOS_FAIL_CHECK(DAOS_FAIL_TX_CONVERT_RESTART))) { /* For external non-snap TX, restart it if pool map is stale. */ if (tx->tx_pm_ver != 0 && !tx->tx_fixed_epoch) { tx->tx_status = TX_FAILED; @@ -3171,8 +3171,14 @@ dc_tx_per_akey_existence_sub_cb(tse_task_t *task, void *data) return 0; } +/* + * Completion callback of the aggregation task that depends on all per-akey existence check + * sub-tasks. It must NOT be registered on the parent (args->task) itself, because dc_tx_post() + * may complete the parent, and completing a task inside its own completion callback re-enters + * tse_task_complete_callback() and corrupts the parent's callback list. + */ static int -dc_tx_per_akey_existence_parent_cb(tse_task_t *task, void *data) +dc_tx_per_akey_existence_agg_cb(tse_task_t *task, void *data) { struct dc_tx_check_existence_cb_args *args = data; struct dc_object *obj = NULL; @@ -3190,6 +3196,10 @@ dc_tx_per_akey_existence_parent_cb(tse_task_t *task, void *data) D_MUTEX_UNLOCK(&tx->tx_lock); } + /* Do not propagate the handled -DER_TX_RESTART to the restarted parent task. */ + if (tx->tx_for_convert && rc == -DER_TX_RESTART) + task->dt_result = 0; + dc_tx_post(tx, obj, args->task, args->opc, rc, 0); obj_decref(obj); @@ -3251,6 +3261,10 @@ dc_tx_check_existence_cb(tse_task_t *task, void *data) D_FREE(args->tmp_iods); } + /* Do not propagate the handled -DER_TX_RESTART to the restarted parent task. */ + if (tx->tx_for_convert && rc == -DER_TX_RESTART) + task->dt_result = 0; + dc_tx_post(tx, obj, args->task, args->opc, rc, 0); obj_decref(obj); @@ -3269,6 +3283,7 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ daos_iod_t *in_iods = iods_or_akeys; daos_iod_t *iods = NULL; tse_task_t *task = NULL; + tse_task_t *agg = NULL; d_list_t task_list; int rc = 0; int i; @@ -3288,6 +3303,22 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ cb_args.iods_or_akeys = iods_or_akeys; cb_args.sgls = sgls; + /* + * The aggregation task (without body) depends on all the sub-tasks, its completion + * callback handles the result. Schedule it before adding dependencies, then it will be + * marked as running and completed when all the sub-tasks completed. + */ + rc = dc_task_create(NULL, tse_task2sched(parent), NULL, &agg); + if (rc != 0) + goto fail; + + /* Hold agg, aborting sub-tasks may complete and release it before the fail path. */ + tse_task_addref(agg); + + rc = tse_task_schedule(agg, false); + if (rc != 0) + goto fail; + /* XXX: individual sub-task for checking each akey's existence independently. */ for (i = 0; i < nr; i++) { @@ -3323,7 +3354,7 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ tse_task_addref(task); tse_task_list_add(task, &task_list); - rc = dc_task_depend(parent, 1, &task); + rc = dc_task_depend(agg, 1, &task); /* * The task is in the task_list, then even if to be aborted, it will be handled @@ -3341,6 +3372,8 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ if (unlikely(d_list_empty(&task_list))) { struct dc_object *obj; + tse_task_complete(agg, 0); + obj = obj_hdl2ptr(oh); D_MUTEX_LOCK(&tx->tx_lock); rc = dc_tx_add_update(tx, obj, flags, dkey, nr, iods_or_akeys, sgls); @@ -3352,12 +3385,24 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ /* Drop the reference that is held via dc_tx_attach(). */ dc_tx_decref(tx); } else { - rc = tse_task_register_comp_cb(parent, dc_tx_per_akey_existence_parent_cb, + rc = tse_task_register_comp_cb(agg, dc_tx_per_akey_existence_agg_cb, &cb_args, sizeof(cb_args)); if (rc != 0) goto fail; - tse_task_list_sched(&task_list, true); + rc = dc_task_depend(parent, 1, &agg); + if (rc != 0) { + /* Abort sub-tasks to complete agg, then agg_cb() will post the + * parent and release the TX. + */ + tse_task_list_traverse(&task_list, shard_task_abort, &rc); + } else { + /* Reset status for the converted task. */ + if (tx->tx_for_convert) + parent->dt_result = 0; + + tse_task_list_sched(&task_list, true); + } } } else { if (task != NULL) @@ -3370,6 +3415,8 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ fail: tse_task_list_traverse(&task_list, shard_task_abort, &rc); + if (agg != NULL) + tse_task_complete(agg, rc); rc = dc_tx_post(tx, NULL, parent, opc, rc, 0); @@ -3377,6 +3424,9 @@ dc_tx_per_akey_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_ dc_tx_decref(tx); } + if (agg != NULL) + tse_task_decref(agg); + return rc; } @@ -3458,7 +3508,9 @@ dc_tx_check_existence_task(enum obj_rpc_opc opc, daos_handle_t oh, struct dc_tx if (rc != 0) { D_ERROR("Fail to add dep on check existence task: "DF_RC"\n", DP_RC(rc)); - goto out; + /* dc_tx_check_existence_cb() will post the parent and release resources. */ + tse_task_complete(task, rc); + return rc; } /* Reset status for the converted task. */ @@ -3703,7 +3755,10 @@ dc_tx_convert_cb(tse_task_t *task, void *data) */ task->dt_result = 0; + /* Hold TX, it may be closed and released via dc_tx_convert_post(). */ + dc_tx_addref(tx); rc = dc_tx_convert_post(tx, obj, opc, rc, 0); + dc_tx_decref(tx); } else { dc_tx_close_internal(tx); } @@ -3735,6 +3790,13 @@ dc_tx_convert_post(struct dc_tx *tx, struct dc_object *obj, enum obj_rpc_opc opc return 0; } + /* + * The condition check task has posted (completed the task and closed the TX) on failure, + * nothing to do. The caller must hold a reference on the TX. + */ + if (tx->tx_closed) + return result; + if (result != 0) D_GOTO(out, rc = result); diff --git a/src/tests/suite/daos_obj.c b/src/tests/suite/daos_obj.c index 635c800b054..e5b321d7426 100644 --- a/src/tests/suite/daos_obj.c +++ b/src/tests/suite/daos_obj.c @@ -1,5 +1,6 @@ /** * (C) Copyright 2016-2024 Intel Corporation. + * (C) Copyright 2026 Hewlett Packard Enterprise Development LP * (C) Copyright 2026 Google LLC * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -4811,6 +4812,82 @@ io_tx_convert(void **state) ioreq_fini(&req); } +static int +tx_convert_restart_update(daos_handle_t oh, uint64_t flags, daos_key_t *dkey, daos_iod_t *iod, + d_sg_list_t *sgl) +{ + int rc; + + /* + * The first hit converts the conditional update to internal TX, the second hit makes the + * existence check of the convert TX see stale pool map, then the TX will be restarted. + * Do not use DAOS_FAIL_ALWAYS here, otherwise the convert TX will keep restarting. + */ + daos_fail_num_set(2); + daos_fail_loc_set(DAOS_FAIL_TX_CONVERT_RESTART | DAOS_FAIL_SOME); + rc = daos_obj_update(oh, DAOS_TX_NONE, flags, dkey, 1, iod, sgl, NULL); + daos_fail_loc_set(0); + daos_fail_num_set(0); + + return rc; +} + +static void +io_tx_convert_restart(void **state) +{ + test_arg_t *arg = *state; + daos_obj_id_t oid; + daos_handle_t oh; + daos_key_t dkey; + daos_iod_t iod = {0}; + daos_recx_t recx; + d_sg_list_t sgl; + d_iov_t sg_iov; + char buf[32]; + int rc; + + FAULT_INJECTION_REQUIRED(); + + oid = daos_test_oid_gen(arg->coh, dts_obj_class, 0, 0, arg->myrank); + rc = daos_obj_open(arg->coh, oid, DAOS_OO_RW, &oh, NULL); + assert_rc_equal(rc, 0); + + dts_buf_render(buf, sizeof(buf)); + d_iov_set(&dkey, "dkey", strlen("dkey")); + d_iov_set(&sg_iov, buf, sizeof(buf)); + sgl.sg_nr = 1; + sgl.sg_nr_out = 0; + sgl.sg_iovs = &sg_iov; + d_iov_set(&iod.iod_name, "akey", strlen("akey")); + recx.rx_idx = 0; + recx.rx_nr = sizeof(buf); + iod.iod_nr = 1; + iod.iod_size = 1; + iod.iod_recxs = &recx; + iod.iod_type = DAOS_IOD_ARRAY; + + print_message("cond dkey insert for non-existent dkey with convert TX restart\n"); + rc = tx_convert_restart_update(oh, DAOS_COND_DKEY_INSERT, &dkey, &iod, &sgl); + assert_rc_equal(rc, 0); + + print_message("cond dkey insert for existing dkey with convert TX restart\n"); + rc = tx_convert_restart_update(oh, DAOS_COND_DKEY_INSERT, &dkey, &iod, &sgl); + assert_rc_equal(rc, -DER_EXIST); + + print_message("per-akey cond insert for existing akey with convert TX restart\n"); + iod.iod_flags = DAOS_COND_AKEY_INSERT; + rc = tx_convert_restart_update(oh, DAOS_COND_PER_AKEY, &dkey, &iod, &sgl); + assert_rc_equal(rc, -DER_EXIST); + + print_message("per-akey cond insert for non-existent akey with convert TX restart\n"); + d_iov_set(&iod.iod_name, "akey_new", strlen("akey_new")); + rc = tx_convert_restart_update(oh, DAOS_COND_PER_AKEY, &dkey, &iod, &sgl); + assert_rc_equal(rc, 0); + + rc = daos_obj_close(oh, NULL); + assert_rc_equal(rc, 0); +} + static void obj_open_perf(void **state) { @@ -5368,6 +5445,7 @@ io_57(void **state) reintegrate_single_pool_rank(arg, 0, false); } +/* clang-format off */ static const struct CMUnitTest io_tests[] = { { "IO1: simple update/fetch/verify", io_simple, async_disable, test_case_teardown}, @@ -5482,7 +5560,10 @@ static const struct CMUnitTest io_tests[] = { io_56, async_disable, test_case_teardown}, { "IO57: collective object query with rank_0 excluded", io_57, rebuild_sub_rf1_setup, test_teardown}, + { "IO58: tx convert restart with conditional update", + io_tx_convert_restart, async_disable, test_case_teardown}, }; +/* clang-format on */ int obj_setup_internal(void **state)