Skip to content

Commit

Permalink
[KIP-460] Remove duplicate ElectLeaders result type (#4867)
Browse files Browse the repository at this point in the history
from external API and avoid exposing internal destructor
  • Loading branch information
emasab authored Oct 9, 2024
1 parent 54480ef commit 7fc5a59
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 40 deletions.
5 changes: 1 addition & 4 deletions examples/elect_leaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,8 @@ print_elect_leaders_result(const rd_kafka_ElectLeaders_result_t *result) {
const rd_kafka_topic_partition_result_t **results;
size_t results_cnt;
size_t i;
const rd_kafka_ElectLeadersResult_t *res;

res = rd_kafka_ElectLeaders_result(result);

results = rd_kafka_ElectLeadersResult_partitions(res, &results_cnt);
results = rd_kafka_ElectLeaders_result_partitions(result, &results_cnt);
printf("ElectLeaders response has %zu partition(s):\n", results_cnt);
for (i = 0; i < results_cnt; i++) {
const rd_kafka_topic_partition_t *partition =
Expand Down
27 changes: 2 additions & 25 deletions src/rdkafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -10039,21 +10039,6 @@ RD_EXPORT void rd_kafka_ElectLeaders(rd_kafka_t *rk,
const rd_kafka_AdminOptions_t *options,
rd_kafka_queue_t *rkqu);

/**
* @brief A struct representing result of elect leaders admin operation.
*/
typedef struct rd_kafka_ElectLeadersResult_s rd_kafka_ElectLeadersResult_t;

/**
* @brief Get the elect leaders result from the elect leaders result event.
*
* @param result The elect leaders result event.
*
* @returns the elect leaders result from the elect leaders result event.
*/
RD_EXPORT const rd_kafka_ElectLeadersResult_t *
rd_kafka_ElectLeaders_result(const rd_kafka_ElectLeaders_result_t *result);

/**
* @brief Get the array of topic partition result objects from the
* elect leaders result event and populates the size of the
Expand All @@ -10066,18 +10051,10 @@ rd_kafka_ElectLeaders_result(const rd_kafka_ElectLeaders_result_t *result);
* elect leaders result event.
*/
RD_EXPORT const rd_kafka_topic_partition_result_t **
rd_kafka_ElectLeadersResult_partitions(
const rd_kafka_ElectLeadersResult_t *result,
rd_kafka_ElectLeaders_result_partitions(
const rd_kafka_ElectLeaders_result_t *result,
size_t *cntp);

/**
* @brief Destroy and free a rd_kafka_ElectLeadersResult_t object.
*
* @param result The rd_kafka_ElectLeadersResult_t object to be destroyed.
*/
RD_EXPORT void
rd_kafka_ElectLeadersResult_destroy(rd_kafka_ElectLeadersResult_t *result);

/**@}*/

/**
Expand Down
26 changes: 17 additions & 9 deletions src/rdkafka_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -9187,13 +9187,7 @@ rd_kafka_ElectLeadersResult_new(rd_list_t *partitions) {
return result;
}

const rd_kafka_ElectLeadersResult_t *
rd_kafka_ElectLeaders_result(const rd_kafka_ElectLeaders_result_t *result) {
return (const rd_kafka_ElectLeadersResult_t *)rd_list_elem(
&result->rko_u.admin_result.results, 0);
}

const rd_kafka_topic_partition_result_t **
static const rd_kafka_topic_partition_result_t **
rd_kafka_ElectLeadersResult_partitions(
const rd_kafka_ElectLeadersResult_t *result,
size_t *cntp) {
Expand All @@ -9202,8 +9196,8 @@ rd_kafka_ElectLeadersResult_partitions(
result->partitions.rl_elems;
}

void rd_kafka_ElectLeadersResult_destroy(
rd_kafka_ElectLeadersResult_t *result) {
static void
rd_kafka_ElectLeadersResult_destroy(rd_kafka_ElectLeadersResult_t *result) {
rd_list_destroy(&result->partitions);
rd_free(result);
}
Expand All @@ -9212,6 +9206,20 @@ static void rd_kafka_ElectLeadersResult_free(void *ptr) {
rd_kafka_ElectLeadersResult_destroy(ptr);
}

static const rd_kafka_ElectLeadersResult_t *rd_kafka_ElectLeaders_result_result(
const rd_kafka_ElectLeaders_result_t *result) {
return (const rd_kafka_ElectLeadersResult_t *)rd_list_elem(
&result->rko_u.admin_result.results, 0);
}

const rd_kafka_topic_partition_result_t **
rd_kafka_ElectLeaders_result_partitions(
const rd_kafka_ElectLeaders_result_t *result,
size_t *cntp) {
return rd_kafka_ElectLeadersResult_partitions(
rd_kafka_ElectLeaders_result_result(result), cntp);
}

/**
* @brief Parse ElectLeadersResponse and create ADMIN_RESULT op.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/rdkafka_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ struct rd_kafka_ElectLeaders_s {
/**
* @struct ElectLeaders result object
*/
struct rd_kafka_ElectLeadersResult_s {
typedef struct rd_kafka_ElectLeadersResult_s {
rd_list_t partitions; /**< Type (rd_kafka_topic_partition_result_t *) */
};
} rd_kafka_ElectLeadersResult_t;

/**@}*/

Expand Down

0 comments on commit 7fc5a59

Please sign in to comment.