Abacn commented on code in PR #40103:
URL: https://github.com/apache/beam/pull/40103#discussion_r3992982547
##########
runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/translation/SparkSessionFactory.java:
##########
@@ -113,15 +115,47 @@ public class SparkSessionFactory {
"/com.esotericsoftware/kryo-shaded",
"/com/esotericsoftware/kryo-shaded");
+ // Users per session created here, guarded by the class lock.
+ private static final Map<SparkSession, Integer> OWNED_SESSIONS = new
HashMap<>();
+
/**
- * Gets active {@link SparkSession} or creates one using {@link
- * SparkStructuredStreamingPipelineOptions}.
+ * Returns the {@link SparkSession} for a pipeline, pair with {@link
#release}. Without {@code
+ * useActiveSparkSession} the session is created here unless a usable one
exists, only sessions
+ * created here are stopped on release.
*/
- public static SparkSession
getOrCreateSession(SparkStructuredStreamingPipelineOptions options) {
+ public static synchronized SparkSession
acquire(SparkStructuredStreamingPipelineOptions options) {
if (options.getUseActiveSparkSession()) {
return SparkSession.active();
}
- return sessionBuilder(options.getSparkMaster(), options).getOrCreate();
+ // Spark 3 also returns stopped sessions.
Review Comment:
Please add a few comments noting why we need to manage active sessions
ourselves now.
##########
runners/spark/src/test/java/org/apache/beam/runners/spark/structuredstreaming/SparkStructuredStreamingPipelineResultTest.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.beam.runners.spark.structuredstreaming;
+
Review Comment:
These tests may be useful, however, a generic idea is to keep test and main
source balanced and test concise, as nowadays it's much easier to write
boilerplate tests than before
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]