mattisonchao commented on code in PR #17711:
URL: https://github.com/apache/pulsar/pull/17711#discussion_r979538656
##########
pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/TopicsImpl.java:
##########
@@ -2705,7 +2707,43 @@ public CompletableFuture<Void>
removeShadowTopicsAsync(String sourceTopic) {
public CompletableFuture<List<String>> getShadowTopicsAsync(String
sourceTopic) {
TopicName tn = validateTopic(sourceTopic);
WebTarget path = topicPath(tn, "shadowTopics");
- return asyncGetRequest(path, new FutureCallback<List<String>>(){});
+ return asyncGetRequest(path, new FutureCallback<List<String>>() {});
+ }
+
+ @Override
+ public String getShadowSource(String shadowTopic) throws
PulsarAdminException {
+ return sync(() -> getShadowSourceAsync(shadowTopic));
+ }
+
+ @Override
+ public CompletableFuture<String> getShadowSourceAsync(String shadowTopic) {
+ return getPropertiesAsync(shadowTopic).thenApply(
+ properties -> properties != null ?
properties.get(PROPERTY_SHADOW_SOURCE_KEY) : null);
+ }
+
+ @Override
+ public void createShadowTopic(String shadowTopic, String sourceTopic,
Map<String, String> properties)
+ throws PulsarAdminException {
+ sync(() -> createShadowTopicAsync(shadowTopic, sourceTopic,
properties));
+ }
+
+ @Override
+ public CompletableFuture<Void> createShadowTopicAsync(String shadowTopic,
String sourceTopic,
+ Map<String, String>
properties) {
+ checkArgument(TopicName.get(shadowTopic).isPersistent(), "Shadow topic
must be persistent");
+ checkArgument(TopicName.get(sourceTopic).isPersistent(), "Source topic
must be persistent");
+ return
getPartitionedTopicMetadataAsync(sourceTopic).thenCompose(sourceTopicMeta -> {
+ HashMap<String, String> shadowProperties = new HashMap<>();
+ if (properties != null) {
+ shadowProperties.putAll(properties);
+ }
+ shadowProperties.put(PROPERTY_SHADOW_SOURCE_KEY, sourceTopic);
+ if (sourceTopicMeta.partitions == 0) {
Review Comment:
if it's better to use `PartitionedTopicMetadata#NON_PARTITIONED` to instead
of 0?
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -1408,14 +1408,38 @@ protected CompletableFuture<Optional<Topic>>
loadOrCreatePersistentTopic(final S
return topicFuture;
}
+ CompletableFuture<Map<String, String>> fetchTopicPropertiesAsync(TopicName
topicName) {
+ if (!topicName.isPartitioned()) {
+ return
managedLedgerFactory.getManagedLedgerPropertiesAsync(topicName.getPersistenceNamingEncoding());
+ } else {
+ TopicName partitionedTopicName =
TopicName.get(topicName.getPartitionedTopicName());
+ return fetchPartitionedTopicMetadataAsync(partitionedTopicName)
+ .thenCompose(metadata -> {
+ if (metadata.partitions == 0) {
Review Comment:
if it's better to use `PartitionedTopicMetadata#NON_PARTITIONED` to instead
of 0?
--
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]