-
Notifications
You must be signed in to change notification settings - Fork 928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Introduce expire_tags action and procedure with olderThan user custom time #4138
base: master
Are you sure you want to change the base?
Changes from 3 commits
9ba6a4e
be3cbe0
43e512a
0d97581
19f4895
559f322
b48f58b
64772ed
b5362c7
d6b616b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import org.apache.paimon.table.sink.BatchWriteBuilder; | ||
import org.apache.paimon.table.sink.StreamWriteBuilder; | ||
import org.apache.paimon.table.source.ReadBuilder; | ||
import org.apache.paimon.tag.TagTimeExpire; | ||
import org.apache.paimon.types.RowType; | ||
import org.apache.paimon.utils.SimpleFileReader; | ||
|
||
|
@@ -164,6 +165,9 @@ default void deleteBranches(String branchNames) { | |
@Experimental | ||
ExpireSnapshots newExpireChangelog(); | ||
|
||
/** Expire tags. */ | ||
TagTimeExpire newExpireTags(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont introduce this method to Table, it is not so useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed. Removed it, just depends on TagAutoManager. |
||
|
||
// =============== Read & Write Operations ================== | ||
|
||
/** Returns a new read builder. */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** A manager to expire tags by time. */ | ||
|
@@ -41,6 +42,8 @@ public class TagTimeExpire { | |
private final TagDeletion tagDeletion; | ||
private final List<TagCallback> callbacks; | ||
|
||
private LocalDateTime expirationTime; | ||
|
||
private TagTimeExpire( | ||
SnapshotManager snapshotManager, | ||
TagManager tagManager, | ||
|
@@ -52,8 +55,9 @@ private TagTimeExpire( | |
this.callbacks = callbacks; | ||
} | ||
|
||
public void run() { | ||
public List<String> expire() { | ||
List<Pair<Tag, String>> tags = tagManager.tagObjects(); | ||
List<String> expired = new ArrayList<>(); | ||
for (Pair<Tag, String> pair : tags) { | ||
Tag tag = pair.getLeft(); | ||
String tagName = pair.getRight(); | ||
|
@@ -62,14 +66,23 @@ public void run() { | |
if (createTime == null || timeRetained == null) { | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For tag without createTime, can we just check its file creation time? |
||
} | ||
if (LocalDateTime.now().isAfter(createTime.plus(timeRetained))) { | ||
if ((expirationTime == null | ||
&& LocalDateTime.now().isAfter(createTime.plus(timeRetained))) | ||
|| (expirationTime != null && expirationTime.isAfter(createTime))) { | ||
LOG.info( | ||
"Delete tag {}, because its existence time has reached its timeRetained of {}.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOG.info( |
||
tagName, | ||
timeRetained); | ||
tagManager.deleteTag(tagName, tagDeletion, snapshotManager, callbacks); | ||
expired.add(tagName); | ||
} | ||
} | ||
return expired; | ||
} | ||
|
||
public TagTimeExpire withExpirationTime(LocalDateTime expirationTime) { | ||
this.expirationTime = expirationTime; | ||
return this; | ||
} | ||
|
||
public static TagTimeExpire create( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.flink.action; | ||
|
||
import org.apache.paimon.flink.procedure.ExpireTagsProcedure; | ||
|
||
import org.apache.flink.table.procedure.DefaultProcedureContext; | ||
|
||
import java.util.Map; | ||
|
||
/** Expire tags action for Flink. */ | ||
public class ExpireTagsAction extends ActionBase { | ||
|
||
private final String table; | ||
private final String expirationTime; | ||
|
||
public ExpireTagsAction( | ||
String warehouse, | ||
String table, | ||
String expirationTime, | ||
Map<String, String> catalogConfig) { | ||
super(warehouse, catalogConfig); | ||
this.table = table; | ||
this.expirationTime = expirationTime; | ||
} | ||
|
||
@Override | ||
public void run() throws Exception { | ||
ExpireTagsProcedure expireTagsProcedure = new ExpireTagsProcedure(); | ||
expireTagsProcedure.withCatalog(catalog); | ||
expireTagsProcedure.call(new DefaultProcedureContext(env), table, expirationTime); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.flink.action; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** Factory to create {@link ExpireTagsAction}. */ | ||
public class ExpireTagsActionFactory implements ActionFactory { | ||
|
||
public static final String IDENTIFIER = "expire_tags"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private |
||
|
||
private static final String EXPIRATION_TIME = "expiration_time"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
String warehouse = params.get(WAREHOUSE); | ||
String table = params.get(TABLE); | ||
String expirationTime = params.get(EXPIRATION_TIME); | ||
Map<String, String> catalogConfig = optionalConfigMap(params, CATALOG_CONF); | ||
|
||
ExpireTagsAction expireTagsAction = | ||
new ExpireTagsAction(warehouse, table, expirationTime, catalogConfig); | ||
return Optional.of(expireTagsAction); | ||
} | ||
|
||
@Override | ||
public void printHelp() { | ||
System.out.println("Action \"expire_tags\" expire tags by time."); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax:"); | ||
System.out.println( | ||
" expire_tags --warehouse <warehouse_path> " | ||
+ "--table <database.table_name> " | ||
+ "[--expiration_time <expiration_time>]"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
older_than
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done