Skip to content

Commit cbcd6e8

Browse files
committed
Minor fix
1 parent 7557ade commit cbcd6e8

File tree

1 file changed

+11
-6
lines changed
  • sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state

1 file changed

+11
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStore.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ object StateStore extends Logging {
125125
val MAINTENANCE_INTERVAL_CONFIG = "spark.sql.streaming.stateStore.maintenanceInterval"
126126
val MAINTENANCE_INTERVAL_DEFAULT_SECS = 60
127127

128+
@GuardedBy("loadedProviders")
128129
private val loadedProviders = new mutable.HashMap[StateStoreId, StateStoreProvider]()
129130

130131
class MaintenanceTask(periodMs: Long, task: => Unit, onError: => Unit) {
@@ -138,25 +139,28 @@ object StateStore extends Logging {
138139
} catch {
139140
case NonFatal(e) =>
140141
logWarning("Error running maintenance thread", e)
141-
future.cancel(false) // do interrupt active run, as this is being called from the run
142142
onError
143+
throw e
143144
}
144145
}
145146
}
146147

147148
private val future: ScheduledFuture[_] = executor.scheduleAtFixedRate(
148149
runnable, periodMs, periodMs, TimeUnit.MILLISECONDS)
149150

150-
def stop(): Unit = { future.cancel(false) }
151+
def stop(): Unit = {
152+
future.cancel(false)
153+
executor.shutdown()
154+
}
151155

152-
def isRunning: Boolean = !future.isCancelled
156+
def isRunning: Boolean = !future.isDone
153157
}
154158

155159
@GuardedBy("loadedProviders")
156-
@volatile private var maintenanceTask: MaintenanceTask = null
160+
private var maintenanceTask: MaintenanceTask = null
157161

158162
@GuardedBy("loadedProviders")
159-
@volatile private var _coordRef: StateStoreCoordinatorRef = null
163+
private var _coordRef: StateStoreCoordinatorRef = null
160164

161165
/** Get or create a store associated with the id. */
162166
def get(
@@ -238,6 +242,7 @@ object StateStore extends Logging {
238242
} catch {
239243
case NonFatal(e) =>
240244
logWarning(s"Error managing $provider, stopping management thread")
245+
throw e
241246
}
242247
}
243248
}
@@ -263,7 +268,7 @@ object StateStore extends Logging {
263268
}
264269
}
265270

266-
private def coordinatorRef: Option[StateStoreCoordinatorRef] = synchronized {
271+
private def coordinatorRef: Option[StateStoreCoordinatorRef] = loadedProviders.synchronized {
267272
val env = SparkEnv.get
268273
if (env != null) {
269274
if (_coordRef == null) {

0 commit comments

Comments
 (0)