You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "yuzelin (via GitHub)" <gi...@apache.org> on 2023/06/13 09:34:50 UTC

[GitHub] [incubator-paimon] yuzelin opened a new pull request, #1363: [core] Support deleting tag

yuzelin opened a new pull request, #1363:
URL: https://github.com/apache/incubator-paimon/pull/1363

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #1362
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   `FileStoreTableTestBase#testDeleteTag`
   
   File deletion test:
   `FileDeletionTest#testDeleteTagWithSnapshot`
   `FileDeletionTest#testDeleteTagWithOtherTag`
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
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@paimon.apache.org

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


[GitHub] [incubator-paimon] yuzelin closed pull request #1363: [core] Support deleting tag

Posted by "yuzelin (via GitHub)" <gi...@apache.org>.
yuzelin closed pull request #1363: [core] Support deleting tag
URL: https://github.com/apache/incubator-paimon/pull/1363


-- 
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@paimon.apache.org

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


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1363: [core] Support deleting tag

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1363:
URL: https://github.com/apache/incubator-paimon/pull/1363#discussion_r1233630165


##########
paimon-core/src/test/java/org/apache/paimon/table/IndexFileExpireTableTest.java:
##########
@@ -112,6 +112,20 @@ public void testIndexFileExpirationWithTag() throws Exception {
         checkIndexFiles(tagManager.taggedSnapshot("tag5"));
     }
 
