From e44145104610c1c6d1eecd86c1f534c84fc0f22e Mon Sep 17 00:00:00 2001 From: vchoi-hdfgroup <55293060+vchoi-hdfgroup@users.noreply.github.com> Date: Fri, 17 May 2024 11:05:27 -0500 Subject: [PATCH] Fix for github Issue #1388 can't delete renamed dense attribute with corder tracking enabled (#4462) * Fix for github issue #1388: can't delete renamed dense attribute with corder tracking enabled The problem occurs in step 3(b) below which will delete the attribute with corder x from the creation order index v2 B-tree. The rename sequence in H5A__dense_rename() occurs in the following order: 1) The old attribute with corder x was removed from the creation order index v2 B-tree 2) The new renamed attribute was inserted via H5A__dense_insert(): (a) insert the attribute with new name j into the name index v2 B-tree (b) insert the attribute with corder x into the creation order index v2 B-tree 3) The old attribute was removed via H5A__dense_remove(): (a) remove the attribute with old name k from the name index v2 B-tree (b) remove the attribute with coorder x from the creation order index v2 B-tree Fix: deactivate the "corder_bt2_addr" field so that H5A__dense_remove() won't delete the attribute with corder x from the creation order index v2 B-tree. --- src/H5Adense.c | 9 +++++++-- test/tattr.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/H5Adense.c b/src/H5Adense.c index 48004d2aa70..52a6244d7be 100644 --- a/src/H5Adense.c +++ b/src/H5Adense.c @@ -839,6 +839,7 @@ H5A__dense_rename(H5F_t *f, const H5O_ainfo_t *ainfo, const char *old_name, cons htri_t attr_sharable; /* Flag indicating attributes are shareable */ htri_t shared_mesg; /* Should this message be stored in the Shared Message table? */ bool attr_exists; /* Attribute exists in v2 B-tree */ + H5O_ainfo_t tainfo = *ainfo; /* Copy of ainfo */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -977,8 +978,12 @@ H5A__dense_rename(H5F_t *f, const H5O_ainfo_t *ainfo, const char *old_name, cons else if (shared_mesg < 0) HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "error determining if message should be shared"); - /* Delete old attribute from dense storage */ - if (H5A__dense_remove(f, ainfo, old_name) < 0) + /* Deactivate the field so that H5A__dense_remove() won't delete the new renamed attribute + that was just added to the creation order index v2 B-tree via H5A__dense_insert() */ + tainfo.corder_bt2_addr = HADDR_UNDEF; + + /* Only delete the old attribute (before rename) from the name index v2 B-tree */ + if (H5A__dense_remove(f, (const H5O_ainfo_t *)&tainfo, old_name) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute in dense storage"); done: diff --git a/test/tattr.c b/test/tattr.c index d38fdaabc8d..e15ed5fb736 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -2898,6 +2898,11 @@ test_attr_dense_rename(hid_t fcpl, hid_t fapl) VERIFY(is_dense, true, "H5O__is_attr_dense_test"); } + /* Verify github issue #1388 that the last renamed attribute + with/without tracking corder can be deleted */ + ret = H5Adelete(dataset, new_attrname); + CHECK(ret, FAIL, "H5Adelete"); + /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); @@ -2930,8 +2935,8 @@ test_attr_dense_rename(hid_t fcpl, hid_t fapl) dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT); CHECK(dataset, H5I_INVALID_HID, "H5Dopen2"); - /* Verify renamed attributes */ - for (u = 0; u < (max_compact * 2); u++) { + /* Verify renamed attributes (the last attribute was deleted) */ + for (u = 0; u < (max_compact * 2 - 1); u++) { unsigned value; /* Attribute value */ /* Open attribute */