Skip to content

Commit 925db23

Browse files
committed
FAB-15044 Mig-v1 cleanup #3
In preparation to the alternative migration design (v2), revert some of the commits already merged. Kafka to Raft migration v1 - cleanup #3 kafka2raft green path #3 (of v1) Clean commit 4950edd Change-Id: I52a1283e8b2041983f31071bb0a75c582b031a50 Signed-off-by: Yoav Tock <[email protected]>
1 parent 22ac9e6 commit 925db23

File tree

16 files changed

+45
-739
lines changed

16 files changed

+45
-739
lines changed

orderer/common/broadcast/mock/channel_support_registrar.go

Lines changed: 0 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/common/multichannel/chainsupport.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ type ChainSupport struct {
2727
consensus.Chain
2828
cutter blockcutter.Receiver
2929
identity.SignerSerializer
30-
// Needed for consensus-type migration: to execute the migration state machine correctly,
31-
// chains need to know if they are system or standard channel.
32-
systemChannel bool
3330
}
3431

3532
func newChainSupport(
@@ -59,9 +56,6 @@ func newChainSupport(
5956
),
6057
}
6158

62-
// When ConsortiumsConfig exists, it is the system channel
63-
_, cs.systemChannel = ledgerResources.ConsortiumsConfig()
64-
6559
// Set up the msgprocessor
6660
cs.Processor = msgprocessor.NewStandardChannel(cs, msgprocessor.CreateStandardChannelFilters(cs))
6761

@@ -183,8 +177,3 @@ func (cs *ChainSupport) VerifyBlockSignature(sd []*protoutil.SignedData, envelop
183177
}
184178
return nil
185179
}
186-
187-
// IsSystemChannel returns true if this is the system channel.
188-
func (cs *ChainSupport) IsSystemChannel() bool {
189-
return cs.systemChannel
190-
}

