Skip to content

Commit 28bde92

Browse files
daviesrobjkbonfield
authored andcommitted
Don't drop in-flight decode jobs when seeking in cram_next_slice()
cram_next_slice() with a region set tries to skip over containers with contents that don't overlap the region of interest. For files with a mixture of read lengths, it's possible that some decode jobs have been queued before a later container is skipped. This makes calling cram_seek() hazardous as it drops any in-flight jobs before updating the file position. Instead, call hseek() directly so already-queued decode jobs are retained.
1 parent a11d869 commit 28bde92

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ realn.o realn.pico: realn.c config.h $(htslib_hts_h) $(htslib_sam_h)
525525
textutils.o textutils.pico: textutils.c config.h $(htslib_hfile_h) $(htslib_kstring_h) $(htslib_sam_h) $(hts_internal_h)
526526

527527
cram/cram_codecs.o cram/cram_codecs.pico: cram/cram_codecs.c config.h $(fuzz_settings_h) $(htslib_hts_endian_h) $(htscodecs_varint_h) $(htscodecs_pack_h) $(htscodecs_rle_h) $(cram_h)
528-
cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h)
528+
cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h) $(htslib_hfile_h)
529529
cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c config.h $(cram_h) $(cram_os_h) $(sam_internal_h) $(htslib_hts_h) $(htslib_hts_endian_h) $(textutils_internal_h)
530530
cram/cram_external.o cram/cram_external.pico: cram/cram_external.c config.h $(htscodecs_rANS_static4x16_h) $(htslib_hfile_h) $(cram_h)
531531
cram/cram_index.o cram/cram_index.pico: cram/cram_index.c config.h $(htslib_bgzf_h) $(htslib_hfile_h) $(hts_internal_h) $(cram_h) $(cram_os_h)

cram/cram_decode.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5151
#include "cram.h"
5252
#include "os.h"
5353
#include "../htslib/hts.h"
54+
#include "../htslib/hfile.h"
5455

5556
//Whether CIGAR has just M or uses = and X to indicate match and mismatch
5657
//#define USE_X
@@ -3287,14 +3288,18 @@ cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) {
32873288
break;
32883289
}
32893290

3290-
// before start of range; skip to next container
3291+
// Before start of range; skip to next container.
3292+
// Can't use cram_seek() here as it drops in-progress
3293+
// multi-threaded decode jobs, so call hseek() directly.
32913294
if (fd->range.refid != -1 &&
32923295
c_next->ref_seq_start + c_next->ref_seq_span-1 <
32933296
fd->range.start) {
3294-
c_next->curr_slice_mt = c_next->max_slice;
3295-
cram_seek(fd, c_next->length, SEEK_CUR);
3297+
off_t skip_length = c_next->length;
32963298
cram_free_container(c_next);
32973299
c_next = NULL;
3300+
fd->ooc = 0;
3301+
if (hseek(fd->fp, skip_length, SEEK_CUR) < 0)
3302+
return NULL;
32983303
continue;
32993304
}
33003305
}

0 commit comments

Comments
 (0)