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

minor update on sarama config #461

Merged
merged 4 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion drainer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func GenCheckPointCfg(cfg *Config, id uint64) *checkpoint.Config {

func initializeSaramaGlobalConfig() {
sarama.MaxResponseSize = int32(maxMsgSize)
sarama.MaxRequestSize = int32(maxMsgSize)
// add 1 to avoid confused log: Producer.MaxMessageBytes must be smaller than MaxRequestSize; it will be ignored
sarama.MaxRequestSize = int32(maxMsgSize) + 1
}

func getDDLJob(tiStore kv.Storage, id int64) (*model.Job, error) {
Expand Down
12 changes: 5 additions & 7 deletions pkg/util/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func CreateKafkaProducer(config *sarama.Config, addr []string, kafkaVersion stri
if config == nil {
config = sarama.NewConfig()
}
config.ClientID = "tidb_binlog"
config.Producer.Partitioner = sarama.NewManualPartitioner
config.Producer.MaxMessageBytes = maxMsgSize
config.Producer.Return.Successes = true
Expand Down Expand Up @@ -77,25 +78,22 @@ func NewSaramaConfig(kafkaVersion string, metricsPrefix string) (*sarama.Config,
return nil, errors.Trace(err)
}

config.ClientID = "tidb_binlog"
config.Version = version
log.Debugf("kafka consumer version %v", version)
config.MetricRegistry = metrics.NewPrefixedChildRegistry(GetParentMetricsRegistry(), metricsPrefix)

return config, nil
}

// CreateKafkaConsumer creates a kafka consumer
func CreateKafkaConsumer(kafkaAddrs []string, kafkaVersion string) (sarama.Consumer, error) {
kafkaCfg := sarama.NewConfig()
kafkaCfg.Consumer.Return.Errors = true
version, err := sarama.ParseKafkaVersion(kafkaVersion)
kafkaCfg, err := NewSaramaConfig(kafkaVersion, "drainer.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can CreateKafkaProducer also call this rather than sarama.NewConfig()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateKafkaProducer is useless now, I removed this function in latest commit.

if err != nil {
return nil, errors.Trace(err)
}
kafkaCfg.Version = version
log.Infof("kafka consumer version %v", version)

registry := GetParentMetricsRegistry()
kafkaCfg.MetricRegistry = metrics.NewPrefixedChildRegistry(registry, "drainer.")
kafkaCfg.Consumer.Return.Errors = true

return sarama.NewConsumer(kafkaAddrs, kafkaCfg)
}