gyang94 commented on code in PR #1625:
URL: https://github.com/apache/fluss/pull/1625#discussion_r2371703802
##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/MetadataManager.java:
##########
@@ -302,6 +306,101 @@ public long createTable(
"Fail to create table " + tablePath);
}
+ public void alterTableProperties(
+ TablePath tablePath,
+ List<TableChange.SetOption> setOptions,
+ List<TableChange.ResetOption> resetOptions,
+ boolean ignoreIfNotExists) {
+
+ if (!databaseExists(tablePath.getDatabaseName())) {
+ throw new DatabaseNotExistException(
+ "Database " + tablePath.getDatabaseName() + " does not
exist.");
+ }
+ if (!tableExists(tablePath)) {
+ if (ignoreIfNotExists) {
+ return;
+ } else {
+ throw new TableNotExistException("Table " + tablePath + " does
not exists.");
+ }
+ }
+
+ try {
+ TableRegistration updatedTableRegistration =
+ getUpdatedTableRegistration(tablePath, setOptions,
resetOptions);
+ if (updatedTableRegistration != null) {
+ zookeeperClient.updateTable(tablePath,
updatedTableRegistration);
+ } else {
+ LOG.info(
+ "No properties changed when alter table {}, skip
update table.", tablePath);
+ }
+ } catch (Exception e) {
+ if (e instanceof KeeperException.NoNodeException) {
+ if (ignoreIfNotExists) {
+ return;
+ }
+ throw new TableNotExistException("Table " + tablePath + " does
not exists.");
+ } else {
+ throw new FlussRuntimeException("Failed to alter table: " +
tablePath, e);
+ }
+ }
+ }
+
+ private TableRegistration getUpdatedTableRegistration(
+ TablePath tablePath,
+ List<TableChange.SetOption> setOptions,
+ List<TableChange.ResetOption> resetOptions) {
+
+ TableRegistration existTableReg = getTableRegistration(tablePath);
+
+ Map<String, String> newProperties = new
HashMap<>(existTableReg.properties);
+ Map<String, String> newCustomProperties = new
HashMap<>(existTableReg.customProperties);
+
+ boolean propertiesChanged = false;
+ boolean customPropertiesChanged = false;
+ for (TableChange.SetOption setOption : setOptions) {
+ String key = setOption.getKey();
+ if (ALTERABLE_TABLE_CONFIG.contains(key)) {
+ // only alterable configs can be updated, other properties
keep unchanged.
+ String curValue = newProperties.get(key);
+ String updatedValue = setOption.getValue();
+ if (!updatedValue.equals(curValue)) {
+ propertiesChanged = true;
+ newProperties.put(key, updatedValue);
+ }
+ } else if (ALTERABLE_CLIENT_OPTIONS.contains(key)) {
Review Comment:
@luoyuxia thanks for review. Other comments are resolved except this one.
`ALTERABLE_CLIENT_OPTIONS` is for "alterable" client options. Only client
options in this list are allowed to be changed. Similar to previous
`ALTERABLE_TABLE_OPTIONS`, we have two conditions branches to check whether
this option is in "alterable" table option list and client option list.
--
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]