You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:20:21 UTC

[GitHub] [iceberg] aokolnychyi commented on a change in pull request #1245: Refactor RemoveSnapshots for easier extension

aokolnychyi commented on a change in pull request #1245:
URL: https://github.com/apache/iceberg/pull/1245#discussion_r461930099



##########
File path: core/src/main/java/org/apache/iceberg/ManifestExpirationManager.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.iceberg;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UncheckedIOException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.util.ExpireSnapshotUtil;
+import org.apache.iceberg.util.ExpireSnapshotUtil.ManifestExpirationChanges;
+import org.apache.iceberg.util.ExpireSnapshotUtil.SnapshotExpirationChanges;
+import org.apache.iceberg.util.Tasks;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManifestExpirationManager implements Serializable {
+  private static final Logger LOG = LoggerFactory.getLogger(ManifestExpirationManager.class);
+  private final SnapshotExpirationChanges snapshotChanges;
+  private final Set<Long> validSnapshotIds;
+  private final ManifestExpirationChanges manifestChanges;
+  private final Map<Integer, PartitionSpec> specLookup;
+  private final FileIO io;
+
+  public ManifestExpirationManager(TableMetadata original, TableMetadata current, FileIO io){
+    this.io = io;
+    this.specLookup = current.specsById();
+    this.snapshotChanges = ExpireSnapshotUtil.getExpiredSnapshots(current, original);
+    this.validSnapshotIds = snapshotChanges.getValidSnapshotIds();
+    if (snapshotChanges.getExpiredSnapshots().size() != 0) {
+      this.manifestChanges = ExpireSnapshotUtil.determineManifestChangesFromSnapshotExpiration(
+          snapshotChanges.getValidSnapshotIds(), snapshotChanges.getExpiredSnapshotIds(), current, original, io);
+    } else {
+      this.manifestChanges = null;
+    }
+  }
+
+  public ManifestExpirationChanges getManifestChanges() {
+    return manifestChanges;
+  }
+
+  public SnapshotExpirationChanges getSnapshotChanges() {
+    return snapshotChanges;
+  }
+
+  public Set<String> scanManifestsForAbandonedDeletedFiles() {
+    if (manifestChanges != null) {
+      return scanManifestsForAbandonedDeletedFiles(manifestChanges.manifestsToScan());
+    } else {
+      return Sets.newHashSet();
+    }
+  }
+
+  public Set<String> scanManifestsForAbandonedDeletedFiles(Set<ManifestFile> manifestsWithDeletes) {
+    Set<String> filesToDelete = new HashSet<>();

Review comment:
       Is it thread-safe, btw?




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

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