hermann 0.26.0.0-java → 0.26.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49280cf6226fa7b24a9addc910823bae17cb06f4
4
- data.tar.gz: d736fcac5e71f3e02d6753504d4f1b3b890be4d6
3
+ metadata.gz: 3695bb3cfd9f34a24690d0944f8c0a791c0a592c
4
+ data.tar.gz: b4915f4a6e67eea046c7413fb4899cb968b34d8a
5
5
  SHA512:
6
- metadata.gz: c4f3460b2be2137b2e4b39553ce552316c5abe7c91fc018e336d1d66680461233b39cb4dcf2766fe1848479d81208a649004f0be34235d61c34318f3edfea128
7
- data.tar.gz: 6f72c633e304be050f3abacf75622d00c01fd01ce936d0077a72df87f9493f48b146d6be4e3049611d7498aa6dfe3bccdbb3aca827adfa4b5cd9d8dbe04dba1b
6
+ metadata.gz: f17e8e04a4ee0952bad7c38d627544b567af01caf342b153074be595f1a0bacb45c86de0356e10dc3b2cffcc8c71e9507b3f1fa3c14789c35ef5f2de94f13eb2
7
+ data.tar.gz: ac5177acfa44c01028b3731ecf4a36b8a48dc97e7a126feed5941c4505d0e3a14f24c39f87127d272a0b41bd330325d3c21b16d88bfcaec8231ed3ed69e1eccc
@@ -33,6 +33,11 @@
33
33
 
34
34
  #include "hermann_rdkafka.h"
35
35
 
36
+ /* This header file exposes the functions in librdkafka.a that are needed for
37
+ * consistent partitioning. After librdkafka releases a new tag and Hermann
38
+ * points to it, this can be removed. */
39
+ #include "rdcrc32.h"
40
+
36
41
  #ifdef HAVE_RUBY_VERSION_H
37
42
  #include <ruby/version.h>
38
43
  #endif
@@ -134,6 +139,18 @@ static void msg_delivered(rd_kafka_t *rk,
134
139
  }
135
140
  }
136
141
 
142
+
143
+ /* This function is in rdkafka.h on librdkafka master. As soon as a new
144
+ * version is released and Hermann points to it, this can be removed. */
145
+ int32_t rd_kafka_msg_partitioner_consistent (const rd_kafka_topic_t *rkt,
146
+ const void *key, size_t keylen,
147
+ int32_t partition_cnt,
148
+ void *rkt_opaque,
149
+ void *msg_opaque) {
150
+ return rd_crc32(key, keylen) % partition_cnt;
151
+ }
152
+
153
+
137
154
  /**
138
155
  * Producer partitioner callback.
139
156
  * Used to determine the target partition within a topic for production.
@@ -154,17 +171,11 @@ static int32_t producer_partitioner_callback(const rd_kafka_topic_t *rkt,
154
171
  int32_t partition_cnt,
155
172
  void *rkt_opaque,
156
173
  void *msg_opaque) {
157
- /* Pick a random partition */
158
- int retry = 0;
159
- int32_t partition = RD_KAFKA_PARTITION_UA;
160
-
161
- for (; retry < partition_cnt; retry++) {
162
- partition = rand() % partition_cnt;
163
- if (rd_kafka_topic_partition_available(rkt, partition)) {
164
- break; /* this one will do */
165
- }
174
+ if (keylen) {
175
+ return rd_kafka_msg_partitioner_consistent(rkt, keydata, keylen, partition_cnt, rkt_opaque, msg_opaque);
176
+ } else {
177
+ return rd_kafka_msg_partitioner_random(rkt, keydata, keylen, partition_cnt, rkt_opaque, msg_opaque);
166
178
  }
167
- return partition;
168
179
  }
169
180
 
170
181
  /**
@@ -589,10 +600,11 @@ void producer_init_kafka(VALUE self, HermannInstanceConfig* config) {
589
600
  * @param message VALUE the ruby String containing the outgoing message.
590
601
  * @param topic VALUE the ruby String containing the topic to use for the
591
602
  * outgoing message.
603
+ * @param key VALUE the ruby String containing the key to partition by
592
604
  * @param result VALUE the Hermann::Result object to be fulfilled when the
593
605
  * push completes
594
606
  */
