Skip to content

Commit c27fa3e

Browse files
authored
Merge pull request #3 from dushibaiyu/master
up rdkafka to 0.91
2 parents d9d36e0 + 4901572 commit c27fa3e

File tree

2 files changed

+225
-52
lines changed

2 files changed

+225
-52
lines changed

c/rdkafka.h

100644100755
Lines changed: 118 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern "C" {
5858
#include <basetsd.h>
5959
typedef SSIZE_T ssize_t;
6060
#define RD_UNUSED
61+
#define RD_INLINE __inline
6162
#define RD_DEPRECATED
6263
#undef RD_EXPORT
6364
#ifdef LIBRDKAFKA_EXPORTS
@@ -68,6 +69,7 @@ typedef SSIZE_T ssize_t;
6869

6970
#else
7071
#define RD_UNUSED __attribute__((unused))
72+
#define RD_INLINE inline
7173
#define RD_EXPORT
7274
#define RD_DEPRECATED __attribute__((deprecated))
7375
#endif
@@ -96,7 +98,7 @@ typedef SSIZE_T ssize_t;
9698
* @remark This value should only be used during compile time,
9799
* for runtime checks of version use rd_kafka_version()
98100
*/
99-
#define RD_KAFKA_VERSION 0x00090100
101+
#define RD_KAFKA_VERSION 0x000901ff
100102

101103
/**
102104
* @brief Returns the librdkafka version as integer.
@@ -141,6 +143,19 @@ typedef enum rd_kafka_type_t {
141143
} rd_kafka_type_t;
142144

143145

146+
/**
147+
* @enum Timestamp types
148+
*
149+
* @sa rd_kafka_message_timestamp()
150+
*/
151+
typedef enum rd_kafka_timestamp_type_t {
152+
RD_KAFKA_TIMESTAMP_NOT_AVAILABLE, /**< Timestamp not available */
153+
RD_KAFKA_TIMESTAMP_CREATE_TIME, /**< Message creation time */
154+
RD_KAFKA_TIMESTAMP_LOG_APPEND_TIME /**< Log append time */
155+
} rd_kafka_timestamp_type_t;
156+
157+
158+
144159
/**
145160
* @brief Retrieve supported debug contexts for use with the \c \"debug\"
146161
* configuration property. (runtime)
@@ -252,6 +267,8 @@ typedef enum {
252267
RD_KAFKA_RESP_ERR__AUTHENTICATION = -169,
253268
/** No stored offset */
254269
RD_KAFKA_RESP_ERR__NO_OFFSET = -168,
270+
/** Outdated */
271+
RD_KAFKA_RESP_ERR__OUTDATED = -167,
255272
/** End internal error codes */
256273
RD_KAFKA_RESP_ERR__END = -100,
257274

@@ -322,6 +339,14 @@ typedef enum {
322339
RD_KAFKA_RESP_ERR_GROUP_AUTHORIZATION_FAILED = 30,
323340
/** Cluster authorization failed */
324341
RD_KAFKA_RESP_ERR_CLUSTER_AUTHORIZATION_FAILED = 31,
342+
/** Invalid timestamp */
343+
RD_KAFKA_RESP_ERR_INVALID_TIMESTAMP = 32,
344+
/** Unsupported SASL mechanism */
345+
RD_KAFKA_RESP_ERR_UNSUPPORTED_SASL_MECHANISM = 33,
346+
/** Illegal SASL state */
347+
RD_KAFKA_RESP_ERR_ILLEGAL_SASL_STATE = 34,
348+
/** Unuspported version */
349+
RD_KAFKA_RESP_ERR_UNSUPPORTED_VERSION = 35,
325350

326351
RD_KAFKA_RESP_ERR_END_ALL,
327352
} rd_kafka_resp_err_t;
@@ -530,6 +555,37 @@ rd_kafka_topic_partition_list_add_range (rd_kafka_topic_partition_list_t
530555

531556

532557

558+
/**
559+
* @brief Delete partition from list.
560+
*
561+
* @param rktparlist List to modify
562+
* @param topic Topic name to match
563+
* @param partition Partition to match
564+
*
565+
* @returns 1 if partition was found (and removed), else 0.
566+
*
567+
* @remark Any held indices to elems[] are unusable after this call returns 1.
568+
*/
569+
RD_EXPORT
570+
int
571+
rd_kafka_topic_partition_list_del (rd_kafka_topic_partition_list_t *rktparlist,
572+
const char *topic, int32_t partition);
573+
574+
575+
/**
576+
* @brief Delete partition from list by elems[] index.
577+
*
578+
* @returns 1 if partition was found (and removed), else 0.
579+
*
580+
* @sa rd_kafka_topic_partition_list_del()
581+
*/
582+
RD_EXPORT
583+
int
584+
rd_kafka_topic_partition_list_del_by_idx (
585+
rd_kafka_topic_partition_list_t *rktparlist,
586+
int idx);
587+
588+
533589
/**
534590
* @brief Make a copy of an existing list.
535591
*
@@ -585,9 +641,9 @@ rd_kafka_topic_partition_list_find (rd_kafka_topic_partition_list_t *rktparlist,
585641

586642
/**
587643
* @brief A Kafka message as returned by the \c rd_kafka_consume*() family
588-
* of functions.
644+
* of functions as well as provided to the Producer \c dr_msg_cb().
589645
*
590-
* This object has two purposes:
646+
* For the consumer this object has two purposes:
591647
* - provide the application with a consumed message. (\c err == 0)
592648
* - report per-topic+partition consumer errors (\c err != 0)
593649
*
@@ -600,7 +656,8 @@ typedef struct rd_kafka_message_s {
600656
rd_kafka_resp_err_t err; /**< Non-zero for error signaling. */
601657
rd_kafka_topic_t *rkt; /**< Topic */
602658
int32_t partition; /**< Partition */
603-
void *payload; /**< Depends on the value of \c err :
659+
void *payload; /**< Producer: original message payload.
660+
* Consumer: Depends on the value of \c err :
604661
* - \c err==0: Message payload.
605662
* - \c err!=0: Error string */
606663
size_t len; /**< Depends on the value of \c err :
@@ -640,7 +697,7 @@ void rd_kafka_message_destroy(rd_kafka_message_t *rkmessage);
640697
* @brief Returns the error string for an errored rd_kafka_message_t or NULL if
641698
* there was no error.
642699
*/
643-
static __inline const char *
700+
static RD_INLINE const char *
644701
RD_UNUSED
645702
rd_kafka_message_errstr(const rd_kafka_message_t *rkmessage) {
646703
if (!rkmessage->err)
@@ -652,6 +709,25 @@ rd_kafka_message_errstr(const rd_kafka_message_t *rkmessage) {
652709
return rd_kafka_err2str(rkmessage->err);
653710
}
654711

712+
713+
714+
/**
715+
* @brief Returns the message timestamp for a consumed message.
716+
*
717+
* The timestamp is the number of milliseconds since the epoch (UTC).
718+
*
719+
* \p tstype is updated to indicate the type of timestamp.
720+
*
721+
* @returns message timestamp, or -1 if not available.
722+
*
723+
* @remark Message timestamps require broker version 0.10.0 or later.
724+
*/
725+
RD_EXPORT
726+
int64_t rd_kafka_message_timestamp (const rd_kafka_message_t *rkmessage,
727+
rd_kafka_timestamp_type_t *tstype);
728+
729+
730+
655731
/**@}*/
656732

657733

@@ -805,7 +881,11 @@ void rd_kafka_conf_set_consume_cb (rd_kafka_conf_t *conf,
805881
* such as fetching offsets from an alternate location (on assign)
806882
* or manually committing offsets (on revoke).
807883
*
808-
* The following example show's the application's responsibilities:
884+
* @remark The \p partitions list is destroyed by librdkafka on return
885+
* return from the rebalance_cb and must not be freed or
886+
* saved by the application.
887+
*
888+
* The following example shows the application's responsibilities:
809889
* @code
810890
* static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err,
811891
* rd_kafka_topic_partition_list_t *partitions,
@@ -885,15 +965,16 @@ void rd_kafka_conf_set_error_cb(rd_kafka_conf_t *conf,
885965
/**
886966
* @brief Set throttle callback.
887967
*
888-
* The throttle callback is used in conjunction with
889-
* \c quota.support.enable=true to forward broker throttle times to the
968+
* The throttle callback is used to forward broker throttle times to the
890969
* application for Produce and Fetch (consume) requests.
891970
*
892971
* Callbacks are triggered whenever a non-zero throttle time is returned by
893972
* the broker, or when the throttle time drops back to zero.
894973
*
895974
* An application must call rd_kafka_poll() or rd_kafka_consumer_poll() at
896975
* regular intervals to serve queued callbacks.
976+
*
977+
* @remark Requires broker version 0.9.0 or later.
897978
*/
898979
RD_EXPORT
899980
void rd_kafka_conf_set_throttle_cb (rd_kafka_conf_t *conf,
@@ -1604,7 +1685,7 @@ int rd_kafka_consume_start_queue(rd_kafka_topic_t *rkt, int32_t partition,
16041685
* all messages currently in the local queue.
16051686
*
16061687
* NOTE: To enforce synchronisation this call will block until the internal
1607-
* fetcher has terminated and offsets are commited to configured
1688+
* fetcher has terminated and offsets are committed to configured
16081689
* storage method.
16091690
*
16101691
* The application needs to be stop all consumers before calling
@@ -1787,7 +1868,7 @@ int rd_kafka_consume_callback_queue(rd_kafka_queue_t *rkqu,
17871868
/**
17881869
* @brief Store offset \p offset for topic \p rkt partition \p partition.
17891870
*
1790-
* The offset will be commited (written) to the offset store according
1871+
* The offset will be committed (written) to the offset store according
17911872
* to \c `auto.commit.interval.ms`.
17921873
*
17931874
* @remark \c `auto.commit.enable` must be set to "false" when using this API.
@@ -1873,6 +1954,7 @@ rd_kafka_message_t *rd_kafka_consumer_poll (rd_kafka_t *rk, int timeout_ms);
18731954
* @remark This call will block until the consumer has revoked its assignment,
18741955
* calling the \c rebalance_cb if it is configured, committed offsets
18751956
* to broker, and left the consumer group.
1957+
* The maximum blocking time is roughly limited to session.timeout.ms.
18761958
*
18771959
* @returns An error code indicating if the consumer close was succesful
18781960
* or not.
@@ -1939,7 +2021,30 @@ rd_kafka_commit_message (rd_kafka_t *rk, const rd_kafka_message_t *rkmessage,
19392021

19402022

19412023
/**
1942-
* @brief Retrieve committed positions (offsets) for topics+partitions.
2024+
* @brief Retrieve committed offsets for topics+partitions.
2025+
*
2026+
* The \p offset field of each requested partition will either be set to
2027+
* stored offset or to RD_KAFKA_OFFSET_INVALID in case there was no stored
2028+
* offset for that partition.
2029+
*
2030+
* @returns RD_KAFKA_RESP_ERR_NO_ERROR on success in which case the
2031+
* \p offset or \p err field of each \p partitions' element is filled
2032+
* in with the stored offset, or a partition specific error.
2033+
* Else returns an error code.
2034+
*/
2035+
RD_EXPORT rd_kafka_resp_err_t
2036+
rd_kafka_committed (rd_kafka_t *rk,
2037+
rd_kafka_topic_partition_list_t *partitions,
2038+
int timeout_ms);
2039+
2040+
2041+
2042+
/**
2043+
* @brief Retrieve current positions (offsets) for topics+partitions.
2044+
*
2045+
* The \p offset field of each requested partition will be set to the offset
2046+
* of the last consumed message + 1, or RD_KAFKA_OFFSET_INVALID in case there was
2047+
* no previous message.
19432048
*
19442049
* @returns RD_KAFKA_RESP_ERR_NO_ERROR on success in which case the
19452050
* \p offset or \p err field of each \p partitions' element is filled
@@ -1948,8 +2053,8 @@ rd_kafka_commit_message (rd_kafka_t *rk, const rd_kafka_message_t *rkmessage,
19482053
*/
19492054
RD_EXPORT rd_kafka_resp_err_t
19502055
rd_kafka_position (rd_kafka_t *rk,
1951-
rd_kafka_topic_partition_list_t *partitions,
1952-
int timeout_ms);
2056+
rd_kafka_topic_partition_list_t *partitions);
2057+
19532058

19542059
/**@}*/
19552060

0 commit comments

Comments
 (0)