From 03afad8827561e1ea2bb5b930616d763266f19c9 Mon Sep 17 00:00:00 2001 From: Jay Guo Date: Fri, 21 Jul 2017 15:34:48 +0800 Subject: [PATCH] [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 --- orderer/consensus/kafka/retry.go | 9 ++++++++- orderer/consensus/kafka/retry_test.go | 8 -------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/orderer/consensus/kafka/retry.go b/orderer/consensus/kafka/retry.go index f89a6621290..1b0a7ded273 100644 --- a/orderer/consensus/kafka/retry.go +++ b/orderer/consensus/kafka/retry.go @@ -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) diff --git a/orderer/consensus/kafka/retry_test.go b/orderer/consensus/kafka/retry_test.go index 7e487c9f53f..a4d872f1e39 100644 --- a/orderer/consensus/kafka/retry_test.go +++ b/orderer/consensus/kafka/retry_test.go @@ -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)