bcf_idx_init() calls bgzf_tell() to get the starting index offset. This was OK when single-threaded but broke with multiple threads because bgzf_tell() lies about the file offset unless bgzf_flush() was called first. SAM.gz, BAM and VCF.gz all did this, but BCF didn't leading to an incorrect first index entry when combining multi-threads with indexing on the fly. Fix by adding the missing bgzf_flush() after writing the header.
As a side benefit, the BCF variant records will now start in a fresh BGZF block, instead of being mixed in with part of the BCF header.
test/index.bcf.csi has to be replaced due to the extra flush adding one more block to the (uncompressed) index.bcf file that gets generated by the test harness.
bcf_idx_init()
callsbgzf_tell()
to get the starting index offset. This was OK when single-threaded but broke with multiple threads becausebgzf_tell()
lies about the file offset unlessbgzf_flush()
was called first.SAM.gz
,BAM
andVCF.gz
all did this, butBCF
didn't leading to an incorrect first index entry when combining multi-threads with indexing on the fly. Fix by adding the missingbgzf_flush()
after writing the header.As a side benefit, the BCF variant records will now start in a fresh BGZF block, instead of being mixed in with part of the BCF header.
test/index.bcf.csi has to be replaced due to the extra flush adding one more block to the (uncompressed) index.bcf file that gets generated by the test harness.
Fixes #1740