puzzling file access behavior

I have an HDF5 file containing some metadata. That file is, 99% of the time, only needed to be opened read-only. As such, I have a C++ class that wraps around the access for the metadata and opens the file read-only.

That 1% case, I have a program whose purpose is to update the metadata, and it needs to open the file read-write. The program that does the editing was using the read-only class for convenience, but it seems that things don't work like I was expecting.

If I have the class open the file read-only first, when I try and open it read-write, I get an error saying the file was already open for read-only. This isn't overly surprising, until I started closing the read-only handle before trying to open for read-write. At that point, I still got an error.

To make things clearer as to what I'm describing, here are some timelines:

open(RDONLY)
open(R-W) -> error

open(RDONLY)
close(RDONLY)
open(R-W) -> error (seems strange to me)

open(R-W)
open(RDONLY)
write(R-W) -> internal error, assertion failure. (seems like a bug, should've been an error)
Assertion failed: f->intent & ( 0x0001u), file H5Fio.c, line 154

I'm sure I can work around the issue, but I was hoping for an explanation of the last two conditions.

Hi John,

···

On Jul 30, 2010, at 9:35 AM, John Knutson wrote:

I have an HDF5 file containing some metadata. That file is, 99% of the time, only needed to be opened read-only. As such, I have a C++ class that wraps around the access for the metadata and opens the file read-only.

That 1% case, I have a program whose purpose is to update the metadata, and it needs to open the file read-write. The program that does the editing was using the read-only class for convenience, but it seems that things don't work like I was expecting.

If I have the class open the file read-only first, when I try and open it read-write, I get an error saying the file was already open for read-only. This isn't overly surprising, until I started closing the read-only handle before trying to open for read-write. At that point, I still got an error.

To make things clearer as to what I'm describing, here are some timelines:

open(RDONLY)
open(R-W) -> error

open(RDONLY)
close(RDONLY)
open(R-W) -> error (seems strange to me)

open(R-W)
open(RDONLY)
write(R-W) -> internal error, assertion failure. (seems like a bug, should've been an error)
Assertion failed: f->intent & ( 0x0001u), file H5Fio.c, line 154

I'm sure I can work around the issue, but I was hoping for an explanation of the last two conditions.

  I'm guessing that the read-only opens are leaking open objects, because the second scenario ought to work (and if you can give details about the third scenario, we can try to get it fixed). You might want to experiment with the H5Fget_obj_count/H5Fget_obj_ids and/or H5Pset_fclose_degree in order to gather more information about your application's use of objects in files.

  Quincey