Skip to content

Commit 4aa759b

Browse files
committed
[FAB-2479] Log consumer errors
https://jira.hyperledger.org/browse/FAB-2479 This changeset introduces the `listenForErrors` goroutine. It listens for and logs any errors that happen during the orderer's consumption of a Kafka partition (read: chain). Change-Id: Ia706049ba8c4d36dcfd9c5968b97588670f6046a Signed-off-by: Kostas Christidis <[email protected]>
1 parent f4448b9 commit 4aa759b

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

orderer/kafka/consumer.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"github.com/hyperledger/fabric/orderer/localconfig"
2222
)
2323

24-
// Consumer allows the caller to receive a stream of blobs from the Kafka cluster for a specific partition.
24+
// Consumer allows the caller to receive a stream of blobs
25+
// from the Kafka cluster for a specific partition.
2526
type Consumer interface {
2627
Recv() <-chan *sarama.ConsumerMessage
28+
Errors() <-chan *sarama.ConsumerError
2729
Closeable
2830
}
2931

@@ -49,11 +51,18 @@ func newConsumer(brokers []string, kafkaVersion sarama.KafkaVersion, tls config.
4951
return c, nil
5052
}
5153

52-
// Recv returns a channel with blobs received from the Kafka cluster for a partition.
54+
// Recv returns a channel with blobs received
55+
// from the Kafka cluster for a partition.
5356
func (c *consumerImpl) Recv() <-chan *sarama.ConsumerMessage {
5457
return c.partition.Messages()
5558
}
5659

60+
// Errors returns a channel with errors occuring during
61+
// the consumption of a partition from the Kafka cluster.
62+
func (c *consumerImpl) Errors() <-chan *sarama.ConsumerError {
63+
return c.partition.Errors()
64+
}
65+
5766
// Close shuts down the partition consumer.
5867
// Invoked by the session deliverer's Close method, which is itself called
5968
// during the processSeek function, between disabling and enabling the push.

orderer/kafka/consumer_mock_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func (mc *mockConsumerImpl) Recv() <-chan *sarama.ConsumerMessage {
107107
return nil
108108
}
109109

110+
func (mc *mockConsumerImpl) Errors() <-chan *sarama.ConsumerError {
111+
return nil
112+
}
113+
110114
func (mc *mockConsumerImpl) Close() error {
111115
if err := mc.chainPartitionManager.Close(); err != nil {
112116
return err

orderer/kafka/orderer.go

+10
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,21 @@ func (ch *chainImpl) Start() {
181181
}
182182
ch.consumer = consumer
183183
close(ch.setupChan)
184+
go ch.listenForErrors()
184185

185186
// 3. Set the loop the keep up to date with the chain.
186187
go ch.loop()
187188
}
188189

190+
func (ch *chainImpl) listenForErrors() {
191+
select {
192+
case <-ch.exitChan:
193+
return
194+
case err := <-ch.consumer.Errors():
195+
logger.Error(err)
196+
}
197+
}
198+
189199
// Halt frees the resources which were allocated for this Chain.
190200
// Implements the multichain.Chain interface.
191201
func (ch *chainImpl) Halt() {

orderer/kafka/util.go

+14-16
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,25 @@ import (
2727
ab "github.com/hyperledger/fabric/protos/orderer"
2828
)
2929

30-
// TODO Set the returned config file to more appropriate
31-
// defaults as we're getting closer to a stable release
3230
func newBrokerConfig(kafkaVersion sarama.KafkaVersion, chosenStaticPartition int32, tlsConfig config.TLS) *sarama.Config {
3331
brokerConfig := sarama.NewConfig()
3432

35-
brokerConfig.Version = kafkaVersion
36-
// Set the level of acknowledgement reliability needed from the broker.
37-
// WaitForAll means that the partition leader will wait till all ISRs
38-
// got the message before sending back an ACK to the sender.
39-
brokerConfig.Producer.RequiredAcks = sarama.WaitForAll
40-
// A partitioner is actually not needed the way we do things now,
41-
// but we're adding it now to allow for flexibility in the future.
42-
brokerConfig.Producer.Partitioner = newStaticPartitioner(chosenStaticPartition)
43-
// Set equivalent of kafka producer config max.request.bytes to the deafult
44-
// value of a Kafka broker's socket.request.max.bytes property (100 MiB).
45-
brokerConfig.Producer.MaxMessageBytes = int(sarama.MaxRequestSize)
33+
brokerConfig.Consumer.Return.Errors = true
4634

4735
brokerConfig.Net.TLS.Enable = tlsConfig.Enabled
48-
4936
if brokerConfig.Net.TLS.Enable {
5037
// create public/private key pair structure
5138
keyPair, err := tls.X509KeyPair([]byte(tlsConfig.Certificate), []byte(tlsConfig.PrivateKey))
5239
if err != nil {
5340
panic(fmt.Errorf("Unable to decode public/private key pair. Error: %v", err))
5441
}
55-
5642
// create root CA pool
5743
rootCAs := x509.NewCertPool()
5844
for _, certificate := range tlsConfig.RootCAs {
5945
if !rootCAs.AppendCertsFromPEM([]byte(certificate)) {
6046
panic(fmt.Errorf("Unable to decode certificate. Error: %v", err))
6147
}
6248
}
63-
6449
brokerConfig.Net.TLS.Config = &tls.Config{
6550
Certificates: []tls.Certificate{keyPair},
6651
RootCAs: rootCAs,
@@ -69,6 +54,19 @@ func newBrokerConfig(kafkaVersion sarama.KafkaVersion, chosenStaticPartition int
6954
}
7055
}
7156

57+
// Set the level of acknowledgement reliability needed from the broker.
58+
// WaitForAll means that the partition leader will wait till all ISRs
59+
// got the message before sending back an ACK to the sender.
60+
brokerConfig.Producer.RequiredAcks = sarama.WaitForAll
61+
// A partitioner is actually not needed the way we do things now,
62+
// but we're adding it now to allow for flexibility in the future.
63+
brokerConfig.Producer.Partitioner = newStaticPartitioner(chosenStaticPartition)
64+
// Set equivalent of Kafka producer config max.request.bytes to the default
65+
// value of a Kafka broker's socket.request.max.bytes property (100 MiB).
66+
brokerConfig.Producer.MaxMessageBytes = int(sarama.MaxRequestSize)
67+
68+
brokerConfig.Version = kafkaVersion
69+
7270
return brokerConfig
7371
}
7472

orderer/orderer.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ General:
2828
ClientAuthEnabled: false
2929
ClientRootCAs:
3030

31-
3231
# Log Level: The level at which to log. This accepts logging specifications
3332
# per fabric/docs/Setup/logging-control.md
3433
LogLevel: info

0 commit comments

Comments
 (0)