Skip to content

Commit

Permalink
[GLUTEN-5979][CH] Fix CHListenerApi initialize twice on spark local m…
Browse files Browse the repository at this point in the history
…ode (#6037)
  • Loading branch information
lwz9103 authored Jun 11, 2024
1 parent b37a6e4 commit d3ccd4a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ class CHListenerApi extends ListenerApi with Logging {

override def onExecutorStart(pc: PluginContext): Unit = {
GlutenExecutorEndpoint.executorEndpoint = new GlutenExecutorEndpoint(pc.executorID, pc.conf)
initialize(pc.conf, isDriver = false)
if (pc.conf().get("spark.master").startsWith("local")) {
logDebug("Skipping duplicate initializing clickhouse backend on spark local mode")
} else {
initialize(pc.conf, isDriver = false)
}
}

override def onExecutorShutdown(): Unit = shutdown()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.gluten.execution

import org.apache.gluten.GlutenConfig
import org.apache.gluten.exception.GlutenException
import org.apache.gluten.utils.UTSystemParameters

import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.plans.PlanTest

class GlutenClickHouseNativeLibSuite extends PlanTest {

private def baseSparkConf: SparkConf = {
new SparkConf()
.set("spark.plugins", "org.apache.gluten.GlutenPlugin")
.set("spark.default.parallelism", "1")
.set("spark.memory.offHeap.enabled", "true")
.set("spark.memory.offHeap.size", "1024MB")
.set("spark.gluten.sql.enable.native.validation", "false")
}

test("test columnar lib path not exist") {
var spark: SparkSession = null
try {
spark = SparkSession
.builder()
.master("local[1]")
.config(baseSparkConf)
.config(GlutenConfig.GLUTEN_LIB_PATH, "path/not/exist/libch.so")
.getOrCreate()
spark.sql("select 1").show()
} catch {
case e: Exception =>
assert(e.isInstanceOf[GlutenException])
assert(
e.getMessage.contains(
"library at path: path/not/exist/libch.so is not a file or does not exist"))
} finally {
if (spark != null) {
spark.stop()
}
}
}

test("test CHListenerApi initialize only once") {
var spark: SparkSession = null
try {
spark = SparkSession
.builder()
.master("local[1]")
.config(baseSparkConf)
.config(GlutenConfig.GLUTEN_LIB_PATH, UTSystemParameters.clickHouseLibPath)
.config(GlutenConfig.GLUTEN_EXECUTOR_LIB_PATH, "/path/not/exist/libch.so")
.getOrCreate()
spark.sql("select 1").show()
} finally {
if (spark != null) {
spark.stop()
}
}
}

}

0 comments on commit d3ccd4a

Please sign in to comment.