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

chengpan pushed a commit to branch branch-1.8
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/branch-1.8 by this push:
     new bb30e7890 [KYUUBI #5310] [BATCH] Batch session recovery should start 
after HTTP server getting started
bb30e7890 is described below

commit bb30e789019934b1dec4a5cf88dad17248722fdf
Author: zwangsheng <[email protected]>
AuthorDate: Wed Sep 20 11:02:52 2023 +0800

    [KYUUBI #5310] [BATCH] Batch session recovery should start after HTTP 
server getting started
    
    ### _Why are the changes needed?_
    
    In rare cases, when JettyServer is not fully started, we start the recovery 
task, will get the wrong port.
    
    As a result, we cannot get the task that is not properly submitted by the 
current kyuubi server instance correctly.
    
    Like :
    ```
    mysql> select identifier, kyuubi_instance  from metadata where 
kyuubi_instance like '%:-1';
    +--------------------------------------+----------------------+
    | identifier                           | kyuubi_instance      |
    +--------------------------------------+----------------------+
    | b6e88262-fddb-3ccd-abdf-95ef206e612b | XXXX:-1              |
    | 6a02b526-ed10-3b76-ba36-d61fbaf6b28d | XXXX:-1              |
    | 70a0446e-d3d0-3b13-9d34-4cc90369c2d9 | XXXX:-1              |
    | d290ee2e-b8cd-3bc4-b6c6-72f5b5dfcb9b | XXXX:-1              |
    | 9bb10f4-24b4-3eec-b13b-7932b310cb5cd | XXXX:-1              |
    ```
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run 
test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests)
 locally before make a pull request
    
    In local env, start kyuubi server with this PR, kyuubi server start as 
excpeted.
    
    And i remove start server and runInternal, kyuubi server will wait here.
    
    ### _Was this patch authored or co-authored using generative AI tooling?_
    
    No
    
    Closes #5310 from zwangsheng/rest_client/wait_server_start_start_recovery.
    
    Closes #5310
    
    15282c67e [Cheng Pan] Update 
kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
    d51476b6e [Cheng Pan] Update 
kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
    a276e39fa [zwangsheng] remove useless thread
    2f91f4c85 [zwangsheng] fix comment
    a73fa45e8 [zwangsheng] [REST] RestService should wait jetty server started 
then start to recovery batch session
    
    Lead-authored-by: zwangsheng <[email protected]>
    Co-authored-by: Cheng Pan <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
    (cherry picked from commit 18d043fcbd81861a6964a780e962ce7fb47ca744)
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../org/apache/kyuubi/server/KyuubiRestFrontendService.scala      | 8 +++++++-
 .../src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala  | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
index 20df64df2..28dfab731 100644
--- 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
+++ 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
@@ -183,10 +183,16 @@ class KyuubiRestFrontendService(override val serverable: 
Serverable)
     if (!isStarted.get) {
       try {
         server.start()
-        recoverBatchSessions()
         isStarted.set(true)
         startBatchChecker()
         startInternal()
+        // block until the HTTP server is started, otherwise, we may get
+        // the wrong HTTP server port -1
+        while (server.getState != "STARTED") {
+          info(s"Waiting for $getName's HTTP server getting started")
+          Thread.sleep(1000)
+        }
+        recoverBatchSessions()
       } catch {
         case e: Exception => throw new KyuubiException(s"Cannot start 
$getName", e)
       }
diff --git 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
index 3ee6f0913..00b172f2c 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
@@ -67,6 +67,8 @@ private[kyuubi] case class JettyServer(
       dest: String): Unit = {
     addHandler(JettyUtils.createRedirectHandler(src, dest))
   }
+
+  def getState: String = server.getState
 }
 
 object JettyServer {

Reply via email to