You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/04/26 12:09:34 UTC
[GitHub] [spark] attilapiros commented on a change in pull request #32287: [SPARK-27991][CORE] Defer the fetch request on Netty OOM
attilapiros commented on a change in pull request #32287:
URL: https://github.com/apache/spark/pull/32287#discussion_r620235033
##########
File path: core/src/test/scala/org/apache/spark/storage/ShuffleBlockFetcherIteratorSuite.scala
##########
@@ -48,15 +49,22 @@ class ShuffleBlockFetcherIteratorSuite extends SparkFunSuite with PrivateMethodT
// in the presence of faults.
/** Creates a mock [[BlockTransferService]] that returns data from the given map. */
- private def createMockTransfer(data: Map[BlockId, ManagedBuffer]): BlockTransferService = {
+ private def createMockTransfer(
+ data: Map[BlockId, ManagedBuffer],
+ throwNettyOOM: Boolean = false): BlockTransferService = {
val transfer = mock(classOf[BlockTransferService])
+ var hasThrowOOM = false
when(transfer.fetchBlocks(any(), any(), any(), any(), any(), any())).thenAnswer(
(invocation: InvocationOnMock) => {
val blocks = invocation.getArguments()(3).asInstanceOf[Array[String]]
val listener = invocation.getArguments()(4).asInstanceOf[BlockFetchingListener]
+ val OOMBlockIndex = new Random(System.currentTimeMillis()).nextInt(blocks.length)
- for (blockId <- blocks) {
- if (data.contains(BlockId(blockId))) {
+ for ((blockId, i) <- blocks.zipWithIndex) {
+ if (throwNettyOOM && !hasThrowOOM && i == OOMBlockIndex) {
+ hasThrowOOM = true
+ listener.onBlockFetchFailure(blockId, new TestNettyOutOfMemoryError())
Review comment:
With two lines of code (+ 1 extra line import) you can remove the `TestNettyOutOfMemoryError.scala` file and keep the production code clean from the test implementation detail:
```suggestion
val ctor = classOf[OutOfDirectMemoryError].getDeclaredConstructor(classOf[java.lang.String])
ctor.setAccessible(true)
listener.onBlockFetchFailure(blockId, ctor.newInstance("failed to allocate memory"))
```
The pattern (using `setAccessible`) is already used in Spark.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org