diff --git a/src/common/dav/dav_internal.h b/src/common/dav/dav_internal.h index 0f8ddff5916..7261e7aa291 100644 --- a/src/common/dav/dav_internal.h +++ b/src/common/dav/dav_internal.h @@ -69,6 +69,7 @@ typedef struct dav_obj { static inline struct dav_tx *utx2wtx(struct umem_wal_tx *utx) { + D_ASSERT(utx != NULL); return (struct dav_tx *)&utx->utx_private; } diff --git a/src/common/dav/tx.c b/src/common/dav/tx.c index 45b3daba73c..0dd8af78d02 100644 --- a/src/common/dav/tx.c +++ b/src/common/dav/tx.c @@ -1512,6 +1512,8 @@ dav_reserve(dav_obj_t *pop, struct dav_action *act, size_t size, uint64_t type_n if (palloc_reserve(pop->do_heap, size, NULL, NULL, type_num, 0, 0, 0, act) != 0) { + if (!tx_inprogress) + lw_tx_end(pop, NULL); DAV_API_END(); return 0; } @@ -1565,9 +1567,26 @@ dav_publish(dav_obj_t *pop, struct dav_action *actv, size_t actvcnt) void dav_cancel(dav_obj_t *pop, struct dav_action *actv, size_t actvcnt) { + int rc, tx_inprogress = 0; + DAV_DBG("actvcnt=%zu", actvcnt); + if (get_tx()->stage != DAV_TX_STAGE_NONE) + tx_inprogress = 1; + DAV_API_START(); + if (!tx_inprogress) { + rc = lw_tx_begin(pop); + if (rc) { + D_ERROR("Failed to start local tx. %d\n", rc); + return; + } + } + palloc_cancel(pop->do_heap, actv, actvcnt); + + if (!tx_inprogress) + lw_tx_end(pop, NULL); + DAV_API_END(); } diff --git a/src/common/tests/umem_test_bmem.c b/src/common/tests/umem_test_bmem.c index 07f4a112b36..6e0447be0b3 100644 --- a/src/common/tests/umem_test_bmem.c +++ b/src/common/tests/umem_test_bmem.c @@ -1,6 +1,6 @@ /** * (C) Copyright 2019-2023 Intel Corporation. - * (C) Copyright 2023 Hewlett Packard Enterprise Development LP. + * (C) Copyright 2023-2025 Hewlett Packard Enterprise Development LP. * * SPDX-License-Identifier: BSD-2-Clause-Patent */ @@ -1193,7 +1193,8 @@ test_tx_reserve_publish_cancel(void **state) assert_int_equal(memcmp(rsrv_ptr1, local_buf, 980), 0); assert_int_equal(memcmp(rsrv_ptr2, local_buf, 128), 0); umem_cancel(umm, rsrvd_act); - validate_persist_activity(1, 0); + /* umem_cacnel() internally started tx, which increased one additional resrv_cnt */ + validate_persist_activity(2, 0); utest_get_scm_used_space(arg->ta_utx, &cur_mem_used); assert_true(cur_mem_used >= initial_mem_used); umoff = umem_atomic_alloc(umm, 980, UMEM_TYPE_ANY);