Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/include/daos/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,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)
Expand Down
2 changes: 1 addition & 1 deletion src/object/cli_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -6794,7 +6794,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).
Expand Down
76 changes: 69 additions & 7 deletions src/object/obj_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,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;
Expand Down Expand Up @@ -3282,8 +3282,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;
Expand All @@ -3301,6 +3307,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);

Expand Down Expand Up @@ -3362,6 +3372,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);

Expand All @@ -3380,6 +3394,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;
Expand All @@ -3399,6 +3414,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++) {
Expand Down Expand Up @@ -3434,7 +3465,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
Expand All @@ -3452,6 +3483,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);
Expand All @@ -3463,12 +3496,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)
Expand All @@ -3481,13 +3526,18 @@ 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);

/* Drop the reference that is held via dc_tx_attach(). */
dc_tx_decref(tx);
}

if (agg != NULL)
tse_task_decref(agg);

return rc;
}

Expand Down Expand Up @@ -3569,7 +3619,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. */
Expand Down Expand Up @@ -3814,7 +3866,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);
}
Expand Down Expand Up @@ -3846,6 +3901,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);

Expand Down
81 changes: 81 additions & 0 deletions src/tests/suite/daos_obj.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down
Loading