Skip to content

Commit 9d9294a

Browse files
jongyoulJoshRosen
authored andcommitted
[SPARK-5333][Mesos] MesosTaskLaunchData occurs BufferUnderflowException
- Rewind ByteBuffer before making ByteString (This fixes a bug introduced in apache#3849 / SPARK-4014) Author: Jongyoul Lee <[email protected]> Closes apache#4119 from jongyoul/SPARK-5333 and squashes the following commits: c6693a8 [Jongyoul Lee] [SPARK-5333][Mesos] MesosTaskLaunchData occurs BufferUnderflowException - changed logDebug location 4141f58 [Jongyoul Lee] [SPARK-5333][Mesos] MesosTaskLaunchData occurs BufferUnderflowException - Added license information 2190606 [Jongyoul Lee] [SPARK-5333][Mesos] MesosTaskLaunchData occurs BufferUnderflowException - Adjusted imported libraries b7f5517 [Jongyoul Lee] [SPARK-5333][Mesos] MesosTaskLaunchData occurs BufferUnderflowException - Rewind ByteBuffer before making ByteString
1 parent 4afad9c commit 9d9294a

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosTaskLaunchData.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,29 @@ import java.nio.ByteBuffer
2121

2222
import org.apache.mesos.protobuf.ByteString
2323

24+
import org.apache.spark.Logging
25+
2426
/**
2527
* Wrapper for serializing the data sent when launching Mesos tasks.
2628
*/
2729
private[spark] case class MesosTaskLaunchData(
2830
serializedTask: ByteBuffer,
29-
attemptNumber: Int) {
31+
attemptNumber: Int) extends Logging {
3032

3133
def toByteString: ByteString = {
3234
val dataBuffer = ByteBuffer.allocate(4 + serializedTask.limit)
3335
dataBuffer.putInt(attemptNumber)
3436
dataBuffer.put(serializedTask)
37+
dataBuffer.rewind
38+
logDebug(s"ByteBuffer size: [${dataBuffer.remaining}]")
3539
ByteString.copyFrom(dataBuffer)
3640
}
3741
}
3842

39-
private[spark] object MesosTaskLaunchData {
43+
private[spark] object MesosTaskLaunchData extends Logging {
4044
def fromByteString(byteString: ByteString): MesosTaskLaunchData = {
4145
val byteBuffer = byteString.asReadOnlyByteBuffer()
46+
logDebug(s"ByteBuffer size: [${byteBuffer.remaining}]")
4247
val attemptNumber = byteBuffer.getInt // updates the position by 4 bytes
4348
val serializedTask = byteBuffer.slice() // subsequence starting at the current position
4449
MesosTaskLaunchData(serializedTask, attemptNumber)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.scheduler.mesos
19+
20+
import java.nio.ByteBuffer
21+
22+
import org.scalatest.FunSuite
23+
24+
import org.apache.spark.scheduler.cluster.mesos.MesosTaskLaunchData
25+
26+
class MesosTaskLaunchDataSuite extends FunSuite {
27+
test("serialize and deserialize data must be same") {
28+
val serializedTask = ByteBuffer.allocate(40)
29+
(Range(100, 110).map(serializedTask.putInt(_)))
30+
serializedTask.rewind
31+
val attemptNumber = 100
32+
val byteString = MesosTaskLaunchData(serializedTask, attemptNumber).toByteString
33+
serializedTask.rewind
34+
val mesosTaskLaunchData = MesosTaskLaunchData.fromByteString(byteString)
35+
assert(mesosTaskLaunchData.attemptNumber == attemptNumber)
36+
assert(mesosTaskLaunchData.serializedTask.equals(serializedTask))
37+
}
38+
}

0 commit comments

Comments
 (0)