HeartSaVioR commented on code in PR #59221:
URL: https://github.com/apache/spark/pull/59221#discussion_r4173244815


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/MicroBatchExecution.scala:
##########
@@ -899,6 +906,42 @@ class MicroBatchExecution(
     }
   }
 
+  private def recoverStatefulShufflePartitions(
+      metadata: OffsetSeqMetadataBase,
+      sparkSessionToRunBatches: SparkSession,
+      committedBatchId: Long): OffsetSeqMetadataBase = {
+    if (metadata.version != OffsetSeqLog.VERSION_2 ||
+        OffsetSeqMetadata.readValueOpt(
+          metadata, SQLConf.STATEFUL_SHUFFLE_PARTITIONS_INTERNAL).isDefined ||
+        committedBatchId < 0) {
+      metadata
+    } else {
+      metadata match {
+        case v2: OffsetSeqMetadataV2 =>
+          try {
+            val stateMetadataReader = new StateMetadataPartitionReader(
+              new Path(checkpointFile("state")).getParent.toString,
+              new 
SerializableConfiguration(sparkSessionToRunBatches.sessionState.newHadoopConf()),
+              committedBatchId)
+            stateMetadataReader.stateStoreNumPartitions.map { numPartitions =>
+              logWarning(log"Recovered state-store partition count " +
+                log"${MDC(CONFIG, SQLConf.SHUFFLE_PARTITIONS.key)}=" +
+                log"${MDC(NUM_PARTITIONS, numPartitions)} " +
+                log"from checkpoint state metadata because it was missing from 
the offset log")
+              OffsetSeqMetadata.withStatefulShufflePartitions(v2, 
numPartitions)
+            }.getOrElse(metadata)
+          } catch {
+            case NonFatal(e) =>

Review Comment:
   Let's also have the test case for this to verify we fail the query instead 
of continuing with blindly taking the session config's shuffle partitions.



-- 
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]

Reply via email to