You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "TaoZex (via GitHub)" <gi...@apache.org> on 2023/12/30 16:52:20 UTC

[PR] [Core]Support create and delete branch [incubator-paimon]

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

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   Introduce branch for paimon
   Linked issue: https://github.com/apache/incubator-paimon/issues/2148
   task:https://github.com/apache/incubator-paimon/issues/1795
   <!-- What is the purpose of the change -->
   
   Next, I'll complete the functionality of merge and replace branch, and then finish flink and spark's implementation of this feature.
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### 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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.paimon.schema.SchemaManager.SCHEMA_PREFIX;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SnapshotManager.SNAPSHOT_PREFIX;
+import static org.apache.paimon.utils.TagManager.TAG_PREFIX;
+
+/** Manager for {@code Branch}. */
+public class BranchManager {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BranchManager.class);
+
+    private static final String BRANCH_PREFIX = "branch-";
+
+    private final FileIO fileIO;
+    private final Path tablePath;
+
+    public BranchManager(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.tablePath = path;
+    }
+
+    /** Return the root Directory of branch. */
+    public Path branchDirectory() {
+        return new Path(tablePath + "/branch");
+    }
+
+    /** Return the path of a branch. */
+    public String getBranchPath(String branchName) {
+        return tablePath + "/branch/" + BRANCH_PREFIX + branchName;
+    }
+
+    public Path branchPath(String branchName) {
+        return new Path(getBranchPath(branchName));
+    }
+
+    public Path tagPath(String tagName) {
+        return new Path(tablePath + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path branchTagPath(String branchName, String tagName) {
+        return new Path(getBranchPath(branchName) + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path snapshotPath(long snapshotId) {
+        return new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path branchSnapshotPath(String branchName, long snapshotId) {
+        return new Path(getBranchPath(branchName) + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path schemaPath(long schemaId) {
+        return new Path(tablePath + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public Path branchSchemaPath(String branchName, long schemaId) {
+        return new Path(getBranchPath(branchName) + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public void createBranch(String branchName, String tagName) {
+        checkArgument(!StringUtils.isBlank(branchName), "Branch name '%s' is blank.", branchName);
+        checkArgument(!branchExists(branchName), "Branch name '%s' already exists.", branchName);
+        checkArgument(tagExists(tagName), "Tag name '%s' not exists.", tagName);
+        checkArgument(
+                !branchName.chars().allMatch(Character::isDigit),
+                "Branch name cannot be pure numeric string but is '%s'.",
+                branchName);
+
+        Snapshot snapshot = taggedSnapshot(tagName);
+
+        try {
+            // Copy the corresponding tag, snapshot and schema files into the branch directory
+            fileIO.copyFileUtf8(tagPath(tagName), branchTagPath(branchName, tagName));
+            fileIO.copyFileUtf8(
+                    snapshotPath(snapshot.id()), branchSnapshotPath(branchName, snapshot.id()));
+            fileIO.copyFileUtf8(
+                    schemaPath(snapshot.schemaId()),
+                    branchSchemaPath(branchName, snapshot.schemaId()));
+        } catch (IOException e) {
+            throw new RuntimeException(
+                    String.format(
+                            "Exception occurs when create branch '%s' (directory in %s).",
+                            branchName, getBranchPath(branchName)),
+                    e);
+        }
+    }
+
+    public void deleteBranch(String branchName) {
+        checkArgument(branchExists(branchName), "Branch name '%s' doesn't exist.", branchName);
+        try {
+            // Delete branch directory
+            fileIO.delete(branchPath(branchName), true);
+        } catch (IOException e) {
+            LOG.info(
+                    String.format(
+                            "Deleting the branch failed due to an exception in deleting the directory %s. Please try again.",
+                            getBranchPath(branchName)),
+                    e);
+        }
+    }
+
+    /** Check if path exists. */
+    public boolean fileExists(Path path) {
+        try {
+            if (fileIO.exists(path)) {
+                return true;
+            }
+            return false;
+        } catch (IOException e) {
+            throw new RuntimeException(
+                    String.format("Failed to determine if path '%s' exists.", path), e);
+        }
+    }
+
+    /** Check if a tag exists. */
+    public boolean tagExists(String tagName) {

Review Comment:
   We should not check if a tag exist in `BranchManager`



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


Re: [PR] [Core]Support branch [incubator-paimon]

Posted by "FangYongs (via GitHub)" <gi...@apache.org>.
FangYongs commented on PR #2608:
URL: https://github.com/apache/incubator-paimon/pull/2608#issuecomment-1891201816

   @TaoZex  I found that this PR has added "merge" relevant codes, involving modifications to the file store without tests. Can we follow the original PR implementation to only introduce the `BranchManager` to support `create` and `delete` branch but not involve modifications to the file store? I think this can reduce the risk and merge this PR as soon as possible.


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


Re: [PR] [Core]Support branch [incubator-paimon]

Posted by "TaoZex (via GitHub)" <gi...@apache.org>.
TaoZex commented on PR #2608:
URL: https://github.com/apache/incubator-paimon/pull/2608#issuecomment-1891411505

   @FangYongs Thanks for your advice. I will make changes according to your suggestions, and submit a new pr about merge and replace branch after this pr is merged(with file store tests).


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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.paimon.schema.SchemaManager.SCHEMA_PREFIX;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SnapshotManager.SNAPSHOT_PREFIX;
+import static org.apache.paimon.utils.TagManager.TAG_PREFIX;
+
+/** Manager for {@code Branch}. */
+public class BranchManager {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BranchManager.class);
+
+    private static final String BRANCH_PREFIX = "branch-";
+
+    private final FileIO fileIO;
+    private final Path tablePath;
+
+    public BranchManager(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.tablePath = path;
+    }
+
+    /** Return the root Directory of branch. */
+    public Path branchDirectory() {
+        return new Path(tablePath + "/branch");
+    }
+
+    /** Return the path of a branch. */
+    public String getBranchPath(String branchName) {
+        return tablePath + "/branch/" + BRANCH_PREFIX + branchName;
+    }
+
+    public Path branchPath(String branchName) {
+        return new Path(getBranchPath(branchName));
+    }
+
+    public Path tagPath(String tagName) {
+        return new Path(tablePath + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path branchTagPath(String branchName, String tagName) {
+        return new Path(getBranchPath(branchName) + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path snapshotPath(long snapshotId) {
+        return new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path branchSnapshotPath(String branchName, long snapshotId) {
+        return new Path(getBranchPath(branchName) + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path schemaPath(long schemaId) {
+        return new Path(tablePath + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public Path branchSchemaPath(String branchName, long schemaId) {

Review Comment:
   We should not build tag, snapshot and schema path in `BranchManager`



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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

Posted by "TaoZex (via GitHub)" <gi...@apache.org>.
TaoZex commented on PR #2608:
URL: https://github.com/apache/incubator-paimon/pull/2608#issuecomment-1882576547

   > Hi @TaoZex , are you still working on this PR?
   
   Thanks for your review, I am still working on this pr, and I will improve it according to your suggestions this week. @FangYongs 


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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.paimon.schema.SchemaManager.SCHEMA_PREFIX;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SnapshotManager.SNAPSHOT_PREFIX;
+import static org.apache.paimon.utils.TagManager.TAG_PREFIX;
+
+/** Manager for {@code Branch}. */
+public class BranchManager {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BranchManager.class);
+
+    private static final String BRANCH_PREFIX = "branch-";
+
+    private final FileIO fileIO;
+    private final Path tablePath;
+
+    public BranchManager(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.tablePath = path;
+    }
+
+    /** Return the root Directory of branch. */
+    public Path branchDirectory() {
+        return new Path(tablePath + "/branch");
+    }
+
+    /** Return the path of a branch. */
+    public String getBranchPath(String branchName) {
+        return tablePath + "/branch/" + BRANCH_PREFIX + branchName;
+    }
+
+    public Path branchPath(String branchName) {
+        return new Path(getBranchPath(branchName));
+    }
+
+    public Path tagPath(String tagName) {
+        return new Path(tablePath + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path branchTagPath(String branchName, String tagName) {
+        return new Path(getBranchPath(branchName) + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path snapshotPath(long snapshotId) {
+        return new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path branchSnapshotPath(String branchName, long snapshotId) {
+        return new Path(getBranchPath(branchName) + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path schemaPath(long schemaId) {
+        return new Path(tablePath + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public Path branchSchemaPath(String branchName, long schemaId) {
+        return new Path(getBranchPath(branchName) + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public void createBranch(String branchName, String tagName) {
+        checkArgument(!StringUtils.isBlank(branchName), "Branch name '%s' is blank.", branchName);
+        checkArgument(!branchExists(branchName), "Branch name '%s' already exists.", branchName);
+        checkArgument(tagExists(tagName), "Tag name '%s' not exists.", tagName);
+        checkArgument(
+                !branchName.chars().allMatch(Character::isDigit),
+                "Branch name cannot be pure numeric string but is '%s'.",
+                branchName);
+
+        Snapshot snapshot = taggedSnapshot(tagName);
+
+        try {
+            // Copy the corresponding tag, snapshot and schema files into the branch directory
+            fileIO.copyFileUtf8(tagPath(tagName), branchTagPath(branchName, tagName));
+            fileIO.copyFileUtf8(
+                    snapshotPath(snapshot.id()), branchSnapshotPath(branchName, snapshot.id()));
+            fileIO.copyFileUtf8(
+                    schemaPath(snapshot.schemaId()),
+                    branchSchemaPath(branchName, snapshot.schemaId()));
+        } catch (IOException e) {
+            throw new RuntimeException(
+                    String.format(
+                            "Exception occurs when create branch '%s' (directory in %s).",
+                            branchName, getBranchPath(branchName)),
+                    e);
+        }
+    }
+
+    public void deleteBranch(String branchName) {
+        checkArgument(branchExists(branchName), "Branch name '%s' doesn't exist.", branchName);
+        try {
+            // Delete branch directory
+            fileIO.delete(branchPath(branchName), true);
+        } catch (IOException e) {
+            LOG.info(
+                    String.format(
+                            "Deleting the branch failed due to an exception in deleting the directory %s. Please try again.",
+                            getBranchPath(branchName)),
+                    e);
+        }
+    }
+
+    /** Check if path exists. */
+    public boolean fileExists(Path path) {
+        try {
+            if (fileIO.exists(path)) {
+                return true;
+            }
+            return false;
+        } catch (IOException e) {
+            throw new RuntimeException(
+                    String.format("Failed to determine if path '%s' exists.", path), e);
+        }
+    }
+
+    /** Check if a tag exists. */
+    public boolean tagExists(String tagName) {
+        Path tagPath = tagPath(tagName);
+        return fileExists(tagPath);
+    }
+
+    /** Check if a branch exists. */
+    public boolean branchExists(String branchName) {
+        Path branchPath = branchPath(branchName);
+        return fileExists(branchPath);
+    }
+
+    /** Get the tagged snapshot by name. */
+    public Snapshot taggedSnapshot(String tagName) {

Review Comment:
   We should not get `Snapshot` for given tag name in `BranchManager` like this



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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.paimon.schema.SchemaManager.SCHEMA_PREFIX;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SnapshotManager.SNAPSHOT_PREFIX;
+import static org.apache.paimon.utils.TagManager.TAG_PREFIX;
+
+/** Manager for {@code Branch}. */
+public class BranchManager {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BranchManager.class);
+
+    private static final String BRANCH_PREFIX = "branch-";
+
+    private final FileIO fileIO;
+    private final Path tablePath;
+
+    public BranchManager(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.tablePath = path;
+    }
+
+    /** Return the root Directory of branch. */
+    public Path branchDirectory() {
+        return new Path(tablePath + "/branch");
+    }
+
+    /** Return the path of a branch. */
+    public String getBranchPath(String branchName) {
+        return tablePath + "/branch/" + BRANCH_PREFIX + branchName;
+    }
+
+    public Path branchPath(String branchName) {
+        return new Path(getBranchPath(branchName));
+    }
+
+    public Path tagPath(String tagName) {
+        return new Path(tablePath + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path branchTagPath(String branchName, String tagName) {
+        return new Path(getBranchPath(branchName) + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path snapshotPath(long snapshotId) {
+        return new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path branchSnapshotPath(String branchName, long snapshotId) {
+        return new Path(getBranchPath(branchName) + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path schemaPath(long schemaId) {
+        return new Path(tablePath + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public Path branchSchemaPath(String branchName, long schemaId) {
+        return new Path(getBranchPath(branchName) + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public void createBranch(String branchName, String tagName) {
+        checkArgument(!StringUtils.isBlank(branchName), "Branch name '%s' is blank.", branchName);
+        checkArgument(!branchExists(branchName), "Branch name '%s' already exists.", branchName);
+        checkArgument(tagExists(tagName), "Tag name '%s' not exists.", tagName);
+        checkArgument(
+                !branchName.chars().allMatch(Character::isDigit),
+                "Branch name cannot be pure numeric string but is '%s'.",
+                branchName);
+
+        Snapshot snapshot = taggedSnapshot(tagName);
+
+        try {
+            // Copy the corresponding tag, snapshot and schema files into the branch directory
+            fileIO.copyFileUtf8(tagPath(tagName), branchTagPath(branchName, tagName));

Review Comment:
   Why should we copy tag file to branch directory?



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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

Posted by "TaoZex (via GitHub)" <gi...@apache.org>.
TaoZex commented on PR #2608:
URL: https://github.com/apache/incubator-paimon/pull/2608#issuecomment-1873409018

   The functions of merge branch and replace branch are complete, but I need to implement writing data to branch to test the usability of these functions. A new pr commit will be created after I finish writing data to the branch.


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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.paimon.schema.SchemaManager.SCHEMA_PREFIX;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SnapshotManager.SNAPSHOT_PREFIX;
+import static org.apache.paimon.utils.TagManager.TAG_PREFIX;
+
+/** Manager for {@code Branch}. */
+public class BranchManager {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BranchManager.class);
+
+    private static final String BRANCH_PREFIX = "branch-";
+
+    private final FileIO fileIO;
+    private final Path tablePath;
+
+    public BranchManager(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.tablePath = path;
+    }
+
+    /** Return the root Directory of branch. */
+    public Path branchDirectory() {
+        return new Path(tablePath + "/branch");
+    }
+
+    /** Return the path of a branch. */
+    public String getBranchPath(String branchName) {
+        return tablePath + "/branch/" + BRANCH_PREFIX + branchName;
+    }
+
+    public Path branchPath(String branchName) {
+        return new Path(getBranchPath(branchName));
+    }
+
+    public Path tagPath(String tagName) {
+        return new Path(tablePath + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path branchTagPath(String branchName, String tagName) {
+        return new Path(getBranchPath(branchName) + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path snapshotPath(long snapshotId) {
+        return new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path branchSnapshotPath(String branchName, long snapshotId) {
+        return new Path(getBranchPath(branchName) + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path schemaPath(long schemaId) {
+        return new Path(tablePath + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public Path branchSchemaPath(String branchName, long schemaId) {

Review Comment:
   done. Thanks for your review @FangYongs 



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


Re: [PR] [Core]Support branch [incubator-paimon]

Posted by "TaoZex (via GitHub)" <gi...@apache.org>.
TaoZex closed pull request #2608: [Core]Support branch
URL: https://github.com/apache/incubator-paimon/pull/2608


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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.paimon.schema.SchemaManager.SCHEMA_PREFIX;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SnapshotManager.SNAPSHOT_PREFIX;
+import static org.apache.paimon.utils.TagManager.TAG_PREFIX;
+
+/** Manager for {@code Branch}. */
+public class BranchManager {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BranchManager.class);
+
+    private static final String BRANCH_PREFIX = "branch-";
+
+    private final FileIO fileIO;
+    private final Path tablePath;
+
+    public BranchManager(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.tablePath = path;
+    }
+
+    /** Return the root Directory of branch. */
+    public Path branchDirectory() {
+        return new Path(tablePath + "/branch");
+    }
+
+    /** Return the path of a branch. */
+    public String getBranchPath(String branchName) {
+        return tablePath + "/branch/" + BRANCH_PREFIX + branchName;
+    }
+
+    public Path branchPath(String branchName) {
+        return new Path(getBranchPath(branchName));
+    }
+
+    public Path tagPath(String tagName) {
+        return new Path(tablePath + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path branchTagPath(String branchName, String tagName) {
+        return new Path(getBranchPath(branchName) + "/tag/" + TAG_PREFIX + tagName);
+    }
+
+    public Path snapshotPath(long snapshotId) {
+        return new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path branchSnapshotPath(String branchName, long snapshotId) {
+        return new Path(getBranchPath(branchName) + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId);
+    }
+
+    public Path schemaPath(long schemaId) {
+        return new Path(tablePath + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public Path branchSchemaPath(String branchName, long schemaId) {
+        return new Path(getBranchPath(branchName) + "/schema/" + SCHEMA_PREFIX + schemaId);
+    }
+
+    public void createBranch(String branchName, String tagName) {
+        checkArgument(!StringUtils.isBlank(branchName), "Branch name '%s' is blank.", branchName);
+        checkArgument(!branchExists(branchName), "Branch name '%s' already exists.", branchName);
+        checkArgument(tagExists(tagName), "Tag name '%s' not exists.", tagName);
+        checkArgument(
+                !branchName.chars().allMatch(Character::isDigit),
+                "Branch name cannot be pure numeric string but is '%s'.",
+                branchName);
+
+        Snapshot snapshot = taggedSnapshot(tagName);
+
+        try {
+            // Copy the corresponding tag, snapshot and schema files into the branch directory
+            fileIO.copyFileUtf8(tagPath(tagName), branchTagPath(branchName, tagName));

Review Comment:
   From design:
   ![image](https://github.com/apache/incubator-paimon/assets/45089228/b421e6be-94c4-4d08-8392-6ce31a0eec09)
   
   In addition, I think it makes sense to copy tag. The new branch will make it easier for users to use tag. What do you think about it?



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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

Posted by "FangYongs (via GitHub)" <gi...@apache.org>.
FangYongs commented on PR #2608:
URL: https://github.com/apache/incubator-paimon/pull/2608#issuecomment-1882569008

   Hi @TaoZex , are you still working on this PR?


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


Re: [PR] [Core]Support create and delete branch [incubator-paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java:
##########
@@ -50,7 +50,7 @@ public class SnapshotManager implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    private static final String SNAPSHOT_PREFIX = "snapshot-";
+    protected static final String SNAPSHOT_PREFIX = "snapshot-";

Review Comment:
   The internal prefix should not be accessed by `BranchManager`



##########
paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java:
##########
@@ -46,7 +46,7 @@ public class TagManager {
 
     private static final Logger LOG = LoggerFactory.getLogger(TagManager.class);
 
-    private static final String TAG_PREFIX = "tag-";
+    protected static final String TAG_PREFIX = "tag-";

Review Comment:
   As above



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