Skip to content

Commit

Permalink
[KYUUBI #1568] [FOLLOWUP] Add getSessionEvent in session
Browse files Browse the repository at this point in the history
### _Why are the changes needed?_
KyuubiSessionEvent.apply will get incorrect info.
The first one is  from `Session.getSessionEvent`, the second one is `KyuubiSessionEvent.apply`

![image](https://user-images.githubusercontent.com/18065113/147657104-16247260-4b50-4485-843c-f5dbb0116c99.png)

### _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

- [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #1644 from simon824/1229.

Closes #1568

bc5e4b4 [Simon] Merge branch 'apache:master' into 1229
bb316e6 [simon] Add getSessionEvent in session

Lead-authored-by: Simon <3656562@qq.com>
Co-authored-by: simon <zhangshiming@cvte.com>
Signed-off-by: Kent Yao <yao@apache.org>
  • Loading branch information
2 people authored and yaooqinn committed Jan 4, 2022
1 parent 0f8ebb6 commit dc26f21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Expand Up @@ -22,6 +22,7 @@ import scala.collection.JavaConverters._
import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion, TRowSet, TTableSchema}

import org.apache.kyuubi.{KyuubiSQLException, Logging}
import org.apache.kyuubi.events.KyuubiEvent
import org.apache.kyuubi.operation.{Operation, OperationHandle}
import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation
import org.apache.kyuubi.operation.log.OperationLog
Expand Down Expand Up @@ -216,4 +217,6 @@ abstract class AbstractSession(
override def open(): Unit = {
OperationLog.createOperationLogRootDirectory(this)
}

override def getSessionEvent: Option[KyuubiEvent] = None
}
Expand Up @@ -19,6 +19,7 @@ package org.apache.kyuubi.session

import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion, TRowSet, TTableSchema}

import org.apache.kyuubi.events.KyuubiEvent
import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation
import org.apache.kyuubi.operation.OperationHandle

Expand All @@ -37,6 +38,7 @@ trait Session {
def lastAccessTime: Long
def lastIdleTime: Long
def getNoOperationTime: Long
def getSessionEvent: Option[KyuubiEvent]

def sessionManager: SessionManager

Expand Down
Expand Up @@ -29,11 +29,11 @@ import io.swagger.v3.oas.annotations.tags.Tag
import org.apache.hive.service.rpc.thrift.{TGetInfoType, TProtocolVersion}

import org.apache.kyuubi.Utils.error
import org.apache.kyuubi.events.KyuubiSessionEvent
import org.apache.kyuubi.events.KyuubiEvent
import org.apache.kyuubi.operation.OperationHandle
import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle
import org.apache.kyuubi.server.api.ApiRequestContext
import org.apache.kyuubi.session.{AbstractSession, SessionHandle}
import org.apache.kyuubi.session.SessionHandle
import org.apache.kyuubi.session.SessionHandle.parseSessionHandle

@Tag(name = "Session")
Expand Down Expand Up @@ -61,11 +61,9 @@ private[v1] class SessionsResource extends ApiRequestContext {
description = "get a session event via session handle identifier")
@GET
@Path("{sessionHandle}")
def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): KyuubiSessionEvent = {
def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): KyuubiEvent = {
try {
// TODO: need to use KyuubiSessionEvent in session
KyuubiSessionEvent(fe.be.sessionManager.getSession(
parseSessionHandle(sessionHandleStr)).asInstanceOf[AbstractSession])
fe.be.sessionManager.getSession(parseSessionHandle(sessionHandleStr)).getSessionEvent.get
} catch {
case NonFatal(e) =>
error(s"Invalid $sessionHandleStr", e)
Expand Down
Expand Up @@ -25,7 +25,7 @@ import org.apache.kyuubi.client.KyuubiSyncThriftClient
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf._
import org.apache.kyuubi.engine.EngineRef
import org.apache.kyuubi.events.KyuubiSessionEvent
import org.apache.kyuubi.events.{KyuubiEvent, KyuubiSessionEvent}
import org.apache.kyuubi.ha.client.ZooKeeperClientProvider._
import org.apache.kyuubi.metrics.MetricsConstants._
import org.apache.kyuubi.metrics.MetricsSystem
Expand Down Expand Up @@ -58,6 +58,10 @@ class KyuubiSessionImpl(
private val sessionEvent = KyuubiSessionEvent(this)
EventLoggingService.onEvent(sessionEvent)

override def getSessionEvent: Option[KyuubiEvent] = {
Option(sessionEvent)
}

private var _client: KyuubiSyncThriftClient = _
def client: KyuubiSyncThriftClient = _client

Expand Down

0 comments on commit dc26f21

Please sign in to comment.