Skip to content

Commit

Permalink
Added orig_broker_name to metadata
Browse files Browse the repository at this point in the history
..since orig_broker_id will be -1 for bootstrap brokers.
  • Loading branch information
edenhill committed Mar 30, 2014
1 parent ab2c278 commit f50747e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/rdkafka_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ static void metadata_print (const char *topic,
const struct rd_kafka_metadata *metadata) {
int i, j, k;

printf("Metadata for %s (from broker %"PRId32"):\n",
printf("Metadata for %s (from broker %"PRId32": %s):\n",
topic ? : "all topics",
metadata->orig_broker_id);
metadata->orig_broker_id,
metadata->orig_broker_name);


/* Iterate brokers */
Expand Down
1 change: 1 addition & 0 deletions src/rdkafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ struct rd_kafka_metadata {
struct rd_kafka_metadata_topic *topics; /* Topics */

int32_t orig_broker_id; /* Broker originating this metadata */
char *orig_broker_name; /* Name of originating broker */
};


Expand Down
5 changes: 4 additions & 1 deletion src/rdkafka_broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,17 @@ rd_kafka_metadata_handle (rd_kafka_broker_t *rkb,
int msh_of = 0;
int msh_size;
struct rd_kafka_metadata *md = NULL;
int rkb_namelen = strlen(rkb->rkb_name)+1;

/* We assume that the marshalled representation is
* no more than 4 times larger than the wire representation. */
msh_size = sizeof(*md) + (size * 4);
msh_size = sizeof(*md) + rkb_namelen + (size * 4);
msh_buf = malloc(msh_size);

_MSH_ALLOC(md, sizeof(*md));
md->orig_broker_id = rkb->rkb_nodeid;
_MSH_ALLOC(md->orig_broker_name, rkb_namelen);
memcpy(md->orig_broker_name, rkb->rkb_name, rkb_namelen);

/* Read Brokers */
_READ_I32A(md->broker_cnt);
Expand Down

0 comments on commit f50747e

Please sign in to comment.