Skip to content

rgw/kafka: refactor topic creation to avoid rd_kafka_topic_name() - #59741

Merged
yuvalif merged 1 commit into
ceph:mainfrom
yuvalif:wip-yuval-68033
Sep 12, 2024
Merged

yuvalif merged 1 commit into
ceph:mainfrom
yuvalif:wip-yuval-68033

Conversation

@yuvalif

@yuvalif yuvalif commented Sep 11, 2024

Copy link
Copy Markdown
Contributor

also, use unique_ptr for safer memory management.

Fixes: https://tracker.ceph.com/issues/68033

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@yuvalif
yuvalif requested a review from a team as a code owner September 11, 2024 15:14
@github-actions github-actions Bot added the rgw label Sep 11, 2024
@yuvalif

yuvalif commented Sep 12, 2024

Copy link
Copy Markdown
Contributor Author

@yuvalif
yuvalif merged commit 31a5e2f into ceph:main 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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants