@@ -272,11 +272,13 @@ private[spark] object Utils extends Logging {
272272 /** Copy all data from an InputStream to an OutputStream */
273273 def copyStream (in : InputStream ,
274274 out : OutputStream ,
275- closeStreams : Boolean = false ): Long =
275+ closeStreams : Boolean = false ,
276+ transferToEnabled : Boolean = true ): Long =
276277 {
277278 var count = 0L
278279 try {
279- if (in.isInstanceOf [FileInputStream ] && out.isInstanceOf [FileOutputStream ]) {
280+ if (in.isInstanceOf [FileInputStream ] && out.isInstanceOf [FileOutputStream ]
281+ && transferToEnabled) {
280282 // When both streams are File stream, use transferTo to improve copy performance.
281283 val inChannel = in.asInstanceOf [FileInputStream ].getChannel()
282284 val outChannel = out.asInstanceOf [FileOutputStream ].getChannel()
@@ -292,16 +294,15 @@ private[spark] object Utils extends Logging {
292294 // give user information if not.
293295 // Position will not be increased to the expected length after calling transferTo in
294296 // kernel version 2.6.32, this issue can be seen in
295- // scalastyle:off
296- // https://bugs.openjdk.java.net/browse/JDK-7052359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel)
297- // scalastyle:on
297+ // https://bugs.openjdk.java.net/browse/JDK-7052359
298298 // This will lead to stream corruption issue when using sort-based shuffle (SPARK-3948).
299299 val finalPos = outChannel.position()
300300 assert(finalPos == initialPos + size,
301301 s """
302302 |Current position $finalPos do not equal to expected position ${initialPos + count}
303303 |after transferTo, please check your kernel version to see if it is 2.6.32,
304304 |this is a kernel bug which will lead to unexpected behavior when using transferTo.
305+ |You can set spark.file.transferTo = false to disable this NIO feature.
305306 """ .stripMargin)
306307 } else {
307308 val buf = new Array [Byte ](8192 )
0 commit comments