Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/16220#discussion_r91637016
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/streaming/StreamingQueryManager.scala
---
@@ -265,31 +278,53 @@ class StreamingQueryManager private[sql]
(sparkSession: SparkSession) {
}
val query = new StreamExecution(
sparkSession,
- name,
+ userSpecifiedName.orNull,
checkpointLocation,
logicalPlan,
sink,
trigger,
triggerClock,
outputMode)
- if (activeQueries.values.exists(_.id == query.id)) {
- throw new IllegalStateException(
- s"Cannot start query with id ${query.id} as another query with
same id is " +
- s"already active. Perhaps you are attempting to restart a
query from checkpoint" +
- s"that is already active.")
+ activeQueriesLock.synchronized {
+ if (activeQueries.values.exists(_.id == query.id) ||
pendingQueryIds.contains(query.id)) {
+ throw new IllegalStateException(
+ s"Cannot start query with id ${query.id} as another query with
same id is " +
+ s"already active. Perhaps you are attempting to restart a
query from checkpoint" +
+ s"that is already active.")
+ }
+ pendingQueryIds += query.id
+ }
+ try {
+ query.start()
+ activeQueriesLock.synchronized {
+ // It's possible that `notifyQueryTermination` is called before
we reach here. So we
+ // need to check the query status before adding it into
`activeQueries`.
+ if (query.isActive) {
+ activeQueries.put(query.id, query)
+ pendingQueryIds -= query.id
+ userSpecifiedName.foreach(name => pendingQueryNames -= name)
+ }
+ }
+ query
+ } finally {
+ // In case `query.start()` fails
+ activeQueriesLock.synchronized { pendingQueryIds -= query.id }
+ }
+ } finally {
--- End diff --
you can reduce the nested finally by keeping the id in a var.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]