Skip to content

Commit 3f35491

Browse files
committed
[FAB-3663] Switch event producer timeout to duration
This CR updates the event producer's timeout from an integer to a time duration. This has been done for consistency with other timeouts defined for the peer and orderer. Change-Id: I803a755b20943d192bdb8af92b995dcccdafe531 Signed-off-by: Will Lahti <[email protected]>
1 parent f2e94b3 commit 3f35491

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

events/producer/events.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ type eventProcessor struct {
198198
//we could generalize this with mutiple channels each with its own size
199199
eventChannel chan *pb.Event
200200

201-
//milliseconds timeout for producer to send an event.
201+
//timeout duration for producer to send an event.
202202
//if < 0, if buffer full, unblocks immediately and not send
203203
//if 0, if buffer full, will block and guarantee the event will be sent out
204204
//if > 0, if buffer full, blocks till timeout
205-
timeout int
205+
timeout time.Duration
206206
}
207207

208208
//global eventProcessor singleton created by initializeEvents. Openchain producers
@@ -236,7 +236,7 @@ func (ep *eventProcessor) start() {
236236
}
237237

238238
//initialize and start
239-
func initializeEvents(bufferSize uint, tout int) {
239+
func initializeEvents(bufferSize uint, tout time.Duration) {
240240
if gEventProcessor != nil {
241241
panic("should not be called twice")
242242
}
@@ -329,7 +329,7 @@ func Send(e *pb.Event) error {
329329
logger.Debugf("Event processor timeout > 0")
330330
select {
331331
case gEventProcessor.eventChannel <- e:
332-
case <-time.After(time.Duration(gEventProcessor.timeout) * time.Millisecond):
332+
case <-time.After(gEventProcessor.timeout):
333333
return fmt.Errorf("could not send the blocking event")
334334
}
335335
}

events/producer/producer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package producer
1919
import (
2020
"fmt"
2121
"io"
22+
"time"
2223

2324
"github.com/hyperledger/fabric/common/flogging"
2425
pb "github.com/hyperledger/fabric/protos/peer"
@@ -34,7 +35,7 @@ type EventsServer struct {
3435
var globalEventsServer *EventsServer
3536

3637
// NewEventsServer returns a EventsServer
37-
func NewEventsServer(bufferSize uint, timeout int) *EventsServer {
38+
func NewEventsServer(bufferSize uint, timeout time.Duration) *EventsServer {
3839
if globalEventsServer != nil {
3940
panic("Cannot create multiple event hub servers")
4041
}

events/producer/producer_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/hyperledger/fabric/msp/mgmt/testtools"
3131
"github.com/hyperledger/fabric/protos/peer"
3232
"github.com/hyperledger/fabric/protos/utils"
33+
"github.com/spf13/viper"
34+
"github.com/stretchr/testify/assert"
3335
)
3436

3537
func createEvent() (*peer.Event, error) {
@@ -118,6 +120,17 @@ func TestSignedEvent(t *testing.T) {
118120
}
119121
}
120122

123+
func TestNewEventsServer(t *testing.T) {
124+
viper.Set("peer.events.buffersize", 100)
125+
viper.Set("peer.events.timeout", "1ms")
126+
127+
ehServer := NewEventsServer(
128+
uint(viper.GetInt("peer.events.buffersize")),
129+
viper.GetDuration("peer.events.timeout"))
130+
131+
assert.NotNil(t, ehServer, "nil EventServer found")
132+
}
133+
121134
var signer msp.SigningIdentity
122135
var signerSerialized []byte
123136

peer/node/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func createEventHubServer(secureConfig comm.SecureServerConfig) (comm.GRPCServer
326326
}
327327
ehServer := producer.NewEventsServer(
328328
uint(viper.GetInt("peer.events.buffersize")),
329-
viper.GetInt("peer.events.timeout"))
329+
viper.GetDuration("peer.events.timeout"))
330330

331331
pb.RegisterEventsServer(grpcServer.Server(), ehServer)
332332
return grpcServer, nil

sampleconfig/core.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ peer:
158158
# validator sends
159159
buffersize: 100
160160

161-
# milliseconds timeout for producer to send an event.
161+
# timeout duration for producer to send an event.
162162
# if < 0, if buffer full, unblocks immediately and not send
163163
# if 0, if buffer full, will block and guarantee the event will be sent out
164164
# if > 0, if buffer full, blocks till timeout
165-
timeout: 10
165+
timeout: 10ms
166166

167167
# TLS Settings for p2p communications
168168
tls:

0 commit comments

Comments
 (0)