Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

askwang
Copy link
Contributor

@askwang askwang commented Sep 6, 2024

Purpose

Introduce expire_tags procedure, support expire tags by time.

-- expire tags by tagCreateTime and tagTimeRetained
CALL sys.expire_tags(table => 'default.T')
-- expire tags that tagCreateTime less than older_than
CALL sys.expire_tags(table => 'default.T', older_than => '2024-09-06 11:00:00')

Tests

API and Format

Documentation

@askwang askwang changed the title [WIP][core] Introduce expire_tags procedure [core] Introduce expire_tags procedure Sep 6, 2024
@askwang askwang changed the title [core] Introduce expire_tags procedure [WIP][core] Introduce expire_tags procedure Sep 10, 2024
@askwang askwang changed the title [WIP][core] Introduce expire_tags procedure [core] Introduce expire_tags procedure Sep 10, 2024
<td>
To expire tags by time. Arguments:
<li>identifier: the target table identifier. Cannot be empty.</li>
<li>expiration_time: tagCreateTime before which tags will be removed.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

older_than

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import static org.assertj.core.api.Assertions.assertThat;

/** IT cases for {@link ExpireTagsAction}. */
public class ExpireTagsActionITTest extends ActionITCaseBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpireTagsActionTest

@@ -62,14 +66,23 @@ public void run() {
if (createTime == null || timeRetained == null) {
continue;
}
if (LocalDateTime.now().isAfter(createTime.plus(timeRetained))) {
if ((olderThanTime == null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ((LocalDateTime.now().isAfter(createTime.plus(timeRetained)))
|| (olderThanTime != null && olderThanTime.isAfter(createTime)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tag without createTime, can we just check its file creation time?

Add check file creation time for tag without createTime.
This if locial makes some adjustments, help me review it again

@@ -62,14 +66,23 @@ public void run() {
if (createTime == null || timeRetained == null) {
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tag without createTime, can we just check its file creation time?

@@ -164,6 +165,9 @@ default void deleteBranches(String branchNames) {
@Experimental
ExpireSnapshots newExpireChangelog();

/** Expire tags. */
TagTimeExpire newExpireTags();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont introduce this method to Table, it is not so useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed. Removed it, just depends on TagAutoManager.

@askwang
Copy link
Contributor Author

askwang commented Sep 25, 2024

@JingsongLi Thanks for review, updated

if (createTime == null) {
FileStatus tagFileStatus;
try {
tagFileStatus = fileIO.getFileStatus(tagManager.tagPath(tagName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (timeRetained != null && olderThanTime != null), in this case, we get file status for this tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe if (createTime == null && olderThanTime != null) ?
if timeRetained != null, the tag has own createTime, no need to get file status.

}
if (LocalDateTime.now().isAfter(createTime.plus(timeRetained))) {
Duration timeRetained = tag.getTagTimeRetained();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、Method invocation 'plus' may produce 'NullPointerException',because timeRetained in Tag is nullable. So you should check and handle it.

2、Argument 'createTime' might be null,because createTime in Tag is nullable. So you should check and handle it.

3、Change line 81 if statement to :
boolean xxx = timeRetained != null && LocalDateTime.now().isAfter(createTime.plus(timeRetained));
boolean yyy = olderThanTime != null && olderThanTime.isAfter(createTime);
if (xxx || yyy) {
...
}

if (LocalDateTime.now().isAfter(createTime.plus(timeRetained))) {
Duration timeRetained = tag.getTagTimeRetained();
if ((timeRetained != null && LocalDateTime.now().isAfter(createTime.plus(timeRetained)))
|| (olderThanTime != null && olderThanTime.isAfter(createTime))) {
LOG.info(
"Delete tag {}, because its existence time has reached its timeRetained of {}.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG.info(
"Delete tag {}, because its existence time has reached its timeRetained of {} or" +
" its createTime {} is olderThan olderThanTime {}.",
tagName,
timeRetained,
createTime,
olderThanTime);

ProcedureContext procedureContext, String tableId, @Nullable String olderThanStr)
throws Catalog.TableNotExistException {
FileStoreTable fileStoreTable = (FileStoreTable) table(tableId);
FileStore fileStore = fileStoreTable.store();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline line 56 to line 57

/** A procedure to expire tags by time. */
public class ExpireTagsProcedure extends ProcedureBase {

public static final String IDENTIFIER = "expire_tags";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

List<String> expired = tagTimeExpire.expire();
return expired.isEmpty()
? new Row[] {Row.of("No expired tags.")}
: expired.stream().map(x -> Row.of(x)).toArray(Row[]::new);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to : expired.stream().map(Row::of).toArray(Row[]::new);

/** Factory to create {@link ExpireTagsAction}. */
public class ExpireTagsActionFactory implements ActionFactory {

public static final String IDENTIFIER = "expire_tags";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

List<Pair<Tag, String>> tags = tagManager.tagObjects();
FileIO fileIO = snapshotManager.fileIO();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline this to line 73:
tagFileStatus = snapshotManager.fileIO().getFileStatus(tagManager.tagPath(tagName));

tableIdent,
table -> {
FileStoreTable fileStoreTable = (FileStoreTable) table;
FileStore fileStore = fileStoreTable.store();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline line 77 to line 79

@wwj6591812
Copy link
Contributor

Suggest change title to "Introduce expire_tags action and procedure with olderThan user custom time".

@askwang askwang changed the title [core] Introduce expire_tags procedure [core] Introduce expire_tags action and procedure with olderThan user custom time Sep 27, 2024
@askwang
Copy link
Contributor Author

askwang commented Sep 27, 2024

@wwj6591812 thank you, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants