Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/docs/flink/procedures/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ To expire changelogs. Argument:

- `max_deletes`: the maximum number of changelogs that can be deleted at once.

- `delete_all`: whether to delete all separated changelogs.
- `delete_all`: whether to delete all separated changelogs. When true, cannot be combined with
`retain_max`, `retain_min`, `older_than` or `max_deletes`.

For Flink 1.19 and later, explicit arguments override table retention options for this invocation
without changing the stored table options. Omitted arguments use the table options:
Expand All @@ -108,12 +109,12 @@ without changing the stored table options. Omitted arguments use the table optio
Unset changelog retention options follow the corresponding snapshot retention options.
This also applies to the `expire_changelogs` Flink action. Calling with only a table identifier
therefore expires changelogs according to the table's retention policy. An explicitly supplied
`older_than` must not be empty or whitespace-only, including when `delete_all` is true.
`older_than` must not be empty or whitespace-only.

Previously, omitted arguments used internal defaults instead of table options. Existing calls
may now expire changelogs that were previously retained, or fail if an explicit maximum conflicts
with the table's minimum retention. Specify both bounds when overriding them together.
The `delete_all` path is unchanged and does not use these retention arguments.
Table retention settings do not prevent using `delete_all` on its own.

**Syntax**

Expand All @@ -124,8 +125,10 @@ CALL [catalog.]sys.expire_changelogs(
retain_max => 'retain_max',
retain_min => 'retain_min',
older_than => 'older_than',
max_deletes => 'max_deletes',
delete_all => 'delete_all');
max_deletes => 'max_deletes');

-- Or delete all separated changelogs
CALL [catalog.]sys.expire_changelogs(`table` => 'identifier', delete_all => true);

-- Use indexed argument
-- for Flink 1.18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ public void printHelp() {
+ "--warehouse <warehouse_path> \\\n"
+ "--database <database> \\\n"
+ "--table <table> \\\n"
+ "--retain_max <max> \\\n"
+ "--retain_min <min> \\\n"
+ "--older_than <older_than> \\\n"
+ "--max_deletes <max_deletes> \\\n"
+ "--delete_all <delete_all>");
+ "[--retain_max <max>] \\\n"
+ "[--retain_min <min>] \\\n"
+ "[--older_than <older_than>] \\\n"
+ "[--max_deletes <max_deletes>] \\\n"
+ "[--delete_all <delete_all>]");
System.out.println();
System.out.println(
"When --delete_all is true, it cannot be used with --retain_max, --retain_min, --older_than or --max_deletes.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public String[] call(
checkArgument(
olderThanStr == null || !StringUtils.isNullOrWhitespaceOnly(olderThanStr),
"older_than must not be empty or whitespace-only when specified.");
if (Boolean.TRUE.equals(deleteAll)) {
checkArgument(
retainMax == null
&& retainMin == null
&& olderThanStr == null
&& maxDeletes == null,
"delete_all cannot be used with retain_max, retain_min, older_than or max_deletes.");
}
Table table = table(tableId);
ExpireChangelogImpl expireChangelogs = (ExpireChangelogImpl) table.newExpireChangelog();
ExpireConfig.Builder builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -397,6 +398,99 @@ public void testExpireChangelogsRejectsBlankOlderThan(boolean action) throws Exc
checkBatchRead(10);
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testExpireChangelogsRejectsConflictingDeleteAllArguments(boolean action)
throws Exception {
ChangelogManager cm = prepareRetainedChangelogs();
for (String[] option :
new String[][] {
{"retain_max", "10"},
{"retain_min", "10"},
{"older_than", "2099-01-01 00:00:00"},
{"max_deletes", "1"}
}) {
assertThatThrownBy(() -> expireChangelogs(action, true, option))
.hasStackTraceContaining(
"delete_all cannot be used with retain_max, retain_min, older_than or max_deletes.");
checkChangelogs(cm, 1, 6);
assertThat(cm.safelyGetAllChangelogs()).hasSize(6);
for (long id = 1; id <= 6; id++) {
assertThat(cm.longLivedChangelogExists(id)).isTrue();
}
}
checkSnapshots(paimonTable("word_count").snapshotManager(), 7, 10);
checkBatchRead(10);
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testExpireChangelogsDeleteAllFlag(boolean action) throws Exception {
ChangelogManager cm = prepareRetainedChangelogs();
// Explicit false still applies retention and the deletion limit.
expireChangelogs(
action,
false,
"retain_max",
"8",
"retain_min",
"1",
"older_than",
"2099-01-01 00:00:00",
"max_deletes",
"1");
checkChangelogs(cm, 2, 6);
assertThat(cm.safelyGetAllChangelogs()).hasSize(5);
assertThat(paimonTable("word_count").options())
.containsEntry("changelog.num-retained.min", "10")
.containsEntry("changelog.num-retained.max", "10");
checkSnapshots(paimonTable("word_count").snapshotManager(), 7, 10);
checkBatchRead(10);

// Table retention options do not conflict with delete_all on its own.
expireChangelogs(action, true);
checkAllDeleted(cm);
checkSnapshots(paimonTable("word_count").snapshotManager(), 7, 10);
checkBatchRead(10);
}

private void expireChangelogs(boolean action, boolean deleteAll, String... options)
throws Exception {
if (action) {
List<String> args =
new ArrayList<>(
Arrays.asList(
"expire_changelogs",
"--warehouse",
path,
"--database",
"default",
"--table",
"word_count",
"--delete_all",
Boolean.toString(deleteAll)));
for (int i = 0; i < options.length; i += 2) {
args.add("--" + options[i]);
args.add(options[i + 1]);
}
createAction(ExpireChangelogsAction.class, args.toArray(new String[0])).run();
} else {
StringBuilder statement =
new StringBuilder(
"CALL sys.expire_changelogs(`table` => 'default.word_count', delete_all => ")
.append(deleteAll);
for (int i = 0; i < options.length; i += 2) {
statement.append(", ").append(options[i]).append(" => ");
if (options[i].equals("older_than")) {
statement.append("'").append(options[i + 1]).append("'");
} else {
statement.append(options[i + 1]);
}
}
sql(statement.append(")").toString());
}
}

private ChangelogManager prepareRetainedChangelogs() throws Exception {
sql(
"CREATE TABLE word_count (word STRING PRIMARY KEY NOT ENFORCED, cnt INT)"
Expand Down
Loading