Skip to content

Commit

Permalink
[SPARK-8839] [SQL] ThriftServer2 will remove session and execution no…
Browse files Browse the repository at this point in the history
… matter it's finished or not.

In my test, `sessions` and `executions` in ThriftServer2 is not the same number as the connection number.
For example, if there are 200 clients connecting to the server,  but it will have more than 200 `sessions` and `executions`.
So if it reaches the `retainedStatements`, it has to remove some object which is not finished.
So it may cause the exception described in [Jira Address](https://issues.apache.org/jira/browse/SPARK-8839)

Author: huangzhaowei <carlmartinmax@gmail.com>

Closes #7239 from SaintBacchus/SPARK-8839 and squashes the following commits:

cf7ef40 [huangzhaowei] Remove the a meanless funciton call
3e9a5a6 [huangzhaowei] Add a filter before take
9d5ceb8 [huangzhaowei] [SPARK-8839][SQL]ThriftServer2 will remove session and execution no matter it's finished or not.
  • Loading branch information
SaintBacchus authored and liancheng committed Jul 10, 2015
1 parent 2727304 commit 1903641
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ object HiveThriftServer2 extends Logging {
def onSessionClosed(sessionId: String): Unit = {
sessionList(sessionId).finishTimestamp = System.currentTimeMillis
onlineSessionNum -= 1
trimSessionIfNecessary()
}

def onStatementStart(
Expand Down Expand Up @@ -206,18 +207,20 @@ object HiveThriftServer2 extends Logging {
executionList(id).detail = errorMessage
executionList(id).state = ExecutionState.FAILED
totalRunning -= 1
trimExecutionIfNecessary()
}

def onStatementFinish(id: String): Unit = {
executionList(id).finishTimestamp = System.currentTimeMillis
executionList(id).state = ExecutionState.FINISHED
totalRunning -= 1
trimExecutionIfNecessary()
}

private def trimExecutionIfNecessary() = synchronized {
if (executionList.size > retainedStatements) {
val toRemove = math.max(retainedStatements / 10, 1)
executionList.take(toRemove).foreach { s =>
executionList.filter(_._2.finishTimestamp != 0).take(toRemove).foreach { s =>
executionList.remove(s._1)
}
}
Expand All @@ -226,7 +229,7 @@ object HiveThriftServer2 extends Logging {
private def trimSessionIfNecessary() = synchronized {
if (sessionList.size > retainedSessions) {
val toRemove = math.max(retainedSessions / 10, 1)
sessionList.take(toRemove).foreach { s =>
sessionList.filter(_._2.finishTimestamp != 0).take(toRemove).foreach { s =>
sessionList.remove(s._1)
}
}
Expand Down

0 comments on commit 1903641

Please sign in to comment.