-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix CustomHasher #841
Fix CustomHasher #841
Changes from 2 commits
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 |
---|---|---|
|
@@ -82,18 +82,20 @@ func (p *roundRobinPartitioner) RequiresConsistency() bool { | |
return false | ||
} | ||
|
||
type hasherFunc func() hash.Hash32 | ||
|
||
type hashPartitioner struct { | ||
random Partitioner | ||
hasher hash.Hash32 | ||
} | ||
|
||
// NewCustomHashPartitioner is a wrapper around NewHashPartitioner, | ||
// allowing the use of custom hasher | ||
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. might be worth documenting here that it expects the method reference not an instance of the hasher 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. Absolutely. I might have gotten a bit in a hurry to open the PR, since I realised my mistake. |
||
func NewCustomHashPartitioner(hasher hash.Hash32) PartitionerConstructor { | ||
func NewCustomHashPartitioner(hasher hasherFunc) PartitionerConstructor { | ||
return func(topic string) Partitioner { | ||
p := new(hashPartitioner) | ||
p.random = NewRandomPartitioner(topic) | ||
p.hasher = hasher | ||
p.hasher = hasher() | ||
return p | ||
} | ||
} | ||
|
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.
I wouldn't even bother naming this type, especially since it's weird for a non-exported interface to be an argument to an exported method.
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.
Yeah, true.