Research notes / Scientific data storage
HDF5 SWMR: a readable file is not a complete measurement
Published / Updated / Measured API behavior
A live HDF5 reader can see a structurally valid file while two arrays belonging to one measurement have different lengths. Our controlled experiment demonstrates that boundary, then shows why a publication watermark is useful but is not a snapshot or a durable transaction. A separate closed-file experiment shows how ambiguous coordinate selection changes a derived rate tenfold even when every numeric read succeeds. Cross-file copy controls then show that preserving those numbers need not preserve their coordinate relationships.
On this page14 sections
For a separate archival boundary, see HDF5 virtual datasets: missing sources and search-path substitutions. A closed, intact file can still depend on data stored elsewhere.
What SWMR keeps coherent
HDF5 organizes typed arrays, attributes and groups; the application decides how they represent a scientific record. A dataset is not automatically a transaction. [6]
Single-writer/multiple-reader access orders metadata flushes so that a reader does not follow a pointer to a child structure that has not been flushed. It depends on the underlying system satisfying the required POSIX write semantics. This protects HDF5's internal structure, not an arbitrary relationship such as “every timestamp has a calibrated value.” [2]
The h5py workflow creates objects before switching the writer into SWMR mode. Readers open with swmr=True; the writer flushes datasets and readers refresh them. Notifications are an application responsibility. Neither a notification nor one successful refresh describes every dataset in the file. [1]
A metadata retry is not a drive-health event
On a non-atomic I/O path, a concurrent reader may encounter inconsistent checksummed metadata. HDF5 can retry that read within a configured attempt limit. H5Fget_metadata_read_retry_info reports those retries; H5Pset_metadata_read_attempts controls the limit. These are library metadata observations, not NAND read-retry counters or proof of a failing drive. Increasing the budget cannot validate a scientific record. Our experiment does not measure these counters. [7]
Plan the object schema before enabling SWMR
The documented SWMR scope permits updates to existing dataset payloads, but not adding or deleting objects. It also excludes modification or append operations on variable-length, string and region-reference datatypes. An acquisition design that creates a new group for every measurement therefore needs a different layout or access workflow; switching on SWMR alone does not make that design valid. These are documented restrictions, not extra cases tested by our fixed-integer experiment. [2]
Keep a file-format compatibility policy separate from the publication protocol. The h5py guide warns that the newer SWMR format cannot be opened by older, pre-SWMR libraries. Record the actual reader and writer library versions; the latest label is relative to the installed library, not a permanent format version. [1]
Two arrays, nine observable checkpoints
We used synthetic pairs (10, 100) and (20, 200), stored separately in x and y. A third dataset, published, holds a count chosen by the application. These integers are test inputs, not measurements from a sensor.
A pipe pauses the live writer at each checkpoint while a separate spawned reader refreshes and reads. The reader opens once and stays open. All 3 repetitions produced the same nine outcomes. The pauses make intermediate states reproducible; they do not measure how often a production reader would encounter them.
| Checkpoint | x / y lengths | Watermark | Pairs selected |
|---|---|---|---|
| Initial | 0 / 0 | 0 | [] |
| First x flushed | 1 / 0 | 0 | [] |
| First y flushed | 1 / 1 | 0 | [] |
| Publish one pair | 1 / 1 | 1 | [[10,100]] |
| Second x flushed | 2 / 1 | 1 | [[10,100]] |
| Second y flushed | 2 / 2 | 1 | [[10,100]] |
| Publish two pairs | 2 / 2 | 2 | [[10,100],[20,200]] |
| Invalid watermark | 2 / 2 | 3 | Rejected |
| Published x overwritten | 2 / 2 | 2 | [[999,100],[20,200]] |
After the second x flush, the reader sees lengths 2 / 1 while both reads succeed. After the second y flush, lengths are 2 / 2, but the application has still published only one pair. Equal lengths therefore do not establish the chosen publication boundary either.
This is expected intermediate visibility, not evidence of an HDF5 defect. The engineering risk is treating a readable structure as a complete application record.
A publication watermark needs an immutability rule
Our demonstration appends and flushes both payload arrays before advancing the count. The reader refreshes the count first, captures n, refreshes both arrays, checks that each has at least n rows, and consumes only those rows. It rejects the deliberately invalid count of three when only two pairs exist.
The hidden requirement is that published rows remain unchanged. In the final checkpoint, we intentionally overwrite the first published x with 999, leaving its partner at 100. The count and length checks still pass. A watermark limits the selected prefix; it does not preserve an older version or detect a semantically mismatched pair.
This is a bounded application example, not a proven general-purpose commit protocol. It assumes one writer, monotonic publication during normal operation, immutable published rows, successful payload flushes before publication, and compatible file/driver semantics. A reader must handle temporarily unavailable payload and validate its record schema. Our writer is paused during every observation, so unpaused races and torn marker updates are outside the experiment.
For instrument acquisition, define which arrays, units and calibration version form one record before deciding what “available” means. For mutable records, a count alone cannot supply a consistent historical view. Compare database snapshots and application-consistent backups.
A scientific schema supplies relationships, not a commit
The H5MD paper provides a concrete example: its time-dependent elements associate step, time and value datasets, with matching leading dimensions. It also permits shared time coordinates through hard links. These conventions describe what related samples mean. [8]
Our inference is that a live acquisition application needs both such a schema and an explicit publication rule. A hard link shares an object; it does not atomically advance that object together with every value array. We did not test an H5MD implementation, and the paper is not evidence for SWMR transaction guarantees.
Equal coordinates are not always shared coordinates
In the H5MD paper's position and image example, the schema requires hard links between their corresponding step and time datasets. The time-dependent simulation box must likewise share those datasets with the position group. Equal coordinate values in separately copied objects do not express that required shared identity. This is a source-derived schema requirement, not a tested H5MD migration or a claim that H5MD uses H5DS attributes. [8, sections 3.7 and 3.8]
Our practical inference: migration acceptance needs the application's object-sharing rules as well as value comparisons. The H5DS controls below test a different relationship representation; they illustrate why checking only numbers can miss a broken association, not whether an H5MD reader would accept it.
Which time axis did the reader select?
In a separate closed-file experiment, reversing two scale attachments changed an endpoint rate from 10 to 1 count/s. Every numeric dataset remained readable with Fletcher32 enabled, and the value-array bytes were identical. The reader selected a different coordinate array; storage damage was not involved.
The synthetic values are [0, 10, 20, 30] counts. The file contains /time with [0, 1, 2, 3] seconds and, in the duplicate-name cases, /other_time with [0, 10, 20, 30] seconds. Both attached scales are named time. A new reader selects with value.dims[0]["time"] and computes the difference between the last and first values divided by the coordinate span.
| Configuration | Selected object | Selected coordinates (s) | Rate (count/s) |
|---|---|---|---|
| Attach /time, then /other_time | /time | [0,1,2,3] | 10 |
| Attach /other_time, then /time | /other_time | [0,10,20,30] | 1 |
| One scale, slower coordinates | /time | [0,10,20,30] | 1 |
| One scale, reversed interior samples | /time | [0,2,1,3] | 10 |
h5py documents first-match name lookup and permits nonunique names; both tested source versions implement that search. However, HDF5 specifies the attachment list as an unordered set. Do not use attachment order as a portable selection rule. The order effect above is a two-build observation, not a format guarantee. Multiple scales are legitimate; our consumer's requirement for one time axis is an application policy. [10] [11] [12] [13]
Equal lengths and a plausible rate are insufficient
The single-scale, slower-time control has matching extents, seconds, increasing coordinates and the expected object identity. Its rate is still 1 count/s. Only an independently known sampling expectation distinguishes this from a legitimate slower series. Conversely, the nonmonotonic control returns the apparently expected 10 count/s while reversing two interior samples. One derived statistic cannot validate the complete sequence.
Other controls attach a short or long scale, extend only the values, or extend only the coordinates. Complete numeric reads succeed despite the extent mismatch. A label-only case reads successfully but has no scale attached; its name lookup raises RuntimeError in both builds. These associations and their consistency require application rules, not merely successful HDF5 reads. [11] [14]
The acceptance rule belongs to the application
Our demonstration requires exactly one attached scale, the same HDF5 object as the canonical /time dataset, matching extents, seconds, increasing coordinates and equality to the separately defined expected coordinates. A hard-link alias of that object passes. A correct /time stored elsewhere does not pass when the values are attached to another object. This is not a universal HDF5 validator: other schemas may intentionally permit several scales or unequal extents.
H5MD supplies a useful comparison through its explicit step/time/value relationships and shared-coordinate rules, not a test target. Our practical inference is to preserve the coordinate-selection rule, units, sampling expectations and schema version with the archive, then check them after reopening. An unknown acquisition schedule remains unknown; readability cannot reconstruct it. For live acquisition, coordinate validation complements the publication rule above but adds no transaction guarantee. [8]
Evidence and reproduction
We ran 14 configurations with h5py 3.10.0 / HDF5 1.14.2 / NumPy 1.26.4 and again with h5py 3.15.0 / HDF5 1.14.6 / NumPy 2.3.3, both on Python 3.12.3. Each writer closes before a fresh reader process opens read-only. All 14 semantic rows agree across builds and fresh reruns: 13 readable cases, two accepted by our policy, 11 readable rejections per build. These are 28 configuration/build observations, not independent reliability trials.
The fourteenth case flips one checksum byte in an allocated value chunk and raises OSError on read. All readable cases used active Fletcher32 filtering on the recorded chunks. We did not demonstrate a checksum collision: the normally written coordinates differ in meaning, not in their recoverability. No live acquisition, H5MD/Xarray/netCDF consumer, power loss, performance or production error frequency was tested. [15]
Download the reproduction bundle, 1.14.2 observations and 1.14.6 observations. The method and commands distinguish exact-environment replay from a new-runtime observation. The bundle retains code, tests, requirements, source receipts and the complete result table. See also the dimension-scale definition.
Copying the arrays is not copying the axes
A successful cross-file copy can preserve the numbers and lose their coordinate relationship. Copying a group retained all three arrays, the axis label and a scale count of one, but reading the attached coordinates failed. In a deliberately arranged destination layout, separate dataset copies made indexed axis access return the data array itself. A test-only write through that apparent axis changed the data, not the time coordinates.
Nine constructed configurations, twice on each of HDF5 1.14.2 and 1.14.6, give 36 retained case runs. Inputs are two dimensionless arrays [10,20,30] and [40,50,60], sharing [0,1,2] seconds. Writers close before fresh reader processes inspect the copies. There is no live SWMR writer in this experiment.
| Copy or control | Indexed axis | Named iteration | Bundle policy | Changed by axis write |
|---|---|---|---|---|
whole-file | scale | Succeeded | Accepted | /bundle/time |
group-default | error | Failed | Rejected | None: write failed |
group-expand | error | Failed | Rejected | None: write failed |
separate-default | non-scale | Failed | Rejected | /bundle/a |
separate-expand | non-scale | Failed | Rejected | /bundle/a |
data-only-expand | non-scale | Failed | Rejected | /bundle/a |
rebuild | scale | Succeeded | Accepted | /bundle/time |
wrong-coordinate-control | scale | Succeeded | Rejected | /bundle/time |
forward-only-control | scale | Succeeded | Rejected | /bundle/time |
The hidden boundary is the reference datatype. H5DS stores forward references inside variable-length arrays and reverse references inside compound records. HDF5 1.14.6's attribute-copy path repairs top-level references but excludes nested references in that branch. Thus expand_refs=True did not repair these H5DS associations, although a separate ordinary-reference-attribute control confirmed that the flag worked. [Storage profile] [Pinned copy implementation]
h5py 3.15.0's integer-indexed accessor wraps the returned dataset; named iteration additionally requests scale names. In the invalid-reference fixture, indexed access returned a non-scale while named iteration failed. The wrong target depends on the constructed allocation order. This is not evidence about every file layout or the latest library release. [Accessor implementation]
Preserve relationships as well as values. A byte copy of the closed source and explicit destination H5DS reconstruction passed this fixture. Removing reverse links left readable coordinates but made H5DSis_attached false; attaching wrong coordinates passed the relationship check but failed our independent value expectation. Check intended objects, shared identity, units, values and both reference directions after reopening. Do not blindly copy reserved reference-bearing attributes. [Attachment implementation]
The migration evidence and commands include a reproduction package. These native-VOL, legacy-reference controls are separate from earlier SWMR and coordinate-selection results: no opaque references, other VOL connectors, netCDF/xarray consumer, active acquisition, power loss or production error frequency was tested. The reconstruction is not a general migration tool.
An unlocked file is not permission for a second writer
HDF5's documented scheme separates OS-level file locking from persistent superblock flags. Entering SWMR writing removes the file lock while leaving the relevant writing flags. The absence of a held lock does not turn SWMR into independent multi-writer access. Disabling locking does not provide a replacement coordination protocol. Parallel HDF5 is a separate, coordinated multi-process model. [4]
After an unclean exit, a leftover superblock mark may prevent an ordinary open. The official h5clear documentation explicitly limits its role: clearing such a mark is not general corruption repair. An operator should preserve evidence and establish that no writer is active before considering recovery actions. We did not run that tool; the separate process-exit experiment below leaves the file unchanged. [5]
Flush visibility does not prove power-loss recovery
H5Dflush flushes dataset buffers without evicting their contents. H5Drefresh refreshes the dataset's buffers. The API documentation notes that HDF5 does not control every buffering layer. These operations do not, by themselves, establish an all-or-nothing application transaction across multiple datasets. [3]
Both experiments can read from operating-system cache. We did not trace persistence syscalls, interrupt power, or examine recovery after a kernel crash or reboot. Nothing here establishes that a scalar watermark update is failure-atomic. A durability claim requires its own driver, filesystem and device evidence, as in the crash-test oracle discussion.
After the writer exits, its status flags can remain
A second, separate experiment compares normal close with os._exit(73), which ends the writer without HDF5 close or Python cleanup. Each case creates a new private file, flushes both payload arrays and optionally publishes one pair. The parent waits for the writer to exit before attempting fresh ordinary and SWMR read-only opens. This tests a selected process-exit boundary, not an interruption in the middle of an I/O request.
| Writer boundary | Flags | Ordinary read | SWMR read | Selected pairs |
|---|---|---|---|---|
| Normal close after publication | 0x00 | Opened | Opened | [[10,100]] |
| Exit before publication | 0x05 | Rejected | Opened | [] |
| Exit after publication | 0x05 | Rejected | Opened | [[10,100]] |
| Exit without SWMR | 0x01 | Rejected | Rejected | Not read |
The two unclean SWMR exits retained 0x05: write-access bit 0 and SWMR-write bit 2. The non-SWMR control retained only 0x01 and rejected both opens. Normal close left 0x00 and both opens succeeded in this environment. The format specification defines these bits as cleared at final close. They are file metadata, not a liveness probe or a measurement of corruption. [9]
In the unpublished SWMR case, both payloads were readable but the selected prefix remained empty. In the published case it contained [[10,100]]. A readable payload therefore still does not establish that the application published it. Conversely, an ordinary-open error did not prove that the writer was still alive: this harness had already joined the process.
Boundary: all exits occurred after explicit HDF5 flush calls. No power loss, kernel failure, reboot, torn write, concurrent writer or repair operation was tested; OS and device caches remained available. These 12 case runs are controlled demonstrations, not a failure-rate sample. Do not interpret their successful reads as a power-loss guarantee or use them to justify clearing flags on a production file.
The separate raw observations include full payloads, errors, environment and source/requirements hashes. Run the process-exit harness with the same pinned requirements as the first experiment:
.venv/bin/python hdf5-process-exit.py --repetitions 3 > process-exit.jsonReproduce the observation
For a separate performance boundary, see the chunk-cache experiment: byte capacity, hash slots and selection order can change library rereads without changing which values are returned.
The dataset page provides CSV, raw JSON, environment and source hash. Download the Python harness and pinned requirements into one directory, then run:
python3 -m venv .venv
.venv/bin/pip install --only-binary=:all: -r hdf5-swmr-requirements.txt
.venv/bin/python hdf5-swmr.py --repetitions 3 > observations.jsonThe runner uses private temporary files only, bounded process waits and explicit runtime checks that remain active with Python optimization enabled. Linux, Python and GNU stat are required. Use --temp-dir to select a disposable test directory on the filesystem under examination.
Published environment: h5py 3.15.0, HDF5 1.14.6, NumPy 2.3.3, Python 3.12.3, Linux 6.8.0-146-generic, driver sec2. GNU stat reported ext2/ext3, a filesystem-magic label that does not distinguish ext-family versions. All datasets use one-element chunks without compression. libver="latest" is relative to the installed library; it is not a fixed interoperability target.
This is one host and 27 ordered checkpoints, not 27 independent reliability trials. No confidence interval, latency estimate, hardware-failure claim or general filesystem comparison is warranted.
Primary sources
- h5py 3.15: Single Writer Multiple Reader
- The HDF Group: SWMR metadata flush dependencies
- The HDF Group: H5Dflush and H5Drefresh
- The HDF Group: File locking and superblock flags
- The HDF Group: h5clear is not a general repair tool
- The HDF Group: HDF5 Data Model and File Structure
- The HDF Group: H5Fget_metadata_read_retry_info and metadata read attempts
- de Buyl, Colberg and Hoefling: H5MD (2014), sections 2, 3.4.1, 3.7 and 3.8; DOI 10.1016/j.cpc.2014.01.018
- The HDF Group: File format, version-3 superblock consistency flags
- h5py: Dimension Scales, name lookup and nonunique names
- The HDF Group: Dimension Scales, storage profile and application consistency
- h5py 3.15.0: dimension-scale lookup implementation
- h5py 3.10.0: dimension-scale lookup implementation
- The HDF Group: H5DS attachment and scale-query APIs
- h5py 3.12: Fletcher32 chunk checksum
- HDF5 1.14.6: attribute-copy nested-reference boundary
- HDF5 1.14.6: H5DS reference mode and bidirectional attachment
Original sources checked 17 October 2026; dimension-scale sources and H5MD comparison checked 22 October 2026. Migration implementation sources rechecked 28 October 2026. Documentation and measured library versions are recorded separately.