Skip to content

Commit

Permalink
Fix for github Issue HDFGroup#1388 can't delete renamed dense attribu…
Browse files Browse the repository at this point in the history
…te with corder tracking enabled (HDFGroup#4462)

* Fix for github issue HDFGroup#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.
  • Loading branch information
vchoi-hdfgroup authored and lrknox committed May 20, 2024
1 parent f0a6d59 commit e441451
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/H5Adense.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions test/tattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit e441451

Please sign in to comment.