livy-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vanzin <...@git.apache.org>
Subject [GitHub] incubator-livy pull request #118: [LIVY-503] Separate thrift server session ...
Date Tue, 27 Nov 2018 16:23:47 GMT
Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/incubator-livy/pull/118#discussion_r236741064
  
    --- 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 --
    
    yes because this operation is not atomic otherwise. There are two calls to the context
(getSharedObject and setSharedObject) and they need to be "atomic" from the view of the caller.


---

Mime
View raw message