Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions core/src/main/scala/org/apache/spark/SparkEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,17 @@ object SparkEnv extends Logging {

val useLegacyMemoryManager = conf.getBoolean("spark.memory.useLegacyMode", false)
val memoryManager: MemoryManager =
conf.getOption("spark.memory.manager").filterNot(_.equalsIgnoreCase("default"))
.map(Utils.classForName(_)
.getConstructor(classOf[SparkConf], classOf[Int])
.newInstance(conf, Int.box(numUsableCores))
.asInstanceOf[MemoryManager]).getOrElse {
if (useLegacyMemoryManager) {
new StaticMemoryManager(conf, numUsableCores)
} else {
UnifiedMemoryManager(conf, numUsableCores)
SparkSnappyUtils.loadSnappyManager(conf, numUsableCores).getOrElse {
conf.getOption("spark.memory.manager").filterNot(_.equalsIgnoreCase("default"))
.map(Utils.classForName(_)
.getConstructor(classOf[SparkConf], classOf[Int])
.newInstance(conf, Int.box(numUsableCores))
.asInstanceOf[MemoryManager]).getOrElse {
if (useLegacyMemoryManager) {
new StaticMemoryManager(conf, numUsableCores)
} else {
UnifiedMemoryManager(conf, numUsableCores)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An explicit setting of "spark.memory.manager" should override SnappyUMM. So this should be changed in the getOrElse block of previous code:

      conf.getOption("spark.memory.manager").filterNot(_.equalsIgnoreCase("default"))
      ...
          .asInstanceOf[MemoryManager]).getOrElse {
            SparkSnappyUtils.loadSnappyManager(conf, numUsableCores).getOrElse {
              if (useLegacyMemoryManager)
              ...
            }
          }

}
}

Expand Down
38 changes: 38 additions & 0 deletions core/src/main/scala/org/apache/spark/SparkSnappyUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017 SnappyData, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package org.apache.spark

import org.apache.spark.memory.MemoryManager
import org.apache.spark.util.Utils


object SparkSnappyUtils {

val SNAPPY_UNIFIED_MEMORY_MANAGER_CLASS = "org.apache.spark.memory.SnappyUnifiedMemoryManager"

def loadSnappyManager(conf: SparkConf, numUsableCores: Int): Option[MemoryManager] = {
try {
Some(Utils.classForName(SNAPPY_UNIFIED_MEMORY_MANAGER_CLASS)
.getConstructor(classOf[SparkConf], classOf[Int])
.newInstance(conf, Int.box(numUsableCores))
.asInstanceOf[MemoryManager])
} catch {
case ex: ClassNotFoundException => None
}
}

}