-
Notifications
You must be signed in to change notification settings - Fork 666
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
Support partitioner callback in producer #16
Comments
Out of curiousity, can you share your custom partitioner? |
@edenhill It's application specific. Basically |
Okay, what you'll need to do in the meantime is get the partition count (with GetMetadata()) for your topic(s) and then run your partitioner prior to calling Produce() and setting Message.Partition accordingly. |
The problem with implementing partitioner_cb support in high-level language bindings is that the partitioner callback may be called from an internal librdkafka thread and this isn't trivial to handle in cgo, cpython, et, al. But here's a dumb idea: It would look something like this:
I know it is ugly, but would it be a reasonable workaround for you until proper Go partitioners are supported? |
I wouldn't even need an entirely custom partitioner, I would just need the same key to always go to the same partition. Perhaps it would be possible to bake in something like that, for example by adding another constant besides |
@tchap the default partitioner is Consistent-Random, which maps the same key to the same partition, so you should be fine. |
The next version of librdkafka (the underlying Kafka client) will expose the builtin partitioners as configuration properties, allowing you to change to an alternative builtin partitioner, such as the Java compatible murmur2_random partitioner. Search for 'partitioner' here: https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md Custom partitioners are not yet exposed in the Go client though. |
I have a usecase which really needs this, and I'm trying any kind of workaround and it seems not to be easy.
Then, I casted the pointer to an uintptr, and then, casted again to int, and then I ran into a runtime exception saying:
At this point, I stopped trying, but it looks like it wants me to use Do you have any tips for completing this workaround? |
Due to the generic way configuration is passed from Go to C it is a bit tricky to add a special case for Do note that this callback may be called from internal librdkafka threads and it is not clear to me how to safely trigger a Go call from such a thread. |
Thank you, @edenhill ! What I actually need is not generic custom partitioner. Rather, what I'm looking for is a way to hash based on something other than the kafka key, since I'm using the key for other purposes. It looks like hashing based on the msg_opaque would work for me.
as long as I can set the msg_opaque at the golang level and it looks like i can (https://github.com/confluentinc/confluent-kafka-go/blob/master/kafka/message.go#L79). Would you accept a PR to add a new builtin partitioner to librdkafka, like this: |
I strongly advise you to stick to the existing semantics of keys in Kafka, they are used for partitioning and compaction. We will not accept a PR that does partitioning on something else than the key, sorry. Also, the msg_opaque is used by the Go client internally to map C messages back to Go messages. |
|
This ship has sailed for a while at my company. In the future when we upgrade to kafka 0.11, we'll probably stick this metadata in the 0.11+ Headers. Additionally, we have no use for compaction and have it turned off for our use case. |
This is a possibility too. I will re-visit that. It was my first option, but ran into social problems :) |
We would love to have this available in the producer, as we're moving from Sarama to confluent-kafka-go, but we still need to support Sarama's default partitioner, which uses the 32 bit FNV-1a hashing algorithm (part of For now we will follow @edenhill's advice (i.e. get topic metadata, run custom Go partitioner prior to |
Yeah, the simplest alternative is to add it as a builtin partitioner to librdkafka. Find all occurences of |
@edenhill hello. I have an idea that the message of key="a" send to partition-0 and other message of key="b" send to partition-1. the other message ...
} int err = rd_kafka_produce(rkt, RD_KAFKA_PARTITION_UA, RD_KAFKA_MSG_F_COPY, |
No description provided.
The text was updated successfully, but these errors were encountered: