line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kafka::Internals; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Kafka::Internals - Constants and functions used internally. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This documentation refers to C version 1.07 . |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
16
|
|
|
16
|
|
229284
|
use 5.010; |
|
16
|
|
|
|
|
50
|
|
16
|
16
|
|
|
16
|
|
83
|
use strict; |
|
16
|
|
|
|
|
29
|
|
|
16
|
|
|
|
|
333
|
|
17
|
16
|
|
|
16
|
|
69
|
use warnings; |
|
16
|
|
|
|
|
35
|
|
|
16
|
|
|
|
|
698
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '1.07'; |
22
|
|
|
|
|
|
|
|
23
|
16
|
|
|
|
|
805
|
use Exporter qw( |
24
|
|
|
|
|
|
|
import |
25
|
16
|
|
|
16
|
|
99
|
); |
|
16
|
|
|
|
|
35
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
28
|
|
|
|
|
|
|
$APIKEY_PRODUCE |
29
|
|
|
|
|
|
|
$APIKEY_FETCH |
30
|
|
|
|
|
|
|
$APIKEY_OFFSET |
31
|
|
|
|
|
|
|
$APIKEY_METADATA |
32
|
|
|
|
|
|
|
$APIKEY_FINDCOORDINATOR |
33
|
|
|
|
|
|
|
$APIKEY_APIVERSIONS |
34
|
|
|
|
|
|
|
$APIKEY_OFFSETCOMMIT |
35
|
|
|
|
|
|
|
$APIKEY_OFFSETFETCH |
36
|
|
|
|
|
|
|
$DEFAULT_RAISE_ERROR |
37
|
|
|
|
|
|
|
$MAX_CORRELATIONID |
38
|
|
|
|
|
|
|
$MAX_INT16 |
39
|
|
|
|
|
|
|
$MAX_INT32 |
40
|
|
|
|
|
|
|
$MAX_SOCKET_REQUEST_BYTES |
41
|
|
|
|
|
|
|
$PRODUCER_ANY_OFFSET |
42
|
|
|
|
|
|
|
debug_level |
43
|
|
|
|
|
|
|
_isbig |
44
|
|
|
|
|
|
|
_get_CorrelationId |
45
|
|
|
|
|
|
|
format_message |
46
|
|
|
|
|
|
|
format_reference |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
16
|
|
|
16
|
|
85
|
use overload; |
|
16
|
|
|
|
|
61
|
|
|
16
|
|
|
|
|
114
|
|
52
|
16
|
|
|
16
|
|
908
|
use Carp; |
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
832
|
|
53
|
16
|
|
|
16
|
|
85
|
use Const::Fast; |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
119
|
|
54
|
16
|
|
|
16
|
|
6871
|
use Data::Dumper (); |
|
16
|
|
|
|
|
85621
|
|
|
16
|
|
|
|
|
449
|
|
55
|
16
|
|
|
|
|
790
|
use Params::Util qw( |
56
|
|
|
|
|
|
|
_INSTANCE |
57
|
16
|
|
|
16
|
|
1099
|
); |
|
16
|
|
|
|
|
7635
|
|
58
|
16
|
|
|
16
|
|
1857
|
use Try::Tiny; |
|
16
|
|
|
|
|
8493
|
|
|
16
|
|
|
|
|
755
|
|
59
|
|
|
|
|
|
|
|
60
|
16
|
|
|
|
|
5778
|
use Kafka qw( |
61
|
|
|
|
|
|
|
%ERROR |
62
|
|
|
|
|
|
|
$ERROR_MISMATCH_ARGUMENT |
63
|
16
|
|
|
16
|
|
405
|
); |
|
16
|
|
|
|
|
27
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
use 5.010; |
70
|
|
|
|
|
|
|
use strict; |
71
|
|
|
|
|
|
|
use warnings; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Kafka::Internals qw( |
74
|
|
|
|
|
|
|
$MAX_SOCKET_REQUEST_BYTES |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $bin_stream_size = $MAX_SOCKET_REQUEST_BYTES; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This module is private and should not be used directly. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
In order to achieve better performance, functions of this module do |
84
|
|
|
|
|
|
|
not perform arguments validation. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 EXPORT |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The following constants are available for export |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#-- Api Keys |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head3 C<$APIKEY_PRODUCE> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The numeric code that the C in the request take for the C request type. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
const our $APIKEY_PRODUCE => 0; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head3 C<$APIKEY_FETCH> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The numeric code that the C in the request take for the C request type. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
const our $APIKEY_FETCH => 1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head3 C<$APIKEY_OFFSET> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The numeric code that the C in the request take for the C request type. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
const our $APIKEY_OFFSET => 2; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head3 C<$APIKEY_METADATA> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The numeric code that the C in the request take for the C request type. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
const our $APIKEY_METADATA => 3; |
121
|
|
|
|
|
|
|
# The numeric code that the ApiKey in the request take for the C request type. |
122
|
|
|
|
|
|
|
const our $APIKEY_LEADERANDISR => 4; # Not used now |
123
|
|
|
|
|
|
|
# The numeric code that the ApiKey in the request take for the C request type. |
124
|
|
|
|
|
|
|
const our $APIKEY_STOPREPLICA => 5; # Not used now |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head3 C<$APIKEY_OFFSETCOMMIT> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The numeric code that the ApiKey in the request take for the C request type. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
const our $APIKEY_OFFSETCOMMIT => 8; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head3 C<$APIKEY_OFFSETFETCH> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The numeric code that the ApiKey in the request take for the C request type. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
const our $APIKEY_OFFSETFETCH => 9; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head3 C<$APIKEY_FINDCOORDINATOR> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
The numeric code that the C in the request take for the C request type. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
const our $APIKEY_FINDCOORDINATOR => 10; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head3 C<$APIKEY_APIVERSIONS> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
The numeric code that the C in the request take for the C request type. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
const our $APIKEY_APIVERSIONS => 18; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Important configuration properties |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head3 C<$MAX_SOCKET_REQUEST_BYTES> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
The maximum number of bytes in a socket request. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The maximum size of a request that the socket server will accept. |
161
|
|
|
|
|
|
|
Default limit (as configured in F) is 104857600. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
const our $MAX_SOCKET_REQUEST_BYTES => 100 * 1024 * 1024; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head3 C<$PRODUCER_ANY_OFFSET> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
According to Apache Kafka documentation: 'When the producer is sending messages it doesn't actually know the offset and can fill in any |
169
|
|
|
|
|
|
|
value here it likes.' |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
const our $PRODUCER_ANY_OFFSET => 0; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head3 C<$MAX_CORRELATIONID> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Largest positive integer on 32-bit machines. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
const our $MAX_CORRELATIONID => 0x7fffffff; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head3 C<$MAX_INT32> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Largest positive integer on 32-bit machines. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
const our $MAX_INT32 => 0x7fffffff; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head3 C<$MAX_INT16> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Largest positive int16 value. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
const our $MAX_INT16 => 0x7fff; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
#-- public functions ----------------------------------------------------------- |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
#-- private functions ---------------------------------------------------------- |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Used to generate a CorrelationId. |
200
|
|
|
|
|
|
|
sub _get_CorrelationId { |
201
|
10174
|
|
|
10174
|
|
76966
|
return( -int( rand( $MAX_CORRELATIONID ) ) ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# Verifies that the argument is of Math::BigInt type |
205
|
|
|
|
|
|
|
sub _isbig { |
206
|
10386
|
|
|
10386
|
|
13539
|
my ( $num ) = @_; |
207
|
|
|
|
|
|
|
|
208
|
10386
|
|
|
|
|
200184
|
return defined _INSTANCE( $num, 'Math::BigInt' ); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
#-- public attributes ---------------------------------------------------------- |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 METHODS |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The following methods are defined in the C: |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#-- public methods ------------------------------------------------------------- |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head3 C |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Gets or sets debug level for a particular L module, based on environment variable C or flags. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$flags - (string) argument that can be used to pass coma delimited module names (omit C). |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Returns C<$DEBUG> level for the module from which C was called. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
our %_debug_levels; # per-module levels cache to speed-up multiple calls to debug_level() |
231
|
|
|
|
|
|
|
sub debug_level { |
232
|
16
|
|
|
16
|
|
104
|
no strict 'refs'; ## no critic |
|
16
|
|
|
|
|
26
|
|
|
16
|
|
|
|
|
8206
|
|
233
|
|
|
|
|
|
|
|
234
|
36552
|
|
66
|
36552
|
1
|
10474840
|
my $class = ref( $_[0] ) || $_[0]; |
235
|
|
|
|
|
|
|
|
236
|
36552
|
100
|
100
|
|
|
97493
|
return ${ $_debug_levels{ $class } } if @_ == 1 && exists $_debug_levels{ $class }; |
|
36521
|
|
|
|
|
72426
|
|
237
|
|
|
|
|
|
|
|
238
|
31
|
|
100
|
|
|
121
|
my $flags = $_[1] // $ENV{PERL_KAFKA_DEBUG}; |
239
|
31
|
100
|
|
|
|
112
|
if( defined $flags ) { |
240
|
9
|
|
|
|
|
34
|
foreach my $spec ( split /\s*,\s*/, $flags ) { |
241
|
12
|
|
|
|
|
36
|
my @elements = split( /\s*:\s*/, $spec, 2 ); |
242
|
12
|
|
|
|
|
15
|
my( $module_name, $level ); |
243
|
12
|
100
|
|
|
|
22
|
if ( scalar( @elements ) > 1 ) { |
244
|
8
|
|
|
|
|
12
|
( $module_name, $level ) = @elements; |
245
|
|
|
|
|
|
|
} else { |
246
|
4
|
|
|
|
|
19
|
$module_name = ( $class =~ /([^:]+)$/ )[0]; |
247
|
4
|
|
|
|
|
8
|
$level = $spec; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
12
|
|
|
|
|
13
|
*{ "Kafka::${module_name}::DEBUG" } = \$level; ## no critic |
|
12
|
|
|
|
|
54
|
|
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
31
|
|
|
|
|
43
|
$_debug_levels{ $class } = \${ "${class}::DEBUG" }; ## no critic |
|
31
|
|
|
|
|
141
|
|
254
|
|
|
|
|
|
|
|
255
|
31
|
|
|
|
|
44
|
return ${ $_debug_levels{ $class } }; |
|
31
|
|
|
|
|
171
|
|
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 format_reference |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
say format_reference( $object ); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Dumps reference using preconfigured L. Produces less verbose |
263
|
|
|
|
|
|
|
output than default L settings. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
my $dumper; |
268
|
|
|
|
|
|
|
my $empty_array = []; |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub format_reference { |
271
|
62
|
|
|
62
|
1
|
106
|
my ( $value ) = @_; |
272
|
|
|
|
|
|
|
|
273
|
62
|
100
|
|
|
|
124
|
unless( $dumper ) { |
274
|
5
|
|
|
|
|
105
|
$dumper = Data::Dumper->new( $empty_array ) |
275
|
|
|
|
|
|
|
->Indent( 0 ) |
276
|
|
|
|
|
|
|
->Terse( 1 ) |
277
|
|
|
|
|
|
|
->Quotekeys( 0 ) |
278
|
|
|
|
|
|
|
->Sortkeys( 1 ) |
279
|
|
|
|
|
|
|
->Useperl( 1 ) # XS version seems to have a bug which sometimes results in modification of original object |
280
|
|
|
|
|
|
|
# ->Sparseseen( 1 ) # speed up since we don't use "Seen" hash |
281
|
|
|
|
|
|
|
; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
62
|
|
|
|
|
563
|
my $r; |
285
|
62
|
100
|
66
|
|
|
180
|
if ( |
286
|
|
|
|
|
|
|
overload::Overloaded( $value ) && |
287
|
|
|
|
|
|
|
overload::Method( $value, '""' ) |
288
|
|
|
|
|
|
|
) { |
289
|
8
|
|
|
|
|
1594
|
$r = "$value"; # force stringification |
290
|
|
|
|
|
|
|
} else { |
291
|
54
|
|
|
|
|
2228
|
$r = $dumper->Values( [ $value ] )->Dump; |
292
|
54
|
|
|
|
|
8903
|
$dumper->Reset->Values( $empty_array ); |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
62
|
|
|
|
|
18157
|
return $r; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head2 format_message |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
$string = format_message( 'Object %d loaded. Status: %s', $id, $message ); |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Returns string formatted using printf-style syntax. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
If there are more than one argument and the first argument contains C<%...> |
305
|
|
|
|
|
|
|
conversions, arguments are converted to a string message using C. In this case, undefined |
306
|
|
|
|
|
|
|
values are printed as C<< >> and references are converted to strings using L. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=cut |
309
|
|
|
|
|
|
|
sub format_message { |
310
|
825
|
|
50
|
825
|
1
|
2273
|
my $format = shift // return; |
311
|
|
|
|
|
|
|
|
312
|
825
|
|
|
|
|
1031
|
my $got = scalar @_; |
313
|
|
|
|
|
|
|
|
314
|
825
|
50
|
33
|
|
|
3212
|
return $format unless $got && $format =~ /\%/; |
315
|
|
|
|
|
|
|
|
316
|
825
|
|
|
|
|
957
|
my $expected = 0; |
317
|
825
|
|
|
|
|
4308
|
while ( $format =~ /(%%|%[^%])/g ) { |
318
|
1821
|
50
|
|
|
|
3889
|
next if $1 eq '%%'; # don't count escape sequence |
319
|
1821
|
|
|
|
|
4378
|
++$expected; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
825
|
50
|
|
|
|
1382
|
Carp::cluck "Wrong number of arguments: $expected vs $got" unless $got == $expected; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
return sprintf $format, map { |
325
|
825
|
100
|
|
|
|
1288
|
!defined $_ |
|
1821
|
100
|
|
|
|
8791
|
|
326
|
|
|
|
|
|
|
? '' |
327
|
|
|
|
|
|
|
: ref $_ |
328
|
|
|
|
|
|
|
? format_reference( $_ ) |
329
|
|
|
|
|
|
|
: $_ |
330
|
|
|
|
|
|
|
} @_; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
#-- private attributes --------------------------------------------------------- |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
#-- private methods ------------------------------------------------------------ |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
1; |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
__END__ |