You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "mrcnc (via GitHub)" <gi...@apache.org> on 2024/12/02 23:18:31 UTC

Re: [PR] GCP: Implement SupportsRecoveryOperations for GCSFileIO [iceberg]

mrcnc commented on code in PR #11565:
URL: https://github.com/apache/iceberg/pull/11565#discussion_r1866755677


##########
gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java:
##########
@@ -242,4 +250,116 @@ private void internalDeleteFiles(Stream<BlobId> blobIdsToDelete) {
     Streams.stream(Iterators.partition(blobIdsToDelete.iterator(), gcpProperties.deleteBatchSize()))
         .forEach(batch -> client().delete(batch));
   }
+
+  @Override
+  public boolean recoverFile(String path) {
+    Preconditions.checkArgument(
+        !Strings.isNullOrEmpty(path), "Cannot recover file: path must not be null or empty");
+
+    try {
+      BlobId blobId = BlobId.fromGsUtilUri(path);
+
+      // first attempt to restore with soft-delete
+      if (recoverSoftDeletedObject(blobId)) {
+        return true;
+      }
+
+      // fallback to restoring by copying the latest version
+      if (recoverLatestVersion(blobId)) {
+        return true;
+      }
+
+    } catch (IllegalArgumentException e) {
+      LOG.warn("Invalid GCS path format: {}", path, e);
+    }
+
+    return false;
+  }
+
+  /**
+   * Attempts to restore a soft-deleted object.
+   *
+   * <p>Requires {@code storage.objects.restore} permission
+   *
+   * <p>See <a
+   * href="https://cloud.google.com/storage/docs/use-soft-deleted-objects#restore">docs</a>
+   *
+   * @param blobId the blob identifier
+   * @return {@code true} if blob was recovered, {@code false} if not
+   */
+  protected boolean recoverSoftDeletedObject(BlobId blobId) {
+    try {
+      BucketInfo.SoftDeletePolicy policy = client().get(blobId.getBucket()).getSoftDeletePolicy();
+      if (Duration.ofSeconds(0).equals(policy.getRetentionDuration())) {

Review Comment:
   Good point!  I think we can remove the check for the soft delete policy b/c the list will return 0 soft deleted objects



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org