mahsoodebrahim commented on code in PR #18696:
URL: https://github.com/apache/hudi/pull/18696#discussion_r3262912774


##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/RestoreToInstantProcedure.scala:
##########
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hudi.command.procedures
+
+import org.apache.hudi.HoodieCLIUtils
+import org.apache.hudi.avro.model.HoodieRestoreMetadata
+import org.apache.hudi.client.SparkRDDWriteClient
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.fs.ConsistencyGuardConfig
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.table.timeline.HoodieInstant
+import org.apache.hudi.config.HoodieWriteConfig
+import org.apache.hudi.exception.HoodieException
+import org.apache.hudi.hadoop.fs.HadoopFSUtils
+import org.apache.hudi.storage.StoragePath
+
+import org.apache.hadoop.fs.Path
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.hudi.command.procedures.RestoreToInstantProcedure._
+import org.apache.spark.sql.types.{DataTypes, Metadata, StructField, 
StructType}
+
+import java.util.function.Supplier
+
+import scala.collection.JavaConverters._
+
+/**
+ * Stored procedure to perform a full point-in-time table restore to a given 
instant.
+ *
+ * Unlike [[RollbackToSavepointProcedure]] (which requires a savepoint at the 
target instant),
+ * this procedure calls restoreToInstant() directly and works on any arbitrary 
instant on the
+ * active timeline.
+ *
+ * Parameters:
+ *   - table / path: identifies the Hudi table (one must be provided)
+ *   - instant_time: target commit to restore to (required when 
audit_only=false; must be omitted
+ *                   when audit_only=true)
+ *   - restore_instant_time: the restore operation's own timeline timestamp 
(the start_restore_time
+ *                   value returned by a prior restore_to_instant call). 
Required when
+ *                   audit_only=true; must be omitted otherwise.
+ *   - enable_metadata: whether the metadata table is enabled (default: true)
+ *   - rollback_parallelism: Spark parallelism for rollback and audit 
operations (default: 4)
+ *   - enable_consistency_guard: enable consistency guard for file existence 
checks (default: false)
+ *   - audit_post_restore: after restoring, verify that all rolled-back files 
are absent (default: false)
+ *   - audit_only: skip the restore and only audit a previously completed 
restore instant (default: false)
+ *
+ * Output columns:
+ *   - restore_result: true if restore succeeded; null if audit_only=true
+ *   - start_restore_time: the restore operation's own timeline timestamp; 
null if audit_only=true.
+ *                         Save this value to use as restore_instant_time for 
a subsequent audit_only call.
+ *   - time_taken_in_millis: restore duration; null if audit_only=true
+ *   - instants_rolled_back: number of commits rolled back; null if 
audit_only=true
+ *   - audit_result: one of "PASSED" / "FAILED" / "INCONCLUSIVE" when an audit 
ran; null otherwise.
+ *                   INCONCLUSIVE means at least one file existence check 
threw an IOException
+ *                   (e.g. transient cloud-storage timeout) — re-run 
audit_only=true to retry.
+ */
+class RestoreToInstantProcedure extends BaseProcedure with ProcedureBuilder 
with Logging {
+
+  private val PARAMETERS = Array[ProcedureParameter](
+    ProcedureParameter.optional(0, "table", DataTypes.StringType),
+    ProcedureParameter.optional(1, "instant_time", DataTypes.StringType),
+    ProcedureParameter.optional(2, "enable_metadata", DataTypes.BooleanType, 
true),
+    ProcedureParameter.optional(3, "rollback_parallelism", 
DataTypes.IntegerType, 4),
+    ProcedureParameter.optional(4, "enable_consistency_guard", 
DataTypes.BooleanType, false),
+    ProcedureParameter.optional(5, "audit_post_restore", 
DataTypes.BooleanType, false),
+    ProcedureParameter.optional(6, "audit_only", DataTypes.BooleanType, false),
+    ProcedureParameter.optional(7, "path", DataTypes.StringType),
+    ProcedureParameter.optional(8, "restore_instant_time", 
DataTypes.StringType)

Review Comment:
   The input parameter is now start_restore_time to match the output column. 
The round-trip is now self-evident: capture start_restore_time from the result 
row, pass it as start_restore_time in the audit call.



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

Reply via email to