Skip to content

Update built-in partitioner options to include murmur2 #396

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

Merged
merged 3 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions confluent_kafka/src/confluent_kafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,70 +1451,6 @@ static int producer_conf_set_special (Handle *self, rd_kafka_conf_t *conf,

return 1;

} else if (!strcasecmp(name, "partitioner") ||
!strcasecmp(name, "partitioner_callback")) {

if ((vs = cfl_PyObject_Unistr(valobj))) {
/* Use built-in C partitioners,
* based on their name. */
PyObject *vs8;
val = cfl_PyUnistr_AsUTF8(vs, &vs8);

if (!strcmp(val, "random"))
rd_kafka_topic_conf_set_partitioner_cb(
tconf, rd_kafka_msg_partitioner_random);
else if (!strcmp(val, "consistent"))
rd_kafka_topic_conf_set_partitioner_cb(
tconf, rd_kafka_msg_partitioner_consistent);
else if (!strcmp(val, "consistent_random"))
rd_kafka_topic_conf_set_partitioner_cb(
tconf, rd_kafka_msg_partitioner_consistent_random);
else {
cfl_PyErr_Format(
RD_KAFKA_RESP_ERR__INVALID_ARG,
"unknown builtin partitioner: %s "
"(available: random, consistent, consistent_random)",
val);
Py_XDECREF(vs8);
Py_DECREF(vs);
return -1;
}

Py_XDECREF(vs8);
Py_DECREF(vs);

} else {
/* Custom partitioner (Python callback) */

if (!PyCallable_Check(valobj)) {
cfl_PyErr_Format(
RD_KAFKA_RESP_ERR__INVALID_ARG,
"%s requires a callable "
"object", name);
return -1;
}

/* FIXME: Error out until GIL+rdkafka lock-ordering is fixed. */
if (1) {
cfl_PyErr_Format(
RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED,
"custom partitioner support not yet implemented");
return -1;
}

if (self->u.Producer.partitioner_cb)
Py_DECREF(self->u.Producer.partitioner_cb);

self->u.Producer.partitioner_cb = valobj;
Py_INCREF(self->u.Producer.partitioner_cb);

/* Use trampoline to call Python code. */
rd_kafka_topic_conf_set_partitioner_cb(tconf,
Producer_partitioner_cb);
}

return 1;

} else if (!strcmp(name, "delivery.report.only.error")) {
/* Since we allocate msgstate for each produced message
* with a callback we can't use delivery.report.only.error
Expand Down
23 changes: 23 additions & 0 deletions tests/test_Producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,26 @@ def handle_dr(err, msg):
p.produce('mytopic', "\xc2\xc2", on_delivery=handle_dr)

p.flush()


def test_set_partioner_murmur2():
Copy link
Contributor

Choose a reason for hiding this comment

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

partitioner

Copy link
Contributor

Choose a reason for hiding this comment

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

still partioner

"""
Test ability to set built-in partitioner type murmur
"""
Producer({'partitioner': 'murmur2'})


def test_set_partioner_murmur2_random():
"""
Test ability to set built-in partitioner type murmur2_random
"""
Producer({'partitioner': 'murmur2_random'})


def test_set_invalid_partioner_murmur():
"""
Assert invalid partitioner raises KafkaException
"""
with pytest.raises(KafkaException) as e:
Producer({'partitioner': 'murmur'})
assert e == 'unknown builtin partitioner: murmur' in e
Copy link
Contributor

Choose a reason for hiding this comment

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

are you certain this works, referencing the exception from with the block?
I think it needs to go in the outer block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would fail otherwise no? I have tested it without checking for the raised exception at all and it raised the appropriate exception

Copy link
Contributor

Choose a reason for hiding this comment

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

the assert is never reached since Producer() raises an exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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