Skip to content

[feature] Support alter database comment and custom properties#1172

Open
LiebingYu wants to merge 1 commit intoapache:mainfrom
LiebingYu:alter_database
Open

[feature] Support alter database comment and custom properties#1172
LiebingYu wants to merge 1 commit intoapache:mainfrom
LiebingYu:alter_database

Conversation

@LiebingYu
Copy link
Contributor

Purpose

Linked issue: close #1151

Brief change log

Tests

API and Format

Documentation

@polyzos polyzos force-pushed the main branch 3 times, most recently from d88c76c to 434a4f4 Compare August 31, 2025 15:13
@LiebingYu LiebingYu force-pushed the alter_database branch 2 times, most recently from 98ba457 to c3292f4 Compare October 27, 2025 06:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds end-to-end support for ALTER DATABASE to update a database’s comment and custom properties across the RPC API, server coordinator, Java client admin, and Flink catalog integration (linked to #1151).

Changes:

  • Introduces a new RPC API (ALTER_DATABASE) with request/response messages and gateway wiring.
  • Implements server-side handling to apply database property changes and persist them in ZooKeeper.
  • Adds client- and Flink-side implementations plus new unit/integration tests for altering database properties/comments.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
fluss-server/src/test/java/org/apache/fluss/server/coordinator/TestCoordinatorGateway.java Extends test gateway interface with alterDatabase stub.
fluss-server/src/main/java/org/apache/fluss/server/zk/ZooKeeperClient.java Adds ZK helper to update an existing database znode payload.
fluss-server/src/main/java/org/apache/fluss/server/utils/ServerRpcMessageUtils.java Adds PbAlterConfig → DatabaseChange conversions (including comment special-casing).
fluss-server/src/main/java/org/apache/fluss/server/entity/DatabasePropertyChanges.java New internal representation of database property/comment changes.
fluss-server/src/main/java/org/apache/fluss/server/coordinator/MetadataManager.java Adds coordinator logic to apply and persist database changes.
fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java Adds alterDatabase RPC handler + conversion to DatabasePropertyChanges.
fluss-rpc/src/main/proto/FlussApi.proto Defines AlterDatabaseRequest/Response messages.
fluss-rpc/src/main/java/org/apache/fluss/rpc/protocol/ApiKeys.java Adds new ALTER_DATABASE API key.
fluss-rpc/src/main/java/org/apache/fluss/rpc/gateway/AdminGateway.java Exposes alterDatabase on the admin RPC gateway.
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/sink/testutils/TestAdminAdapter.java Updates test adapter interface surface with alterDatabase stub.
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/catalog/FlinkCatalogTest.java Adds catalog-level unit coverage for altering database props/comments.
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/catalog/FlinkCatalogITCase.java Adds SQL-based IT coverage for ALTER DATABASE ... SET (...).
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/catalog/FlinkCatalog.java Implements Flink Catalog#alterDatabase by diffing descriptors into DatabaseChanges.
fluss-common/src/main/java/org/apache/fluss/metadata/DatabaseChange.java New public change model for database alters (set/reset/updateComment).
fluss-common/src/main/java/org/apache/fluss/config/FlussConfigUtils.java Adds shared constant COMMENT_PROP_NAME = "comment".
fluss-client/src/test/java/org/apache/fluss/client/admin/FlussAdminITCase.java Adds IT coverage for admin-side alter database flows.
fluss-client/src/main/java/org/apache/fluss/client/utils/ClientRpcMessageUtils.java Adds DatabaseChange → PbAlterConfig conversion for database alters.
fluss-client/src/main/java/org/apache/fluss/client/admin/FlussAdmin.java Implements Admin#alterDatabase RPC call construction and dispatch.
fluss-client/src/main/java/org/apache/fluss/client/admin/Admin.java Adds new public alterDatabase API to the Admin interface.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +161 to +162
// Update the database in ZooKeeper
DatabaseRegistration updatedRegistration = DatabaseRegistration.of(newDescriptor);
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

alterDatabaseProperties builds DatabaseRegistration via DatabaseRegistration.of(newDescriptor), which sets both createdTime and modifiedTime to System.currentTimeMillis(). This will overwrite the database's original create time on every ALTER. Consider constructing the updated registration using the existing createdTime from the current DB registration/info and only bumping modifiedTime (similar to how TableRegistration#newProperties preserves createdTime).

Suggested change
// Update the database in ZooKeeper
DatabaseRegistration updatedRegistration = DatabaseRegistration.of(newDescriptor);
// Preserve original createdTime and only update modifiedTime
long createdTime = databaseInfo.getCreatedTime();
long modifiedTime = System.currentTimeMillis();
DatabaseRegistration updatedRegistration =
new DatabaseRegistration(newDescriptor, createdTime, modifiedTime);

Copilot uses AI. Check for mistakes.
newCustomProperties.keySet().removeAll(changes.customPropertiesToReset);

boolean hasCommentChange =
!currentDescriptor.getComment().equals(Optional.ofNullable(changes.commentToSet));
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

hasCommentChange is derived from changes.commentToSet, but commentToSet defaults to null. That means an ALTER that only changes custom properties (or even an empty change list) will be interpreted as a comment change and will clear any existing comment. The change model needs a tri-state (no-op vs set comment vs reset comment), e.g., a boolean commentTouched flag in DatabasePropertyChanges that's only set when a comment change is explicitly requested.

Suggested change
!currentDescriptor.getComment().equals(Optional.ofNullable(changes.commentToSet));
changes.commentToSet != null
&& !currentDescriptor
.getComment()
.equals(Optional.of(changes.commentToSet));

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +53
private String commentToSet = null;

Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

commentToSet defaults to null, but null is also the desired value for a legitimate "reset comment" operation. As written, DatabasePropertyChanges cannot represent "no comment change" vs "reset comment", which leads to unintended comment clearing when only properties are altered. Consider adding an explicit flag (e.g., commentChanged/commentTouched) or storing the comment change as an Optional wrapper distinct from the value itself.

Copilot uses AI. Check for mistakes.
customPropertiesToReset.add(key);
}

public void setComment(String comment) {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

Builder#setComment accepts a non-null String, but it is called with updateComment.getComment() which can be null (to reset the comment). Please update the method signature/annotation to accept @Nullable and (ideally) also record that the comment was explicitly changed so null can mean "reset" rather than "not provided".

Suggested change
public void setComment(String comment) {
public void setComment(@Nullable String comment) {

Copilot uses AI. Check for mistakes.

@Override
public String toString() {
return "SetComment{" + "comment='" + comment + '\'' + '}';
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

UpdateComment#toString() returns the prefix SetComment{...} which doesn't match the class name / operation (UpdateComment). This makes logs/debug output confusing; consider updating the string to reflect UpdateComment (and include whether it is clearing vs setting).

Suggested change
return "SetComment{" + "comment='" + comment + '\'' + '}';
return "UpdateComment{"
+ (comment == null ? "clearComment" : "comment='" + comment + '\'')
+ '}';

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@loserwang1024 loserwang1024 left a comment

Choose a reason for hiding this comment

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

Thanks for your job, I have left some comment.

} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
if (CatalogExceptionUtils.isDatabaseNotExist(t)) {
if (!ignoreIfNotExists) {
Copy link
Contributor

Choose a reason for hiding this comment

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

admin.alterDatabase(databaseName, databaseChanges, ignoreIfNotExists) already handle ignoreIfNotExists. Thus, just throw exception here

}

// alter database request and response
message AlterDatabaseRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

where is comment? I think comment should be seperated from config_changes, @wuchong , WDYT?

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.

[Feature] Support alter database to update comment and custom properties

3 participants