Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain all pending index entries. #319

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Change Log

*Fixed:*

* Write all pending index entries to the file when `gsd_flush()` is called after `gsd_write_chunk()`
and before `gsd_end_frame()` (`#319 <https://github.com/glotzerlab/gsd/pull/319>`__).
* Readthedocs builds with pandas 2.2.0
(`#322 <https://github.com/glotzerlab/gsd/pull/322>`__).

Expand Down
2 changes: 1 addition & 1 deletion gsd/gsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ int gsd_flush(struct gsd_handle* handle)
{
handle->frame_index.data[i]
= handle->frame_index
.data[handle->frame_index.size - handle->pending_index_entries];
.data[handle->frame_index.size - handle->pending_index_entries + i];
}
}

Expand Down
26 changes: 26 additions & 0 deletions gsd/test/test_fl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,29 @@ def test_file_exists_error():
schema_version=[1, 2],
):
pass


def test_pending_index_entries(tmp_path):
"""Ensure that gsd preserves pending index entries."""
with gsd.fl.open(
tmp_path / 'test_pending_index_entries.gsd',
'w',
application='My application',
schema='My Schema',
schema_version=[1, 0],
) as f:
# Frame 0 must be complete to trigger the bug.
f.write_chunk(name='0', data=numpy.array([0]))
f.end_frame()

for i in range(16):
f.write_chunk(name=str(i), data=numpy.array([i]))

# Flush with pending chunks in the frame index.
f.flush()

f.end_frame()

# All test chunks should be present in the file.
for i in range(16):
assert f.chunk_exists(name=str(i), frame=1)
Loading