From 84661e854a4465825f2374dce363f7ce566819ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=E2=80=99Mara?= Date: Fri, 21 Apr 2023 01:18:46 +1000 Subject: [PATCH 1/4] Increment version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b887ee7..3b04983 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BGZFStreams" uuid = "28d598bf-9b8f-59f1-b38c-5a06b4a0f5e6" authors = ["Sabrina Jaye Ward ", "Kenta Sato ", "Daniel C. Jones ", "Tony Kelman ", "Elliot Saba ", "Christian Theil Have"] -version = "0.3.1" +version = "0.3.2" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" From 0d628fdc17dc0edbeeada3819d344419874e863d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sat, 20 Nov 2021 10:10:42 +1100 Subject: [PATCH 2/4] Add threads to test environment It appears that the number of threads allowed in CI is capped at 2. --- .github/workflows/UnitTests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/UnitTests.yml b/.github/workflows/UnitTests.yml index 2e5befe..f73eeb4 100644 --- a/.github/workflows/UnitTests.yml +++ b/.github/workflows/UnitTests.yml @@ -40,6 +40,8 @@ jobs: uses: julia-actions/julia-buildpkg@v1 - name: Run Tests uses: julia-actions/julia-runtest@v1 + env: + JULIA_NUM_THREADS: "2" - name: Create CodeCov uses: julia-actions/julia-processcoverage@v1 - name: Upload CodeCov From 5e7a38a4c4a7fa41911d35ba971fcf00422cb284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Mon, 15 Nov 2021 09:28:31 +1100 Subject: [PATCH 3/4] Add informational message Displays the number of threads in used when testing. --- test/runtests.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index afc1de6..1cc9bd6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,8 @@ using BGZFStreams using Test +@info "Environment" Threads.nthreads() + @testset "VirtualOffset" begin voff = VirtualOffset(0, 0) @test voff == VirtualOffset(0, 0) From 6bc27f91468e55a400fb69901800fa6ed12fe82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=E2=80=99Mara?= Date: Fri, 21 Apr 2023 00:54:26 +1000 Subject: [PATCH 4/4] Correct `ensure_buffered_data` The `read_blocks!` function does not necessarily fill/overwrite blocks till `lastindex(stream.blocks)`, we need to ensure `stream.block_index` does not increment past the index of the last loaded block. --- src/bgzfstream.jl | 19 +++++++++++++++---- test/runtests.jl | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/bgzfstream.jl b/src/bgzfstream.jl index a2421ee..07ae41b 100644 --- a/src/bgzfstream.jl +++ b/src/bgzfstream.jl @@ -84,6 +84,9 @@ mutable struct BGZFStream{T<:IO} <: IO # current block index block_index::Int + # index of the last block loaded + last_block_index::Int + # whether stream is open isopen::Bool @@ -91,6 +94,10 @@ mutable struct BGZFStream{T<:IO} <: IO onclose::Function end +function BGZFStream(io, mode, blocks, block_index, isopen, onclose) # This method maintains compatibility after the inclusion of the `last_block_index` field to `BGZFStream`. + return BGZFStream(io, mode, blocks, block_index, 0, isopen, onclose) +end + # BGZF blocks are no larger than 64 KiB before and after compression. const BGZF_MAX_BLOCK_SIZE = UInt(64 * 1024) @@ -315,16 +322,19 @@ end @inline function ensure_buffered_data(stream) #@assert stream.mode == READ_MODE @label doit - while stream.block_index ≤ lastindex(stream.blocks) + while stream.block_index < stream.last_block_index @inbounds block = stream.blocks[stream.block_index] - if is_eof_block(block.compressed_block) # Note: `read_blocks!` does not necessarily fill/overwrite blocks till `lastindex(stream.blocks)`, we need to stop incrementing `stream.block_index` when an eof block is encountered. - break - end if block.position ≤ block.size return stream.block_index end stream.block_index += 1 end + if stream.block_index == stream.last_block_index + @inbounds block = stream.blocks[stream.block_index] + if block.position ≤ block.size + return stream.block_index + end + end if !eof(stream.io) read_blocks!(stream) @goto doit @@ -364,6 +374,7 @@ function read_blocks!(stream) end while n_blocks < length(stream.blocks) && !eof(stream.io) block = stream.blocks[n_blocks += 1] + stream.last_block_index = n_blocks if has_position block.block_offset = position(stream.io) end diff --git a/test/runtests.jl b/test/runtests.jl index 1cc9bd6..231db6c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -173,8 +173,8 @@ end @test stream.blocks |> length == 1 # Note: only one block when writing, @test stream.blocks[1].size == BGZFStreams.BGZF_SAFE_BLOCK_SIZE - # Generate n blocks of data. - data = rand(0x00:0xf0, (n*BGZFStreams.BGZF_SAFE_BLOCK_SIZE) ) + # Generate n+1 blocks of data. + data = rand(0x00:0xf0, ((n+1)*BGZFStreams.BGZF_SAFE_BLOCK_SIZE) ) write_offsets = BGZFStreams.VirtualOffset[]