595
- static VALUE producer_push_single(VALUE self, VALUE message, VALUE topic, VALUE result) {
607
+ static VALUE producer_push_single(VALUE self, VALUE message, VALUE topic, VALUE partition_key, VALUE result) {
596
608
 
597
609
  HermannInstanceConfig* producerConfig;
598
610
  /* Context pointer, pointing to `result`, for the librdkafka delivery
@@ -600,6 +612,7 @@ static VALUE producer_push_single(VALUE self, VALUE message, VALUE topic, VALUE
600
612
  */
601
613
  hermann_push_ctx_t *delivery_ctx = (hermann_push_ctx_t *)malloc(sizeof(hermann_push_ctx_t));
602
614
  rd_kafka_topic_t *rkt = NULL;
615
+ rd_kafka_topic_conf_t *rkt_conf = NULL;
603
616
 
604
617
  TRACER("self: %p, message: %p, result: %p)\n", self, message, result);
605
618
 
@@ -622,9 +635,15 @@ static VALUE producer_push_single(VALUE self, VALUE message, VALUE topic, VALUE
622
635
 
623
636
  TRACER("kafka initialized\n");
624
637
 
638
+ /* Topic configuration */
639
+ rkt_conf = rd_kafka_topic_conf_new();
640
+
641
+ /* Set the partitioner callback */
642
+ rd_kafka_topic_conf_set_partitioner_cb(rkt_conf, producer_partitioner_callback);
643
+
625
644
  rkt = rd_kafka_topic_new(producerConfig->rk,
626
645
  RSTRING_PTR(topic),
627
- NULL);
646
+ rkt_conf);
628
647
 
629
648
  if (NULL == rkt) {
630
649
  rb_raise(rb_eRuntimeError, "Could not construct a topic structure");
@@ -645,8 +664,8 @@ static VALUE producer_push_single(VALUE self, VALUE message, VALUE topic, VALUE
645
664
  RD_KAFKA_MSG_F_COPY,
646
665
  RSTRING_PTR(message),
647
666
  RSTRING_LEN(message),
648
- NULL,
649
- 0,
667
+ RSTRING_PTR(partition_key),
668
+ RSTRING_LEN(partition_key),
650
669
  delivery_ctx)) {
651
670
  fprintf(stderr, "%% Failed to produce to topic %s partition %i: %s\n",
652
671
  rd_kafka_topic_name(producerConfig->rkt), producerConfig->partition,
@@ -1240,7 +1259,7 @@ void Init_hermann_rdkafka() {
1240
1259
  rb_define_method(c_producer, "initialize_copy", producer_init_copy, 1);
1241
1260
 
1242
1261
  /* Producer.push_single(msg) */
1243
- rb_define_method(c_producer, "push_single", producer_push_single, 3);
1262
+ rb_define_method(c_producer, "push_single", producer_push_single, 4);
1244
1263
 
1245
1264
  /* Producer.tick */
1246
1265
  rb_define_method(c_producer, "tick", producer_tick, 1);
@@ -0,0 +1,103 @@
1
+ /**
2
+ * \file rdcrc32.h
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Tue May 8 17:36:59 2012,
6
+ * by pycrc v0.7.10, http://www.tty1.net/pycrc/
7
+ *
8
+ * NOTE: Contains librd modifications:
9
+ * - rd_crc32() helper.
10
+ * - __RDCRC32___H__ define (was missing the '32' part).
11
+ *
12
+ * using the configuration:
13
+ * Width = 32
14
+ * Poly = 0x04c11db7
15
+ * XorIn = 0xffffffff
16
+ * ReflectIn = True
17
+ * XorOut = 0xffffffff
18
+ * ReflectOut = True
19
+ * Algorithm = table-driven
20
+ *****************************************************************************/
21
+ #ifndef __RDCRC32___H__
22
+ #define __RDCRC32___H__
23
+
24
+ #include <stdlib.h>
25
+ #include <stdint.h>
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+
32
+ /**
33
+ * The definition of the used algorithm.
34
+ *****************************************************************************/
35
+ #define CRC_ALGO_TABLE_DRIVEN 1
36
+
37
+
38
+ /**
39
+ * The type of the CRC values.
40
+ *
41
+ * This type must be big enough to contain at least 32 bits.
42
+ *****************************************************************************/
43
+ typedef uint32_t rd_crc32_t;
44
+
45
+
46
+ /**
47
+ * Reflect all bits of a \a data word of \a data_len bytes.
48
+ *
49
+ * \param data The data word to be reflected.
50
+ * \param data_len The width of \a data expressed in number of bits.
51
+ * \return The reflected data.
52
+ *****************************************************************************/
53
+ rd_crc32_t rd_crc32_reflect(rd_crc32_t data, size_t data_len);
54
+
55
+
56
+ /**
57
+ * Calculate the initial crc value.
58
+ *
59
+ * \return The initial crc value.
60
+ *****************************************************************************/
61
+ static inline rd_crc32_t rd_crc32_init(void)
62
+ {
63
+ return 0xffffffff;
64
+ }
65
+
66
+
67
+ /**
68
+ * Update the crc value with new data.
69
+ *
70
+ * \param crc The current crc value.
71
+ * \param data Pointer to a buffer of \a data_len bytes.
72
+ * \param data_len Number of bytes in the \a data buffer.
73
+ * \return The updated crc value.
74
+ *****************************************************************************/
75
+ rd_crc32_t rd_crc32_update(rd_crc32_t crc, const unsigned char *data, size_t data_len);
76
+
77
+
78
+ /**
79
+ * Calculate the final crc value.
80
+ *
81
+ * \param crc The current crc value.
82
+ * \return The final crc value.
83
+ *****************************************************************************/
84
+ static inline rd_crc32_t rd_crc32_finalize(rd_crc32_t crc)
85
+ {
86
+ return crc ^ 0xffffffff;
87
+ }
88
+
89
+
90
+ /**
91
+ * Wrapper for performing CRC32 on the provided buffer.
92
+ */
93
+ static inline rd_crc32_t rd_crc32 (const char *data, size_t data_len) {
94
+ return rd_crc32_finalize(rd_crc32_update(rd_crc32_init(),
95
+ (const unsigned char *)data,
96
+ data_len));
97
+ }
98
+
99
+ #ifdef __cplusplus
100
+ } /* closing brace for extern "C" */
101
+ #endif
102
+
103
+ #endif /* __RDCRC32___H__ */
@@ -63,8 +63,7 @@ module Hermann
63
63
  end
64
64
 
65
65
  if Hermann.jruby?
66
- key = opts.has_key?(:partition_key) ? opts[:partition_key].to_java : nil
67
- result = @internal.push_single(value, topic, key)
66
+ result = @internal.push_single(value, topic, opts[:partition_key], nil)
68
67
  unless result.nil?
69
68
  @children << result
70
69
  end
@@ -76,7 +75,7 @@ module Hermann
76
75
  # librdkafka callback queue overflow
77
76
  tick_reactor
78
77
  result = create_result
79
- @internal.push_single(value, topic, result)
78
+ @internal.push_single(value, topic, opts[:partition_key].to_s, result)
80
79
  end
81
80
 
82
81
  return result
@@ -43,7 +43,8 @@ module Hermann
43
43
  # @return +Concurrent::Promise+ Representa a promise to send the
44
44
  # data to the kafka broker. Upon execution the Promise's status
45
45
  # will be set
46
- def push_single(msg, topic, key)
46
+ def push_single(msg, topic, key, _)
47
+ key = key && key.to_java
47
48
  Concurrent::Promise.execute {
48
49
  data = ProducerUtil::KeyedMessage.new(topic, nil, key, msg.to_java_bytes)
49
50
  begin
@@ -1,3 +1,3 @@
1
1
  module Hermann
2
- VERSION = '0.26.0'
2
+ VERSION = '0.26.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermann
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0.0
4
+ version: 0.26.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - R. Tyler Croy
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-08 00:00:00.000000000 Z
13
+ date: 2015-09-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: 1.8.2
21
21
  name: json
@@ -23,13 +23,13 @@ dependencies:
23
23
  type: :runtime
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: 1.8.2
29
29
  - !ruby/object:Gem::Dependency
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: 0.3.4
35
35
  name: thread_safe
@@ -37,13 +37,13 @@ dependencies:
37
37
  type: :runtime
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: 0.3.4
43
43
  - !ruby/object:Gem::Dependency
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: 0.7.0
49
49
  name: concurrent-ruby
@@ -51,16 +51,16 @@ dependencies:
51
51
  type: :runtime
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: 0.7.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0.1'
63
- - - '>='
63
+ - - ">="
64
64
  - !ruby/object:Gem::Version
65
65
  version: 0.1.10
66
66
  name: jar-dependencies
@@ -68,10 +68,10 @@ dependencies:
68
68
  type: :runtime
69
69
  version_requirements: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ~>
71
+ - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0.1'
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 0.1.10
77
77
  description: Ruby gem for talking to Kafka
@@ -87,6 +87,7 @@ files:
87
87
  - ext/hermann/extconf.rb
88
88
  - ext/hermann/hermann_rdkafka.c
89
89
  - ext/hermann/hermann_rdkafka.h
90
+ - ext/hermann/rdcrc32.h
90
91
  - lib/hermann.rb
91
92
  - lib/hermann/consumer.rb
92
93
  - lib/hermann/discovery/metadata.rb
@@ -110,21 +111,20 @@ require_paths:
110
111
  - lib
111
112
  required_ruby_version: !ruby/object:Gem::Requirement
112
113
  requirements:
113
- - - '>='
114
+ - - ">="
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  requirements:
118
- - - '>='
119
+ - - ">="
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements:
122
123
  - jar org.apache.kafka:kafka_2.10, ~>0.8.1.1
123
124
  - jar log4j:log4j, ~>1.2.16
124
125
  rubyforge_project:
125
- rubygems_version: 2.4.5
126
+ rubygems_version: 2.4.8
126
127
  signing_key:
127
128
  specification_version: 3
128
129
  summary: A Kafka consumer/producer gem supporting both MRI and JRuby
129
130
  test_files: []
130
- has_rdoc: