You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@livy.apache.org by "askhatri (via GitHub)" <gi...@apache.org> on 2023/01/23 11:45:06 UTC

[GitHub] [incubator-livy] askhatri opened a new pull request, #384: [LIVY-968][SERVER] Provide ttl field for a livy session

askhatri opened a new pull request, #384:
URL: https://github.com/apache/incubator-livy/pull/384

   ## What changes were proposed in this pull request?
   
   A session should have a field 'ttl' (Time to live) which once exceeded should get the session killed.This field can be a parameter in the POST /sessions request and then be a part of session object. Livy has a config `livy.server.session.timeout` but this is a global config and cannot be configured for a session. A 'ttl' field can help set this for a session level.
   
   JIRA: https://issues.apache.org/jira/browse/LIVY-968
   
   ## How was this patch tested?
   
   Verified manually by creating interactive session via REST API call in a local Yarn cluster. Also, we have add the new unit tests.
   


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] ksumit commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "ksumit (via GitHub)" <gi...@apache.org>.
ksumit commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1089591529


##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -36,7 +36,7 @@
 public abstract class ClientConf<T extends ClientConf>
   implements Iterable<Map.Entry<String, String>> {
 
-  protected Logger LOG = LoggerFactory.getLogger(getClass());
+  protected static Logger LOG = LoggerFactory.getLogger(ClientConf.class);

Review Comment:
   should this be final too?



##########
server/src/main/scala/org/apache/livy/sessions/Session.scala:
##########
@@ -138,6 +138,7 @@ abstract class Session(
     val id: Int,
     val name: Option[String],
     val owner: String,
+    val ttl: Option[String],

Review Comment:
   should we add an auxiliary constructor as well that matches the existing constructor (4 parameters only) and takes the global session timeout as ttl by default? this will help reduce the amount of change in this PR.



##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =

Review Comment:
   nanoseconds seems too much to me, from my exposure to customer usecases i think ttl in minutes should be enough. curious to know when nanoseconds level of granularity would be useful.
   
   please consider simplifying this further by making this an `Int` or `Long` and avoiding all the parsing and validation logic. for the variable naming, what do you think of `ttlInMinutes` or `ttlInSeconds`?



##########
docs/rest-api.md:
##########
@@ -151,6 +151,11 @@ Creates a new interactive Scala, Python, or R shell in the cluster.
     <td>Timeout in second to which session be orphaned</td>
     <td>int</td>
   </tr>
+  <tr>
+    <td>ttl</td>
+    <td>The timeout for this inactive session</td>

Review Comment:
   would be useful to provide some examples here.
   
   `timeout for this inactive session in minutes/seconds, example: 10`



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] lmccay merged pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "lmccay (via GitHub)" <gi...@apache.org>.
lmccay merged PR #384:
URL: https://github.com/apache/incubator-livy/pull/384


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] codecov-commenter commented on pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#issuecomment-1400242778

   # [Codecov](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#384](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (791f34f) into [master](https://codecov.io/gh/apache/incubator-livy/commit/8d07eee831221093f55203190d38d793234c5db7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8d07eee) will **decrease** coverage by `2.51%`.
   > The diff coverage is `84.84%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master     #384      +/-   ##
   ============================================
   - Coverage     68.26%   65.76%   -2.51%     
   + Complexity      844      824      -20     
   ============================================
     Files           103      103              
     Lines          5965     5988      +23     
     Branches        907      911       +4     
   ============================================
   - Hits           4072     3938     -134     
   - Misses         1333     1524     +191     
   + Partials        560      526      -34     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../server/interactive/CreateInteractiveRequest.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXJ2ZXIvaW50ZXJhY3RpdmUvQ3JlYXRlSW50ZXJhY3RpdmVSZXF1ZXN0LnNjYWxh) | `75.00% <66.66%> (-5.00%)` | :arrow_down: |
   | [...java/org/apache/livy/client/common/ClientConf.java](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvbGl2eS9jbGllbnQvY29tbW9uL0NsaWVudENvbmYuamF2YQ==) | `95.83% <71.42%> (-3.24%)` | :arrow_down: |
   | [...va/org/apache/livy/client/common/HttpMessages.java](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvbGl2eS9jbGllbnQvY29tbW9uL0h0dHBNZXNzYWdlcy5qYXZh) | `95.34% <100.00%> (+0.11%)` | :arrow_up: |
   | [...la/org/apache/livy/server/batch/BatchSession.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXJ2ZXIvYmF0Y2gvQmF0Y2hTZXNzaW9uLnNjYWxh) | `84.69% <100.00%> (-2.05%)` | :arrow_down: |
   | [...e/livy/server/interactive/InteractiveSession.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXJ2ZXIvaW50ZXJhY3RpdmUvSW50ZXJhY3RpdmVTZXNzaW9uLnNjYWxh) | `57.34% <100.00%> (-12.42%)` | :arrow_down: |
   | [...server/interactive/InteractiveSessionServlet.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXJ2ZXIvaW50ZXJhY3RpdmUvSW50ZXJhY3RpdmVTZXNzaW9uU2VydmxldC5zY2FsYQ==) | `61.71% <100.00%> (-6.00%)` | :arrow_down: |
   | [.../main/scala/org/apache/livy/sessions/Session.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXNzaW9ucy9TZXNzaW9uLnNjYWxh) | `73.68% <100.00%> (+0.23%)` | :arrow_up: |
   | [...cala/org/apache/livy/sessions/SessionManager.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXNzaW9ucy9TZXNzaW9uTWFuYWdlci5zY2FsYQ==) | `82.17% <100.00%> (+0.36%)` | :arrow_up: |
   | [...a/org/apache/livy/server/ThriftServerFactory.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXJ2ZXIvVGhyaWZ0U2VydmVyRmFjdG9yeS5zY2FsYQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...main/scala/org/apache/livy/server/LivyServer.scala](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2VydmVyL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvbGl2eS9zZXJ2ZXIvTGl2eVNlcnZlci5zY2FsYQ==) | `2.23% <0.00%> (-29.47%)` | :arrow_down: |
   | ... and [22 more](https://codecov.io/gh/apache/incubator-livy/pull/384?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1094126791


##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -265,6 +265,51 @@ private Map<String, ConfPair> allAlternativeKeys() {
     return altToNewKeyMap;
   }
 
+  public static boolean validateTtl(String ttl) {

Review Comment:
   Added the logic to reuse the same method.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1098605784


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =
+              ClientConf.getTimeAsNanos(session.ttl.orNull, session.id, sessionTimeout)

Review Comment:
   Considering the support for session recovery, we have decided to avoid converting it into long value during session creation.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] gyogal commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "gyogal (via GitHub)" <gi...@apache.org>.
gyogal commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1086915353


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =
+              ClientConf.getTimeAsNanos(session.ttl.orNull, session.id, sessionTimeout)

Review Comment:
   The TTL string is currently only validated here. If the formatting is invalid it seems like this will keep logging error messages every time `expired()` is called. To prevent this, the string could be validated as the session in created.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1094129232


##########
server/src/main/scala/org/apache/livy/server/interactive/CreateInteractiveRequest.scala:
##########
@@ -50,6 +51,7 @@ class CreateInteractiveRequest {
       (if (queue.isDefined) s"queue: ${queue.get}, " else "") +
       (if (name.isDefined) s"name: ${name.get}, " else "") +
       (if (conf.nonEmpty) s"conf: ${conf.mkString(",")}, " else "") +
-      s"heartbeatTimeoutInSecond: $heartbeatTimeoutInSecond]"
+      s"heartbeatTimeoutInSecond: $heartbeatTimeoutInSecond, " +
+      (if (ttl.isDefined) s"driverMemory: ${ttl.get}]" else "]")

Review Comment:
   Done



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1098603641


##########
server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala:
##########
@@ -52,15 +53,18 @@ class InteractiveSessionServlet(
 
   override protected def createSession(req: HttpServletRequest): InteractiveSession = {
     val createRequest = bodyAs[CreateInteractiveRequest](req)
+    val sessionId = sessionManager.nextId();
+    ClientConf.getTimeAsNanos(createRequest.ttl.orNull, sessionId, 0L);

Review Comment:
   I have changed the code by removing 0L and also added comment to avoid the confusion. We can not parse and set the ttl value during session creation as ttl field is taking String where as calculated value is in long. If we are a need field as "calculatedTtlValue" then it will be more complexity and very default to support session recovery scenario.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1098606596


##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -265,6 +265,51 @@ private Map<String, ConfPair> allAlternativeKeys() {
     return altToNewKeyMap;
   }
 
+  public static boolean validateTtl(String ttl) {
+    if (ttl == null || ttl.trim().isEmpty()) {
+      return true;
+    }
+    Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(ttl.trim().toLowerCase());
+    if (!m.matches()) {
+      LOG.error("Invalid ttl string: " + ttl);
+      return false;
+    }
+    long val = Long.parseLong(m.group(1));
+    if (val <= 0L) {
+      LOG.error("Invalid ttl value: " + val);
+      return false;
+    }
+    String suffix = m.group(2);
+    if (suffix != null && !TIME_SUFFIXES.containsKey(suffix)) {
+      LOG.error("Invalid ttl suffix: " + suffix);
+      return false;
+    }
+    return true;
+  }
+
+  public static long getTimeAsNanos(String time, int sessionId, long defaultVale) {

Review Comment:
   I have updated the code to avoid the code duplication.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1094128364


##########
client-common/src/main/java/org/apache/livy/client/common/HttpMessages.java:
##########
@@ -61,9 +61,10 @@ public static class SessionInfo implements ClientMessage {
     public final String kind;
     public final Map<String, String> appInfo;
     public final List<String> log;
+    public final String ttl;
 
     public SessionInfo(int id, String name, String appId, String owner, String proxyUser,

Review Comment:
   This constructor is not used in test classes and it is only one place in InteractiveSessionServlet.scala so we can skip adding extra constructor I believe.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] ksumit commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "ksumit (via GitHub)" <gi...@apache.org>.
ksumit commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1089796453


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =

Review Comment:
   hi @askhatri, i should have been more specific, i had following specific concerns:
   1. the logic on parsing the string and converting it to seconds, milliseconds etc seems more complex. instead i was proposing that we use `Int` or `Long` and use number to denote the ttl value
   2. fix the granularity for ttl either in minutes or seconds to avoid the complexity
   3. depending on whether we fix it in minutes or seconds to be very explicit, name the variable as `ttlInMinutes` or `ttlInSeconds`



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1089635745


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =

Review Comment:
   nanoseconds logic is only for internal calculation and `System.nanoTime()` is an existing code. End user has option to provide the value like "30s" for 30 seconds and "2m" for 2 minutes.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#issuecomment-1418960419

   Hi @ksumit , most of the changes are completed. Could you please check if we are good to merge it?
   CC: @gyogal 


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1089637122


##########
server/src/main/scala/org/apache/livy/sessions/Session.scala:
##########
@@ -138,6 +138,7 @@ abstract class Session(
     val id: Int,
     val name: Option[String],
     val owner: String,
+    val ttl: Option[String],

Review Comment:
   Sure @ksumit , I will check the possibility to add a auxiliary constructor.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#issuecomment-1420928594

   Hi @ksumit , today I have updated the code for further review. 😊
   CC: @gyogal 


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1092752125


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =

Review Comment:
   I got it @ksumit . So presently we have three options now:
   1) Use "ttl" with "String" datatype and keep parsing logic same as global config.
   2) Change filed name to "ttlInMinutes" with "Int" datatype and support only minutes in user inputs.
   3) Change filed name to "ttlInSeconds" with "Int" datatype and support only seconds in user inputs.
   
   Since the logic to parse string already and it is consistent with global configuration we are planing to go with option 1. i.e. using "ttl" field as "String".



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1094130842


##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -265,6 +265,51 @@ private Map<String, ConfPair> allAlternativeKeys() {
     return altToNewKeyMap;
   }
 
+  public static boolean validateTtl(String ttl) {
+    if (ttl == null || ttl.trim().isEmpty()) {
+      return true;
+    }
+    Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(ttl.trim().toLowerCase());
+    if (!m.matches()) {
+      LOG.error("Invalid ttl string: " + ttl);
+      return false;
+    }
+    long val = Long.parseLong(m.group(1));
+    if (val <= 0L) {
+      LOG.error("Invalid ttl value: " + val);
+      return false;
+    }
+    String suffix = m.group(2);
+    if (suffix != null && !TIME_SUFFIXES.containsKey(suffix)) {
+      LOG.error("Invalid ttl suffix: " + suffix);
+      return false;
+    }
+    return true;
+  }
+
+  public static long getTimeAsNanos(String time, int sessionId, long defaultVale) {

Review Comment:
   `getTimeAsMs()` is defined at class level as non-static method whereas `getTimeAsNanos()` is a static method. It not easy to reuse I believe.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] ksumit commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "ksumit (via GitHub)" <gi...@apache.org>.
ksumit commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1097865760


##########
server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala:
##########
@@ -52,15 +53,18 @@ class InteractiveSessionServlet(
 
   override protected def createSession(req: HttpServletRequest): InteractiveSession = {
     val createRequest = bodyAs[CreateInteractiveRequest](req)
+    val sessionId = sessionManager.nextId();
+    ClientConf.getTimeAsNanos(createRequest.ttl.orNull, sessionId, 0L);

Review Comment:
   this could be place for us to parse and set the ttl value correctly:
   1. if it's present and valid, parse it and set to the parsed value
   2. if it's invalid, set it to the global session timeout value or reject the request.
   
   This method call is doing the same thing but passing 0L as default value seems hacky/confusing to me. Also calling a get method in isolation without using the return value seems hacky/confusing to me.



##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =
+              ClientConf.getTimeAsNanos(session.ttl.orNull, session.id, sessionTimeout)

Review Comment:
   I agree with @gyogal, if the string was validated and converted to valid long value at session creation, we would not have to worry about these issues at later stages. If this value is not passed in the request, we can use the global timeout value from `livy.server.session.timeout` or `LivyConf.SESSION_TIMEOUT`?



##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -265,6 +265,51 @@ private Map<String, ConfPair> allAlternativeKeys() {
     return altToNewKeyMap;
   }
 
+  public static boolean validateTtl(String ttl) {
+    if (ttl == null || ttl.trim().isEmpty()) {
+      return true;
+    }
+    Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(ttl.trim().toLowerCase());
+    if (!m.matches()) {
+      LOG.error("Invalid ttl string: " + ttl);
+      return false;
+    }
+    long val = Long.parseLong(m.group(1));
+    if (val <= 0L) {
+      LOG.error("Invalid ttl value: " + val);
+      return false;
+    }
+    String suffix = m.group(2);
+    if (suffix != null && !TIME_SUFFIXES.containsKey(suffix)) {
+      LOG.error("Invalid ttl suffix: " + suffix);
+      return false;
+    }
+    return true;
+  }
+
+  public static long getTimeAsNanos(String time, int sessionId, long defaultVale) {

Review Comment:
   Hey @askhatri, there is a lot of duplicate code in `getTimeAsMs()` and `getTimeAsNanos()`, here is how i think this can be resolved (please see the changed methods below, i've merged some of your validation logic as well). My hope is that we will be able to use `getTimeAsMs()` in this form instead of `getTimeAsNanos()`.
   ```
     public long getTimeAsMs(ConfEntry e) {
       String time = get(e, String.class);
       if (time == null) {
         check(e.dflt() != null,
             "ConfEntry %s doesn't have a default value, cannot convert to time value.", e.key());
         time = (String) e.dflt();
       }
       return getTimeAsMs(time);
     }
   
     public static long getTimeAsMs(String time) {
       check(time != null && !time.trim().isEmpty(), "Invalid time string: %s", time);
       Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(time.toLowerCase());
       if (!m.matches()) {
         throw new IllegalArgumentException("Invalid time string: " + time);
       }
   
       long val = Long.parseLong(m.group(1));
       String suffix = m.group(2);
   
       if (suffix != null && !TIME_SUFFIXES.containsKey(suffix)) {
         throw new IllegalArgumentException("Invalid suffix: \"" + suffix + "\"");
       }
   
       return TimeUnit.MILLISECONDS.convert(val,
         suffix != null ? TIME_SUFFIXES.get(suffix) : TimeUnit.MILLISECONDS);
     }
   
     private static void check(boolean test, String message, Object... args) {
       if (!test) {
         throw new IllegalArgumentException(String.format(message, args));
       }
     }
   ```



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1099668310


##########
server/src/main/scala/org/apache/livy/server/SessionServlet.scala:
##########
@@ -131,13 +131,18 @@ abstract class SessionServlet[S <: Session, R <: RecoveryMetadata](
       if (tooManySessions) {
         BadRequest(ResponseMessage("Rejected, too many sessions are being created!"))
       } else {
-        val session = sessionManager.register(createSession(request))
-        // Because it may take some time to establish the session, update the last activity
-        // time before returning the session info to the client.
-        session.recordActivity()
-        Created(clientSessionView(session, request),
-          headers = Map("Location" ->
-            (getRequestPathInfo(request) + url(getSession, "id" -> session.id.toString))))
+        try {
+          val session = sessionManager.register(createSession(request))
+          // Because it may take some time to establish the session, update the last activity
+          // time before returning the session info to the client.
+          session.recordActivity()
+          Created(clientSessionView(session, request),
+            headers = Map("Location" ->
+              (getRequestPathInfo(request) + url(getSession, "id" -> session.id.toString))))
+        } catch {
+          case e: IllegalArgumentException =>
+            BadRequest(ResponseMessage("Rejected, Invalid ttl field: " + e.getMessage))

Review Comment:
   I have updated the code as requested.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1099667793


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +170,12 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            var calculatedTimeout = sessionTimeout;
+            if (session.ttl.isDefined) {
+              calculatedTimeout = ClientConf.getTimeAsMs(session.ttl.orNull)

Review Comment:
   I have removed `orNull`.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1094126344


##########
server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala:
##########
@@ -52,15 +53,20 @@ class InteractiveSessionServlet(
 
   override protected def createSession(req: HttpServletRequest): InteractiveSession = {
     val createRequest = bodyAs[CreateInteractiveRequest](req)
-    InteractiveSession.create(
-      sessionManager.nextId(),
-      createRequest.name,
-      remoteUser(req),
-      proxyUser(req, createRequest.proxyUser),
-      livyConf,
-      accessManager,
-      createRequest,
-      sessionStore)
+    if (ClientConf.validateTtl(createRequest.ttl.orNull)) {
+      InteractiveSession.create(
+        sessionManager.nextId(),
+        createRequest.name,
+        remoteUser(req),
+        proxyUser(req, createRequest.proxyUser),
+        livyConf,
+        accessManager,
+        createRequest,
+        sessionStore,
+        createRequest.ttl)
+    } else {
+      null

Review Comment:
   I have fixed this by adding logic to throw an error.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] ksumit commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "ksumit (via GitHub)" <gi...@apache.org>.
ksumit commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1099607027


##########
server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala:
##########
@@ -52,15 +53,23 @@ class InteractiveSessionServlet(
 
   override protected def createSession(req: HttpServletRequest): InteractiveSession = {
     val createRequest = bodyAs[CreateInteractiveRequest](req)
+    val sessionId = sessionManager.nextId();
+
+    // Calling getTimeAsMs just to validate the ttl value
+    if (createRequest.ttl.isDefined) {
+      ClientConf.getTimeAsMs(createRequest.ttl.orNull);

Review Comment:
   we don't need to do `orNull` here right?



##########
server/src/main/scala/org/apache/livy/server/SessionServlet.scala:
##########
@@ -131,13 +131,18 @@ abstract class SessionServlet[S <: Session, R <: RecoveryMetadata](
       if (tooManySessions) {
         BadRequest(ResponseMessage("Rejected, too many sessions are being created!"))
       } else {
-        val session = sessionManager.register(createSession(request))
-        // Because it may take some time to establish the session, update the last activity
-        // time before returning the session info to the client.
-        session.recordActivity()
-        Created(clientSessionView(session, request),
-          headers = Map("Location" ->
-            (getRequestPathInfo(request) + url(getSession, "id" -> session.id.toString))))
+        try {
+          val session = sessionManager.register(createSession(request))
+          // Because it may take some time to establish the session, update the last activity
+          // time before returning the session info to the client.
+          session.recordActivity()
+          Created(clientSessionView(session, request),
+            headers = Map("Location" ->
+              (getRequestPathInfo(request) + url(getSession, "id" -> session.id.toString))))
+        } catch {
+          case e: IllegalArgumentException =>
+            BadRequest(ResponseMessage("Rejected, Invalid ttl field: " + e.getMessage))

Review Comment:
   Right now, the message may be related to ttl field validation but this doesn't have to be right? Can we do this instead please?
   
   ```
   BadRequest(ResponseMessage("Rejected, Reason: " + e.getMessage))
   ```



##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +170,12 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            var calculatedTimeout = sessionTimeout;
+            if (session.ttl.isDefined) {
+              calculatedTimeout = ClientConf.getTimeAsMs(session.ttl.orNull)

Review Comment:
   we don't need `orNull` here right?



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#issuecomment-1422675913

   > Minor comments, looks good otherwise. Please fix them and i will approve from my side. Thank you for your contribution @askhatri
   
   All comments fixed today as suggested by you.


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1099667890


##########
server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala:
##########
@@ -52,15 +53,23 @@ class InteractiveSessionServlet(
 
   override protected def createSession(req: HttpServletRequest): InteractiveSession = {
     val createRequest = bodyAs[CreateInteractiveRequest](req)
+    val sessionId = sessionManager.nextId();
+
+    // Calling getTimeAsMs just to validate the ttl value
+    if (createRequest.ttl.isDefined) {
+      ClientConf.getTimeAsMs(createRequest.ttl.orNull);

Review Comment:
   I have removed `orNull`.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] ksumit commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "ksumit (via GitHub)" <gi...@apache.org>.
ksumit commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1093693598


##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -265,6 +265,51 @@ private Map<String, ConfPair> allAlternativeKeys() {
     return altToNewKeyMap;
   }
 
+  public static boolean validateTtl(String ttl) {

Review Comment:
   Looks like `validateTtl()` and `getTimeAsNanos()` are using a lot of duplicate code, could we avoid this? 



##########
server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala:
##########
@@ -52,15 +53,20 @@ class InteractiveSessionServlet(
 
   override protected def createSession(req: HttpServletRequest): InteractiveSession = {
     val createRequest = bodyAs[CreateInteractiveRequest](req)
-    InteractiveSession.create(
-      sessionManager.nextId(),
-      createRequest.name,
-      remoteUser(req),
-      proxyUser(req, createRequest.proxyUser),
-      livyConf,
-      accessManager,
-      createRequest,
-      sessionStore)
+    if (ClientConf.validateTtl(createRequest.ttl.orNull)) {
+      InteractiveSession.create(
+        sessionManager.nextId(),
+        createRequest.name,
+        remoteUser(req),
+        proxyUser(req, createRequest.proxyUser),
+        livyConf,
+        accessManager,
+        createRequest,
+        sessionStore,
+        createRequest.ttl)
+    } else {
+      null

Review Comment:
   should this be considered an error case instead and we throw an appropriate error message here? Or could we log the failure and use the global ttl value in this case as the default value?



##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =

Review Comment:
   I see now that global configuration is also using this complicated logic. Thanks for pointing that out. I also noticed that there are bunch of other configurations that follow this same logic. So we can leave this as it is. I'm concerned about duplicate code logic in `getTimeAsMs()` and `getTimeAsNanos()`, please see if we can avoid the same or reuse what's already there?



##########
server/src/main/scala/org/apache/livy/server/interactive/CreateInteractiveRequest.scala:
##########
@@ -50,6 +51,7 @@ class CreateInteractiveRequest {
       (if (queue.isDefined) s"queue: ${queue.get}, " else "") +
       (if (name.isDefined) s"name: ${name.get}, " else "") +
       (if (conf.nonEmpty) s"conf: ${conf.mkString(",")}, " else "") +
-      s"heartbeatTimeoutInSecond: $heartbeatTimeoutInSecond]"
+      s"heartbeatTimeoutInSecond: $heartbeatTimeoutInSecond, " +
+      (if (ttl.isDefined) s"driverMemory: ${ttl.get}]" else "]")

Review Comment:
   typo: we need `ttl` instead of `driverMemory`



##########
client-common/src/main/java/org/apache/livy/client/common/HttpMessages.java:
##########
@@ -61,9 +61,10 @@ public static class SessionInfo implements ClientMessage {
     public final String kind;
     public final Map<String, String> appInfo;
     public final List<String> log;
+    public final String ttl;
 
     public SessionInfo(int id, String name, String appId, String owner, String proxyUser,

Review Comment:
   given that ttl is optional field, should we create an override constructor without this parameter? that way you will be able to avoid other changes in test classes.



##########
server/src/main/scala/org/apache/livy/server/SessionServlet.scala:
##########
@@ -131,13 +131,18 @@ abstract class SessionServlet[S <: Session, R <: RecoveryMetadata](
       if (tooManySessions) {
         BadRequest(ResponseMessage("Rejected, too many sessions are being created!"))
       } else {
-        val session = sessionManager.register(createSession(request))
-        // Because it may take some time to establish the session, update the last activity
-        // time before returning the session info to the client.
-        session.recordActivity()
-        Created(clientSessionView(session, request),
-          headers = Map("Location" ->
-            (getRequestPathInfo(request) + url(getSession, "id" -> session.id.toString))))
+        val input = createSession(request)
+        if(input == null) {
+          BadRequest(ResponseMessage("Rejected, invalid value for ttl field!"))

Review Comment:
   should we throw an exception in `createSession()` and use appropriate message from that to return the `ResponseMessage` here? There could potentially be other reasons on why `createSession()` could return null, right?



##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -265,6 +265,51 @@ private Map<String, ConfPair> allAlternativeKeys() {
     return altToNewKeyMap;
   }
 
+  public static boolean validateTtl(String ttl) {
+    if (ttl == null || ttl.trim().isEmpty()) {
+      return true;
+    }
+    Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(ttl.trim().toLowerCase());
+    if (!m.matches()) {
+      LOG.error("Invalid ttl string: " + ttl);
+      return false;
+    }
+    long val = Long.parseLong(m.group(1));
+    if (val <= 0L) {
+      LOG.error("Invalid ttl value: " + val);
+      return false;
+    }
+    String suffix = m.group(2);
+    if (suffix != null && !TIME_SUFFIXES.containsKey(suffix)) {
+      LOG.error("Invalid ttl suffix: " + suffix);
+      return false;
+    }
+    return true;
+  }
+
+  public static long getTimeAsNanos(String time, int sessionId, long defaultVale) {

Review Comment:
   What is your opinion in reusing `getTimeAsMs()` instead of creating a new one? Other than the granularity, do you see any other gap between `getTimeAsMs()` and `getTimeAsNanos()` implementations?



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1097283480


##########
server/src/main/scala/org/apache/livy/sessions/SessionManager.scala:
##########
@@ -168,7 +169,9 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : ClassTag](
             false
           } else {
             val currentTime = System.nanoTime()
-            currentTime - session.lastActivity > sessionTimeout
+            val calculatedTimeout =
+              ClientConf.getTimeAsNanos(session.ttl.orNull, session.id, sessionTimeout)

Review Comment:
   I have completed this code changes.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1094129015


##########
server/src/main/scala/org/apache/livy/server/SessionServlet.scala:
##########
@@ -131,13 +131,18 @@ abstract class SessionServlet[S <: Session, R <: RecoveryMetadata](
       if (tooManySessions) {
         BadRequest(ResponseMessage("Rejected, too many sessions are being created!"))
       } else {
-        val session = sessionManager.register(createSession(request))
-        // Because it may take some time to establish the session, update the last activity
-        // time before returning the session info to the client.
-        session.recordActivity()
-        Created(clientSessionView(session, request),
-          headers = Map("Location" ->
-            (getRequestPathInfo(request) + url(getSession, "id" -> session.id.toString))))
+        val input = createSession(request)
+        if(input == null) {
+          BadRequest(ResponseMessage("Rejected, invalid value for ttl field!"))

Review Comment:
   I have updated the code to avoid returning null.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] gyogal commented on pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "gyogal (via GitHub)" <gi...@apache.org>.
gyogal commented on PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#issuecomment-1423887628

   This looks good to me as well. Thinking about it, it may be good to introduce a maximum or a limit for this, so that it cannot be longer than a set amount. But this could be addressed in a separate ticket.


-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1089633885


##########
client-common/src/main/java/org/apache/livy/client/common/ClientConf.java:
##########
@@ -36,7 +36,7 @@
 public abstract class ClientConf<T extends ClientConf>
   implements Iterable<Map.Entry<String, String>> {
 
-  protected Logger LOG = LoggerFactory.getLogger(getClass());
+  protected static Logger LOG = LoggerFactory.getLogger(ClientConf.class);

Review Comment:
   Sure @ksumit , I will try to make it final



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-livy] askhatri commented on a diff in pull request #384: [LIVY-968][SERVER] Provide ttl field for a livy session

Posted by "askhatri (via GitHub)" <gi...@apache.org>.
askhatri commented on code in PR #384:
URL: https://github.com/apache/incubator-livy/pull/384#discussion_r1089636026


##########
docs/rest-api.md:
##########
@@ -151,6 +151,11 @@ Creates a new interactive Scala, Python, or R shell in the cluster.
     <td>Timeout in second to which session be orphaned</td>
     <td>int</td>
   </tr>
+  <tr>
+    <td>ttl</td>
+    <td>The timeout for this inactive session</td>

Review Comment:
   Sure @ksumit , I will try to update this note.



-- 
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: commits-unsubscribe@livy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org