EAHITechnology commented on a change in pull request #696:
URL: https://github.com/apache/pulsar-client-go/pull/696#discussion_r780786317
##########
File path: pulsar/reader_partition.go
##########
@@ -0,0 +1,142 @@
+package pulsar
+
+import (
+ "sync"
+ "time"
+)
+
+func (r *reader) internalTopicReadToPartitions() error {
+ partitions, err := r.client.TopicPartitions(r.topic)
+ if err != nil {
+ return err
+ }
+
+ oldNumPartitions, newNumPartitions := 0, len(partitions)
+
+ r.Lock()
+ defer r.Unlock()
+
+ oldReaders, oldNumPartitions := r.consumers, len(r.consumers)
+ if oldReaders != nil {
+ if oldNumPartitions == newNumPartitions {
+ r.log.Debug("Number of partitions in topic has not
changed")
+ return nil
+ }
+
+ r.log.WithField("old_partitions", oldNumPartitions).
+ WithField("new_partitions", newNumPartitions).
+ Info("Changed number of partitions in topic")
+ }
+
+ r.consumers = make([]*partitionConsumer, newNumPartitions)
+
+ // When for some reason (eg: forced deletion of sub partition) causes
oldNumPartitions> newNumPartitions,
+ // we need to rebuild the cache of new consumers, otherwise the array
will be out of bounds.
+ if oldReaders != nil && oldNumPartitions < newNumPartitions {
+ // Copy over the existing consumer instances
+ for i := 0; i < oldNumPartitions; i++ {
+ r.consumers[i] = oldReaders[i]
+ }
+ }
+
+ type ConsumerError struct {
+ err error
+ partition int
+ consumer *partitionConsumer
+ }
+
+ subscriptionName := r.options.SubscriptionRolePrefix
+ if subscriptionName == "" {
+ subscriptionName = "reader"
Review comment:
ok
--
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]