Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ object HiveThriftServer2 extends Logging {
}

private[thriftserver] object ExecutionState extends Enumeration {
val STARTED, COMPILED, FAILED, FINISHED = Value
val STARTED, COMPILED, FAILED, FINISHED, CLOSED = Value
type ExecutionState = Value
}

Expand All @@ -147,16 +147,17 @@ object HiveThriftServer2 extends Logging {
val startTimestamp: Long,
val userName: String) {
var finishTimestamp: Long = 0L
var closeTimestamp: Long = 0L
var executePlan: String = ""
var detail: String = ""
var state: ExecutionState.Value = ExecutionState.STARTED
val jobId: ArrayBuffer[String] = ArrayBuffer[String]()
var groupId: String = ""
def totalTime: Long = {
if (finishTimestamp == 0L) {
def totalTime(endTime: Long): Long = {
if (endTime == 0L) {
System.currentTimeMillis - startTimestamp
} else {
finishTimestamp - startTimestamp
endTime - startTimestamp
}
}
}
Expand Down Expand Up @@ -254,6 +255,11 @@ object HiveThriftServer2 extends Logging {
trimExecutionIfNecessary()
}

def onOperationClosed(id: String): Unit = synchronized {
executionList(id).closeTimestamp = System.currentTimeMillis
executionList(id).state = ExecutionState.CLOSED
}

private def trimExecutionIfNecessary() = {
if (executionList.size > retainedStatements) {
val toRemove = math.max(retainedStatements / 10, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ private[hive] class SparkExecuteStatementOperation(
}
}

def close(): Unit = {
override def close(): Unit = {
// RDDs will be cleaned automatically upon garbage collection.
logDebug(s"CLOSING $statementId")
cleanup(OperationState.CLOSED)
sqlContext.sparkContext.clearJobGroup()
HiveThriftServer2.listener.onOperationClosed(statementId)
}

def addNonNullColumnValue(from: SparkRow, to: ArrayBuffer[Any], ordinal: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ private[hive] class SparkGetColumnsOperation(

val catalog: SessionCatalog = sqlContext.sessionState.catalog

private var statementId: String = _

override def close(): Unit = {
super.close()
HiveThriftServer2.listener.onOperationClosed(statementId)
}

override def runInternal(): Unit = {
val statementId = UUID.randomUUID().toString
statementId = UUID.randomUUID().toString
// Do not change cmdStr. It's used for Hive auditing and authorization.
val cmdStr = s"catalog : $catalogName, schemaPattern : $schemaName, tablePattern : $tableName"
val logMsg = s"Listing columns '$cmdStr, columnName : $columnName'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ private[hive] class SparkGetSchemasOperation(
schemaName: String)
extends GetSchemasOperation(parentSession, catalogName, schemaName) with Logging {

private var statementId: String = _

override def close(): Unit = {
super.close()
HiveThriftServer2.listener.onOperationClosed(statementId)
}

override def runInternal(): Unit = {
val statementId = UUID.randomUUID().toString
statementId = UUID.randomUUID().toString
// Do not change cmdStr. It's used for Hive auditing and authorization.
val cmdStr = s"catalog : $catalogName, schemaPattern : $schemaName"
val logMsg = s"Listing databases '$cmdStr'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ private[hive] class SparkGetTablesOperation(
extends GetTablesOperation(parentSession, catalogName, schemaName, tableName, tableTypes)
with Logging{

private var statementId: String = _

override def close(): Unit = {
super.close()
HiveThriftServer2.listener.onOperationClosed(statementId)
}

override def runInternal(): Unit = {
val statementId = UUID.randomUUID().toString
statementId = UUID.randomUUID().toString
// Do not change cmdStr. It's used for Hive auditing and authorization.
val cmdStr = s"catalog : $catalogName, schemaPattern : $schemaName"
val tableTypesStr = if (tableTypes == null) "null" else tableTypes.asScala.mkString(",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private[ui] class ThriftServerPage(parent: ThriftServerTab) extends WebUIPage(""
private def generateSQLStatsTable(request: HttpServletRequest): Seq[Node] = {
val numStatement = listener.getExecutionList.size
val table = if (numStatement > 0) {
val headerRow = Seq("User", "JobID", "GroupID", "Start Time", "Finish Time", "Duration",
"Statement", "State", "Detail")
val headerRow = Seq("User", "JobID", "GroupID", "Start Time", "Finish Time", "Close Time",
"Execution Time", "Duration", "Statement", "State", "Detail")
val dataRows = listener.getExecutionList.sortBy(_.startTimestamp).reverse

def generateDataRow(info: ExecutionInfo): Seq[Node] = {
Expand All @@ -90,7 +90,9 @@ private[ui] class ThriftServerPage(parent: ThriftServerTab) extends WebUIPage(""
<td>{info.groupId}</td>
<td>{formatDate(info.startTimestamp)}</td>
<td>{if (info.finishTimestamp > 0) formatDate(info.finishTimestamp)}</td>
<td>{formatDurationOption(Some(info.totalTime))}</td>
<td>{if (info.closeTimestamp > 0) formatDate(info.closeTimestamp)}</td>
<td>{formatDurationOption(Some(info.totalTime(info.finishTimestamp)))}</td>
<td>{formatDurationOption(Some(info.totalTime(info.closeTimestamp)))}</td>
<td>{info.statement}</td>
<td>{info.state}</td>
{errorMessageCell(detail)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ private[ui] class ThriftServerSessionPage(parent: ThriftServerTab)
.filter(_.sessionId == sessionID)
val numStatement = executionList.size
val table = if (numStatement > 0) {
val headerRow = Seq("User", "JobID", "GroupID", "Start Time", "Finish Time", "Duration",
"Statement", "State", "Detail")
val headerRow = Seq("User", "JobID", "GroupID", "Start Time", "Finish Time", "Close Time",
"Execution Time", "Duration", "Statement", "State", "Detail")
val dataRows = executionList.sortBy(_.startTimestamp).reverse

def generateDataRow(info: ExecutionInfo): Seq[Node] = {
Expand All @@ -99,7 +99,9 @@ private[ui] class ThriftServerSessionPage(parent: ThriftServerTab)
<td>{info.groupId}</td>
<td>{formatDate(info.startTimestamp)}</td>
<td>{formatDate(info.finishTimestamp)}</td>
<td>{formatDurationOption(Some(info.totalTime))}</td>
<td>{formatDate(info.closeTimestamp)}</td>
<td>{formatDurationOption(Some(info.totalTime(info.finishTimestamp)))}</td>
<td>{formatDurationOption(Some(info.totalTime(info.closeTimestamp)))}</td>
<td>{info.statement}</td>
<td>{info.state}</td>
{errorMessageCell(detail)}
Expand Down