gengliangwang commented on code in PR #60262:
URL: https://github.com/apache/spark/pull/60262#discussion_r4519949815
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ffi/NativeDataSource.scala:
##########
@@ -1412,17 +1417,21 @@ object NativeHandle extends Logging {
}
/**
- * The stream writers of the streaming queries, by query ID. The Data Source
V2 streaming write
- * has no hook for when the query stops, but a micro-batch streaming query
creates a new stream
- * writer for each micro-batch, after the previous micro-batch committed or
aborted its write, and
- * a restarted query creates a new one. So the previous stream writer of a
query is closed when
- * the query creates a new one, and the last one when it becomes unreachable.
+ * The stream writers of the streaming queries, by query ID, to close those
that are neither
+ * committed nor aborted: a stream writer closes its handle once its
micro-batch is committed or
+ * aborted. The Data Source V2 streaming write has no hook for when the query
stops, but a
+ * micro-batch streaming query creates a new stream writer for each
micro-batch, and a restarted
+ * query creates a new one. So a previous stream writer of a query that is
still open is closed
+ * when the query creates a new one, and the last one when it becomes
unreachable.
*/
object NativeStreamWriters {
// Weak, so that the last stream writer of a query can still become
unreachable.
private val writers = new ConcurrentHashMap[String,
WeakReference[NativeHandle]]()
- /** Registers the new stream writer of the query, and closes its previous
one. */
+ /**
+ * Registers the new stream writer of the query, and closes its previous
one, which has no effect
Review Comment:
Done in 74dfa2459c72: Reworded the comment above the `removeIf` to "Forgets
the queries whose last stream writer became unreachable."
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ffi/NativeDataSource.scala:
##########
@@ -593,17 +594,21 @@ class NativeDataSourceStreamWriter(
location, name, schema, timeZoneId, writerState, partitionId, taskId,
epochId)
}
- // Spark does not abort a committed micro-batch, see ColumnarStreamingWrite.
override def commit(epochId: Long, messages: Array[WriterCommitMessage]):
Unit = {
call(name, "commit a write to") {
library.commit(handle.get, epochId,
NativeWriterCommitMessage.toBytes(messages))
}
+ // Not closed if the commit fails: Spark then aborts the micro-batch,
which closes it. Spark
+ // does not abort a committed micro-batch, see ColumnarStreamingWrite.
+ handle.close()
}
override def abort(epochId: Long, messages: Array[WriterCommitMessage]):
Unit = {
- call(name, "abort a write to") {
- library.abort(handle.get, epochId,
NativeWriterCommitMessage.toBytes(messages))
- }
+ Utils.tryWithSafeFinally {
+ call(name, "abort a write to") {
+ library.abort(handle.get, epochId,
NativeWriterCommitMessage.toBytes(messages))
+ }
+ }(handle.close())
Review Comment:
Done in 74dfa2459c72: Added an "abort" failure step to native_sink's
abortWrite, right after it sets closed_marker. The adapter-level test now fails
the abort of both a batch and a stream writer without a commit, and asserts the
NATIVE_DATA_SOURCE_ERROR plus `_CLOSED` / `_CLOSED_0`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]