Skip to content

Commit

Permalink
[FAB-5341] Solo should respect batchtimeout reconf
Browse files Browse the repository at this point in the history
Solo currently only reads the batch timeout at startup.  This is a
problem, because the batch timeout may be changed dynamically through a
reconfiguration transaction.

This CR simply causes solo to re-query the batch timeout from the config
each time the timer is initialized, rather than once at creation time.

Change-Id: I493fa4edddef40821336aa610ab242a3ffe97d26
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jul 17, 2017
1 parent 36b08c7 commit b817672
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 7 additions & 9 deletions orderer/solo/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ var logger = logging.MustGetLogger("orderer/solo")
type consenter struct{}

type chain struct {
support multichain.ConsenterSupport
batchTimeout time.Duration
sendChan chan *cb.Envelope
exitChan chan struct{}
support multichain.ConsenterSupport
sendChan chan *cb.Envelope
exitChan chan struct{}
}

// New creates a new consenter for the solo consensus scheme.
Expand All @@ -49,10 +48,9 @@ func (solo *consenter) HandleChain(support multichain.ConsenterSupport, metadata

func newChain(support multichain.ConsenterSupport) *chain {
return &chain{
batchTimeout: support.SharedConfig().BatchTimeout(),
support: support,
sendChan: make(chan *cb.Envelope),
exitChan: make(chan struct{}),
support: support,
sendChan: make(chan *cb.Envelope),
exitChan: make(chan struct{}),
}
}

Expand Down Expand Up @@ -92,7 +90,7 @@ func (ch *chain) main() {
case msg := <-ch.sendChan:
batches, committers, ok := ch.support.BlockCutter().Ordered(msg)
if ok && len(batches) == 0 && timer == nil {
timer = time.After(ch.batchTimeout)
timer = time.After(ch.support.SharedConfig().BatchTimeout())
continue
}
for i, batch := range batches {
Expand Down
10 changes: 9 additions & 1 deletion orderer/solo/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ func TestBatchTimer(t *testing.T) {
t.Fatalf("Did not create the second batch, indicating that the timer was not appopriately reset")
}

support.SharedConfigVal.BatchTimeoutVal, _ = time.ParseDuration("10s")
syncQueueMessage(testMessage, bs, support.BlockCutterVal)
select {
case <-support.Blocks:
t.Fatalf("Created another batch, indicating that the timer was not appopriately re-read")
case <-time.After(100 * time.Millisecond):
}

bs.Halt()
select {
case <-support.Blocks:
Expand Down Expand Up @@ -175,7 +183,7 @@ func TestBatchTimerHaltOnFilledBatch(t *testing.T) {
}

// Change the batch timeout to be near instant, if the timer was not reset, it will still be waiting an hour
bs.batchTimeout = time.Millisecond
support.SharedConfigVal.BatchTimeoutVal = time.Millisecond

support.BlockCutterVal.CutNext = false
syncQueueMessage(testMessage, bs, support.BlockCutterVal)
Expand Down

0 comments on commit b817672

Please sign in to comment.