Skip to content

Commit 03afad8

Browse files
committed
[FAB-5413] Add initial execution in retry process.
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 <[email protected]>
1 parent a3f2a02 commit 03afad8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

orderer/consensus/kafka/retry.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ func (rp *retryProcess) try(interval, total time.Duration) error {
5252
return fmt.Errorf("illegal value")
5353
}
5454

55-
var err = fmt.Errorf("process has not been executed yet")
55+
var err error
56+
57+
// If initial operation is successful, we don't bother start retry process
58+
logger.Debugf("[channel: %s] "+rp.msg, rp.channel.topic())
59+
if err := rp.fn(); err == nil {
60+
logger.Debugf("[channel: %s] Error is nil, breaking the retry loop", rp.channel.topic())
61+
return err
62+
}
5663

5764
tickInterval := time.NewTicker(interval)
5865
tickTotal := time.NewTicker(total)

orderer/consensus/kafka/retry_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ func TestRetry(t *testing.T) {
2626

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

29-
t.Run("Exit", func(t *testing.T) {
30-
exitChan := make(chan struct{})
31-
close(exitChan)
32-
rp = newRetryProcess(mockRetryOptions, exitChan, mockChannel, "foo", noErrorFn)
33-
assert.Error(t, rp.retry(), "Expected retry to return an error")
34-
assert.Equal(t, false, flag, "Expected flag to remain set to false")
35-
})
36-
3729
t.Run("Proper", func(t *testing.T) {
3830
exitChan := make(chan struct{})
3931
rp = newRetryProcess(mockRetryOptions, exitChan, mockChannel, "foo", noErrorFn)

0 commit comments

Comments
 (0)