poorbarcode commented on code in PR #22182:
URL: https://github.com/apache/pulsar/pull/22182#discussion_r1532455690


##########
pip/pip-344.md:
##########
@@ -0,0 +1,78 @@
+# PIP-344: Correct the behavior of the public API 
pulsarClient.getPartitionsForTopic(topicName)
+
+# Background knowledge
+
+**Topic auto-creation**
+- The partitioned topic auto-creation is dependent on 
`pulsarClient.getPartitionsForTopic`
+    - It triggers partitioned metadata creation by 
`pulsarClient.getPartitionsForTopic`
+    - And triggers the topic partition creation by producers' registration and 
consumers' registration.
+- When calling `pulsarClient.getPartitionsForTopic(topicName)`, Pulsar will 
automatically create the partitioned topic metadata if it does not exist, 
either using `HttpLookupService` or `BinaryProtoLookupService`.
+
+**Now `pulsarClient.getPartitionsForTopic`'s behavior**
+| case | broker allow `auto-create` | param allow <br> `create if not exists` 
| non-partitioned topic | partitioned topic |  current behavior |
+| --- | --- | --- | --- | --- | --- |
+| 1 | `true/false` | `true/false` | `exists: true` | | REST API: `partitions: 
0`<br> Client API: `partitions: 0` |
+| 2 | `true/false` | `true/false` | | `exists: true` <br> `partitions: 3` | 
REST API: `partitions: 3`<br> Client API: `partitions: 3` |
+| 3 | `true` | `true` | | | REST API: <br> &nbsp;&nbsp;- `create new: true` 
<br> &nbsp;&nbsp;- `partitions: 3` <br> Client API: <br> &nbsp;&nbsp;- `create 
new: true` <br> &nbsp;&nbsp;- `partitions: 3` <br> |
+| 4 | `true` | `false` | | | REST API: <br> &nbsp;&nbsp;- `create new: false` 
<br> &nbsp;&nbsp;- `partitions: 0` <br> Client API: <br> &nbsp;&nbsp;not 
support <br> |
+| 5 | `false` | `true` | | | REST API: <br> &nbsp;&nbsp;- `create new: false` 
<br> &nbsp;&nbsp;- `partitions: 0` <br> Client API: <br> &nbsp;&nbsp;- `create 
new: false` <br> &nbsp;&nbsp;- `partitions: 0` <br> |
+
+# Motivation
+
+The param `create if not exists` of the Client API is always `true.`
+
+- For case 4 of `pulsarClient.getPartitionsForTopic`'s behavior, it always 
tries to create the partitioned metadata, but the API name is `getxxx`.
+- For case 5 of `pulsarClient.getPartitionsForTopic`'s behavior, it returns a 
`0` partitioned metadata, but the topic does not exist. For the correct 
behavior of this case, we had discussed 
[here](https://github.com/apache/pulsar/issues/8813) before.

Review Comment:
   > Sorry, we will not change this behavior for the existing method since it 
will always create topic.
   For the newly added method, we will use false as default and return NOT 
FOUND if the topic doesn't exist?
   
   Good suggestion. Added a new API that will respond to a not found error if 
the topic does not exist and keep the behavior of the old API as before.



-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to