turboFei commented on code in PR #6040:
URL: https://github.com/apache/kyuubi/pull/6040#discussion_r1477415856


##########
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/SparkSQLEngine.scala:
##########
@@ -170,18 +170,41 @@ case class SparkSQLEngine(spark: SparkSession) extends 
Serverable("SparkSQLEngin
     val maxLifetime = conf.get(ENGINE_SPARK_MAX_LIFETIME)
     val deregistered = new AtomicBoolean(false)
     if (maxLifetime > 0) {
+      val gracefulPeriod = conf.get(ENGINE_SPARK_MAX_LIFETIME_GRACEFUL_PERIOD)
       val checkTask: Runnable = () => {
-        if (!shutdown.get && System.currentTimeMillis() - getStartTime > 
maxLifetime) {
+        val elapsedTime = System.currentTimeMillis() - getStartTime
+        if (!shutdown.get && elapsedTime > maxLifetime) {
           if (deregistered.compareAndSet(false, true)) {
-            info(s"Spark engine has been running for more than $maxLifetime 
ms," +
-              s" deregistering from engine discovery space.")
-            frontendServices.flatMap(_.discoveryService).foreach(_.stop())
+            ThreadUtils.runInNewThread("engine-de-register", isDaemon = false) 
{
+              // for ETCD, the de-registering process might be blocked, so 
deregister it async
+              info(s"Spark engine has been running for more than $maxLifetime 
ms," +
+                s" deregistering from engine discovery space.")
+              frontendServices.flatMap(_.discoveryService).foreach(_.stop())

Review Comment:
   ```
   09:46:29.180 vertx-blocked-thread-checker WARN BlockedThreadChecker: Thread 
Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 19018 ms, time 
limit is 2000 ms
   io.vertx.core.VertxException: Thread blocked
           at java.lang.Thread.sleep(Native Method)
           at 
org.apache.kyuubi.ha.client.ServiceDiscovery.stopGracefully(ServiceDiscovery.scala:71)
           at 
org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient$DeRegisterWatcher.$anonfun$onNext$2(EtcdDiscoveryClient.scala:384)
           at 
org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient$DeRegisterWatcher.$anonfun$onNext$2$adapted(EtcdDiscoveryClient.scala:381)
           at 
org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient$DeRegisterWatcher$$Lambda$2964/1803489267.apply(Unknown
 Source)
           at 
scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
           at 
scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
           at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
           at 
org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient$DeRegisterWatcher.onNext(EtcdDiscoveryClient.scala:381)
           at 
io.etcd.jetcd.impl.WatchImpl$WatcherImpl.onNext(WatchImpl.java:307)
           at 
io.etcd.jetcd.impl.WatchImpl$WatcherImpl$$Lambda$2892/1233911532.handle(Unknown 
Source)
           at 
io.vertx.grpc.stub.StreamObserverReadStream.onNext(StreamObserverReadStream.java:37)
           at 
io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onMessage(ClientCalls.java:468)
           at 
io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:667)
           at 
io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:654)
           at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
           at 
io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
           at 
io.vertx.grpc.VertxChannelBuilder.lambda$null$0(VertxChannelBuilder.java:305)
           at 
io.vertx.grpc.VertxChannelBuilder$$Lambda$2847/1899882869.handle(Unknown Source)
           at 
io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:276)
   
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to