From fa46bcf14575fdb99519799bf8042316983856e8 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 7 Aug 2024 20:22:05 +0800 Subject: [PATCH 1/2] should not copy sync.Map in loadBalancer.go --- golang/loadBalancer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/golang/loadBalancer.go b/golang/loadBalancer.go index da2dd647..dece95c0 100644 --- a/golang/loadBalancer.go +++ b/golang/loadBalancer.go @@ -30,7 +30,7 @@ import ( type PublishingLoadBalancer interface { TakeMessageQueueByMessageGroup(messageGroup *string) ([]*v2.MessageQueue, error) - TakeMessageQueues(excluded sync.Map, count int) ([]*v2.MessageQueue, error) + TakeMessageQueues(excluded *sync.Map, count int) ([]*v2.MessageQueue, error) CopyAndUpdate([]*v2.MessageQueue) PublishingLoadBalancer } @@ -63,7 +63,7 @@ func (plb *publishingLoadBalancer) TakeMessageQueueByMessageGroup(messageGroup * }, nil } -func (plb *publishingLoadBalancer) TakeMessageQueues(excluded sync.Map, count int) ([]*v2.MessageQueue, error) { +func (plb *publishingLoadBalancer) TakeMessageQueues(excluded *sync.Map, count int) ([]*v2.MessageQueue, error) { if len(plb.messageQueues) == 0 { return nil, fmt.Errorf("messageQueues is empty") } From 4cbe1adfb5623e331b77322839b7ff7d33dff5bd Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 7 Aug 2024 20:23:59 +0800 Subject: [PATCH 2/2] avoid copy sync.Map --- golang/producer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/producer.go b/golang/producer.go index 3e878a93..5f0a355d 100644 --- a/golang/producer.go +++ b/golang/producer.go @@ -79,7 +79,7 @@ func (p *defaultProducer) wrapHeartbeatRequest() *v2.HeartbeatRequest { } func (p *defaultProducer) takeMessageQueues(plb PublishingLoadBalancer) ([]*v2.MessageQueue, error) { - return plb.TakeMessageQueues(p.isolated, p.getRetryMaxAttempts()) + return plb.TakeMessageQueues(&p.isolated, p.getRetryMaxAttempts()) } func (p *defaultProducer) getPublishingTopicRouteResult(ctx context.Context, topic string) (PublishingLoadBalancer, error) {