Skip to content

Commit

Permalink
add host buffer handle spill lock test
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Puller <[email protected]>
  • Loading branch information
zpuller committed Dec 16, 2024
1 parent 664ec96 commit 82b0d7e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class SpillableHostBufferHandle private (
0L
}
}
// Make sure to only set spilling to false if it was previously set to true
setSpilling(false)
releaseHostResource()
spilled
Expand Down Expand Up @@ -499,6 +500,7 @@ class SpillableDeviceBufferHandle private (
}
}
}
// Make sure to only set spilling to false if it was previously set to true
setSpilling(false)
spilled
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ class SpillFrameworkSuite
testBufferFileDeletion(canShareDiskPaths = true)
}

test("handle cannot spill once marked as spilling by another thread") {
test("device handle cannot spill once marked as spilling by another thread") {
val (ct, _) = buildContiguousTable()
val buff = ct.getBuffer
buff.incRefCount()
Expand All @@ -1126,4 +1126,22 @@ class SpillFrameworkSuite
}
}

test("host handle cannot spill once marked as spilling by another thread") {
withResource(SpillableHostBufferHandle(HostMemoryBuffer.allocate(512))) { hostHandle =>
assert(hostHandle.spillable)

// we're just simulating the another thread coming in and spilling here
// so we don't have to worry about a race
assert(hostHandle.setSpilling(true))
// the "other thread is spilling" so we cannot claim the spill lock
assert(!hostHandle.setSpilling(true))
assertResult(0)(SpillFramework.stores.hostStore.spill(hostHandle.approxSizeInBytes))
assert(hostHandle.setSpilling(false))

// now that nobody else is spilling (but the buffer is still not actually spilled),
// we will succeed
assertResult(512)(SpillFramework.stores.hostStore.spill(hostHandle.approxSizeInBytes))
}
}

}

0 comments on commit 82b0d7e

Please sign in to comment.