klevy-toast opened a new issue, #1429:
URL: https://github.com/apache/pulsar-client-go/issues/1429

   When using the client to check a value on the namespace / topic that may be 
either _unset_ or _set to 0_, there is no way to distinguish the two states, 
which is misleading and incorrect. By contrast, the java pulsar admin client 
shows `null` for an unset value and `0` for a value that is set to 0. This is 
consequential because most of these settings appear on multiple layers - they 
can be applied at the broker level, or namespace level, or topic level. Setting 
them to `0` explicitly disables them and is different from an unset value, 
which will then default to whatever is set at a higher level.
   
   As far as I can tell, this applies to the following methods:
   
   1. **GetNamespaceMessageTTL** / **GetNamespaceMessageTTLWithContext**
   2. **GetMaxConsumersPerTopic** / **GetMaxConsumersPerTopicWithContext**
   3. **GetMaxProducersPerTopic** / **GetMaxProducersPerTopicWithContext**
   4. **GetMaxConsumersPerSubscription** / 
**GetMaxConsumersPerSubscriptionWithContext**
   5. **GetMaxTopicsPerNamespace** / **GetMaxTopicsPerNamespaceWithContext**
   6. **GetOffloadThreshold** / **GetOffloadThresholdWithContext**
   7. **GetOffloadThresholdInSeconds** / 
**GetOffloadThresholdInSecondsWithContext**
   8. **GetOffloadDeleteLag** / **GetOffloadDeleteLagWithContext**
   9. **GetCompactionThreshold** / **GetCompactionThresholdWithContext**
   
   #### Topic Admin Methods (18 methods)
   
   1. **GetMessageTTL** / **GetMessageTTLWithContext**
   2. **GetMaxProducers** / **GetMaxProducersWithContext**
   3. **GetMaxConsumers** / **GetMaxConsumersWithContext**
   4. **GetMaxUnackMessagesPerConsumer** / 
**GetMaxUnackMessagesPerConsumerWithContext**
   5. **GetMaxUnackMessagesPerSubscription** / 
**GetMaxUnackMessagesPerSubscriptionWithContext**
   6. **GetCompactionThreshold** / **GetCompactionThresholdWithContext**
   7. **GetMaxConsumersPerSubscription** / 
**GetMaxConsumersPerSubscriptionWithContext**
   8. **GetMaxMessageSize** / **GetMaxMessageSizeWithContext**
   9. **GetMaxSubscriptionsPerTopic** / 
**GetMaxSubscriptionsPerTopicWithContext**
   10. **GetDeduplicationSnapshotInterval** / 
**GetDeduplicationSnapshotIntervalWithContext**
   
   #### Expected behavior
   
   Since the `int` type is used, we should use a sentinel value of -1 to 
signify that the value is not actually set.
   
   
   #### Actual behavior
   
   An empty response is unmarshalled as 0.
   
   #### Steps to reproduce
   Example for topics - getMaxConsumers
   ```
   package main
   
   import (
        "fmt"
        "log"
        "os"
   
        "github.com/apache/pulsar-client-go/pulsaradmin"
        "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
   )
   
   func main() {
        topic := "persistent://public/default/test-topic"
        if len(os.Args) > 1 {
                topic = os.Args[1]
        }
   
        webServiceURL := os.Getenv("PULSAR_WEB_SERVICE_URL")
        if webServiceURL == "" {
                webServiceURL = "http://localhost:8080";
        }
   
        cfg := &pulsaradmin.Config{
                WebServiceURL: webServiceURL,
        }
        if token := os.Getenv("PULSAR_AUTH_TOKEN"); token != "" {
                cfg.Token = token
        }
   
        client, err := pulsaradmin.NewClient(cfg)
        if err != nil {
                log.Fatalf("Failed to create client: %v", err)
        }
   
        topicName, err := utils.GetTopicName(topic)
        if err != nil {
                log.Fatalf("Failed to parse topic: %v", err)
        }
   
        fmt.Printf("Topic: %s\n\n", topic)
   
        // Create topic
        client.Topics().Create(*topicName, 0)
   
        // Initial value
        val, _ := client.Topics().GetMaxConsumers(*topicName)
        fmt.Printf("Initial: %d\n", val)
   
        // Set to 0
        err = client.Topics().SetMaxConsumers(*topicName, 0)
        if err != nil {
                log.Fatalf("Set failed: %v", err)
        }
        val, _ = client.Topics().GetMaxConsumers(*topicName)
        fmt.Printf("After set to 0: %d\n", val)
   
        // Remove
        err = client.Topics().RemoveMaxConsumers(*topicName)
        if err != nil {
                log.Fatalf("Remove failed: %v", err)
        }
        val, _ = client.Topics().GetMaxConsumers(*topicName)
        fmt.Printf("After remove: %d\n", val)
   
        fmt.Println("\nResult: Topic API always returns 0, cannot distinguish 
between unset/0/removed")
   }
   ```
   
   
   #### System configuration
   **Pulsar version**: 4.x but applies to all
   


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