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


##########
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:
   If we fail to get the value from both offset log and state metadata, yes we 
do not have a way to know the true value of state shuffle partitions, and we 
must not pick the session config value because this violates why we pin the 
config.



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