Skip to content

Commit 2c9fd1b

Browse files
author
Kostas Christidis
committed
[FAB-2484] Prevent unclean leader election
https://jira.hyperledger.org/browse/FAB-2484 This fixes the bug described in: https://jira.hyperledger.org/browse/FAB-2259 Kafka ships with the `unclean.leader.election.enable` setting set to `true`. For our use case, this default is wrong as it trades consistency off for availability. Concretely, consider this worst-case scenario that goes against every proper practice: - Two brokers: B0 and B1 - A replication factor of 2 - `min.insync.replicas` set to 1 (the default) Assume B1 is the partition leader replica (though this doesn't really matter). B1 receives a batch of messages from an ordering service node, and writes them to disk. B0 does the same, replicating B1. We shut B0 down. We send a new batch of messages to the cluster (read: B1); B1 writes them to disk. We shut B1 down and then bring B0 up. If we send a new batch of messages to the cluster (read: B0), it will write them to disk using _re-using (some/all of) the offsets that B1 had used for its last batch of messages. This means we are rewriting the blockchain, which is obviously unacceptable. This changeset prevents this from happening. Change-Id: Iaa8f8a9fb3a5e001d4deeebcf2774f2a1026855c Signed-off-by: Kostas Christidis <kostas@christidis.io>
1 parent 2df8355 commit 2c9fd1b

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

bddtests/environments/kafka/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
kafka:
77
image: hyperledger/fabric-kafka
88
environment:
9+
KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
910
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1011
depends_on:
1112
- zookeeper

bddtests/environments/orderer-1-kafka-1/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
image: hyperledger/fabric-kafka
2121
environment:
2222
KAFKA_BROKER_ID: 0
23+
KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
2324
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
2425
depends_on:
2526
- zookeeper

bddtests/environments/orderer-1-kafka-3/docker-compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,28 @@ services:
2222
image: hyperledger/fabric-kafka
2323
environment:
2424
KAFKA_BROKER_ID: 0
25-
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
2625
KAFKA_DEFAULT_REPLICATION_FACTOR: 3
26+
KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
27+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
2728
depends_on:
2829
- zookeeper
2930

3031
kafka1:
3132
image: hyperledger/fabric-kafka
3233
environment:
3334
KAFKA_BROKER_ID: 1
34-
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
3535
KAFKA_DEFAULT_REPLICATION_FACTOR: 3
36+
KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
37+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
3638
depends_on:
3739
- zookeeper
3840

3941
kafka2:
4042
image: hyperledger/fabric-kafka
4143
environment:
4244
KAFKA_BROKER_ID: 2
43-
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
4445
KAFKA_DEFAULT_REPLICATION_FACTOR: 3
46+
KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
47+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
4548
depends_on:
4649
- zookeeper

bddtests/environments/orderer-n-kafka-n/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
kafka:
1818
image: hyperledger/fabric-kafka
1919
environment:
20+
KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE: "false"
2021
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
2122
depends_on:
2223
- zookeeper

orderer/orderer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ General:
2929

3030
# Log Level: The level at which to log. This accepts logging specifications
3131
# per: fabric/docs/Setup/logging-control.md
32-
LogLevel: info
32+
LogLevel: debug
3333

3434
# Genesis method: The method by which to retrieve/generate the genesis
3535
# block. Available values are "provisional", "file". Provisional utilizes

0 commit comments

Comments
 (0)