This is an automated email from the ASF dual-hosted git repository.

ggal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-livy.git


The following commit(s) were added to refs/heads/master by this push:
     new c28f2fce [LIVY-1009] Add support for global TTL for sessions
c28f2fce is described below

commit c28f2fce58e1fc2e69b1c7470bd9c02d8cb196a6
Author: nileshrathi345 <[email protected]>
AuthorDate: Mon Aug 11 17:52:41 2025 +0530

    [LIVY-1009] Add support for global TTL for sessions
    
    ## What changes were proposed in this pull request?
    
    Added two new Livy configuration parameters as below:
    
    ```
    Enabled to check whether TTL Livy sessions should be stopped.
    livy.server.session.ttl-check = false
    
    Time in milliseconds on how long Livy will wait before TTL is an inactive 
session.
    Note that the inactive session could be busy running jobs.
    livy.server.session.ttl = 8h
    ```
    
    ## How was this patch tested?
    
    Read LIVY-1009 for details.
---
 conf/livy.conf.template                                    |  7 +++++++
 server/src/main/scala/org/apache/livy/LivyConf.scala       |  7 +++++++
 .../scala/org/apache/livy/sessions/SessionManager.scala    | 14 +++++++++++---
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/conf/livy.conf.template b/conf/livy.conf.template
index fe257c93..87b14b08 100644
--- a/conf/livy.conf.template
+++ b/conf/livy.conf.template
@@ -67,6 +67,13 @@
 # How long a finished session state should be kept in LivyServer for query.
 # livy.server.session.state-retain.sec = 600s
 
+# Enabled to check whether TTL Livy sessions should be stopped.
+# livy.server.session.ttl-check = false
+
+# Time in milliseconds on how long Livy will wait before TTL is an inactive 
session.
+# Note that the inactive session could be busy running jobs.
+# livy.server.session.ttl = 8h
+
 # If livy should impersonate the requesting users when creating a new session.
 # livy.impersonation.enabled = false
 
diff --git a/server/src/main/scala/org/apache/livy/LivyConf.scala 
b/server/src/main/scala/org/apache/livy/LivyConf.scala
index 8346b4b5..218589d5 100644
--- a/server/src/main/scala/org/apache/livy/LivyConf.scala
+++ b/server/src/main/scala/org/apache/livy/LivyConf.scala
@@ -354,6 +354,13 @@ object LivyConf {
   // Max creating session in livyServer
   val SESSION_MAX_CREATION = Entry("livy.server.session.max-creation", 100)
 
+  // Enabled to check whether TTL Livy sessions should be stopped.
+  val SESSION_TTL_CHECK = Entry("livy.server.session.ttl-check", false)
+
+  // Time in milliseconds on how long Livy will wait before TTL is an inactive 
session.
+  // Note that the inactive session could be busy running jobs.
+  val SESSION_TTL = Entry("livy.server.session.ttl", "8h")
+
   val SESSION_ALLOW_CUSTOM_CLASSPATH = 
Entry("livy.server.session.allow-custom-classpath", false)
 
   val SPARK_MASTER = "spark.master"
diff --git 
a/server/src/main/scala/org/apache/livy/sessions/SessionManager.scala 
b/server/src/main/scala/org/apache/livy/sessions/SessionManager.scala
index 8742f65e..1dc1d820 100644
--- a/server/src/main/scala/org/apache/livy/sessions/SessionManager.scala
+++ b/server/src/main/scala/org/apache/livy/sessions/SessionManager.scala
@@ -83,6 +83,10 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : 
ClassTag](
 
   private[this] final val sessionTimeout = 
livyConf.getTimeAsMs(LivyConf.SESSION_TIMEOUT)
 
+  private[this] final val sessionTtlCheck = 
livyConf.getBoolean(LivyConf.SESSION_TTL_CHECK)
+
+  private[this] final val sessionTtl = 
livyConf.getTimeAsMs(LivyConf.SESSION_TTL)
+
   private[this] final val sessionStateRetainedInSec =
     
TimeUnit.MILLISECONDS.toNanos(livyConf.getTimeAsMs(LivyConf.SESSION_STATE_RETAIN_TIME))
 
@@ -178,9 +182,13 @@ class SessionManager[S <: Session, R <: RecoveryMetadata : 
ClassTag](
             if (currentTime - session.lastActivity > calculatedTimeout) {
               return true
             }
-            if (session.ttl.isDefined && session.startedOn.isDefined) {
-              calculatedTimeout = TimeUnit.MILLISECONDS.toNanos(
-                ClientConf.getTimeAsMs(session.ttl.get))
+            if (sessionTtlCheck && session.startedOn.isDefined) {
+              if (session.ttl.isDefined) {
+                calculatedTimeout = TimeUnit.MILLISECONDS.toNanos(
+                  ClientConf.getTimeAsMs(session.ttl.get))
+              } else {
+                calculatedTimeout = TimeUnit.MILLISECONDS.toNanos(sessionTtl)
+              }
               if (currentTime - session.startedOn.get > calculatedTimeout) {
                 return true
               }

Reply via email to