Skip to content

Commit

Permalink
Properly clean up cache when failing to load an object header
Browse files Browse the repository at this point in the history
  • Loading branch information
fortnern committed May 10, 2024
1 parent 603f8b1 commit f838899
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/H5Gint.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ static herr_t
H5G__open_oid(H5G_t *grp)
{
bool obj_opened = false;
htri_t msg_exists;
herr_t ret_value = SUCCEED;

FUNC_ENTER_PACKAGE
Expand All @@ -523,8 +524,14 @@ H5G__open_oid(H5G_t *grp)
obj_opened = true;

/* Check if this object has the right message(s) to be treated as a group */
if ((H5O_msg_exists(&(grp->oloc), H5O_STAB_ID) <= 0) && (H5O_msg_exists(&(grp->oloc), H5O_LINFO_ID) <= 0))
HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "not a group");
if ((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID)) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't check if symbol table message exists");
if (!msg_exists) {
if ((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_LINFO_ID)) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't check if link info message exists");
if (!msg_exists)
HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "not a group");
}

done:
if (ret_value < 0) {
Expand Down
16 changes: 14 additions & 2 deletions src/H5Oint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,8 @@ H5O_protect(const H5O_loc_t *loc, unsigned prot_flags, bool pin_all_chunks)
if (cont_msg_info.msgs)
cont_msg_info.msgs = (H5O_cont_t *)H5FL_SEQ_FREE(H5O_cont_t, cont_msg_info.msgs);

if (H5O_unprotect(loc, oh, H5AC__NO_FLAGS_SET) < 0)
/* Unprotect the ohdr and delete it from cache since if we failed to load it it's in an inconsistent state */
if (H5O_unprotect(loc, oh, H5AC__DELETED_FLAG) < 0)
HDONE_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, NULL, "unable to release object header");
}

Expand Down Expand Up @@ -1234,10 +1235,21 @@ H5O_unprotect(const H5O_loc_t *loc, H5O_t *oh, unsigned oh_flags)
} /* end if */
} /* end for */

/* Reet the flag from the unprotect */
/* Reset the flag from the unprotect */
oh->chunks_pinned = false;
} /* end if */

/* Remove the other chunks if we're removing the ohdr (due to a failure) */
if (oh_flags & H5AC__DELETED_FLAG) {
unsigned u; /* Local index variable */

/* Iterate over chunks > 0 */
for (u = 1; u < oh->nchunks; u++)
/* Expunge chunk proxy from cache */
if (H5AC_expunge_entry(loc->file, H5AC_OHDR_CHK, oh->chunk[u].addr, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPIN, FAIL, "unable to expunge object header chunk");
} /* end if */

/* Unprotect the object header */
if (H5AC_unprotect(loc->file, H5AC_OHDR, oh->chunk[0].addr, oh, oh_flags) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to release object header");
Expand Down

0 comments on commit f838899

Please sign in to comment.