Skip to content

Commit ac67a7e

Browse files
committed
address comments
1 parent 7be6916 commit ac67a7e

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

fluss-common/src/main/java/org/apache/fluss/metadata/DatabaseChange.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public int hashCode() {
175175

176176
@Override
177177
public String toString() {
178-
return "SetComment{" + "comment='" + comment + '\'' + '}';
178+
return "UpdateComment{" + "comment='" + comment + '\'' + '}';
179179
}
180180
}
181181
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,17 @@ public void alterDatabaseProperties(
150150
throw new DatabaseNotExistException("Database " + databaseName + " not exists.");
151151
}
152152

153-
DatabaseInfo databaseInfo = getDatabase(databaseName);
154-
DatabaseDescriptor currentDescriptor = databaseInfo.getDatabaseDescriptor();
153+
DatabaseRegistration databaseRegistration = getDatabaseRegistration(databaseName);
154+
DatabaseDescriptor currentDescriptor = databaseRegistration.toDatabaseDescriptor();
155155

156156
// Create updated descriptor
157157
DatabaseDescriptor newDescriptor =
158158
getUpdatedDatabaseDescriptor(currentDescriptor, databasePropertyChanges);
159159

160160
if (newDescriptor != null) {
161161
// Update the database in ZooKeeper
162-
DatabaseRegistration updatedRegistration = DatabaseRegistration.of(newDescriptor);
162+
DatabaseRegistration updatedRegistration =
163+
databaseRegistration.newProperties(newDescriptor);
163164
zookeeperClient.updateDatabase(databaseName, updatedRegistration);
164165
LOG.info("Successfully altered database properties for database: {}", databaseName);
165166
} else {
@@ -189,16 +190,13 @@ private DatabaseDescriptor getUpdatedDatabaseDescriptor(
189190
// reset properties
190191
newCustomProperties.keySet().removeAll(changes.customPropertiesToReset);
191192

192-
boolean hasCommentChange =
193-
!currentDescriptor.getComment().equals(Optional.ofNullable(changes.commentToSet));
194-
195193
if (newCustomProperties.equals(currentDescriptor.getCustomProperties())
196-
&& !hasCommentChange) {
194+
&& !changes.isCommentChanged()) {
197195
return null;
198196
}
199197

200198
String newComment =
201-
hasCommentChange
199+
changes.isCommentChanged()
202200
? changes.commentToSet
203201
: currentDescriptor.getComment().orElse(null);
204202

@@ -209,7 +207,15 @@ private DatabaseDescriptor getUpdatedDatabaseDescriptor(
209207
}
210208

211209
public DatabaseInfo getDatabase(String databaseName) throws DatabaseNotExistException {
210+
DatabaseRegistration databaseReg = getDatabaseRegistration(databaseName);
211+
return new DatabaseInfo(
212+
databaseName,
213+
databaseReg.toDatabaseDescriptor(),
214+
databaseReg.createdTime,
215+
databaseReg.modifiedTime);
216+
}
212217

218+
public DatabaseRegistration getDatabaseRegistration(String databaseName) {
213219
Optional<DatabaseRegistration> optionalDB;
214220
try {
215221
optionalDB = zookeeperClient.getDatabase(databaseName);
@@ -221,13 +227,7 @@ public DatabaseInfo getDatabase(String databaseName) throws DatabaseNotExistExce
221227
if (!optionalDB.isPresent()) {
222228
throw new DatabaseNotExistException("Database '" + databaseName + "' does not exist.");
223229
}
224-
225-
DatabaseRegistration databaseReg = optionalDB.get();
226-
return new DatabaseInfo(
227-
databaseName,
228-
databaseReg.toDatabaseDescriptor(),
229-
databaseReg.createdTime,
230-
databaseReg.modifiedTime);
230+
return optionalDB.get();
231231
}
232232

233233
public boolean databaseExists(String databaseName) {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@ public class DatabasePropertyChanges {
2929

3030
public final Map<String, String> customPropertiesToSet;
3131
public final Set<String> customPropertiesToReset;
32+
3233
public final String commentToSet;
3334

35+
private final boolean commentChanged;
36+
3437
protected DatabasePropertyChanges(
3538
Map<String, String> customPropertiesToSet,
3639
Set<String> customPropertiesToReset,
37-
@Nullable String commentToSet) {
40+
@Nullable String commentToSet,
41+
boolean commentChanged) {
3842
this.customPropertiesToSet = customPropertiesToSet;
3943
this.customPropertiesToReset = customPropertiesToReset;
4044
this.commentToSet = commentToSet;
45+
this.commentChanged = commentChanged;
46+
}
47+
48+
public boolean isCommentChanged() {
49+
return commentChanged;
4150
}
4251

4352
public static DatabasePropertyChanges.Builder builder() {
@@ -50,6 +59,7 @@ public static class Builder {
5059
private final Set<String> customPropertiesToReset = new HashSet<>();
5160

5261
private String commentToSet = null;
62+
private boolean commentChanged = false;
5363

5464
public void setCustomProperty(String key, String value) {
5565
customPropertiesToSet.put(key, value);
@@ -59,13 +69,14 @@ public void resetCustomProperty(String key) {
5969
customPropertiesToReset.add(key);
6070
}
6171

62-
public void setComment(String comment) {
72+
public void setComment(@Nullable String comment) {
6373
this.commentToSet = comment;
74+
this.commentChanged = true;
6475
}
6576

6677
public DatabasePropertyChanges build() {
6778
return new DatabasePropertyChanges(
68-
customPropertiesToSet, customPropertiesToReset, commentToSet);
79+
customPropertiesToSet, customPropertiesToReset, commentToSet, commentChanged);
6980
}
7081
}
7182
}

fluss-server/src/main/java/org/apache/fluss/server/zk/data/DatabaseRegistration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public DatabaseDescriptor toDatabaseDescriptor() {
5454
return builder.build();
5555
}
5656

57+
public DatabaseRegistration newProperties(DatabaseDescriptor databaseDescriptor) {
58+
return new DatabaseRegistration(
59+
databaseDescriptor.getComment().orElse(null),
60+
databaseDescriptor.getCustomProperties(),
61+
createdTime,
62+
System.currentTimeMillis());
63+
}
64+
5765
public static DatabaseRegistration of(DatabaseDescriptor databaseDescriptor) {
5866
final long currentMillis = System.currentTimeMillis();
5967
return new DatabaseRegistration(

0 commit comments

Comments
 (0)