Skip to content

Commit

Permalink
Fix producer panic by oldProducers (#598)
Browse files Browse the repository at this point in the history
* Fix producer panic by oldProducers

Signed-off-by: xiaolongran <[email protected]>

* fix comments

Signed-off-by: xiaolongran <[email protected]>

* fix comments

Signed-off-by: xiaolongran <[email protected]>

* fix ci error

Signed-off-by: xiaolongran <[email protected]>
  • Loading branch information
wolfstudy authored Aug 25, 2021
1 parent bbffae2 commit baaf68d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
16 changes: 13 additions & 3 deletions pulsar/consumer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/apache/pulsar-client-go/pulsar/internal"
pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
"github.com/apache/pulsar-client-go/pulsar/log"
"github.com/pkg/errors"
)

const defaultNackRedeliveryDelay = 1 * time.Minute
Expand Down Expand Up @@ -266,16 +267,25 @@ func (c *consumer) internalTopicSubscribeToPartitions() error {
return nil
}

if oldNumPartitions > newNumPartitions {
c.log.WithField("old_partitions", oldNumPartitions).
WithField("new_partitions", newNumPartitions).
Error("Does not support scaling down operations on topic partitions")
return errors.New("Does not support scaling down operations on topic partitions")
}

c.log.WithField("old_partitions", oldNumPartitions).
WithField("new_partitions", newNumPartitions).
Info("Changed number of partitions in topic")
}

c.consumers = make([]*partitionConsumer, newNumPartitions)

// Copy over the existing consumer instances
for i := 0; i < oldNumPartitions; i++ {
c.consumers[i] = oldConsumers[i]
if oldConsumers != nil {
// Copy over the existing consumer instances
for i := 0; i < oldNumPartitions; i++ {
c.consumers[i] = oldConsumers[i]
}
}

type ConsumerError struct {
Expand Down
17 changes: 14 additions & 3 deletions pulsar/producer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/apache/pulsar-client-go/pulsar/internal"
"github.com/apache/pulsar-client-go/pulsar/log"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -182,16 +183,26 @@ func (p *producer) internalCreatePartitionsProducers() error {
return nil
}

if oldNumPartitions > newNumPartitions {
p.log.WithField("old_partitions", oldNumPartitions).
WithField("new_partitions", newNumPartitions).
Error("Does not support scaling down operations on topic partitions")
return errors.New("Does not support scaling down operations on topic partitions")
}

p.log.WithField("old_partitions", oldNumPartitions).
WithField("new_partitions", newNumPartitions).
Info("Changed number of partitions in topic")

}

p.producers = make([]Producer, newNumPartitions)

// Copy over the existing consumer instances
for i := 0; i < oldNumPartitions; i++ {
p.producers[i] = oldProducers[i]
if oldProducers != nil {
// Copy over the existing consumer instances
for i := 0; i < oldNumPartitions; i++ {
p.producers[i] = oldProducers[i]
}
}

type ProducerError struct {
Expand Down

0 comments on commit baaf68d

Please sign in to comment.