Skip to content
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

Merged
merged 3 commits into from
Mar 2, 2017
Merged

Fix CustomHasher #841

merged 3 commits into from
Mar 2, 2017

Conversation

kruftmeister
Copy link
Contributor

@kruftmeister kruftmeister commented Mar 2, 2017

I had to realise that even though now the same hashing algorithm was used across services to determine the partition, the problem that messages published under the same key on log compact topics still ended up on different partitions. Unfortunately I found out that I made a huge mistake by passing an already instantiated hasher. Thus the proposed fix: pass a callback so the hasher is instantiated just before needed (thanks to the wiki page for helping my understanding of the publisher's flow).

Passing an already instantiated hasher is a really bad idea. Instead pass a function returning the expected interface,
so the hasher is instantiated when needed, also assuring there's one hasher for each partitionDispatcher and thus avoid concurrency problems."
@kruftmeister kruftmeister changed the title Hasher callback Fix CustomHasher Mar 2, 2017
partitioner.go Outdated
@@ -82,18 +82,20 @@ func (p *roundRobinPartitioner) RequiresConsistency() bool {
return false
}

type hasherFunc func() hash.Hash32
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true.

partitioner.go Outdated
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Remove type hasherFunc.
Adjust doc comments for the NewCustomHashPartitioner.
@eapache
Copy link
Contributor

eapache commented Mar 2, 2017

Thanks! While technically this is a breaking API change the method was just introduced, broken in its current format, and never included in an actual release, so I think we can skirt the go rules for this one.

@eapache eapache merged commit 8093021 into IBM:master Mar 2, 2017
@kruftmeister
Copy link
Contributor Author

Thank you too! Those were also my thoughts, plus the fact that without this change, it was simply broken. Also learned a lesson or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants