-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[msg] Do not Close singleton MessageProcessors when closing connections #3934
Changes from 2 commits
5e4e5bf
acb8e21
17b7a0c
827f024
70159ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,17 +132,58 @@ type MessageProcessor interface { | |
Close() | ||
} | ||
|
||
// NewMessageProcessorFn creates a new MessageProcessor scoped to a single connection. Messages are processed serially | ||
// in a connection. | ||
type NewMessageProcessorFn func() MessageProcessor | ||
// MessageProcessorPool returns MessageProcessors. | ||
type MessageProcessorPool interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO a bit confusing using the name "pool" here since it isn't actually pooling anything, just controlling if the provided processor itself should get closed or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well the singleton is definitely pooling. do you have another naming suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea i originally had a wrapper that did nothing on Close. To me that seemed weird since it was so coupled the |
||
// Get returns a MessageProcessor. | ||
Get() MessageProcessor | ||
// Put returns the MessageProcessor. | ||
Put(mp MessageProcessor) | ||
// Close the pool. | ||
Close() | ||
} | ||
|
||
// SingletonMessageProcessor returns a MessageProcessorPool that shares the same MessageProcessor for all users. The | ||
// MessageProcessor is closed when the pool is closed. | ||
func SingletonMessageProcessor(mp MessageProcessor) MessageProcessorPool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this referenced anywhere? Am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it already existed https://github.com/m3db/m3/blob/master/src/cmd/services/m3coordinator/server/m3msg/config.go#L89 The function signature just changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see - thanks |
||
return &singletonMessageProcessorPool{mp: mp} | ||
} | ||
|
||
type singletonMessageProcessorPool struct { | ||
mp MessageProcessor | ||
} | ||
|
||
func (s singletonMessageProcessorPool) Get() MessageProcessor { | ||
return s.mp | ||
} | ||
|
||
func (s singletonMessageProcessorPool) Put(MessageProcessor) { | ||
// mp is shared by all users, nothing to do. | ||
} | ||
|
||
// SingletonMessageProcessor uses the same MessageProcessor for all connections. | ||
func SingletonMessageProcessor(p MessageProcessor) NewMessageProcessorFn { | ||
return func() MessageProcessor { | ||
return p | ||
} | ||
func (s singletonMessageProcessorPool) Close() { | ||
s.mp.Close() | ||
} | ||
|
||
// NewMessageProcessorPool returns a MessageProcessorPool that creates a new MessageProcessor for every call to Get | ||
// and closes the MessageProcessor for every call to Put. | ||
func NewMessageProcessorPool(fn func() MessageProcessor) MessageProcessorPool { | ||
return &messageProcessorPool{fn: fn} | ||
} | ||
|
||
type messageProcessorPool struct { | ||
fn func() MessageProcessor | ||
} | ||
|
||
func (m messageProcessorPool) Get() MessageProcessor { | ||
return m.fn() | ||
} | ||
|
||
func (m messageProcessorPool) Put(mp MessageProcessor) { | ||
mp.Close() | ||
} | ||
|
||
func (m messageProcessorPool) Close() {} | ||
|
||
// NewNoOpMessageProcessor creates a new MessageProcessor that does nothing. | ||
func NewNoOpMessageProcessor() MessageProcessor { | ||
return &noOpMessageProcessor{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test fails without the fix (too many calls to MessageProcessor.Close)