HDFGroup / hdf5

Official HDF5® Library Repository
https://www.hdfgroup.org/
Other
600 stars 244 forks source link

Setting strict libver bounds in FAPL causes unexpected H5Fopen failures that do not occur with file switch #4849

Open markcmiller86 opened 2 weeks ago

markcmiller86 commented 2 weeks ago

In the code below, I compare setting setting libver bounds in FAPL used in H5Fopen to using switch to change libver bounds after the file is open.

Since the libver bounds in the fapl is intended to effect only the objects created thereafter, I am puzzled why the attempts to open a file created with libver set to LATEST then fail when FAPL sets libver to v18. I mean, shouldn't the open succeed and then behave as if H5Fset_libver_bounds() was called. Its particularly strange in the read-only case because no objects will be created under those conditions and the libver setting is kinda meaningless.

#include <hdf5.h>

int main(int argc, char **argv)
{
    hid_t fapl1 = H5Pcreate(H5P_FILE_ACCESS);
    hid_t fapl2 = H5Pcreate(H5P_FILE_ACCESS);
    hid_t fapl3 = H5Pcreate(H5P_FILE_ACCESS);

    H5Pset_libver_bounds(fapl1, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
    hid_t fid = H5Fcreate("foo.hdf5", H5F_ACC_TRUNC, H5P_DEFAULT, fapl1);
    H5Pclose(fapl1);
    H5Fclose(fid);

    /* fails in read-write mode */
    H5Pset_libver_bounds(fapl2, H5F_LIBVER_V18, H5F_LIBVER_V18);
    fid = H5Fopen("foo.hdf5", H5F_ACC_RDWR, fapl2);
    H5Fclose(fid);

    /* fails in read-only mode */
    fid = H5Fopen("foo.hdf5", H5F_ACC_RDONLY, fapl2);
    H5Fclose(fid);
    H5Pclose(fapl2);

    /* But, this works fine */
    fid = H5Fopen("foo.hdf5", H5F_ACC_RDWR, fapl3);
    H5Fset_libver_bounds(fid, H5F_LIBVER_V18, H5F_LIBVER_V18);
    H5Pclose(fapl3);
    H5Fclose(fid);

    return 0;
}
markcmiller86 commented 2 weeks ago

I believe that if you reverse the ordering of the libver settings and instead create file using a fapl with libver v18 in both high and low and then attempt to open it with a fapl that sets libver to latest, that also fails.

markcmiller86 commented 1 week ago

Just one other observation to share here and that is that the libver bounds property is associated with file access, not file creation properties. Therefere, I would NOT expect it to have affected the file creation. Furthermore, the documentation regarding setting of libver bounds (in props or on an open file) does not speak specifically to file creation...only object creation in a file.