Skip to content

Commit 8976800

Browse files
committed
[server] Forbid resetting table.datalake.enabled
1 parent 8dfd695 commit 8976800

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

fluss-common/src/main/java/org/apache/fluss/config/FlussConfigUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ public class FlussConfigUtils {
3737
public static final String CLIENT_SECURITY_PREFIX = "client.security.";
3838

3939
public static final List<String> ALTERABLE_TABLE_OPTIONS;
40+
public static final List<String> RESETTABLE_TABLE_OPTIONS;
4041

4142
static {
4243
TABLE_OPTIONS = extractConfigOptions("table.");
4344
CLIENT_OPTIONS = extractConfigOptions("client.");
4445
ALTERABLE_TABLE_OPTIONS =
4546
Collections.singletonList(ConfigOptions.TABLE_DATALAKE_ENABLED.key());
47+
RESETTABLE_TABLE_OPTIONS = Collections.emptyList();
4648
}
4749

4850
public static boolean isTableStorageConfig(String key) {
@@ -53,6 +55,10 @@ public static boolean isAlterableTableOption(String key) {
5355
return ALTERABLE_TABLE_OPTIONS.contains(key);
5456
}
5557

58+
public static boolean isResettableTableOption(String key) {
59+
return RESETTABLE_TABLE_OPTIONS.contains(key);
60+
}
61+
5662
@VisibleForTesting
5763
static Map<String, ConfigOption<?>> extractConfigOptions(String prefix) {
5864
Map<String, ConfigOption<?>> options = new HashMap<>();

fluss-lake/fluss-lake-paimon/src/test/java/org/apache/fluss/lake/paimon/LakeEnabledTableCreateITCase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.fluss.config.ConfigOptions;
2424
import org.apache.fluss.config.Configuration;
2525
import org.apache.fluss.exception.FlussRuntimeException;
26+
import org.apache.fluss.exception.InvalidAlterTableException;
2627
import org.apache.fluss.exception.InvalidTableException;
2728
import org.apache.fluss.metadata.Schema;
2829
import org.apache.fluss.metadata.TableChange;
@@ -429,6 +430,15 @@ void testAlterLakeEnabledLogTable() throws Exception {
429430
}),
430431
"log_c1,log_c2",
431432
BUCKET_NUM);
433+
434+
// reset lake
435+
TableChange.ResetOption resetLake =
436+
TableChange.reset(ConfigOptions.TABLE_DATALAKE_ENABLED.key());
437+
List<TableChange> resetChanges = Collections.singletonList(resetLake);
438+
assertThatThrownBy(() -> admin.alterTable(logTablePath, resetChanges, false).get())
439+
.cause()
440+
.isInstanceOf(InvalidAlterTableException.class)
441+
.hasMessage("The option 'table.datalake.enabled' is not supported to reset.");
432442
}
433443

434444
@Test

fluss-server/src/main/java/org/apache/fluss/server/coordinator/MetadataManager.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,7 @@ public void alterTableProperties(
324324
TableInfo tableInfo = tableReg.toTableInfo(tablePath, schemaInfo);
325325

326326
// validate the changes
327-
validateAlterTableProperties(
328-
tableInfo,
329-
tablePropertyChanges.tableKeysToChange(),
330-
tablePropertyChanges.customKeysToChange());
327+
validateAlterTableProperties(tableInfo, tablePropertyChanges);
331328

332329
TableDescriptor tableDescriptor = tableInfo.toTableDescriptor();
333330
TableDescriptor newDescriptor =

fluss-server/src/main/java/org/apache/fluss/server/entity/TablePropertyChanges.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ protected TablePropertyChanges(
4242
this.customPropertiesToReset = customPropertiesToReset;
4343
}
4444

45+
public boolean tableKeyToReset(String key) {
46+
return tablePropertiesToReset.contains(key);
47+
}
48+
4549
public Set<String> tableKeysToChange() {
4650
Set<String> keys = new HashSet<>(tablePropertiesToSet.keySet());
4751
keys.addAll(tablePropertiesToReset);

fluss-server/src/main/java/org/apache/fluss/server/utils/TableDescriptorValidation.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.fluss.metadata.MergeEngineType;
3232
import org.apache.fluss.metadata.TableDescriptor;
3333
import org.apache.fluss.metadata.TableInfo;
34+
import org.apache.fluss.server.entity.TablePropertyChanges;
3435
import org.apache.fluss.types.DataType;
3536
import org.apache.fluss.types.DataTypeRoot;
3637
import org.apache.fluss.types.RowType;
@@ -48,6 +49,7 @@
4849

4950
import static org.apache.fluss.config.FlussConfigUtils.TABLE_OPTIONS;
5051
import static org.apache.fluss.config.FlussConfigUtils.isAlterableTableOption;
52+
import static org.apache.fluss.config.FlussConfigUtils.isResettableTableOption;
5153
import static org.apache.fluss.config.FlussConfigUtils.isTableStorageConfig;
5254
import static org.apache.fluss.metadata.TableDescriptor.BUCKET_COLUMN_NAME;
5355
import static org.apache.fluss.metadata.TableDescriptor.OFFSET_COLUMN_NAME;
@@ -106,27 +108,41 @@ public static void validateTableDescriptor(TableDescriptor tableDescriptor, int
106108
}
107109

108110
public static void validateAlterTableProperties(
109-
TableInfo currentTable, Set<String> tableKeysToChange, Set<String> customKeysToChange) {
110-
tableKeysToChange.forEach(
111-
k -> {
112-
if (isTableStorageConfig(k) && !isAlterableTableOption(k)) {
113-
throw new InvalidAlterTableException(
114-
"The option '" + k + "' is not supported to alter yet.");
115-
}
116-
});
111+
TableInfo currentTable, TablePropertyChanges tablePropertyChanges) {
112+
tablePropertyChanges
113+
.tableKeysToChange()
114+
.forEach(
115+
k -> {
116+
if (isTableStorageConfig(k)) {
117+
if (!isAlterableTableOption(k)) {
118+
throw new InvalidAlterTableException(
119+
"The option '"
120+
+ k
121+
+ "' is not supported to alter yet.");
122+
}
123+
124+
if (tablePropertyChanges.tableKeyToReset(k)
125+
&& !isResettableTableOption(k)) {
126+
throw new InvalidAlterTableException(
127+
"The option '" + k + "' is not supported to reset.");
128+
}
129+
}
130+
});
117131

118132
TableConfig currentConfig = currentTable.getTableConfig();
119133
if (currentConfig.isDataLakeEnabled() && currentConfig.getDataLakeFormat().isPresent()) {
120134
String format = currentConfig.getDataLakeFormat().get().toString();
121-
customKeysToChange.forEach(
122-
k -> {
123-
if (k.startsWith(format + ".")) {
124-
throw new InvalidConfigException(
125-
String.format(
126-
"Property '%s' is not supported to alter which is for datalake table.",
127-
k));
128-
}
129-
});
135+
tablePropertyChanges
136+
.customKeysToChange()
137+
.forEach(
138+
k -> {
139+
if (k.startsWith(format + ".")) {
140+
throw new InvalidConfigException(
141+
String.format(
142+
"Property '%s' is not supported to alter which is for datalake table.",
143+
k));
144+
}
145+
});
130146
}
131147
}
132148

0 commit comments

Comments
 (0)