JingsongLi commented on code in PR #1271:
URL: https://github.com/apache/incubator-paimon/pull/1271#discussion_r1212508323
##########
paimon-core/src/main/java/org/apache/paimon/table/FileStoreTable.java:
##########
@@ -90,4 +90,6 @@ default Optional<String> comment() {
default BinaryTableStats getSchemaFieldStats(DataFileMeta dataFileMeta) {
return dataFileMeta.valueStats();
}
+
+ void createTag(String tagName);
Review Comment:
create this method in `Table`
##########
paimon-core/src/main/java/org/apache/paimon/AbstractFileStore.java:
##########
@@ -181,4 +184,15 @@ public PartitionExpire newPartitionExpire(String
commitUser) {
newScan(),
newCommit(commitUser));
}
+
+ @Override
+ public void createTag(String tagName) {
Review Comment:
Just in table level, don't need in store level.
##########
paimon-core/src/main/java/org/apache/paimon/table/FileStoreTable.java:
##########
@@ -90,4 +90,6 @@ default Optional<String> comment() {
default BinaryTableStats getSchemaFieldStats(DataFileMeta dataFileMeta) {
return dataFileMeta.valueStats();
}
+
+ void createTag(String tagName);
Review Comment:
`createTag(String name, long snapshotId)` is better?
##########
paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.io.IOException;
+
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+
+/** Manager for {@code Tag}. */
+public class TagManager {
+
+ private final FileIO fileIO;
+ private final Path tablePath;
+
+ public TagManager(FileIO fileIO, Path tablePath) {
+ this.fileIO = fileIO;
+ this.tablePath = tablePath;
+ }
+
+ /** Return the path of a tag. */
+ public Path tagPath(String tagName) {
+ return new Path(tablePath + "/tag/" + tagName);
+ }
+
+ /** Create a tag from given snapshot and save it in the storage. */
+ public void commitTag(Snapshot snapshot, String tagName) {
+ checkArgument(!tagExists(tagName), "Tag name '%s' already exists.",
tagName);
+
+ Path newTagPath = tagPath(tagName);
+ try {
+ fileIO.writeFileUtf8(newTagPath, snapshot.toJson());
+ } catch (IOException e) {
+ throw new RuntimeException(
+ String.format(
+ "Exception occurs when committing tag '%s' (path
%s). "
+ + "Cannot clean up because we can't
determine the success.",
+ tagName, newTagPath),
+ e);
+ }
+ }
+
+ /** Check if a tag exists. */
+ public boolean tagExists(String tagName) {
+ Path path = tagPath(tagName);
+ try {
+ return fileIO.exists(path);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ String.format(
+ "Failed to determine if tag '%s' exists in path
%s.", tagName, path),
+ e);
+ }
+ }
+
+ /** Get the tagged snapshot. */
+ public Snapshot snapshot(String tagName) {
Review Comment:
tagSnapshot
--
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]