Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set default of SendResult.Status and fix panic #495

Merged
merged 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (td *traceDispatcher) sendTraceDataByMQ(keySet Keyset, regionID string, dat
var req = td.buildSendRequest(mq, msg)
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
err := td.cli.InvokeAsync(ctx, addr, req, func(command *remote.RemotingCommand, e error) {
resp := new(primitive.SendResult)
resp := primitive.NewSendResult()
if e != nil {
rlog.Info("send trace data error.", map[string]interface{}{
"traceData": data,
Expand Down
4 changes: 4 additions & 0 deletions primitive/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ type SendResult struct {
TraceOn bool
}

func NewSendResult() *SendResult {
return &SendResult{Status: SendUnknownError}
}

// SendResult send message result to string(detail result)
func (result *SendResult) String() string {
return fmt.Sprintf("SendResult [sendStatus=%d, msgIds=%s, offsetMsgId=%s, queueOffset=%d, messageQueue=%s]",
Expand Down
6 changes: 3 additions & 3 deletions producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (p *defaultProducer) SendSync(ctx context.Context, msgs ...*primitive.Messa

msg := p.encodeBatch(msgs...)

resp := new(primitive.SendResult)
resp := primitive.NewSendResult()
if p.interceptor != nil {
primitive.WithMethod(ctx, primitive.SendSync)
producerCtx := &primitive.ProducerCtx{
Expand Down Expand Up @@ -245,7 +245,7 @@ func (p *defaultProducer) sendAsync(ctx context.Context, msg *primitive.Message,

ctx, _ = context.WithTimeout(ctx, 3*time.Second)
return p.client.InvokeAsync(ctx, addr, p.buildSendRequest(mq, msg), func(command *remote.RemotingCommand, err error) {
resp := new(primitive.SendResult)
resp := primitive.NewSendResult()
if err != nil {
h(ctx, nil, err)
} else {
Expand Down Expand Up @@ -366,7 +366,7 @@ func (p *defaultProducer) selectMessageQueue(msg *primitive.Message) *primitive.
return nil
}

if result.MqList != nil && len(result.MqList) <= 0 {
if len(result.MqList) <= 0 {
rlog.Error("can not find proper message queue", nil)
return nil
}
Expand Down