Skip to content

Commit a99e792

Browse files
committed
[FAB-1365] Introduce Kafka container message types
https://jira.hyperledger.org/browse/FAB-1365 The revised Kafka consenter needs two special messages: 1. A time-to-cut message that is used to mark the end of a block, and 2. A no-op message that each shim posts when bootstrapped by the multichain manager to prevent the possibility of "listening in" (seeking and consuming) on a topic/partition that nobody has posted to yet [1]. This is an operation that panics in Kafka: "[ERROR] Cannot retrieve required offset from Kafka cluster: kafka server: The request attempted to perform an operation on an invalid topic." These messages are special because they don't carry transactions, and because the Kafka consenter will treat them in a special way: it will ignore every time-to-cut message (for a specific block number) besides the first one, and it will ignore all "no-op" messages when processing incoming messages from the chain partition. This changeset defines the types that will carry these messages, as well as helper functions to generate them. Note that these are not hooked into the main path yet, though a preview of these in action can be found here: https://github.com/kchristidis/fabric/blob/47752ed61fcab1b26207a9e9075c1c793d723912/orderer/kafka/main.go#L142 https://github.com/kchristidis/fabric/blob/47752ed61fcab1b26207a9e9075c1c793d723912/orderer/kafka/main.go#L164 https://github.com/kchristidis/fabric/blob/47752ed61fcab1b26207a9e9075c1c793d723912/orderer/kafka/main.go#L204 These changes will be hooked into the main path in a follow-up changeset that introduces the revised Kafka consenter. [1] We ask the consenter to "listen in" on an empty topic/partition every time a new chain is created, since we never actually post the genesis block to that chain's partition. Change-Id: Ic7ebbf2585e6e8e5080866e0d110d9cff5a16de5 Signed-off-by: Kostas Christidis <[email protected]>
1 parent 71a3389 commit a99e792

File tree

5 files changed

+317
-7
lines changed

5 files changed

+317
-7
lines changed

orderer/kafka/util.go

+31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kafka
1919
import (
2020
"github.com/Shopify/sarama"
2121
"github.com/hyperledger/fabric/orderer/localconfig"
22+
ab "github.com/hyperledger/fabric/protos/orderer"
2223
)
2324

2425
const (
@@ -41,6 +42,36 @@ func newBrokerConfig(conf *config.TopLevel) *sarama.Config {
4142
return brokerConfig
4243
}
4344

45+
func newConnectMessage() *ab.KafkaMessage {
46+
return &ab.KafkaMessage{
47+
Type: &ab.KafkaMessage_Connect{
48+
Connect: &ab.KafkaMessageConnect{
49+
Payload: nil,
50+
},
51+
},
52+
}
53+
}
54+
55+
func newRegularMessage(payload []byte) *ab.KafkaMessage {
56+
return &ab.KafkaMessage{
57+
Type: &ab.KafkaMessage_Regular{
58+
Regular: &ab.KafkaMessageRegular{
59+
Payload: payload,
60+
},
61+
},
62+
}
63+
}
64+
65+
func newTimeToCutMessage(blockNumber uint64) *ab.KafkaMessage {
66+
return &ab.KafkaMessage{
67+
Type: &ab.KafkaMessage_TimeToCut{
68+
TimeToCut: &ab.KafkaMessageTimeToCut{
69+
BlockNumber: blockNumber,
70+
},
71+
},
72+
}
73+
}
74+
4475
func newMsg(payload []byte, topic string) *sarama.ProducerMessage {
4576
return &sarama.ProducerMessage{
4677
Topic: topic,

protos/orderer/ab.pb.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.pb.go

+17-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/kafka.pb.go

+223
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/kafka.proto

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
syntax = "proto3";
18+
19+
option go_package = "github.com/hyperledger/fabric/protos/orderer";
20+
21+
package orderer;
22+
23+
message KafkaMessage {
24+
oneof Type {
25+
KafkaMessageRegular regular = 1;
26+
KafkaMessageTimeToCut time_to_cut = 2;
27+
KafkaMessageConnect connect = 3;
28+
}
29+
}
30+
31+
message KafkaMessageRegular {
32+
bytes payload = 1;
33+
}
34+
35+
message KafkaMessageTimeToCut {
36+
uint64 block_number = 1;
37+
}
38+
39+
message KafkaMessageConnect {
40+
bytes payload = 1;
41+
}

0 commit comments

Comments
 (0)