Skip to content

Commit eb88d26

Browse files
committed
FAB-15043 Mig-v1 cleanup #2
In preparation to the alternative migration design (v2), revert some of the commits already merged. Kafka to Raft migration v1 - cleanup #2 Clean Kafka2Raft green path #4 (of v1) Clean commit 0504983 Change-Id: Ic7274401fdc58870c997b3204c21f548c7f5d1af Signed-off-by: Yoav Tock <[email protected]>
1 parent 01a7c89 commit eb88d26

File tree

6 files changed

+8
-148
lines changed

6 files changed

+8
-148
lines changed

orderer/common/multichannel/chainsupport.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/hyperledger/fabric/orderer/common/msgprocessor"
1616
"github.com/hyperledger/fabric/orderer/consensus"
1717
cb "github.com/hyperledger/fabric/protos/common"
18-
"github.com/hyperledger/fabric/protos/orderer"
1918
"github.com/hyperledger/fabric/protos/utils"
2019
"github.com/pkg/errors"
2120
)
@@ -69,14 +68,6 @@ func newChainSupport(
6968
// Set up the block writer
7069
cs.BlockWriter = newBlockWriter(lastBlock, registrar, cs)
7170

72-
// TODO Identify recovery after crash in the middle of consensus-type migration
73-
if cs.detectMigration(lastBlock) {
74-
// We do this because the last block after migration (COMMIT/CONTEXT) carries Kafka metadata.
75-
// This prevents the code down the line from unmarshaling it as Raft, and panicking.
76-
metadata.Value = nil
77-
logger.Debugf("[channel: %s] Consensus-type migration: restart on to Raft, resetting Kafka block metadata", cs.ChainID())
78-
}
79-
8071
// Set up the consenter
8172
consenterType := ledgerResources.SharedConfig().ConsensusType()
8273
consenter, ok := consenters[consenterType]
@@ -94,53 +85,6 @@ func newChainSupport(
9485
return cs
9586
}
9687

97-
// detectMigration identifies restart after consensus-type migration was committed (green path).
98-
// Restart after migration is detected by:
99-
// 1. The Kafka2RaftMigration capability in on
100-
// 2. The last block carries a config-tx
101-
// 3. In the config-tx, you have:
102-
// - (system-channel && state=COMMIT), OR
103-
// - (standard-channel && state=CONTEXT)
104-
// This assumes that migration was successful (green path). When migration ends successfully,
105-
// every channel will have a config block as the last block. On the system channel, containing state=COMMIT;
106-
// on standard channels, containing state=CONTEXT.
107-
func (cs *ChainSupport) detectMigration(lastBlock *cb.Block) bool {
108-
isMigration := false
109-
110-
if !cs.ledgerResources.SharedConfig().Capabilities().Kafka2RaftMigration() {
111-
return isMigration
112-
}
113-
114-
lastConfigIndex, err := utils.GetLastConfigIndexFromBlock(lastBlock)
115-
if err != nil {
116-
logger.Panicf("Chain did not have appropriately encoded last config in its latest block: %s", err)
117-
}
118-
119-
logger.Debugf("[channel: %s], sysChan=%v, lastConfigIndex=%d, H=%d, mig-state: %s",
120-
cs.ChainID(), cs.systemChannel, lastConfigIndex, cs.ledgerResources.Height(),
121-
cs.ledgerResources.SharedConfig().ConsensusMigrationState())
122-
123-
if lastConfigIndex == lastBlock.Header.Number { //The last block was a config-tx
124-
state := cs.ledgerResources.SharedConfig().ConsensusMigrationState()
125-
if cs.systemChannel {
126-
if state == orderer.ConsensusType_MIG_STATE_COMMIT {
127-
isMigration = true
128-
}
129-
} else {
130-
if state == orderer.ConsensusType_MIG_STATE_CONTEXT {
131-
isMigration = true
132-
}
133-
}
134-
135-
if isMigration {
136-
logger.Infof("[channel: %s], Restarting after consensus-type migration. New consensus-type is: %s",
137-
cs.ChainID(), cs.ledgerResources.SharedConfig().ConsensusType())
138-
}
139-
}
140-
141-
return isMigration
142-
}
143-
14488
// Block returns a block with the following number,
14589
// or nil if such a block doesn't exist.
14690
func (cs *ChainSupport) Block(number uint64) *cb.Block {

orderer/consensus/etcdraft/chain.go

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,7 @@ func (c *Chain) Start() {
330330
}
331331

332332
isJoin := c.support.Height() > 1
333-
isMigration := false
334-
if isJoin {
335-
isMigration = c.detectMigration()
336-
}
337-
c.Node.start(c.fresh, isJoin, isMigration)
333+
c.Node.start(c.fresh, isJoin)
338334

339335
close(c.startC)
340336
close(c.errorC)
@@ -358,42 +354,6 @@ func (c *Chain) Start() {
358354
c.periodicChecker.Run()
359355
}
360356

361-
// detectMigration detects if the orderer restarts right after consensus-type migration,
362-
// in which the Height>1 but previous blocks were created by Kafka.
363-
// If this is the case, Raft should be started like it is joining a new channel.
364-
func (c *Chain) detectMigration() bool {
365-
startOfChain := false
366-
if c.support.SharedConfig().Capabilities().Kafka2RaftMigration() {
367-
lastConfigIndex, err := utils.GetLastConfigIndexFromBlock(c.lastBlock)
368-
if err != nil {
369-
c.logger.Panicf("Chain did not have appropriately encoded last config in its latest block: %s", err)
370-
}
371-
372-
c.logger.Debugf("Detecting if consensus-type migration, sysChan=%v, lastConfigIndex=%d, Height=%d, mig-state: %s",
373-
c.support.IsSystemChannel(), lastConfigIndex, c.lastBlock.Header.Number+1, c.support.SharedConfig().ConsensusMigrationState().String())
374-
375-
if lastConfigIndex != c.lastBlock.Header.Number { // The last block is not a config-tx
376-
return startOfChain
377-
}
378-
379-
// The last block was a config-tx
380-
if c.support.IsSystemChannel() {
381-
if c.support.SharedConfig().ConsensusMigrationState() == orderer.ConsensusType_MIG_STATE_COMMIT {
382-
startOfChain = true
383-
}
384-
} else {
385-
if c.support.SharedConfig().ConsensusMigrationState() == orderer.ConsensusType_MIG_STATE_CONTEXT {
386-
startOfChain = true
387-
}
388-
}
389-
390-
if startOfChain {
391-
c.logger.Infof("Restarting after consensus-type migration. Type: %s, just starting the channel.", c.support.SharedConfig().ConsensusType())
392-
}
393-
}
394-
return startOfChain
395-
}
396-
397357
// Order submits normal type transactions for ordering.
398358
func (c *Chain) Order(env *common.Envelope, configSeq uint64) error {
399359
c.Metrics.NormalProposalsReceived.Add(1)
@@ -1329,14 +1289,6 @@ func (c *Chain) getInFlightConfChange() *raftpb.ConfChange {
13291289
return nil
13301290
}
13311291

1332-
// Detect if it is a restart right after consensus-type migration. If yes, return early in order to avoid using
1333-
// the block metadata as etcdraft.BlockMetadata (see below). Right after migration the block metadata will carry
1334-
// Kafka metadata. The etcdraft.BlockMetadata should be extracted from the ConsensusType.Metadata, instead.
1335-
if c.detectMigration() {
1336-
c.logger.Infof("Restarting after consensus-type migration. Type: %s, just starting the chain.", c.support.SharedConfig().ConsensusType())
1337-
return nil
1338-
}
1339-
13401292
// extracting current Raft configuration state
13411293
confState := c.Node.ApplyConfChange(raftpb.ConfChange{})
13421294

orderer/consensus/etcdraft/chain_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,12 +3500,7 @@ func newChain(timeout time.Duration, channel string, dataDir string, id uint64,
35003500

35013501
support := &consensusmocks.FakeConsenterSupport{}
35023502
support.ChainIDReturns(channel)
3503-
support.SharedConfigReturns(&mockconfig.Orderer{
3504-
BatchTimeoutVal: timeout,
3505-
CapabilitiesVal: &mockconfig.OrdererCapabilities{
3506-
Kafka2RaftMigVal: false,
3507-
},
3508-
})
3503+
support.SharedConfigReturns(&mockconfig.Orderer{BatchTimeoutVal: timeout})
35093504

35103505
cutter := mockblockcutter.NewReceiver()
35113506
close(cutter.Block)

orderer/consensus/etcdraft/consenter.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package etcdraft
88

99
import (
1010
"bytes"
11-
"encoding/hex"
1211
"path"
1312
"reflect"
1413
"time"
@@ -120,27 +119,11 @@ func (c *Consenter) detectSelfID(consenters map[uint64]*etcdraft.Consenter) (uin
120119

121120
// HandleChain returns a new Chain instance or an error upon failure
122121
func (c *Consenter) HandleChain(support consensus.ConsenterSupport, metadata *common.Metadata) (consensus.Chain, error) {
123-
124-
if support.SharedConfig().Capabilities().Kafka2RaftMigration() {
125-
c.Logger.Debugf("SharedConfig.ConsensusType fields: Type=%s, ConsensusMigrationState=%s, ConsensusMigrationContext=%d, ConsensusMetadata length=%d",
126-
support.SharedConfig().ConsensusType(), support.SharedConfig().ConsensusMigrationState(),
127-
support.SharedConfig().ConsensusMigrationContext(), len(support.SharedConfig().ConsensusMetadata()))
128-
if support.SharedConfig().ConsensusMigrationState() != orderer.ConsensusType_MIG_STATE_NONE {
129-
c.Logger.Debugf("SharedConfig.ConsensusType: ConsensusMetadata dump:\n%s", hex.Dump(support.SharedConfig().ConsensusMetadata()))
130-
}
131-
}
132-
133122
m := &etcdraft.ConfigMetadata{}
134123
if err := proto.Unmarshal(support.SharedConfig().ConsensusMetadata(), m); err != nil {
135124
return nil, errors.Wrap(err, "failed to unmarshal consensus metadata")
136125
}
137126

138-
if support.SharedConfig().Capabilities().Kafka2RaftMigration() &&
139-
support.SharedConfig().ConsensusMigrationState() != orderer.ConsensusType_MIG_STATE_NONE {
140-
c.Logger.Debugf("SharedConfig().ConsensusMetadata(): %s", m.String())
141-
c.Logger.Debugf("block metadata.Value dump: \n%s", hex.Dump(metadata.Value))
142-
}
143-
144127
if m.Options == nil {
145128
return nil, errors.New("etcdraft options have not been provided")
146129
}

orderer/consensus/etcdraft/consenter_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ var _ = Describe("Consenter", func() {
156156
metadata := utils.MarshalOrPanic(m)
157157
support.SharedConfigReturns(&mockconfig.Orderer{
158158
ConsensusMetadataVal: metadata,
159-
CapabilitiesVal: &mockconfig.OrdererCapabilities{
160-
Kafka2RaftMigVal: false,
161-
},
162-
BatchSizeVal: &orderer.BatchSize{PreferredMaxBytes: 2 * 1024 * 1024},
159+
BatchSizeVal: &orderer.BatchSize{PreferredMaxBytes: 2 * 1024 * 1024},
163160
})
164161

165162
consenter := newConsenter(chainGetter)
@@ -199,10 +196,7 @@ var _ = Describe("Consenter", func() {
199196
support := &consensusmocks.FakeConsenterSupport{}
200197
support.SharedConfigReturns(&mockconfig.Orderer{
201198
ConsensusMetadataVal: metadata,
202-
CapabilitiesVal: &mockconfig.OrdererCapabilities{
203-
Kafka2RaftMigVal: false,
204-
},
205-
BatchSizeVal: &orderer.BatchSize{PreferredMaxBytes: 2 * 1024 * 1024},
199+
BatchSizeVal: &orderer.BatchSize{PreferredMaxBytes: 2 * 1024 * 1024},
206200
})
207201
support.ChainIDReturns("foo")
208202

@@ -224,10 +218,7 @@ var _ = Describe("Consenter", func() {
224218
metadata := utils.MarshalOrPanic(m)
225219
support.SharedConfigReturns(&mockconfig.Orderer{
226220
ConsensusMetadataVal: metadata,
227-
CapabilitiesVal: &mockconfig.OrdererCapabilities{
228-
Kafka2RaftMigVal: false,
229-
},
230-
BatchSizeVal: &orderer.BatchSize{PreferredMaxBytes: 2 * 1024 * 1024},
221+
BatchSizeVal: &orderer.BatchSize{PreferredMaxBytes: 2 * 1024 * 1024},
231222
})
232223

233224
consenter := newConsenter(chainGetter)

orderer/consensus/etcdraft/node.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,15 @@ type node struct {
4646
raft.Node
4747
}
4848

49-
func (n *node) start(fresh, join, migration bool) {
49+
func (n *node) start(fresh, join bool) {
5050
raftPeers := RaftPeers(n.metadata.ConsenterIds)
5151
n.logger.Debugf("Starting raft node: #peers: %v", len(raftPeers))
5252

5353
var campaign bool
5454
if fresh {
5555
if join {
56-
if !migration {
57-
raftPeers = nil
58-
n.logger.Info("Starting raft node to join an existing channel")
59-
60-
} else {
61-
n.logger.Info("Starting raft node to join an existing channel, after consensus-type migration")
62-
}
56+
raftPeers = nil
57+
n.logger.Info("Starting raft node to join an existing channel")
6358
} else {
6459
n.logger.Info("Starting raft node as part of a new channel")
6560

0 commit comments

Comments
 (0)