Skip to content

Commit

Permalink
[FAB-5413] Add initial execution in retry process.
Browse files Browse the repository at this point in the history
Retry process should do an initial execution before starting
retry time ticker, otherwise there is a delay for each retry,
which accumulatively will cause slow start of kafka chain.

Change-Id: I9c2aafeb73e366b72d94e317088548e4754ee8c4
Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
  • Loading branch information
guoger committed Jul 21, 2017
1 parent a3f2a02 commit 03afad8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 8 additions & 1 deletion orderer/consensus/kafka/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ func (rp *retryProcess) try(interval, total time.Duration) error {
return fmt.Errorf("illegal value")
}

var err = fmt.Errorf("process has not been executed yet")
var err error

// If initial operation is successful, we don't bother start retry process
logger.Debugf("[channel: %s] "+rp.msg, rp.channel.topic())
if err := rp.fn(); err == nil {
logger.Debugf("[channel: %s] Error is nil, breaking the retry loop", rp.channel.topic())
return err
}

tickInterval := time.NewTicker(interval)
tickTotal := time.NewTicker(total)
Expand Down
8 changes: 0 additions & 8 deletions orderer/consensus/kafka/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ func TestRetry(t *testing.T) {

errorFn := func() error { return fmt.Errorf("foo") }

t.Run("Exit", func(t *testing.T) {
exitChan := make(chan struct{})
close(exitChan)
rp = newRetryProcess(mockRetryOptions, exitChan, mockChannel, "foo", noErrorFn)
assert.Error(t, rp.retry(), "Expected retry to return an error")
assert.Equal(t, false, flag, "Expected flag to remain set to false")
})

t.Run("Proper", func(t *testing.T) {
exitChan := make(chan struct{})
rp = newRetryProcess(mockRetryOptions, exitChan, mockChannel, "foo", noErrorFn)
Expand Down

0 comments on commit 03afad8

Please sign in to comment.