Skip to content

Don't use HDF5's default locking behavior when opening files read only#38

Merged
mgeplf merged 1 commit intomasterfrom
remove-file-locks
Apr 10, 2026
Merged

Don't use HDF5's default locking behavior when opening files read only#38
mgeplf merged 1 commit intomasterfrom
remove-file-locks

Conversation

@mgeplf
Copy link
Copy Markdown
Collaborator

@mgeplf mgeplf commented Apr 1, 2026

  • HDF5 uses file locks to implement a Single Writer, Multiple Reader model
  • We expect the SONATA HDF5 files to always be finished reading, so we
    don't benefit from this, and on some files systems, there are a finite
    amount of locks (plus it's a pessimizing default)
  • we don't want to rely on HDF5_USE_FILE_LOCKING to be set
  • see more info: https://support.hdfgroup.org/documentation/hdf5/latest/_file_lock.html
  • Note: this requires that any other files opened with the HDF5 library
    be opened with the same flags. Thus, if h5py is used to open the file
    concurrently with libsonata, there may be failures if the locking
    flags aren't set the same we are using use_file_locking=True and
    ignore_when_disabled=True

@mgeplf mgeplf force-pushed the remove-file-locks branch 3 times, most recently from f6d235c to 461ad4c Compare April 1, 2026 13:15
@mgeplf mgeplf changed the title HDF5 uses file locks to implement a Single Writer, multiple reader model Don't use HDF5's default locking behavior when opening files read only Apr 1, 2026
* HDF5 uses file locks to implement a `Single Writer, Multiple Reader` model
* We expect the SONATA HDF5 files to always be finished reading, so we
  don't benefit from this, and on some files systems, there are a finite
  amount of locks (plus it's a pessimizing default)
* we don't want to rely on `HDF5_USE_FILE_LOCKING` to be set
* see more info: https://support.hdfgroup.org/documentation/hdf5/latest/_file_lock.html
* Note: this requires that any other files opened with the HDF5 library
  be opened with the same flags.  Thus, if `h5py` is used to open the file
  concurrently with `libsonata`, there may be failures if the locking
  flags aren't set the same we are using `use_file_locking=True` and
  `ignore_when_disabled=True`
@mgeplf mgeplf force-pushed the remove-file-locks branch from 461ad4c to 8b25884 Compare April 2, 2026 09:01
Copy link
Copy Markdown
Collaborator

@WeinaJi WeinaJi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not famliar with HighFive. This change looks correct according to the HDF5 doc.
I don't know if it is easy to test this change, but since the CI tests pass, I am ok with merging it.

@jplanasc
Copy link
Copy Markdown
Contributor

jplanasc commented Apr 8, 2026

I wonder if this should not be implemented in the HighFive library?

If I understand correctly, the purpose of using HighFive is to make H5 file access easier, but here we're introducing a direct interaction with the HDF5 library?

Comment thread src/hdf5_reader.cpp
, _ignore_when_disabled(ignore_when_disabled) { }

void apply(const hid_t list) const {
herr_t err = H5Pset_file_locking(list, _use_file_locking, _ignore_when_disabled);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the documentation, it seems that this is supported from version 1.10.1, but if compiled with an older version this will crash? Shouldn't it be protected, or the HDF5 dependency set to a minimum version?

@jplanasc
Copy link
Copy Markdown
Contributor

jplanasc commented Apr 8, 2026

Also, another thought: could the file locking be disabled at compile time (when we install HDF5) to avoid misbehavior if using h5py?

I understand this is meant to be used in a very specific, controlled environment, so would that be enough?

@mgeplf
Copy link
Copy Markdown
Collaborator Author

mgeplf commented Apr 8, 2026

but if compiled with an older version this will crash

It wouldn't compile, but I also don't think it's worth dealing with something that was first released in 2009.

I wonder if this should not be implemented in the HighFive library?

I have a PR open already: highfive-devs/highfive#114
But it'll take a while for it to get in an released.

could the file locking be disabled at compile time (when we install HDF5) to avoid misbehavior if using h5py?

One can open the file in h5py with locking disabled, so I'm not sure if it's good to disable it at compile time.
I don't think we'll know until people complain.

Copy link
Copy Markdown
Contributor

@jplanasc jplanasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mgeplf mgeplf merged commit 17dbfdf into master Apr 10, 2026
23 checks passed
@mgeplf mgeplf deleted the remove-file-locks branch April 10, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants