Skip to content

Commit 438b78b

Browse files
committed
[SPARK-31422][CORE] Fix NPE when BlockManagerSource is used after BlockManagerMaster stops
1 parent 2d3692e commit 438b78b

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

core/src/main/scala/org/apache/spark/storage/BlockManagerMaster.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ class BlockManagerMaster(
167167
* amount of remaining memory.
168168
*/
169169
def getMemoryStatus: Map[BlockManagerId, (Long, Long)] = {
170+
if (driverEndpoint == null) return Map.empty
170171
driverEndpoint.askSync[Map[BlockManagerId, (Long, Long)]](GetMemoryStatus)
171172
}
172173

173174
def getStorageStatus: Array[StorageStatus] = {
175+
if (driverEndpoint == null) return Array.empty
174176
driverEndpoint.askSync[Array[StorageStatus]](GetStorageStatus)
175177
}
176178

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.storage
19+
20+
import org.junit.Assert.assertTrue
21+
22+
import org.apache.spark.{SparkConf, SparkFunSuite}
23+
24+
class BlockManagerMasterSuite extends SparkFunSuite {
25+
26+
test("getMemoryStatus should not fail after BlockManagerMaster stops") {
27+
val bmm = new BlockManagerMaster(null, null, new SparkConf, true)
28+
assertTrue(bmm.getMemoryStatus.isEmpty)
29+
}
30+
31+
test("getStorageStatus should not fail after BlockManagerMaster stops") {
32+
val bmm = new BlockManagerMaster(null, null, new SparkConf, true)
33+
assertTrue(bmm.getStorageStatus.isEmpty)
34+
}
35+
}

0 commit comments

Comments
 (0)