Repository navigation
rgw/kafka: refactor topic creation to avoid rd_kafka_topic_name() - #59741
Merged
Merged
Conversation
also, use unique_ptr for safer memory management. Fixes: https://tracker.ceph.com/issues/68033 Signed-off-by: Yuval Lifshitz <[email protected]>
cbodley
approved these changes
Sep 11, 2024
Contributor
Author
This was referenced Sep 12, 2024
thuvh
added a commit
to thuvh/ceph
that referenced
this pull request
Nov 23, 2026
Tracker ceph#69566 asks for a test covering the scenario where a Kafka broker rejects topic creation -- e.g. the topic already exists with conflicting ACLs. That is the same path that caused the crash in ceph#68033, where rd_kafka_topic_name() was called on a NULL rd_kafka_topic_t*. The crash itself was fixed in PR ceph#59741, but the post-fix branch in rgw_kafka.cc (publish_internal invoking the callback with a negative errno when rd_kafka_topic_new() returns NULL) was never exercised by an automated test: there was not even a C++ unit test for rgw_kafka, unlike the analogous amqp endpoint. Add a controllable kafka_mock (replacing the no-op kafka_stub) and a unittest_rgw_kafka modeled on unittest_rgw_amqp. The mock lets tests force rd_kafka_topic_new() / rd_kafka_produce() to fail and toggle ack/nack on poll. The TopicCreationFailure test forces RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS and asserts the publish callback fires with a negative errno and no crash, so any future regression that revisits the NULL topic handle will surface in CI. Fixes: https://tracker.ceph.com/issues/69566 Related: https://tracker.ceph.com/issues/68033 Signed-off-by: Hoai-Thu Vuong <[email protected]>
thuvh
added a commit
to thuvh/ceph
that referenced
this pull request
Nov 30, 2026
Tracker ceph#69566 asks for a test covering the scenario where a Kafka broker rejects topic creation -- e.g. the topic already exists with conflicting ACLs. That is the same path that caused the crash in ceph#68033, where rd_kafka_topic_name() was called on a NULL rd_kafka_topic_t*. The crash itself was fixed in PR ceph#59741, but the post-fix branch in rgw_kafka.cc (publish_internal invoking the callback with a negative errno when rd_kafka_topic_new() returns NULL) was never exercised by an automated test: there was not even a C++ unit test for rgw_kafka, unlike the analogous amqp endpoint. Add a controllable kafka_mock and a unittest_rgw_kafka modeled on unittest_rgw_amqp. The mock lets tests force rd_kafka_topic_new() / rd_kafka_produce() to fail and toggle ack/nack on poll. The TopicCreationFailure test forces RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS and asserts the publish callback fires with a negative errno and no crash, so any future regression that revisits the NULL topic handle will surface in CI. The existing kafka_stub is kept unchanged as the link-fallback for other RGW test binaries. The mock and the stub define the same rd_kafka_* symbols and so cannot coexist in one binary: unittest_rgw_kafka drops kafka_stub from its lib list (list(REMOVE_ITEM)) and links kafka_mock instead. No other test binary's link behavior changes. Fixes: https://tracker.ceph.com/issues/69566 Related: https://tracker.ceph.com/issues/68033 Signed-off-by: Hoai-Thu Vuong <[email protected]>
thuvh
added a commit
to thuvh/ceph
that referenced
this pull request
Nov 30, 2026
Tracker ceph#69566 asks for a test covering the scenario where a Kafka broker rejects topic creation -- e.g. the topic already exists with conflicting ACLs. That is the same path that caused the crash in ceph#68033, where rd_kafka_topic_name() was called on a NULL rd_kafka_topic_t*. The crash itself was fixed in PR ceph#59741, but the post-fix branch in rgw_kafka.cc (publish_internal invoking the callback with a negative errno when rd_kafka_topic_new() returns NULL) was never exercised by an automated test: there was not even a C++ unit test for rgw_kafka, unlike the analogous amqp endpoint. Add a controllable kafka_mock and a unittest_rgw_kafka modeled on unittest_rgw_amqp. The mock lets tests force rd_kafka_topic_new() / rd_kafka_produce() to fail and toggle ack/nack on poll. The TopicCreationFailure test forces RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS and asserts the publish callback fires with a negative errno and no crash, so any future regression that revisits the NULL topic handle will surface in CI. The existing kafka_stub is kept as the high-priority link-fallback for general RGW test binaries, and is made link-compatible with the mock by declaring its rd_kafka_* symbols weak. The mock's strong symbols override the stub's weak ones when both are linked into the same binary (unittest_rgw_kafka links ${rgw_libs} kafka_mock), so the two libraries coexist with no list surgery and no multiple-definition conflict. Tests that link only the stub keep its no-op behavior unchanged. Fixes: https://tracker.ceph.com/issues/69566 Related: https://tracker.ceph.com/issues/68033 Signed-off-by: Hoai-Thu Vuong <[email protected]>
thuvh
added a commit
to thuvh/ceph
that referenced
this pull request
Nov 30, 2026
Tracker ceph#69566 asks for a test covering the scenario where a Kafka broker rejects topic creation -- e.g. the topic already exists with conflicting ACLs. That is the same path that caused the crash in ceph#68033, where rd_kafka_topic_name() was called on a NULL rd_kafka_topic_t*. The crash itself was fixed in PR ceph#59741, but the post-fix branch in rgw_kafka.cc (publish_internal invoking the callback with a negative errno when rd_kafka_topic_new() returns NULL) was never exercised by an automated test: there was not even a C++ unit test for rgw_kafka, unlike the analogous amqp endpoint. Add a controllable kafka_mock and a unittest_rgw_kafka modeled on unittest_rgw_amqp. The mock lets tests force rd_kafka_topic_new() / rd_kafka_produce() to fail and toggle ack/nack on poll. The TopicCreationFailure test forces RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS and asserts the publish callback fires with a negative errno and no crash, so any future regression that revisits the NULL topic handle will surface in CI. The existing kafka_stub is kept as the high-priority link-fallback for general RGW test binaries (its no-op behavior is unchanged). The mock is kept link-compatible with the stub by marking the stub's rd_kafka_* symbols weak (__attribute__((weak))) so that, in principle, a strong-definition mock can override them when both are linked together. In practice, static-archive pull-in is order-dependent, so unittest_rgw_kafka uses list(REMOVE_ITEM) to exclude kafka_stub from its lib list and links kafka_mock instead; the weak attributes stay as defense-in-depth documentation. No other test binary's link behavior changes. Fixes: https://tracker.ceph.com/issues/69566 Related: https://tracker.ceph.com/issues/68033 Signed-off-by: Hoai-Thu Vuong <[email protected]>
4 of 14 tasks
thuvh
added a commit
to thuvh/ceph
that referenced
this pull request
Nov 30, 2026
Tracker ceph#69566 asks for a test covering the scenario where a Kafka broker rejects the topic RGW tries to produce to -- e.g. the topic was already created with conflicting ACLs. That is the same path that caused the crash in ceph#68033, where rd_kafka_topic_name() was called on a NULL rd_kafka_topic_t*. The crash itself was fixed in PR ceph#59741, but the post-fix branch in rgw_kafka.cc (publish_internal invoking the callback with a negative errno on broker rejection, instead of dereferencing the topic handle) was never exercised by an automated test: there was not even a C++ unit test for rgw_kafka, unlike the analogous amqp endpoint. Rather than hand-rolling a mock of the librdkafka C API (which would duplicate librdkafka's own behavior for very little value), drive the *real* librdkafka linked into RGW against librdkafka's in-process mock cluster (rdkafka_mock.h, shipped with librdkafka >= 2.x; Ceph already requires rdkafka >= 2.11). The mock cluster speaks the Kafka wire protocol on localhost sockets, so rgw_kafka.cc exercises its real producer-creation / topic-handle / produce / delivery-report paths. rd_kafka_mock_topic_set_error() makes the broker return an error in Metadata responses for a given topic; librdkafka surfaces that as a produce delivery failure; rgw_kafka's post-ceph#59741 code fires the user callback with a negative errno instead of crashing. unittest_rgw_kafka covers: - TopicAuthorizationFailed: the ceph#69566 "already created with ACL" scenario (RD_KAFKA_RESP_ERR_TOPIC_AUTHORIZATION_FAILED in Metadata) - TopicAlreadyExists: the literal error in ceph#68033's description - PublishAck: the happy path, callback rc == 0 - ProduceFailure: broker rejects the produce itself (ApiKey 0 / ProduceRequest via rd_kafka_mock_push_request_errors) The existing kafka_stub is kept unchanged as the link-fallback for other RGW test binaries. unittest_rgw_kafka links the real RDKafka::RDKafka instead of kafka_stub (the two define the same rd_kafka_* symbols so they cannot coexist in one binary): the stub is dropped from its lib list via list(REMOVE_ITEM), as before. No other test binary's link behavior changes. Fixes: https://tracker.ceph.com/issues/69566 Related: https://tracker.ceph.com/issues/68033 Signed-off-by: Hoai-Thu Vuong <[email protected]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
also, use unique_ptr for safer memory management.
Fixes: https://tracker.ceph.com/issues/68033
Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e