You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@livy.apache.org by mgaido91 <gi...@git.apache.org> on 2018/11/27 16:06:02 UTC
[GitHub] incubator-livy pull request #118: [LIVY-503] Separate thrift server session ...
Github user mgaido91 commented on a diff in the pull request:
https://github.com/apache/incubator-livy/pull/118#discussion_r236611216
--- Diff: thriftserver/session/src/main/java/org/apache/livy/thriftserver/session/ThriftSessionState.java ---
@@ -0,0 +1,126 @@
+/*
+ * 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.livy.thriftserver.session;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.types.StructType;
+
+import org.apache.livy.JobContext;
+
+/**
+ * State related to one Thrift session. One instance of this class is stored in the session's
+ * shared object map for each Thrift session that connects to the backing Livy session.
+ */
+class ThriftSessionState {
+
+ private static String SESSION_STATE_KEY_PREFIX = "livy.sessionState.";
+ private static Object CREATE_LOCK = new Object();
+
+ private static String sessionKey(String sessionId) {
+ return SESSION_STATE_KEY_PREFIX + sessionId;
+ }
+
+ static ThriftSessionState get(JobContext ctx, String sessionId) {
+ checkNotNull(sessionId, "No session ID.");
+ try {
+ return (ThriftSessionState) ctx.getSharedObject(sessionKey(sessionId));
+ } catch (NoSuchElementException nsee) {
+ throw new NoSuchElementException(String.format("Session %s not found.", sessionId));
+ }
+ }
+
+ static ThriftSessionState create(JobContext ctx, String sessionId) throws Exception {
+ checkNotNull(sessionId, "No session ID.");
+ String key = sessionKey(sessionId);
+ synchronized (CREATE_LOCK) {
--- End diff --
do we really need to synchronize this?
---