LuciferYang commented on code in PR #58167:
URL: https://github.com/apache/spark/pull/58167#discussion_r4573390877


##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -1054,6 +1054,24 @@
     ],
     "sqlState" : "55019"
   },
+  "CHECKPOINT_DIRECTORY_PARTITION_COUNT_MISMATCH" : {
+    "message" : [
+      "The checkpoint directory <path> records <expected> partition(s) but 
<found> partition file(s) were found."
+    ],
+    "subClass" : {
+      "MISSING_FILES" : {
+        "message" : [
+          "One or more trailing part files may have been lost. Use 
`spark.checkpoint.verifyPartitionCount.enabled=false` to bypass this check and 
load the truncated directory as-is."

Review Comment:
   For keyed DStream state, loading with the check off does not go as the error 
text suggests. State checkpoints from `mapWithState`, the default 
`updateStateByKey` overloads, and `reduceByKeyAndWindow` with an inverse 
function keep `_partitioner`, so the RDD loaded from the M surviving files 
still reports `HashPartitioner(N)`. `updateStateByKey` and 
`reduceByKeyAndWindow` then fail the first batch with 
`ArrayIndexOutOfBoundsException`. `mapWithState` builds only M partitions, so 
updates for keys in the missing partitions are dropped every batch with no 
error, and later checkpoints record M, so the check no longer sees the loss.
   
   This predates the PR, but the error text now recommends it on DStream 
recovery, the only production reader. Could both sub-condition texts and the 
config doc warn that for keyed state this can fail the batch or silently drop 
data? Ignoring a recorded partitioner whose count no longer matches would fix 
the behavior, but I would keep that out of this PR.



##########
streaming/src/main/scala/org/apache/spark/streaming/Checkpoint.scala:
##########
@@ -68,7 +69,10 @@ class Checkpoint(ssc: StreamingContext, val checkpointTime: 
Time)
       "spark.yarn.principal",
       "spark.kerberos.keytab",
       "spark.kerberos.principal",
-      UI_FILTERS.key)
+      UI_FILTERS.key,
+      // An operator who hits CHECKPOINT_DIRECTORY_PARTITION_COUNT_MISMATCH on 
recovery is told to
+      // restart with this flag off; it must be read from the new environment 
for that to work.
+      CHECKPOINT_VERIFY_PARTITION_COUNT_ENABLED.key)

Review Comment:
   Adding the key to `propertiesToReload`, which I suggested last round, makes 
the flag stick once used. `createSparkConf()` starts from the saved 
`sparkConfPairs` and overrides a reloaded key only when the new environment 
sets it, and every later `Checkpoint` saves the recovered conf. So after one 
restart with `--conf spark.checkpoint.verifyPartitionCount.enabled=false`, 
later restarts without the flag still run with the check off, and since the key 
is internal, nothing tells the operator to pass `=true`.
   
   Adding `.remove(CHECKPOINT_VERIFY_PARTITION_COUNT_ENABLED.key)` to the chain 
below would take the value only from the current launch. A `false` set in 
`creatingFunc`'s conf would not survive recovery, which seems fine for a 
launch-time flag. To pin it, the test could stop the context the SPARK-6331 
block leaves running (otherwise `SparkContext.getOrCreate` reuses it), recover 
from `newCp` with `verifyKey=false`, check the recovered conf has `false`, 
build a `Checkpoint` from it, clear the property, and assert its 
`createSparkConf()` lacks `verifyKey`.



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