WIP: morph: Introduce new parameters for subscriber constructor #708

Closed
aarifullin wants to merge 1 commit from aarifullin/frostfs-node:fix/subscriber_ch_sizes into support/v0.37

View file

@ -60,9 +60,16 @@ type (
// Params is a group of Subscriber constructor parameters. // Params is a group of Subscriber constructor parameters.
Params struct { Params struct {
Log *logger.Logger Log *logger.Logger
StartFromBlock uint32 StartFromBlock uint32
Client *client.Client Client *client.Client
NotificationsConfig NotificationsConfig
}
NotificationsConfig struct {
NotificationChannelSize uint32
BlockChannelSize uint32
NotaryRequestChannelSize uint32
} }
) )
@ -169,7 +176,7 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
blockChan: make(chan *block.Block), blockChan: make(chan *block.Block),
notaryChan: make(chan *result.NotaryRequestEvent), notaryChan: make(chan *result.NotaryRequestEvent),
current: newSubChannels(), current: newSubChannels(p.NotificationsConfig),
subscribedEvents: make(map[util.Uint160]bool), subscribedEvents: make(map[util.Uint160]bool),
subscribedNotaryEvents: make(map[util.Uint160]bool), subscribedNotaryEvents: make(map[util.Uint160]bool),
@ -259,7 +266,14 @@ func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) (
cliCh := s.client.NotificationChannel() cliCh := s.client.NotificationChannel()
s.Lock() s.Lock()
chs := newSubChannels()
param := NotificationsConfig{
NotificationChannelSize: uint32(cap(s.current.NotifyChan)),
BlockChannelSize: uint32(cap(s.current.BlockChan)),
NotaryRequestChannelSize: uint32(cap(s.current.NotaryChan)),
}
chs := newSubChannels(param)
go func() { go func() {
finishCh <- s.restoreSubscriptions(chs.NotifyChan, chs.BlockChan, chs.NotaryChan) finishCh <- s.restoreSubscriptions(chs.NotifyChan, chs.BlockChan, chs.NotaryChan)
}() }()
@ -270,11 +284,11 @@ func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) (
return true, cliCh return true, cliCh
} }
func newSubChannels() subChannels { func newSubChannels(param NotificationsConfig) subChannels {
return subChannels{ return subChannels{
NotifyChan: make(chan *state.ContainedNotificationEvent), NotifyChan: make(chan *state.ContainedNotificationEvent, param.NotificationChannelSize),
BlockChan: make(chan *block.Block), BlockChan: make(chan *block.Block, param.BlockChannelSize),
NotaryChan: make(chan *result.NotaryRequestEvent), NotaryChan: make(chan *result.NotaryRequestEvent, param.NotaryRequestChannelSize),
} }
} }