orderer/common/multichannel/registrar.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ func (r *Registrar) Initialize(consenters map[string]consensus.Consenter) {
146146
r.consenters = consenters
147147
existingChains := r.ledgerFactory.ChainIDs()
148148

149-
//TODO To initialize after consensus-type migration, it is necessary to identify the system channel and create it first,
150-
// determining the correct consensus-type and the state of the migration. This is needed for recovery, in case the
151-
// migration process crashes before it is committed.
152-
153149
for _, chainID := range existingChains {
154150
rl, err := r.ledgerFactory.GetOrCreate(chainID)
155151
if err != nil {
@@ -232,10 +228,6 @@ func (r *Registrar) BroadcastChannelSupport(msg *cb.Envelope) (*cb.ChannelHeader
232228
cs := r.GetChain(chdr.ChannelId)
233229
// New channel creation
234230
if cs == nil {
235-
// Prevent channel creation during consensus-type migration
236-
if r.ConsensusMigrationPending() {
237-
return chdr, true, nil, errors.New("cannot create channel because consensus-type migration is pending")
238-
}
239231
cs = r.systemChannel
240232
}
241233

@@ -251,68 +243,6 @@ func (r *Registrar) BroadcastChannelSupport(msg *cb.Envelope) (*cb.ChannelHeader
251243
return chdr, isConfig, cs, nil
252244
}
253245

254-
// ConsensusMigrationPending checks whether consensus-type migration is started on the system channel.
255-
func (r *Registrar) ConsensusMigrationPending() bool {
256-
//Note: systemChannel.MigrationStatus().IsPending() is thread safe, takes a mutex
257-
return r.systemChannel.MigrationStatus().IsPending()
258-
}
259-
260-
// ConsensusMigrationStart checks whether consensus-type migration had started,
261-
// and then marks all standard channels as started.
262-
func (r *Registrar) ConsensusMigrationStart(context uint64) error {
263-
r.lock.Lock()
264-
defer r.lock.Unlock()
265-
266-
for id, chain := range r.chains {
267-
if id != r.systemChannel.ChainID() && chain.MigrationStatus().IsPending() {
268-
return errors.Errorf("cannot start new consensus-type migration because standard channel %s, still pending", id)
269-
}
270-
}
271-
272-
for _, chain := range r.chains {
273-
chain.MigrationStatus().SetStateContext(ab.ConsensusType_MIG_STATE_START, context)
274-
}
275-
logger.Debugf("Consensus-type migration: all standard channels marked as started, context=%d", context)
276-
277-
return nil
278-
}
279-
280-
// ConsensusMigrationCommit checks pre-conditions and commits the consensus-type migration.
281-
func (r *Registrar) ConsensusMigrationCommit() error {
282-
r.lock.Lock()
283-
defer r.lock.Unlock()
284-
285-
sysState, sysContext := r.systemChannel.MigrationStatus().StateContext()
286-
if !(sysState == ab.ConsensusType_MIG_STATE_START && sysContext > 0) {
287-
return errors.Errorf("cannot commit consensus-type migration because system channel (%s): state=%s, context=%d (expect: state=%s, context>0)",
288-
r.systemChannel.ChainID(), sysState, sysContext, ab.ConsensusType_MIG_STATE_START)
289-
}
290-
291-
for id, chain := range r.chains {
292-
st, ctx := chain.MigrationStatus().StateContext()
293-
if id == r.systemChannel.ChainID() {
294-
continue
295-
}
296-
if st != ab.ConsensusType_MIG_STATE_CONTEXT {
297-
return errors.Errorf("cannot commit consensus-type migration because standard channel %s, still pending, state=%s", id, st)
298-
}
299-
if ctx != sysContext {
300-
return errors.Errorf("cannot commit consensus-type migration because standard channel %s, bad context=%d, expected=%d", id, ctx, sysContext)
301-
}
302-
}
303-
304-
r.systemChannel.MigrationStatus().SetStateContext(ab.ConsensusType_MIG_STATE_COMMIT, sysContext)
305-
logger.Debugf("Consensus-type migration: system channel marked as committed, context=%d", sysContext)
306-
307-
return nil
308-
}
309-
310-
// ConsensusMigrationAbort checks pre-conditions and aborts the consensus-type migration.
311-
func (r *Registrar) ConsensusMigrationAbort() error {
312-
//TODO implement the consensus-type migration abort path
313-
return fmt.Errorf("Not implemented yet")
314-
}
315-
316246
// GetChain retrieves the chain support for a chain if it exists.
317247
func (r *Registrar) GetChain(chainID string) *ChainSupport {
318248
r.lock.RLock()

orderer/common/multichannel/registrar_test.go

Lines changed: 1 addition & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/golang/protobuf/proto"
1313
"github.com/hyperledger/fabric/common/ledger/blockledger"
14-
ramledger "github.com/hyperledger/fabric/common/ledger/blockledger/ram"
14+
"github.com/hyperledger/fabric/common/ledger/blockledger/ram"
1515
"github.com/hyperledger/fabric/common/metrics/disabled"
1616
mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config"
1717
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
@@ -27,7 +27,6 @@ import (
2727
"github.com/hyperledger/fabric/protoutil"
2828
"github.com/pkg/errors"
2929
"github.com/stretchr/testify/assert"
30-
"github.com/stretchr/testify/require"
3130
)
3231

3332
//go:generate counterfeiter -o mocks/signer_serializer.go --fake-name SignerSerializer . signerSerializer
@@ -202,159 +201,6 @@ func TestNewRegistrar(t *testing.T) {
202201
})
203202
}
204203

205-
// This test essentially brings the entire system up and is ultimately what main.go will replicate,
206-
// doing it on the system and two standard channels.
207-
// Then, it is testing the methods that implement the MigrationController interface,
208-
// used in consensus-type migration.
209-
func Test3ChanConsensusMigrationController(t *testing.T) {
210-
const (
211-
testChainID1 = genesisconfig.TestChainID + "1"
212-
testChainID2 = genesisconfig.TestChainID + "2"
213-
)
214-
215-
var genesisBlockSys *cb.Block
216-
var genesisBlockStd1 *cb.Block
217-
var genesisBlockStd2 *cb.Block
218-
219-
//system channel
220-
confSys := configtxgentest.Load(genesisconfig.SampleInsecureSoloProfile)
221-
genesisBlockSys = encoder.New(confSys).GenesisBlock()
222-
//standard channel, no Consortiums
223-
confStd := configtxgentest.Load(genesisconfig.SampleInsecureSoloProfile)
224-
confStd.Consortiums = nil
225-
genesisBlockStd1 = encoder.New(confStd).GenesisBlockForChannel(testChainID1)
226-
genesisBlockStd2 = encoder.New(confStd).GenesisBlockForChannel(testChainID2)
227-
228-
t.Run("Green path", func(t *testing.T) {
229-
lf, rls := newRAMLedgerAndFactory3Chan(10,
230-
genesisconfig.TestChainID, genesisBlockSys,
231-
testChainID1, genesisBlockStd1,
232-
testChainID2, genesisBlockStd2)
233-
234-
consenters := make(map[string]consensus.Consenter)
235-
consenters[confSys.Orderer.OrdererType] = &mockConsenter{}
236-
237-
manager := NewRegistrar(lf, mockCrypto(), &disabled.Provider{})
238-
manager.Initialize(consenters)
239-
240-
chainSupport := manager.GetChain("Fake")
241-
assert.Nilf(t, chainSupport, "Should not have found a chain that was not created")
242-
243-
chainSupport = manager.GetChain(genesisconfig.TestChainID)
244-
assert.NotNilf(t, chainSupport, "Should have gotten chain which was initialized by ramledger")
245-
assert.True(t, chainSupport.IsSystemChannel())
246-
assert.True(t, !chainSupport.MigrationStatus().IsPending())
247-
248-
testMessageOrderAndRetrieval(confSys.Orderer.BatchSize.MaxMessageCount, genesisconfig.TestChainID, chainSupport, rls[0], t)
249-
250-
//standard channel 1
251-
chainSupport1 := manager.GetChain(testChainID1)
252-
assert.NotNilf(t, chainSupport1, "Should have gotten chain which was initialized by ramledger")
253-
assert.True(t, !chainSupport1.IsSystemChannel())
254-
assert.True(t, !chainSupport1.MigrationStatus().IsPending())
255-
256-
testMessageOrderAndRetrieval(confSys.Orderer.BatchSize.MaxMessageCount, testChainID1, chainSupport1, rls[1], t)
257-
258-
//standard channel 2
259-
chainSupport2 := manager.GetChain(testChainID2)
260-
assert.NotNilf(t, chainSupport2, "Should have gotten chain which was initialized by ramledger")
261-
assert.True(t, !chainSupport2.IsSystemChannel())
262-
assert.True(t, !chainSupport2.MigrationStatus().IsPending())
263-
264-
testMessageOrderAndRetrieval(confSys.Orderer.BatchSize.MaxMessageCount, testChainID2, chainSupport2, rls[2], t)
265-
266-
assert.Equal(t, 3, manager.ChannelsCount(), "Three channels")
267-
268-
// Test MigrationController methods
269-
assert.True(t, !manager.ConsensusMigrationPending())
270-
err := manager.ConsensusMigrationCommit()
271-
assert.EqualError(t, err,
272-
"cannot commit consensus-type migration because system channel (testchainid): state=MIG_STATE_NONE, context=0 (expect: state=MIG_STATE_START, context>0)")
273-
274-
ctx := uint64(5)
275-
err = manager.ConsensusMigrationStart(ctx)
276-
assert.NoError(t, err, "Migration start")
277-
assert.True(t, manager.ConsensusMigrationPending())
278-
assert.True(t, chainSupport.MigrationStatus().IsPending())
279-
assert.True(t, chainSupport1.MigrationStatus().IsPending())
280-
assert.True(t, chainSupport2.MigrationStatus().IsPending())
281-
err = manager.ConsensusMigrationStart(ctx)
282-
// Iteration order is unpredictable... can be 1 or 2
283-
assert.Regexp(t, "cannot start new consensus-type migration because standard channel testchainid[12], still pending", err.Error())
284-
285-
configTx := makeConfigTx(genesisconfig.TestChainID+"Fake", 6)
286-
_, _, _, err = manager.BroadcastChannelSupport(configTx)
287-
assert.Equal(t, "cannot create channel because consensus-type migration is pending", err.Error())
288-
289-
err = manager.ConsensusMigrationCommit()
290-
// Iteration order is unpredictable... can be 1 or 2
291-
assert.Regexp(t, "cannot commit consensus-type migration because standard channel testchainid[12], still pending, state=MIG_STATE_START", err.Error())
292-
293-
chainSupport1.MigrationStatus().SetStateContext(ab.ConsensusType_MIG_STATE_CONTEXT, ctx)
294-
assert.True(t, chainSupport1.MigrationStatus().IsPending())
295-
err = manager.ConsensusMigrationCommit()
296-
assert.EqualError(t, err, "cannot commit consensus-type migration because standard channel testchainid2, still pending, state=MIG_STATE_START")
297-
298-
chainSupport2.MigrationStatus().SetStateContext(ab.ConsensusType_MIG_STATE_CONTEXT, ctx+1)
299-
assert.True(t, chainSupport2.MigrationStatus().IsPending())
300-
301-
err = manager.ConsensusMigrationCommit()
302-
assert.EqualError(t, err, "cannot commit consensus-type migration because standard channel testchainid2, bad context=6, expected=5")
303-
304-
chainSupport2.MigrationStatus().SetStateContext(ab.ConsensusType_MIG_STATE_CONTEXT, ctx)
305-
assert.True(t, chainSupport2.MigrationStatus().IsPending())
306-
307-
err = manager.ConsensusMigrationCommit()
308-
assert.NoError(t, err, "Migration can commit")
309-
})
310-
311-
t.Run("Abort path", func(t *testing.T) {
312-
lf, rls := newRAMLedgerAndFactory3Chan(10,
313-
genesisconfig.TestChainID, genesisBlockSys,
314-
testChainID1, genesisBlockStd1,
315-
testChainID2, genesisBlockStd2)
316-
317-
consenters := make(map[string]consensus.Consenter)
318-
consenters[confSys.Orderer.OrdererType] = &mockConsenter{}
319-
320-
manager := NewRegistrar(lf, mockCrypto(), &disabled.Provider{})
321-
manager.Initialize(consenters)
322-
323-
chainSupport := manager.GetChain("Fake")
324-
assert.Nilf(t, chainSupport, "Should not have found a chain that was not created")
325-
326-
chainSupport = manager.GetChain(genesisconfig.TestChainID)
327-
require.NotNilf(t, chainSupport, "Should have gotten chain which was initialized by ramledger")
328-
testMessageOrderAndRetrieval(confSys.Orderer.BatchSize.MaxMessageCount, genesisconfig.TestChainID, chainSupport, rls[0], t)
329-
330-
//standard channel 1
331-
chainSupport1 := manager.GetChain(testChainID1)
332-
require.NotNilf(t, chainSupport1, "Should have gotten chain which was initialized by ramledger")
333-
testMessageOrderAndRetrieval(confSys.Orderer.BatchSize.MaxMessageCount, testChainID1, chainSupport1, rls[1], t)
334-
335-
//standard channel 2
336-
chainSupport2 := manager.GetChain(testChainID2)
337-
require.NotNilf(t, chainSupport2, "Should have gotten chain which was initialized by ramledger")
338-
testMessageOrderAndRetrieval(confSys.Orderer.BatchSize.MaxMessageCount, testChainID2, chainSupport2, rls[2], t)
339-
340-
assert.Equal(t, 3, manager.ChannelsCount(), "Three channels")
341-
342-
// Test MigrationController methods
343-
ctx := uint64(5)
344-
err := manager.ConsensusMigrationStart(ctx)
345-
assert.NoError(t, err, "Migration start")
346-
assert.True(t, manager.ConsensusMigrationPending())
347-
assert.True(t, chainSupport.MigrationStatus().IsPending())
348-
chainSupport1.MigrationStatus().SetStateContext(ab.ConsensusType_MIG_STATE_CONTEXT, ctx)
349-
assert.True(t, chainSupport1.MigrationStatus().IsPending())
350-
351-
err = manager.ConsensusMigrationAbort()
352-
assert.EqualError(t, err, "Not implemented yet")
353-
354-
//TODO test abort path here, when implemented
355-
})
356-
}
357-
358204
func TestCreateChain(t *testing.T) {
359205
//system channel
360206
confSys := configtxgentest.Load(genesisconfig.SampleInsecureSoloProfile)

0 commit comments

Comments
 (0)