+    @Test
+    public void testIndexFileExpirationWhenDeletingTag() throws Exception {

Review Comment:
   This test is too simple.



##########
paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java:
##########
@@ -281,4 +283,20 @@ public void createTag(String tagName, long fromSnapshotId) {
         TagManager tagManager = new TagManager(fileIO, path);
         tagManager.createTag(snapshot, tagName);
     }
+
+    @Override
+    public void deleteTag(String tagName) {
+        checkArgument(!StringUtils.isBlank(tagName), "Tag name '%s' is blank.", tagName);
+
+        TagManager tagManager = new TagManager(fileIO, path);
+        SnapshotManager snapshotManager = snapshotManager();
+        Snapshot taggedSnapshot = tagManager.taggedSnapshot(tagName);
+
+        if (!snapshotManager.snapshotExists(taggedSnapshot.id())) {

Review Comment:
   `if (!snapshotManager.snapshotExists(taggedSnapshot.id())) {`
   Put this into `tagDeletion.delete`.



##########
paimon-core/src/main/java/org/apache/paimon/operation/TagDeletion.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileHandler;
+import org.apache.paimon.manifest.IndexManifestEntry;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.manifest.ManifestFile;
+import org.apache.paimon.manifest.ManifestFileMeta;
+import org.apache.paimon.manifest.ManifestList;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.TagManager;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.paimon.operation.DeletionUtils.containsDataFile;
+import static org.apache.paimon.operation.DeletionUtils.indexDataFiles;
+import static org.apache.paimon.operation.DeletionUtils.readEntries;
+import static org.apache.paimon.operation.DeletionUtils.tryDeleteDirectories;
+
+/**
+ * Delete tag files. This class doesn't check changelog files because they are handled by {@link
+ * SnapshotDeletion}.
+ */
+public class TagDeletion {
+
+    private final FileIO fileIO;
+    private final FileStorePathFactory pathFactory;
+    private final ManifestList manifestList;
+    private final ManifestFile manifestFile;
+    private final IndexFileHandler indexFileHandler;
+
+    private final SnapshotManager snapshotManager;
+    private final List<Snapshot> taggedSnapshots;
+
+    private final Map<BinaryRow, Map<Integer, Set<String>>> skippedDataFiles;
+    private final Set<String> skippedManifests;
+
+    public TagDeletion(
+            FileIO fileIO,
+            Path tablePath,
+            FileStorePathFactory pathFactory,
+            ManifestList manifestList,
+            ManifestFile manifestFile,
+            IndexFileHandler indexFileHandler) {
+        this.fileIO = fileIO;
+        this.pathFactory = pathFactory;
+        this.manifestList = manifestList;
+        this.manifestFile = manifestFile;
+        this.indexFileHandler = indexFileHandler;
+
+        this.snapshotManager = new SnapshotManager(fileIO, tablePath);
+        this.taggedSnapshots = new TagManager(fileIO, tablePath).taggedSnapshots();
+
+        this.skippedDataFiles = new HashMap<>();
+        this.skippedManifests = new HashSet<>();
+    }
+
+    /** Delete unused data files, manifest files and empty data file directories of tag. */
+    public void delete(Snapshot taggedSnapshot) {
+        // collect from the earliest snapshot's base
+        Snapshot earliest = snapshotManager.snapshot(snapshotManager.earliestSnapshotId());
+        collectSkip(earliest.baseManifests(manifestList));
+
+        // collect from the neighbor tags
+        int index = findIndex(taggedSnapshot);
+        if (index - 1 >= 0) {
+            collectSkip(taggedSnapshots.get(index - 1).dataManifests(manifestList));
+        }
+        if (index + 1 < taggedSnapshots.size()) {
+            collectSkip(taggedSnapshots.get(index + 1).dataManifests(manifestList));
+        }
+
+        // delete data files and empty directories
+        deleteDataFiles(taggedSnapshot);
+        // delete manifests
+        deleteManifestFiles(taggedSnapshot);
+    }
+
+    private void collectSkip(List<ManifestFileMeta> manifestFileMetas) {
+        Iterable<ManifestEntry> entries = readEntries(manifestFileMetas, manifestFile);
+        indexDataFiles(skippedDataFiles, ManifestEntry.mergeEntries(entries));
+        skippedManifests.addAll(

Review Comment:
   You should use `SnapshotDeletion.collectManifestSkippingSet`.



##########
paimon-core/src/main/java/org/apache/paimon/operation/TagDeletion.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileHandler;
+import org.apache.paimon.manifest.IndexManifestEntry;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.manifest.ManifestFile;
+import org.apache.paimon.manifest.ManifestFileMeta;
+import org.apache.paimon.manifest.ManifestList;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.TagManager;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.paimon.operation.DeletionUtils.containsDataFile;
+import static org.apache.paimon.operation.DeletionUtils.indexDataFiles;
+import static org.apache.paimon.operation.DeletionUtils.readEntries;
+import static org.apache.paimon.operation.DeletionUtils.tryDeleteDirectories;
+
+/**
+ * Delete tag files. This class doesn't check changelog files because they are handled by {@link
+ * SnapshotDeletion}.
+ */
+public class TagDeletion {
+
+    private final FileIO fileIO;
+    private final FileStorePathFactory pathFactory;
+    private final ManifestList manifestList;
+    private final ManifestFile manifestFile;
+    private final IndexFileHandler indexFileHandler;
+
+    private final SnapshotManager snapshotManager;
+    private final List<Snapshot> taggedSnapshots;
+
+    private final Map<BinaryRow, Map<Integer, Set<String>>> skippedDataFiles;
+    private final Set<String> skippedManifests;
+
+    public TagDeletion(
+            FileIO fileIO,
+            Path tablePath,
+            FileStorePathFactory pathFactory,
+            ManifestList manifestList,
+            ManifestFile manifestFile,
+            IndexFileHandler indexFileHandler) {
+        this.fileIO = fileIO;
+        this.pathFactory = pathFactory;
+        this.manifestList = manifestList;
+        this.manifestFile = manifestFile;
+        this.indexFileHandler = indexFileHandler;
+
+        this.snapshotManager = new SnapshotManager(fileIO, tablePath);
+        this.taggedSnapshots = new TagManager(fileIO, tablePath).taggedSnapshots();
+
+        this.skippedDataFiles = new HashMap<>();
+        this.skippedManifests = new HashSet<>();
+    }
+
+    /** Delete unused data files, manifest files and empty data file directories of tag. */
+    public void delete(Snapshot taggedSnapshot) {
+        // collect from the earliest snapshot's base
+        Snapshot earliest = snapshotManager.snapshot(snapshotManager.earliestSnapshotId());
+        collectSkip(earliest.baseManifests(manifestList));
+
+        // collect from the neighbor tags
+        int index = findIndex(taggedSnapshot);
+        if (index - 1 >= 0) {
+            collectSkip(taggedSnapshots.get(index - 1).dataManifests(manifestList));
+        }
+        if (index + 1 < taggedSnapshots.size()) {
+            collectSkip(taggedSnapshots.get(index + 1).dataManifests(manifestList));
+        }
+
+        // delete data files and empty directories
+        deleteDataFiles(taggedSnapshot);
+        // delete manifests
+        deleteManifestFiles(taggedSnapshot);
+    }
+
+    private void collectSkip(List<ManifestFileMeta> manifestFileMetas) {
+        Iterable<ManifestEntry> entries = readEntries(manifestFileMetas, manifestFile);
+        indexDataFiles(skippedDataFiles, ManifestEntry.mergeEntries(entries));

Review Comment:
   `readEntries` and `indexDataFiles` always together.
   You can introduce a method to do two things.



-- 
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@paimon.apache.org

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


[GitHub] [incubator-paimon] yuzelin merged pull request #1363: [core] Support deleting tag

Posted by "yuzelin (via GitHub)" <gi...@apache.org>.
yuzelin merged PR #1363:
URL: https://github.com/apache/incubator-paimon/pull/1363


-- 
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@paimon.apache.org

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


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1363: [core] Support deleting tag

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1363:
URL: https://github.com/apache/incubator-paimon/pull/1363#discussion_r1230393460


##########
paimon-core/src/main/java/org/apache/paimon/operation/DeletionUtils.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.manifest.ManifestFile;
+import org.apache.paimon.manifest.ManifestFileMeta;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.ParallellyExecuteUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** Util methods for snapshot and tag deletion. */
+public class DeletionUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DeletionUtils.class);
+
+    public static Iterable<ManifestEntry> readEntries(
+            List<ManifestFileMeta> manifests, ManifestFile manifestFile) {
+        return ParallellyExecuteUtils.parallelismBatchIterable(
+                files ->
+                        files.parallelStream()
+                                .flatMap(m -> manifestFile.read(m.fileName()).stream())
+                                .collect(Collectors.toList()),
+                manifests,
+                null);

Review Comment:
   It is better to read number from configuration.



##########
paimon-core/src/main/java/org/apache/paimon/operation/DeletionUtils.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.manifest.ManifestFile;
+import org.apache.paimon.manifest.ManifestFileMeta;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.ParallellyExecuteUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** Util methods for snapshot and tag deletion. */
+public class DeletionUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DeletionUtils.class);
+
+    public static Iterable<ManifestEntry> readEntries(
+            List<ManifestFileMeta> manifests, ManifestFile manifestFile) {
+        return ParallellyExecuteUtils.parallelismBatchIterable(
+                files ->
+                        files.parallelStream()
+                                .flatMap(m -> manifestFile.read(m.fileName()).stream())
+                                .collect(Collectors.toList()),
+                manifests,
+                null);
+    }
+
+    public static void indexDataFiles(

Review Comment:
   Don't name `indexDataFile`, it will be confused with `indexFiles`(see Snapshot.indexManifest).



-- 
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@paimon.apache.org

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


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1363: [core] Support deleting tag

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1363:
URL: https://github.com/apache/incubator-paimon/pull/1363#discussion_r1233632226


##########
paimon-core/src/main/java/org/apache/paimon/operation/TagDeletion.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileHandler;
+import org.apache.paimon.manifest.IndexManifestEntry;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.manifest.ManifestFile;
+import org.apache.paimon.manifest.ManifestFileMeta;
+import org.apache.paimon.manifest.ManifestList;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.TagManager;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.paimon.operation.DeletionUtils.containsDataFile;
+import static org.apache.paimon.operation.DeletionUtils.indexDataFiles;
+import static org.apache.paimon.operation.DeletionUtils.readEntries;
+import static org.apache.paimon.operation.DeletionUtils.tryDeleteDirectories;
+
+/**
+ * Delete tag files. This class doesn't check changelog files because they are handled by {@link
+ * SnapshotDeletion}.
+ */
+public class TagDeletion {
+
+    private final FileIO fileIO;
+    private final FileStorePathFactory pathFactory;
+    private final ManifestList manifestList;
+    private final ManifestFile manifestFile;
+    private final IndexFileHandler indexFileHandler;
+
+    private final SnapshotManager snapshotManager;
+    private final List<Snapshot> taggedSnapshots;
+
+    private final Map<BinaryRow, Map<Integer, Set<String>>> skippedDataFiles;
+    private final Set<String> skippedManifests;
+
+    public TagDeletion(
+            FileIO fileIO,
+            Path tablePath,
+            FileStorePathFactory pathFactory,
+            ManifestList manifestList,
+            ManifestFile manifestFile,
+            IndexFileHandler indexFileHandler) {
+        this.fileIO = fileIO;
+        this.pathFactory = pathFactory;
+        this.manifestList = manifestList;
+        this.manifestFile = manifestFile;
+        this.indexFileHandler = indexFileHandler;
+
+        this.snapshotManager = new SnapshotManager(fileIO, tablePath);
+        this.taggedSnapshots = new TagManager(fileIO, tablePath).taggedSnapshots();
+
+        this.skippedDataFiles = new HashMap<>();
+        this.skippedManifests = new HashSet<>();
+    }
+
+    /** Delete unused data files, manifest files and empty data file directories of tag. */
+    public void delete(Snapshot taggedSnapshot) {
+        // collect from the earliest snapshot's base
+        Snapshot earliest = snapshotManager.snapshot(snapshotManager.earliestSnapshotId());
+        collectSkip(earliest.baseManifests(manifestList));
+
+        // collect from the neighbor tags
+        int index = findIndex(taggedSnapshot);
+        if (index - 1 >= 0) {
+            collectSkip(taggedSnapshots.get(index - 1).dataManifests(manifestList));
+        }
+        if (index + 1 < taggedSnapshots.size()) {
+            collectSkip(taggedSnapshots.get(index + 1).dataManifests(manifestList));
+        }
+
+        // delete data files and empty directories
+        deleteDataFiles(taggedSnapshot);
+        // delete manifests
+        deleteManifestFiles(taggedSnapshot);
+    }
+
+    private void collectSkip(List<ManifestFileMeta> manifestFileMetas) {
+        Iterable<ManifestEntry> entries = readEntries(manifestFileMetas, manifestFile);
+        indexDataFiles(skippedDataFiles, ManifestEntry.mergeEntries(entries));

Review Comment:
   `ManifestEntry.mergeEntries` and `indexDataFiles` always together.
   You can introduce a method to do two things.



-- 
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@paimon.apache.org

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