Last active
April 12, 2018 16:49
-
-
Save aeppert/9a623fb6973696e45f8074353796370a to your computer and use it in GitHub Desktop.
librdkafka round-robin partitioner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RRPartitionerCb : public RdKafka::PartitionerCb { | |
public: | |
RRPartitionerCb() { partition = 0; } | |
int32_t partitioner_cb(const RdKafka::Topic *topic, | |
const std::string *key, | |
int32_t partition_cnt, | |
void *msg_opaque) { | |
if((partition+1) > (partition_cnt-1)) { | |
partition = 0; | |
return partition; | |
} | |
partition++; | |
return partition; | |
} | |
private: | |
int32_t partition; | |
}; |
Ah, indeed you would be correct. That is the simplification. This is what happens when one writes code at 1AM takes a nap and still has the over-complicated logic in one's head... Thank you for that!.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe I wasn't clear before, but I agree that the expression (partition + 1) > (partition_cnt -1) is needed for exactly the case you mentioned. What I was suggesting is that with that expression, you don't need partition > (partition_cnt-1). I would expect that anytime
x > y
was true,x + 1 > y
would also be true. At least I can't think of a case where you would not have the same result with