sarama icon indicating copy to clipboard operation
sarama copied to clipboard

Why is there three partitions and one consumer under the distribution strategy of the balancestrategyrange of the consumergroup? At this time, the consumer is always assigned the same partition

Open J-Orange-Sun opened this issue 3 years ago • 1 comments

Versions

Please specify real version numbers or git SHAs, not just "Latest" since that changes fairly regularly.

Sarama Kafka Go
1.24.1 2.5.0 1.16.8
Configuration

What configuration values are you using for Sarama and Kafka? sarama

//initSaramaConfig 初始化 Sarama 配置
func initSaramaConfig(cfg *config.Kafka) (*sarama.Config, error){

	config := sarama.NewConfig()
	//重试发送消息总次数
	config.Producer.Retry.Max = cfg.ProducerRetries
	config.Producer.Flush.MaxMessages = cfg.ProducerBatchSize
	config.Producer.Flush.Frequency = util.MustParseDuration(cfg.ProducerLinger)
	config.Producer.Flush.Bytes = cfg.ProducerBuffMemory
	config.Producer.Return.Successes = true
	config.Producer.Return.Errors = true
	config.Consumer.Offsets.Initial = sarama.OffsetNewest
	config.Consumer.Return.Errors = true

	config.Consumer.Group.Rebalance.Timeout = time.Second * 10
	config.Consumer.Group.Rebalance.Strategy = sarama.BalanceStrategyRange

	version, err := sarama.ParseKafkaVersion("2.5.0")
	config.Version = version

	if err != nil {
		zap.L().Fatal("[KAFKA] Parse Kafka version error", zap.Error(err))
		return nil, err
	}

	if cfg.IsSSL {

		if cfg.SslClientCertPemLocation == "" || cfg.SslClientKeyPemLocation == "" || cfg.SslServerCerPemLocation == "" {
			zap.L().Info("Please config perm location")
		}

		tlsConfig, err := NewTLSConfig(
			cfg.SslClientCertPemLocation,
			cfg.SslClientKeyPemLocation,
			cfg.SslServerCerPemLocation)
		if err != nil {
			zap.L().Fatal("[KAFKA] SSL ERROR", zap.Error(err))
		}
		// This can be used on test server if domain does not match cert:
		tlsConfig.InsecureSkipVerify = true
		config.Net.TLS.Enable = true
		config.Net.TLS.Config = tlsConfig
	}

	return config, err

}

kafka

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092

delete.topic.enable=true
host.name=kafka-003
listeners=PLAINTEXT://kafka-003:9894,SSL://kafka-003:9994
advertised.listeners=PLAINTEXT://kafka-003:9894,SSL://kafka-003:9994
ssl.truststore.location=/Users/sunlin/Documents/local/cert_test/kafka.server.truststore.jks
ssl.truststore.password=rawpool
ssl.keystore.location=/Users/sunlin/Documents/local/cert_test/kafka.server.keystore.jks
ssl.keystore.password=rawpool
ssl.key.password=rawpool
security.inter.broker.protocol=SSL
ssl.endpoint.identification.algorithm=
#ssl.client.auth=required
ssl.client.auth=none
#ssl.secure.random.implementation=SHA1PRNG
ssl.enabled.protocols=TLSv1.2,TLSv1.1,TLSv1
message.max.bytes=900000000
replica.fetch.max.bytes=900000000
listener.name.internal.ssl.endpoint.identification.algorithm=

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma separated list of directories under which to store log files
log.dirs=/tmp/kafka-logs

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=3

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2184

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000


############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0

Logs

When filing an issue please provide logs from Sarama and Kafka if at all possible. You can set sarama.Logger to a log.Logger to capture Sarama debug output.

logs: CLICK ME

{"L":"warn","@timestamp":"2022-02-09T16:54:21.268+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share456","Partition":2,"Offset":220}
{"L":"warn","@timestamp":"2022-02-09T16:54:33.278+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share458","Partition":2,"Offset":221}
{"L":"warn","@timestamp":"2022-02-09T16:54:51.301+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share461","Partition":2,"Offset":222}
{"L":"warn","@timestamp":"2022-02-09T16:54:57.309+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share462","Partition":2,"Offset":223}
{"L":"warn","@timestamp":"2022-02-09T16:55:27.345+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share467","Partition":2,"Offset":224}
{"L":"warn","@timestamp":"2022-02-09T16:56:03.382+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share473","Partition":2,"Offset":225}
{"L":"warn","@timestamp":"2022-02-09T16:56:09.392+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share474","Partition":2,"Offset":226}
{"L":"warn","@timestamp":"2022-02-09T16:56:33.434+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share478","Partition":2,"Offset":227}
{"L":"warn","@timestamp":"2022-02-09T16:56:45.457+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share480","Partition":2,"Offset":228}
{"L":"warn","@timestamp":"2022-02-09T16:57:03.469+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share483","Partition":2,"Offset":229}
{"L":"warn","@timestamp":"2022-02-09T16:57:15.480+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share485","Partition":2,"Offset":230}
{"L":"warn","@timestamp":"2022-02-09T16:57:39.518+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share489","Partition":2,"Offset":231}
{"L":"warn","@timestamp":"2022-02-09T16:57:51.529+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share491","Partition":2,"Offset":232}
{"L":"warn","@timestamp":"2022-02-09T16:58:09.556+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share494","Partition":2,"Offset":233}
{"L":"warn","@timestamp":"2022-02-09T16:58:27.574+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share497","Partition":2,"Offset":234}
{"L":"warn","@timestamp":"2022-02-09T16:58:33.578+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share498","Partition":2,"Offset":235}
{"L":"warn","@timestamp":"2022-02-09T16:58:45.589+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share500","Partition":2,"Offset":236}
{"L":"warn","@timestamp":"2022-02-09T16:59:27.647+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share507","Partition":2,"Offset":237}
{"L":"warn","@timestamp":"2022-02-09T16:59:51.675+0800","C":"service/syncServer.go:60","msg":"[KAFKA] Sync Key ","Message Key":"Share511","Partition":2,"Offset":238}


producer


Send Message Key  Share456  Value  aa 456  Partition  2  Offset  220
Send Message Key  Share457  Value  aa 457  Partition  0  Offset  229
Send Message Key  Share458  Value  aa 458  Partition  2  Offset  221
Send Message Key  Share459  Value  aa 459  Partition  0  Offset  230
Send Message Key  Share460  Value  aa 460  Partition  0  Offset  231
Send Message Key  Share461  Value  aa 461  Partition  2  Offset  222
Send Message Key  Share462  Value  aa 462  Partition  2  Offset  223
Send Message Key  Share463  Value  aa 463  Partition  1  Offset  224
Send Message Key  Share464  Value  aa 464  Partition  1  Offset  225
Send Message Key  Share465  Value  aa 465  Partition  0  Offset  232
Send Message Key  Share466  Value  aa 466  Partition  0  Offset  233
Send Message Key  Share467  Value  aa 467  Partition  2  Offset  224
Send Message Key  Share468  Value  aa 468  Partition  1  Offset  226
Send Message Key  Share469  Value  aa 469  Partition  0  Offset  234
Send Message Key  Share470  Value  aa 470  Partition  1  Offset  227
Send Message Key  Share471  Value  aa 471  Partition  0  Offset  235
Send Message Key  Share472  Value  aa 472  Partition  0  Offset  236
Send Message Key  Share473  Value  aa 473  Partition  2  Offset  225
Send Message Key  Share474  Value  aa 474  Partition  2  Offset  226
Send Message Key  Share475  Value  aa 475  Partition  1  Offset  228
Send Message Key  Share476  Value  aa 476  Partition  1  Offset  229
Send Message Key  Share477  Value  aa 477  Partition  0  Offset  237
Send Message Key  Share478  Value  aa 478  Partition  2  Offset  227
Send Message Key  Share479  Value  aa 479  Partition  1  Offset  230
Send Message Key  Share480  Value  aa 480  Partition  2  Offset  228
Send Message Key  Share481  Value  aa 481  Partition  0  Offset  238
Send Message Key  Share482  Value  aa 482  Partition  1  Offset  231
Send Message Key  Share483  Value  aa 483  Partition  2  Offset  229
Send Message Key  Share484  Value  aa 484  Partition  1  Offset  232
Send Message Key  Share485  Value  aa 485  Partition  2  Offset  230
Send Message Key  Share486  Value  aa 486  Partition  0  Offset  239
Send Message Key  Share487  Value  aa 487  Partition  1  Offset  233
Send Message Key  Share488  Value  aa 488  Partition  1  Offset  234
Send Message Key  Share489  Value  aa 489  Partition  2  Offset  231
Send Message Key  Share490  Value  aa 490  Partition  1  Offset  235
Send Message Key  Share491  Value  aa 491  Partition  2  Offset  232
Send Message Key  Share492  Value  aa 492  Partition  0  Offset  240
Send Message Key  Share493  Value  aa 493  Partition  1  Offset  236
Send Message Key  Share494  Value  aa 494  Partition  2  Offset  233
Send Message Key  Share495  Value  aa 495  Partition  0  Offset  241
Send Message Key  Share496  Value  aa 496  Partition  1  Offset  237
Send Message Key  Share497  Value  aa 497  Partition  2  Offset  234
Send Message Key  Share498  Value  aa 498  Partition  2  Offset  235
Send Message Key  Share499  Value  aa 499  Partition  0  Offset  242
Send Message Key  Share500  Value  aa 500  Partition  2  Offset  236
Send Message Key  Share501  Value  aa 501  Partition  0  Offset  243
Send Message Key  Share502  Value  aa 502  Partition  0  Offset  244
Send Message Key  Share503  Value  aa 503  Partition  1  Offset  238
Send Message Key  Share504  Value  aa 504  Partition  0  Offset  245
Send Message Key  Share505  Value  aa 505  Partition  1  Offset  239
Send Message Key  Share506  Value  aa 506  Partition  1  Offset  240
Send Message Key  Share507  Value  aa 507  Partition  2  Offset  237
Send Message Key  Share508  Value  aa 508  Partition  0  Offset  246
Send Message Key  Share509  Value  aa 509  Partition  1  Offset  241
Send Message Key  Share510  Value  aa 510  Partition  0  Offset  247
Send Message Key  Share511  Value  aa 511  Partition  2  Offset  238

Problem Description

J-Orange-Sun avatar Feb 09 '22 09:02 J-Orange-Sun

saramaConsumerGroup, err = sarama.NewConsumerGroup(brokerList, groupId, config)
ctx = context.Background()
if err != nil {
	zap.L().Fatal("[KAFKA] kafka consumer group connect error", zap.Error(err))
}

J-Orange-Sun avatar Feb 09 '22 09:02 J-Orange-Sun

Thank you for taking the time to raise this issue. However, it has not had any activity on it in the past 90 days and will be closed in 30 days if no updates occur. Please check if the main branch has already resolved the issue since it was raised. If you believe the issue is still valid and you would like input from the maintainers then please comment to ask for it to be reviewed.

github-actions[bot] avatar Aug 18 '23 14:08 github-actions[bot]

@J-Orange-Sun sorry for the slow response to your issue, did you resolve this one?

dnwe avatar Aug 18 '23 20:08 dnwe

Thank you for taking the time to raise this issue. However, it has not had any activity on it in the past 90 days and will be closed in 30 days if no updates occur. Please check if the main branch has already resolved the issue since it was raised. If you believe the issue is still valid and you would like input from the maintainers then please comment to ask for it to be reviewed.

github-actions[bot] avatar Nov 17 '23 00:11 github-actions[bot]