heesung-sn commented on code in PR #17238:
URL: https://github.com/apache/pulsar/pull/17238#discussion_r1199270887


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -601,6 +602,60 @@ private CompletableFuture<Map<String, String>> 
getPropertiesAsync() {
         });
     }
 
+    protected CompletableFuture<Void> internalUpdatePropertiesAsync(boolean 
authoritative,
+                                                                    
Map<String, String> properties) {
+        if (properties == null || properties.isEmpty()) {
+            log.warn("[{}] [{}] properties is empty, ignore update", 
clientAppId(), topicName);
+            return CompletableFuture.completedFuture(null);
+        }
+        return validateTopicOwnershipAsync(topicName, authoritative)
+            .thenCompose(__ -> validateTopicOperationAsync(topicName, 
TopicOperation.PRODUCE))
+            .thenCompose(__ -> {
+                if (topicName.isPartitioned()) {
+                    return 
internalUpdateNonPartitionedTopicProperties(properties);
+                } else {
+                    return 
pulsar().getBrokerService().fetchPartitionedTopicMetadataAsync(topicName)
+                        .thenCompose(metadata -> {
+                            if (metadata.partitions == 0) {
+                                return 
internalUpdateNonPartitionedTopicProperties(properties);
+                            }
+                            return namespaceResources()
+                                
.getPartitionedTopicResources().updatePartitionedTopicAsync(topicName,
+                                    p -> new 
PartitionedTopicMetadata(p.partitions,
+                                        MapUtils.putAll(p.properties, 
properties.entrySet().toArray())));
+                        });
+                }
+            }).thenAccept(__ ->
+                log.info("[{}] [{}] update properties success with properties 
{}",
+                    clientAppId(), topicName, properties));
+    }
+
+    private CompletableFuture<Void> 
internalUpdateNonPartitionedTopicProperties(Map<String, String> properties) {
+        CompletableFuture<Void> future = new CompletableFuture<>();
+        pulsar().getBrokerService().getTopicIfExists(topicName.toString())
+            .thenAccept(opt -> {
+                if (!opt.isPresent()) {
+                    throw new RestException(Status.NOT_FOUND,
+                        getTopicNotFoundErrorMessage(topicName.toString()));
+                }
+                ManagedLedger managedLedger = ((PersistentTopic) 
opt.get()).getManagedLedger();
+                managedLedger.asyncSetProperties(properties, new 
AsyncCallbacks.UpdatePropertiesCallback() {
+
+                    @Override
+                    public void updatePropertiesComplete(Map<String, String> 
properties, Object ctx) {
+                        
managedLedger.getConfig().getProperties().putAll(properties);

Review Comment:
   `managedLedger.getConfig().getProperties()` can return NPE if the topic is 
from the older code without the `properties`.



-- 
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]

Reply via email to