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

[query] Fix data race in FASTA reader #9427

Merged
merged 1 commit into from Sep 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions hail/src/main/scala/is/hail/io/reference/FASTAReader.scala
Expand Up @@ -73,7 +73,7 @@ class FASTAReader(val tmpdir: String, val fsBc: BroadcastValue[FS], val rg: Refe
reader.value.getSubsequenceAt(contig, start, if (end > maxEnd) maxEnd else end).getBaseString
}

private def fillBlock(blockIdx: Int) {
private def fillBlock(blockIdx: Int): String = {
val seq = new StringBuilder
val start = blockIdx.toLong * blockSize
var pos = start
Expand All @@ -85,13 +85,17 @@ class FASTAReader(val tmpdir: String, val fsBc: BroadcastValue[FS], val rg: Refe
pos += query.length
}

cache.put(blockIdx, seq.result())
val res = seq.result()
cache.put(blockIdx, res)
res
}

private def readBlock(blockIdx: Int): String = {
if (!cache.containsKey(blockIdx))
val x = cache.get(blockIdx)
if (x != null)
x
else
fillBlock(blockIdx)
cache.get(blockIdx)
}

private def readBlock(blockIdx: Int, offset: Int): String = {
Expand Down