Set kafka read timeout to 10s and make it configurable (#27238)

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
pull/27276/head
yihao.dai 2023-09-20 22:01:27 +08:00 committed by GitHub
parent 93e2eb78c9
commit fe01d54eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -123,6 +123,7 @@ pulsar:
# saslPassword:
# saslMechanisms: PLAIN
# securityProtocol: SASL_SSL
# readTimeout: 10 # read message timeout in seconds
rocksmq:
# The path where the message is stored in rocksmq

View File

@ -11,6 +11,7 @@ import (
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)
type Consumer struct {
@ -140,7 +141,8 @@ func (kc *Consumer) Chan() <-chan mqwrapper.Message {
}
return
default:
e, err := kc.c.ReadMessage(30 * time.Second)
readTimeout := paramtable.Get().KafkaCfg.ReadTimeout.GetAsDuration(time.Second)
e, err := kc.c.ReadMessage(readTimeout)
if err != nil {
// if we failed to read message in 30 Seconds, print out a warn message since there should always be a tt
log.Warn("consume msg failed", zap.Any("topic", kc.topic), zap.String("groupID", kc.groupID), zap.Error(err))

View File

@ -637,6 +637,7 @@ type KafkaConfig struct {
SecurityProtocol ParamItem `refreshable:"false"`
ConsumerExtraConfig ParamGroup `refreshable:"false"`
ProducerExtraConfig ParamGroup `refreshable:"false"`
ReadTimeout ParamItem `refreshable:"true"`
}
func (k *KafkaConfig) Init(base *BaseTable) {
@ -692,6 +693,14 @@ func (k *KafkaConfig) Init(base *BaseTable) {
Version: "2.2.0",
}
k.ProducerExtraConfig.Init(base.mgr)
k.ReadTimeout = ParamItem{
Key: "kafka.readTimeout",
DefaultValue: "10",
Version: "2.3.1",
Export: true,
}
k.ReadTimeout.Init(base.mgr)
}
// /////////////////////////////////////////////////////////////////////////////

View File

@ -13,6 +13,7 @@ package paramtable
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
@ -167,6 +168,7 @@ func TestServiceParam(t *testing.T) {
assert.Empty(t, kc.Address.GetValue())
assert.Equal(t, kc.SaslMechanisms.GetValue(), "PLAIN")
assert.Equal(t, kc.SecurityProtocol.GetValue(), "SASL_SSL")
assert.Equal(t, kc.ReadTimeout.GetAsDuration(time.Second), 10*time.Second)
}
})