coderzc commented on code in PR #25134:
URL: https://github.com/apache/pulsar/pull/25134#discussion_r2734668517


##########
pip/pip-452.md:
##########
@@ -0,0 +1,263 @@
+# PIP-452: Customizable topic listing of namespace with properties
+
+# Motivation
+Currently, the CommandGetTopicsOfNamespace logic in the Pulsar Broker is 
hard-coded to scan the metadata store (ZooKeeper) for all children nodes under 
a namespace.
+
+This implementation limits the flexibility required for complex multi-tenant 
scenarios:
+
+No Client Context: The broker cannot distinguish who is asking for the topics 
or why. It cannot filter topics based on client properties (these client 
properties may correspond to, or be derived from topic properties).
+
+Inefficient Filtering: For namespaces with millions of topics, the broker must 
fetch the full list into memory before applying the topics_pattern regex. There 
is no way to "push down" the filtering to the data source (e.g., a database 
with an index).
+
+To address these issues, I propose making the topic listing logic pluggable 
and extending the protocol to accept client properties.
+
+# Goals
+
+## In Scope
+
+Protocol: Add a properties field to `CommandGetTopicsOfNamespace` to carry 
client-side context.
+
+Broker: Extend `BrokerInterceptor` to allow plugins to intercept the "Get 
Topics" request.
+
+Client: Update the Java Client to forward Consumer properties to the lookup 
service when using Regex subscriptions.
+
+Admin API & CLI: Update the REST API and CLI to accept properties for listing 
topics in a namespace.
+
+Configuration: Add a broker configuration to enable/disable topic list 
watching.
+
+## Out of Scope
+
+Not support topic list watching for customized topic listing in this PIP. It 
can be considered in future work.
+If you want to use this feature, you need to disable topic list watcher by set 
`enableBrokerTopicListWatcher = false`.
+
+# High Level Design
+We will modify the Pulsar Protocol to carry a properties map. On the Broker 
side, we will add a new method to the BrokerInterceptor interface.
+The default implementation will preserve the existing behavior (fetching from 
ZooKeeper). The Broker's connection handler will simply delegate the request to 
this strategy.
+
+# Detailed Design
+
+## Public-facing Changes
+
+### Configuration
+
+broker.conf
+```properties
+# Enables watching topic add/remove events on broker side. It is separated 
from enableBrokerSideSubscriptionPatternEvaluation.
+enableBrokerTopicListWatcher = true
+```
+
+### Protocol Changes
+Update `PulsarApi.proto` to include the properties field.
+
+PulsarApi.proto
+```protobuf
+message CommandGetTopicsOfNamespace {
+    required uint64 request_id = 1;
+    required string namespace = 2;
+    optional Mode mode = 3 [default = PERSISTENT];
+    
+    // Existing fields for filtering and hash optimization
+    optional string topics_pattern = 4;
+    optional string topics_hash = 5;
+
+    // New field: Context properties from the client
+    repeated KeyValue properties = 6;
+}
+```
+
+### REST API & CLI Changes
+
+Add `properties` parameter to the REST API endpoint for listing topics in a 
namespace to list topic with specific properties for customizable topic listing.
+
+REST API (URL encoding is required for values):
+```
+GET /admin/v2/persistent/{tenant}/{namespace}?properties=k1=v1,k2=v2
+```
+
+CLI:
+```
+pulsar-admin topics list <tenant>/<namespace> -p k1=v1 -p k2=v2
+```
+
+## Design & Implementation Details
+### Broker Changes
+
+Add `TopicListingResult` for listing topic results
+
+```java
+package org.apache.pulsar.broker.namespace;
+
+import java.util.List;
+import java.util.Objects;
+
+public record TopicListingResult (List<String> topics, boolean filtered) {
+
+    public TopicListingResult{
+        Objects.requireNonNull(topics, "topics");
+    }
+}
+```
+Update BrokerInterceptor Interface
+Add a default method in BrokerInterceptor. It returns null by default, 
indicating no interception (to maintain backward compatibility).
+
+```Java
+
+package org.apache.pulsar.broker.intercept;
+
+import java.util.Optional;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode;
+import java.util.concurrent.CompletableFuture;
+import java.util.Map;
+
+public interface BrokerInterceptor extends AutoCloseable {
+
+    // ... existing methods ...
+
+    /**
+     * Intercept the GetTopicsOfNamespace request.
+     * <p>
+     * This method allows plugins to override the default topic discovery 
logic (ZooKeeper scan).
+     * It enables fetching topics from external sources (e.g., databases, 
other metadata stores)
+     * based on the provided client context properties.
+     *
+     * @param namespace     The namespace being queried.
+     * @param mode          The query mode (PERSISTENT, NON_PERSISTENT, or 
ALL).
+     * @param topicsPattern Optional regex pattern provided by the client.
+     * @param properties    Context properties provided by the client.
+     * @return A CompletableFuture containing the result:
+     * If the future completes with {@code Optional.empty()}, proceed to the 
next interceptor or broker's default logic to list all topics.
+     */
+    default CompletableFuture<Optional<TopicListingResult>> 
interceptGetTopicsOfNamespace(

Review Comment:
   done



##########
pip/pip-452.md:
##########
@@ -0,0 +1,263 @@
+# PIP-452: Customizable topic listing of namespace with properties
+
+# Motivation
+Currently, the CommandGetTopicsOfNamespace logic in the Pulsar Broker is 
hard-coded to scan the metadata store (ZooKeeper) for all children nodes under 
a namespace.
+
+This implementation limits the flexibility required for complex multi-tenant 
scenarios:
+
+No Client Context: The broker cannot distinguish who is asking for the topics 
or why. It cannot filter topics based on client properties (these client 
properties may correspond to, or be derived from topic properties).
+
+Inefficient Filtering: For namespaces with millions of topics, the broker must 
fetch the full list into memory before applying the topics_pattern regex. There 
is no way to "push down" the filtering to the data source (e.g., a database 
with an index).
+
+To address these issues, I propose making the topic listing logic pluggable 
and extending the protocol to accept client properties.
+
+# Goals
+
+## In Scope
+
+Protocol: Add a properties field to `CommandGetTopicsOfNamespace` to carry 
client-side context.
+
+Broker: Extend `BrokerInterceptor` to allow plugins to intercept the "Get 
Topics" request.
+
+Client: Update the Java Client to forward Consumer properties to the lookup 
service when using Regex subscriptions.
+
+Admin API & CLI: Update the REST API and CLI to accept properties for listing 
topics in a namespace.
+
+Configuration: Add a broker configuration to enable/disable topic list 
watching.
+
+## Out of Scope
+
+Not support topic list watching for customized topic listing in this PIP. It 
can be considered in future work.
+If you want to use this feature, you need to disable topic list watcher by set 
`enableBrokerTopicListWatcher = false`.
+
+# High Level Design
+We will modify the Pulsar Protocol to carry a properties map. On the Broker 
side, we will add a new method to the BrokerInterceptor interface.
+The default implementation will preserve the existing behavior (fetching from 
ZooKeeper). The Broker's connection handler will simply delegate the request to 
this strategy.
+
+# Detailed Design
+
+## Public-facing Changes
+
+### Configuration
+
+broker.conf
+```properties
+# Enables watching topic add/remove events on broker side. It is separated 
from enableBrokerSideSubscriptionPatternEvaluation.
+enableBrokerTopicListWatcher = true
+```
+
+### Protocol Changes
+Update `PulsarApi.proto` to include the properties field.
+
+PulsarApi.proto
+```protobuf
+message CommandGetTopicsOfNamespace {
+    required uint64 request_id = 1;
+    required string namespace = 2;
+    optional Mode mode = 3 [default = PERSISTENT];
+    
+    // Existing fields for filtering and hash optimization
+    optional string topics_pattern = 4;
+    optional string topics_hash = 5;
+
+    // New field: Context properties from the client
+    repeated KeyValue properties = 6;
+}
+```
+
+### REST API & CLI Changes
+
+Add `properties` parameter to the REST API endpoint for listing topics in a 
namespace to list topic with specific properties for customizable topic listing.
+
+REST API (URL encoding is required for values):
+```
+GET /admin/v2/persistent/{tenant}/{namespace}?properties=k1=v1,k2=v2
+```
+
+CLI:
+```
+pulsar-admin topics list <tenant>/<namespace> -p k1=v1 -p k2=v2

Review Comment:
   done



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