Prepare the VFD SWMR reader for a "floating" shadow index by overhauling
the way that the shadow header and shadow index are loaded.
In H5FD__vfd_swmr_load_hdr_and_idx(), adopt a new protocol for reading
the shadow file:
0 If the maximum number of retries have been attempted, then exit
with an error.
1 Try to read the shadow file *header*. If successful, continue to 2.
If there is a hard failure, then return an error. If there is a failure
that may be transient, then sleep and ret...
Prepare a bit to let the shadow index "float": drastically
simplify H5FD__vfd_swmr_index_deserialize(): reuse
h5_retry_init()/h5_retry_next() for retry loops.
Don't wait for the fstat(2) to read the correct size, because the
read(2) will return short if the file isn't long enough. (This change
should save at least one system call, always.)
Leave a bunch of comments about the changes that I will have to make so
that the shadow index will float.
NFCI: do not cast H5MM_malloc() return values...
Now that we're buffering the removed pages to process at once,
it's not necessary to iterate over pass numbers any more,
so just use two loops.
While I'm in here, change a comment or formatting here and there.
H5F_vfd_swmr_reader_end_of_tick(),
compares both new and old shadow indices and calls H5PB_remove_entry()
on each entry that was in the old index but is not in the new.
Ever since H5PB_remove_entry() started removing shadow index
entries, it has been possible for H5F_vfd_swmr_reader_end_of_tick()
to walk past the end of the new shadow index or even to skip entries
in the new index. Sometimes an assertion failed when that happened.
I have restructured the code in H5F_vfd_swmr_reader_end_of_...
Simplify nested logic in H5FD_vfd_swmr_get_tick_and_idx().
assert() our expectation that either a NULL index was passed, or a
pointer to the index length was passed in, too.
Correct some irregular indentation, delete an unused line, split an
`if ((p = allocate(...)) == NULL) { }` into two statements, `p =
allocate(...); if (p == NULL) { }`, put a semicolon at the end of an
HGOTO_ERROR(), remove comments /* end if */, /* end for */ after closing
curly braces.
Make H5FD__vfd_swmr_load_hdr_and_idx() simpler and faster: copy a
pointer to the metadata index instead of copying the index itself. Use
struct assignment instead of copying individual struct members. Lower a
staircase.
After quick-sorting the index, go ahead and assert that there are not
duplicate entries for the same HDF5 page offset. There's an O(n) cost
to that, but it should be no more than the O(n log n) cost of the
quicksort.
In H5PB_remove_entry(), do not call vfd_swmr_mdf_idx_entry_remove(),
because the H5PB__evict_entry() call should have already done that.
Instead, just assert() that the index entry is not present.
In vfd_swmr_mdf_idx_entry_remove(), give some local variables less wordy
names. While I am here, do not copy the last element of the index over
the element that's being deleted, because in the very next step I'm
shifting all elements over by one.
Change the blah_blah_blah_md_header `index_length` member from
`uint64_t` to `size_t` because it describes the size of an in-core
structure as well as an on-disk one, and `size_t` is wide enough
to store the size of any in-core structure, while `uint64_t` may
be much too wide. Check that `index_length` is no more than SIZE_MAX
after we read it.
Use the "tail queue" from queue(3) for the delayed free list of shadow images.
Delete the little-used free-list length, dl_len, and just count up the list
entries when diagnostic code needs the length.
Extract the code for deferring shadow-image free into a new subroutine,
`vfd_swmr_idx_entry_defer_free()`.
Rename type `deferred_free_head_t` as `deferred_free_queue_t`.
Remove the disused H5F__LL_{REMOVE,PREPEND} macros.
Add some diagnostic code and #if 0'd assertions.
Change `qsort(ptr, ...
Allocate regionsin the shadow file of page size or greater size with page
alignment. The VFD SWMR code had always assumed that the regions were aligned
to page size. It would blithely round the start addresses of regions to the
next lower page. When the region was freed, the freespace manager (H5MV) would
suffer an assertion or corruption.
Align the shadow images on page boundaries so that they don't overlap. This
seems to be the programmer's original intention. It sure makes debugging
easier to have non-overlapping shadow images.
In the faked-up shadow-index entries, assign independent page numbers in the
HDF5 file and in the shadow file. I had added assertions that the page numbers
were unique, and this caused those assertions to fail. I don't know if I'll
keep the assertions, but this is an inexpensive change that makes the test more
realistic.
Follow the naming convention enforced by FUNC_ENTER_/FUNC_EXIT_* macros (?)
where static routines have to have double underscores (__) in their name or
else the library asserts false.
Remove disused duplicate of H5F__idx_entry_cmp(). I probably introduced that
by accident when I merged Vailin's changes that moved some functions from one
file to another.
Shorten the type name `H5F_vfd_swmr_eot_queue_entry_t` to `eot_queue_entry_t`:
people have to read and type this stuff!
Use TAILQ_* macros instead of an unnecessary custom implementation of
doubly-linked lists.