dalli 5.3.3 → 5.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/dalli/client.rb +1 -1
- data/lib/dalli/pipelined_getter.rb +5 -4
- data/lib/dalli/protocol/base.rb +9 -2
- data/lib/dalli/protocol/connection_manager.rb +181 -5
- data/lib/dalli/protocol/held_replies.rb +169 -0
- data/lib/dalli/version.rb +1 -1
- data/lib/dalli.rb +1 -0
- metadata +74 -69
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bcdbff6c85bb9b36e985afe7760f3a30b347e7e9cac5ab91220d1df40fbe9321
|
|
4
|
+
data.tar.gz: cd31ee942d757acd20c3dd6686bfb16ce8f5ace3246df87d3bb8d0152f9bd140
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e617006601c20a575781cb74c2393b79fe4b06d4179f44bf2cc87a150396843fbf57181e91040d8060f0e572a7bd27d7de82bf748da125eaadcdfb2c5ae25a38
|
|
7
|
+
data.tar.gz: 1981431f621ca9f4ad053d0df4bd712bdddd0c4e5847545cfe7bee03446a70b3c3ecd472eda799a1c33e3c61331b6114ee497b699d85431c0152a969536693ee
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ Dalli Changelog
|
|
|
4
4
|
Unreleased
|
|
5
5
|
==========
|
|
6
6
|
|
|
7
|
+
5.3.4
|
|
8
|
+
==========
|
|
9
|
+
|
|
10
|
+
Bug fixes:
|
|
11
|
+
|
|
12
|
+
- `Client#with`, which lets a bare client stand in for a connection pool, now accepts and ignores the arguments `ConnectionPool#with` takes, such as `timeout:`. Before, passing any raised `ArgumentError` (#1323, @byroot)
|
|
13
|
+
- A request larger than the socket buffers no longer stalls until `socket_timeout` and marks the server down. memcached stops reading a connection while its replies go unread, so a large `get_multi`, `get_multi_cas`, `get_multi_with_metadata` or `delete_multi` (whose missing keys each get a reply) waited on the server. Over a Unix socket, whose buffer doesn't grow, this started at about 1,000 keys for `get_multi_cas`. Replies that arrive while a request is being sent are now read and held, checked as they arrive against what the requests sent could get back (#1328, based on #1326 by @edcarvio)
|
|
14
|
+
|
|
7
15
|
5.3.3
|
|
8
16
|
==========
|
|
9
17
|
|
data/lib/dalli/client.rb
CHANGED
|
@@ -247,13 +247,14 @@ module Dalli
|
|
|
247
247
|
def servers_with_response(servers, timeout)
|
|
248
248
|
return [] if servers.empty?
|
|
249
249
|
|
|
250
|
-
# A bounded read can stop while OpenSSL still holds decrypted bytes
|
|
251
|
-
#
|
|
252
|
-
#
|
|
250
|
+
# A bounded read can stop while OpenSSL still holds decrypted bytes,
|
|
251
|
+
# and replies that arrived while the requests were sent are held by the
|
|
252
|
+
# connection. IO.select only sees the underlying socket, so process
|
|
253
|
+
# those bytes before waiting for another network event.
|
|
253
254
|
buffered = nil
|
|
254
255
|
servers.each do |server|
|
|
255
256
|
sock = server.sock
|
|
256
|
-
(buffered ||= []) << server if sock.respond_to?(:pending_data?) && sock.pending_data?
|
|
257
|
+
(buffered ||= []) << server if server.held_replies? || (sock.respond_to?(:pending_data?) && sock.pending_data?)
|
|
257
258
|
end
|
|
258
259
|
return buffered if buffered
|
|
259
260
|
|
data/lib/dalli/protocol/base.rb
CHANGED
|
@@ -47,6 +47,7 @@ module Dalli
|
|
|
47
47
|
@verify_reply_keys = client_options[:verify_reply_keys] ? true : false
|
|
48
48
|
@value_marshaller = @raw_mode ? StringMarshaller.new(@options) : ValueMarshaller.new(@options)
|
|
49
49
|
@connection_manager = ConnectionManager.new(hostname, port, socket_type, @options)
|
|
50
|
+
@connection_manager.max_reply_value_bytes = @value_marshaller.max_response_bytes
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
# Returns true if client is in raw mode (no serialization/compression).
|
|
@@ -254,6 +255,12 @@ module Dalli
|
|
|
254
255
|
!response_buffer.in_progress?
|
|
255
256
|
end
|
|
256
257
|
|
|
258
|
+
# Replies that arrived while the request was sent, which IO.select
|
|
259
|
+
# can't see (see ConnectionManager#send_while_reading)
|
|
260
|
+
def held_replies?
|
|
261
|
+
@connection_manager.held_replies?
|
|
262
|
+
end
|
|
263
|
+
|
|
257
264
|
def quiet?
|
|
258
265
|
Thread.current[::Dalli::QUIET]
|
|
259
266
|
end
|
|
@@ -487,8 +494,8 @@ module Dalli
|
|
|
487
494
|
def drain_pipeline_responses(results)
|
|
488
495
|
return unless connected?
|
|
489
496
|
|
|
490
|
-
#
|
|
491
|
-
return unless sock.wait_readable(0)
|
|
497
|
+
# Replies held while this chunk was sent first, then the socket
|
|
498
|
+
return unless @connection_manager.held_replies? || sock.wait_readable(0)
|
|
492
499
|
|
|
493
500
|
# Read available data without blocking
|
|
494
501
|
response_buffer.read
|
|
@@ -33,6 +33,13 @@ module Dalli
|
|
|
33
33
|
# cleared with the write buffer whenever the connection closes.
|
|
34
34
|
attr_writer :response_buffer
|
|
35
35
|
|
|
36
|
+
# The largest value a reply held during a send may declare: the
|
|
37
|
+
# protocol's max_response_bytes (see HeldReplies). Kept in options, as
|
|
38
|
+
# each instance variable here costs every request a little.
|
|
39
|
+
def max_reply_value_bytes=(bytes)
|
|
40
|
+
@options[:max_reply_value_bytes] = bytes
|
|
41
|
+
end
|
|
42
|
+
|
|
36
43
|
def initialize(hostname, port, socket_type, client_options)
|
|
37
44
|
@hostname = hostname
|
|
38
45
|
@port = port
|
|
@@ -46,6 +53,11 @@ module Dalli
|
|
|
46
53
|
@write_buffer = []
|
|
47
54
|
@write_buffer_bytes = 0
|
|
48
55
|
@response_buffer = nil
|
|
56
|
+
# Replies that arrived while a request was being sent, read before the
|
|
57
|
+
# socket while @held (see #send_while_reading)
|
|
58
|
+
@held_replies = nil
|
|
59
|
+
@held = false
|
|
60
|
+
@unanswered_bytes = 0
|
|
49
61
|
|
|
50
62
|
@fail_count = 0
|
|
51
63
|
reset_down_info
|
|
@@ -128,6 +140,9 @@ module Dalli
|
|
|
128
140
|
reconnect_on_fork if fork_detected?
|
|
129
141
|
return if @sock.nil? || @quiet_responses_pending
|
|
130
142
|
|
|
143
|
+
# Held replies with no request waiting for them were never asked for
|
|
144
|
+
return close if @held
|
|
145
|
+
|
|
131
146
|
now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
|
|
132
147
|
idle = now - @last_used_at
|
|
133
148
|
@last_used_at = now
|
|
@@ -180,6 +195,9 @@ module Dalli
|
|
|
180
195
|
@pid = nil
|
|
181
196
|
@quiet_responses_pending = false
|
|
182
197
|
discard_write_buffer
|
|
198
|
+
discard_held
|
|
199
|
+
@held_replies&.reset_accounting
|
|
200
|
+
@unanswered_bytes = 0
|
|
183
201
|
@response_buffer&.clear
|
|
184
202
|
abort_request!
|
|
185
203
|
end
|
|
@@ -232,6 +250,9 @@ module Dalli
|
|
|
232
250
|
# accepts connections but never answers would otherwise reset it on
|
|
233
251
|
# every retry and never reach socket_max_failures.
|
|
234
252
|
@fail_count = 0
|
|
253
|
+
# The server has read everything sent so far: it answered the last of it
|
|
254
|
+
@unanswered_bytes = 0
|
|
255
|
+
@held_replies.reset_accounting if @held_replies&.counting?
|
|
235
256
|
end
|
|
236
257
|
|
|
237
258
|
# Ends a request whose reply isn't read with it: a quiet write, or one of
|
|
@@ -265,13 +286,21 @@ module Dalli
|
|
|
265
286
|
# never sends CRLF can't grow the read buffer without bound.
|
|
266
287
|
MAX_LINE_BYTES = 8 * 1024
|
|
267
288
|
|
|
289
|
+
# TruffleRuby's gets with a limit doesn't find a two-byte separator whose
|
|
290
|
+
# bytes arrive in separate reads: it waits for more, or returns the line
|
|
291
|
+
# without them. Every reply line ends in CRLF, checked after the read,
|
|
292
|
+
# so reading to the LF finds the same lines.
|
|
293
|
+
LINE_SEPARATOR = RUBY_ENGINE == 'truffleruby' ? "\n" : "\r\n"
|
|
294
|
+
|
|
268
295
|
def read_line
|
|
296
|
+
return held_line if @held
|
|
297
|
+
|
|
269
298
|
flush_write_buffer
|
|
270
|
-
data = timed_tls_operation { @sock.gets(
|
|
299
|
+
data = timed_tls_operation { @sock.gets(LINE_SEPARATOR, MAX_LINE_BYTES) }
|
|
271
300
|
error_on_request!('EOF in read_line') if data.nil?
|
|
272
301
|
# Without its CRLF the line either ran past MAX_LINE_BYTES or was cut
|
|
273
302
|
# short by EOF; either way the connection is out of step
|
|
274
|
-
|
|
303
|
+
line_too_long! unless data.end_with?("\r\n")
|
|
275
304
|
data
|
|
276
305
|
rescue SystemCallError, *TIMEOUT_ERRORS, *SSL_ERRORS, EOFError => e
|
|
277
306
|
error_on_request!(e)
|
|
@@ -292,6 +321,8 @@ module Dalli
|
|
|
292
321
|
|
|
293
322
|
if RUBY_ENGINE == 'jruby'
|
|
294
323
|
def read(count)
|
|
324
|
+
return held_read(count) if @held
|
|
325
|
+
|
|
295
326
|
check_read_size!(count)
|
|
296
327
|
flush_write_buffer
|
|
297
328
|
@sock.readfull(count)
|
|
@@ -300,6 +331,8 @@ module Dalli
|
|
|
300
331
|
end
|
|
301
332
|
else
|
|
302
333
|
def read(count)
|
|
334
|
+
return held_read(count) if @held
|
|
335
|
+
|
|
303
336
|
check_read_size!(count)
|
|
304
337
|
flush_write_buffer
|
|
305
338
|
read_bytes(count)
|
|
@@ -321,6 +354,16 @@ module Dalli
|
|
|
321
354
|
# is sent once it grows past this size, or when a reply is read.
|
|
322
355
|
WRITE_BUFFER_FLUSH_BYTES = 64 * 1024
|
|
323
356
|
|
|
357
|
+
# Less than any socket send buffer: 8 KiB is the smallest default
|
|
358
|
+
# (Unix sockets on macOS), and Linux doubles a requested SO_SNDBUF from
|
|
359
|
+
# a minimum of 2,304 bytes
|
|
360
|
+
BLOCKING_WRITE_BYTES = 4 * 1024
|
|
361
|
+
|
|
362
|
+
# jruby-openssl won't read while it has encrypted bytes it couldn't send,
|
|
363
|
+
# and they can't go until the server reads, which it won't while its
|
|
364
|
+
# replies go unread. On JRuby a TLS request is sent as before.
|
|
365
|
+
HALF_DUPLEX_TLS = RUBY_ENGINE == 'jruby'
|
|
366
|
+
|
|
324
367
|
def write(bytes)
|
|
325
368
|
@write_buffer << bytes
|
|
326
369
|
@write_buffer_bytes += bytes.bytesize
|
|
@@ -345,12 +388,20 @@ module Dalli
|
|
|
345
388
|
end
|
|
346
389
|
|
|
347
390
|
# Non-blocking read. Here to support the operation
|
|
348
|
-
# of the get_multi operation
|
|
391
|
+
# of the get_multi operation. Held replies come first.
|
|
349
392
|
def read_available(...)
|
|
393
|
+
return take_held(@held_replies.bytesize) if @held
|
|
394
|
+
|
|
350
395
|
flush_write_buffer
|
|
351
396
|
@sock.read_available(...)
|
|
352
397
|
end
|
|
353
398
|
|
|
399
|
+
# Whether replies that arrived during a send are waiting to be read.
|
|
400
|
+
# IO.select can't see them, so a caller waiting for replies checks first.
|
|
401
|
+
def held_replies?
|
|
402
|
+
@held
|
|
403
|
+
end
|
|
404
|
+
|
|
354
405
|
def max_allowed_failures
|
|
355
406
|
@max_allowed_failures ||= @options[:socket_max_failures] || 2
|
|
356
407
|
end
|
|
@@ -447,15 +498,139 @@ module Dalli
|
|
|
447
498
|
# One write per flush. A TLS socket sends each argument of
|
|
448
499
|
# write(*parts) as its own record and system call, so the parts are
|
|
449
500
|
# joined first.
|
|
501
|
+
#
|
|
502
|
+
# A write blocks while the socket's send buffer is full. memcached stops
|
|
503
|
+
# reading a connection while its replies go unread, so once the requests
|
|
504
|
+
# it hasn't answered are more than the buffers hold, a blocking write
|
|
505
|
+
# and the server wait on each other until socket_timeout. Up to
|
|
506
|
+
# BLOCKING_WRITE_BYTES unanswered, the write fits whatever the server
|
|
507
|
+
# is doing; past that, #send_while_reading takes the replies off the
|
|
508
|
+
# socket while it sends.
|
|
450
509
|
def flush_write_buffer
|
|
451
510
|
return if @write_buffer.empty?
|
|
452
511
|
|
|
453
512
|
# Set before writing: a write that fails may still have sent some bytes
|
|
454
513
|
@request_sent = true if @request_in_progress
|
|
455
|
-
|
|
514
|
+
data = @write_buffer.size == 1 ? @write_buffer.first : joined_write_buffer
|
|
515
|
+
@unanswered_bytes += data.bytesize
|
|
516
|
+
if @unanswered_bytes <= BLOCKING_WRITE_BYTES
|
|
517
|
+
write_blocking(data)
|
|
518
|
+
else
|
|
519
|
+
send_while_reading(data)
|
|
520
|
+
end
|
|
456
521
|
discard_write_buffer
|
|
457
522
|
end
|
|
458
523
|
|
|
524
|
+
# The write every request makes, kept free of a block outside TLS: a
|
|
525
|
+
# block here measurably slowed each request
|
|
526
|
+
def write_blocking(data)
|
|
527
|
+
return @sock.write(data) unless @sock.is_a?(Dalli::Socket::SSLSocket)
|
|
528
|
+
|
|
529
|
+
Timeout.timeout(socket_timeout) { @sock.write(data) }
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
# Sends without blocking, holding the replies that arrive meanwhile (see
|
|
533
|
+
# HeldReplies). Fails after socket_timeout with nothing sent, as a
|
|
534
|
+
# blocking write does, or when a held reply isn't one the requests sent
|
|
535
|
+
# could get.
|
|
536
|
+
def send_while_reading(data)
|
|
537
|
+
return write_blocking(data) if HALF_DUPLEX_TLS && @sock.is_a?(OpenSSL::SSL::SSLSocket)
|
|
538
|
+
|
|
539
|
+
total = data.bytesize
|
|
540
|
+
sent = 0
|
|
541
|
+
deadline = nil
|
|
542
|
+
counted = false
|
|
543
|
+
while sent < total
|
|
544
|
+
rest = sent.zero? ? data : data.byteslice(sent, total - sent)
|
|
545
|
+
result = @sock.write_nonblock(rest, exception: false)
|
|
546
|
+
if result.is_a?(Integer)
|
|
547
|
+
sent += result
|
|
548
|
+
deadline = nil
|
|
549
|
+
else
|
|
550
|
+
# Replies can only be held from here, so the lines are counted now
|
|
551
|
+
counted ||= (@held_replies ||= HeldReplies.new(max_reply_value_bytes)).count_lines(data)
|
|
552
|
+
deadline ||= write_deadline
|
|
553
|
+
wait_to_send(result, deadline)
|
|
554
|
+
end
|
|
555
|
+
end
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
# Waits until the socket takes more, holding any replies that arrive.
|
|
559
|
+
# TLS can need the other direction first, and the socket is ready for
|
|
560
|
+
# the direction it doesn't need, so waiting on that too would return at
|
|
561
|
+
# once: a write can need to read (:wait_readable), and a read can need
|
|
562
|
+
# to write (:wait_writable).
|
|
563
|
+
def wait_to_send(wait_for, deadline)
|
|
564
|
+
readable, = wait_until(deadline, [@sock], wait_for == :wait_writable ? [@sock] : nil)
|
|
565
|
+
return if readable.empty?
|
|
566
|
+
|
|
567
|
+
wait_until(deadline, nil, [@sock]) if hold_arrived_replies == :wait_writable
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
def wait_until(deadline, readers, writers)
|
|
571
|
+
wait = deadline && (deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC))
|
|
572
|
+
raise Timeout::Error, "IO timeout writing to #{name}" if wait && wait <= 0
|
|
573
|
+
|
|
574
|
+
IO.select(readers, writers, nil, wait) or raise Timeout::Error, "IO timeout writing to #{name}"
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
def write_deadline
|
|
578
|
+
socket_timeout && (Process.clock_gettime(Process::CLOCK_MONOTONIC) + socket_timeout)
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
def max_reply_value_bytes
|
|
582
|
+
@options.fetch(:max_reply_value_bytes, MAX_READ_BYTES - 2)
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
# Returns what read_nonblock did when nothing was held
|
|
586
|
+
def hold_arrived_replies
|
|
587
|
+
result = @held_replies.read_from(@sock, @unanswered_bytes)
|
|
588
|
+
@held = true if result.nil?
|
|
589
|
+
result
|
|
590
|
+
rescue HeldReplies::Invalid => e
|
|
591
|
+
error_on_request!("#{name} sent #{e.message}")
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
# A held reply line. One that continues on the socket is finished from
|
|
595
|
+
# there. A CR that ends the held bytes may be the first half of its CRLF,
|
|
596
|
+
# which gets wouldn't find across the two.
|
|
597
|
+
def held_line
|
|
598
|
+
length, whole = @held_replies.next_line_length
|
|
599
|
+
line_too_long! if length > MAX_LINE_BYTES
|
|
600
|
+
return take_held(length) if whole
|
|
601
|
+
|
|
602
|
+
line = take_held(length)
|
|
603
|
+
line << read(1) while line.end_with?("\r") && line.bytesize <= MAX_LINE_BYTES
|
|
604
|
+
line << read_line unless line.end_with?("\r\n")
|
|
605
|
+
line_too_long! if line.bytesize > MAX_LINE_BYTES
|
|
606
|
+
line
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
# count bytes, the held ones first
|
|
610
|
+
def held_read(count)
|
|
611
|
+
check_read_size!(count)
|
|
612
|
+
held = @held_replies.bytesize
|
|
613
|
+
return take_held(count) if held >= count
|
|
614
|
+
|
|
615
|
+
value = take_held(held)
|
|
616
|
+
value << read(count - held)
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
def take_held(count)
|
|
620
|
+
part = @held_replies.take(count)
|
|
621
|
+
@held = false if @held_replies.empty?
|
|
622
|
+
part
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
def discard_held
|
|
626
|
+
@held = false
|
|
627
|
+
@held_replies&.clear
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
def line_too_long!
|
|
631
|
+
error_on_request!("Reply line without CRLF in the first #{MAX_LINE_BYTES} bytes")
|
|
632
|
+
end
|
|
633
|
+
|
|
459
634
|
# Joined as bytes: requests can mix UTF-8 and binary strings, which
|
|
460
635
|
# String#<< refuses to combine when both hold non-ASCII bytes
|
|
461
636
|
if String.method_defined?(:append_as_bytes)
|
|
@@ -509,7 +684,8 @@ module Dalli
|
|
|
509
684
|
flush_write_buffer
|
|
510
685
|
if @awaiting_reply
|
|
511
686
|
@awaiting_reply = false
|
|
512
|
-
|
|
687
|
+
# A reply held while the request was sent has already arrived
|
|
688
|
+
wait_readable! unless @held || @sock.is_a?(::OpenSSL::SSL::SSLSocket)
|
|
513
689
|
end
|
|
514
690
|
super
|
|
515
691
|
rescue SystemCallError, *TIMEOUT_ERRORS, *SSL_ERRORS, EOFError => e
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dalli
|
|
4
|
+
module Protocol
|
|
5
|
+
##
|
|
6
|
+
# Replies that arrived while a request was being sent (see
|
|
7
|
+
# ConnectionManager#send_while_reading), held until the request's reader
|
|
8
|
+
# gets to them. Created only once a send has had to wait, so connections
|
|
9
|
+
# that never send a large request don't carry its state.
|
|
10
|
+
#
|
|
11
|
+
# Held bytes are checked as they arrive, so that what's held is never more
|
|
12
|
+
# than the requests sent could get back: whole reply lines of up to
|
|
13
|
+
# ConnectionManager::MAX_LINE_BYTES, no more replies than request lines
|
|
14
|
+
# sent, and values no larger than max_response_bytes. Anything else raises
|
|
15
|
+
# Invalid as soon as it's read.
|
|
16
|
+
##
|
|
17
|
+
class HeldReplies
|
|
18
|
+
class Invalid < StandardError; end
|
|
19
|
+
|
|
20
|
+
# Read per wakeup: enough to empty a Unix socket's send buffer (208 KiB
|
|
21
|
+
# by default on Linux)
|
|
22
|
+
READ_BYTES = 256 * 1024
|
|
23
|
+
|
|
24
|
+
def initialize(max_value_bytes)
|
|
25
|
+
@max_value_bytes = max_value_bytes
|
|
26
|
+
@buffer = ''.b
|
|
27
|
+
@offset = 0
|
|
28
|
+
@chunk = nil
|
|
29
|
+
@line = ''.b
|
|
30
|
+
reset_accounting
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Whether lines were counted since the server last answered everything
|
|
34
|
+
def counting?
|
|
35
|
+
@counting
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Each request line can get one reply. Only the lines of a send that had
|
|
39
|
+
# to wait are counted: the socket took the others at once, as it does a
|
|
40
|
+
# blocking write's, and each of their bytes is allowed one.
|
|
41
|
+
def count_lines(data)
|
|
42
|
+
@counting = true
|
|
43
|
+
@counted_bytes += data.bytesize
|
|
44
|
+
@lines += data.count("\n")
|
|
45
|
+
true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The server has answered everything sent so far
|
|
49
|
+
def reset_accounting
|
|
50
|
+
@counting = false
|
|
51
|
+
@counted_bytes = 0
|
|
52
|
+
@lines = 0
|
|
53
|
+
@replies = 0
|
|
54
|
+
@value_left = 0
|
|
55
|
+
@line.clear
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Moves the replies that have arrived on sock into the buffer, reading
|
|
59
|
+
# into it directly when it's empty, then checks them. Returns nil once
|
|
60
|
+
# bytes are held, or what read_nonblock returned when none were.
|
|
61
|
+
# unanswered_bytes is everything sent since the server last answered.
|
|
62
|
+
def read_from(sock, unanswered_bytes)
|
|
63
|
+
if empty?
|
|
64
|
+
@offset = 0
|
|
65
|
+
from = 0
|
|
66
|
+
result = sock.read_nonblock(READ_BYTES, @buffer, exception: false)
|
|
67
|
+
else
|
|
68
|
+
compact
|
|
69
|
+
from = @buffer.bytesize
|
|
70
|
+
result = sock.read_nonblock(READ_BYTES, @chunk ||= ''.b, exception: false)
|
|
71
|
+
@buffer << result if result.is_a?(String)
|
|
72
|
+
end
|
|
73
|
+
raise EOFError, 'EOF while sending' if result.nil?
|
|
74
|
+
# Nothing held: TLS read a handshake record, or nothing had arrived
|
|
75
|
+
return result unless result.is_a?(String)
|
|
76
|
+
|
|
77
|
+
check(from, unanswered_bytes)
|
|
78
|
+
nil
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def empty?
|
|
82
|
+
@offset == @buffer.bytesize
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def bytesize
|
|
86
|
+
@buffer.bytesize - @offset
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# The length of the next line, CRLF included, and whether its CRLF is
|
|
90
|
+
# held. Without it, the line runs to the end of what's held.
|
|
91
|
+
def next_line_length
|
|
92
|
+
eol = @buffer.byteindex("\r\n", @offset)
|
|
93
|
+
eol ? [eol + 2 - @offset, true] : [bytesize, false]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# The next count bytes. Bytes that reach the end are copied: a byteslice
|
|
97
|
+
# there would share the buffer's memory and keep it all allocated.
|
|
98
|
+
def take(count)
|
|
99
|
+
if @offset + count < @buffer.bytesize
|
|
100
|
+
part = @buffer.byteslice(@offset, count)
|
|
101
|
+
@offset += count
|
|
102
|
+
else
|
|
103
|
+
part = String.new(capacity: count, encoding: Encoding::BINARY)
|
|
104
|
+
part.bytesplice(0, 0, @buffer, @offset, count)
|
|
105
|
+
clear
|
|
106
|
+
end
|
|
107
|
+
part
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def clear
|
|
111
|
+
@buffer.clear
|
|
112
|
+
@offset = 0
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def compact
|
|
118
|
+
return unless @offset > COMPACT_THRESHOLD && @offset > (@buffer.bytesize / 2)
|
|
119
|
+
|
|
120
|
+
@buffer.bytesplice(0, @offset, '')
|
|
121
|
+
@offset = 0
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Checks the held bytes from pos, keeping its place in a line or value
|
|
125
|
+
# that continues in the next read
|
|
126
|
+
def check(pos, unanswered_bytes)
|
|
127
|
+
size = @buffer.bytesize
|
|
128
|
+
while pos < size
|
|
129
|
+
if @value_left.positive?
|
|
130
|
+
step = [@value_left, size - pos].min
|
|
131
|
+
@value_left -= step
|
|
132
|
+
pos += step
|
|
133
|
+
next
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
eol = @buffer.byteindex("\n", pos)
|
|
137
|
+
@line << @buffer.byteslice(pos, (eol ? eol + 1 : size) - pos)
|
|
138
|
+
line_too_long! if @line.bytesize > ConnectionManager::MAX_LINE_BYTES
|
|
139
|
+
return unless eol
|
|
140
|
+
|
|
141
|
+
pos = eol + 1
|
|
142
|
+
check_reply(@line, unanswered_bytes)
|
|
143
|
+
@line.clear
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def check_reply(line, unanswered_bytes)
|
|
148
|
+
line_too_long! unless line.end_with?("\r\n")
|
|
149
|
+
|
|
150
|
+
@replies += 1
|
|
151
|
+
if @replies > unanswered_bytes - @counted_bytes + @lines
|
|
152
|
+
raise Invalid, 'more replies than requests while they were being sent'
|
|
153
|
+
end
|
|
154
|
+
return unless line.start_with?('VA ')
|
|
155
|
+
|
|
156
|
+
size = line[/\AVA (\d+)[ \r]/, 1]&.to_i
|
|
157
|
+
unless size && size <= @max_value_bytes
|
|
158
|
+
raise Invalid, 'a value larger than max_response_bytes while a request was being sent'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
@value_left = size + 2
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def line_too_long!
|
|
165
|
+
raise Invalid, "a reply line without CRLF in the first #{ConnectionManager::MAX_LINE_BYTES} bytes"
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
data/lib/dalli/version.rb
CHANGED
data/lib/dalli.rb
CHANGED
|
@@ -91,6 +91,7 @@ require_relative 'dalli/ring'
|
|
|
91
91
|
require_relative 'dalli/protocol'
|
|
92
92
|
require_relative 'dalli/protocol/base'
|
|
93
93
|
require_relative 'dalli/protocol/connection_manager'
|
|
94
|
+
require_relative 'dalli/protocol/held_replies'
|
|
94
95
|
require_relative 'dalli/protocol/meta'
|
|
95
96
|
require_relative 'dalli/protocol/response_buffer'
|
|
96
97
|
require_relative 'dalli/protocol/server_config_parser'
|
metadata
CHANGED
|
@@ -1,96 +1,101 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dalli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.3.
|
|
4
|
+
version: 5.3.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Peter M. Goldstein
|
|
8
|
-
- Mike Perham
|
|
7
|
+
- Peter M. Goldstein
|
|
8
|
+
- Mike Perham
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: logger
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
-
|
|
18
|
+
- ">="
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: "0"
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
-
|
|
26
|
+
- ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: "0"
|
|
27
29
|
description: High performance memcached client for Ruby
|
|
28
30
|
email:
|
|
29
|
-
- peter.m.goldstein@gmail.com
|
|
30
|
-
- mperham@gmail.com
|
|
31
|
+
- peter.m.goldstein@gmail.com
|
|
32
|
+
- mperham@gmail.com
|
|
31
33
|
executables: []
|
|
32
34
|
extensions: []
|
|
33
35
|
extra_rdoc_files: []
|
|
34
36
|
files:
|
|
35
|
-
- CHANGELOG.md
|
|
36
|
-
- Gemfile
|
|
37
|
-
- LICENSE
|
|
38
|
-
- README.md
|
|
39
|
-
- lib/dalli.rb
|
|
40
|
-
- lib/dalli/cache_result.rb
|
|
41
|
-
- lib/dalli/cas/client.rb
|
|
42
|
-
- lib/dalli/client.rb
|
|
43
|
-
- lib/dalli/compressor.rb
|
|
44
|
-
- lib/dalli/flags.rb
|
|
45
|
-
- lib/dalli/instrumentation.rb
|
|
46
|
-
- lib/dalli/json_serializer.rb
|
|
47
|
-
- lib/dalli/key_grouping.rb
|
|
48
|
-
- lib/dalli/key_manager.rb
|
|
49
|
-
- lib/dalli/options.rb
|
|
50
|
-
- lib/dalli/pipelined_deleter.rb
|
|
51
|
-
- lib/dalli/pipelined_getter.rb
|
|
52
|
-
- lib/dalli/pipelined_setter.rb
|
|
53
|
-
- lib/dalli/protocol.rb
|
|
54
|
-
- lib/dalli/protocol/base.rb
|
|
55
|
-
- lib/dalli/protocol/connection_manager.rb
|
|
56
|
-
- lib/dalli/protocol/
|
|
57
|
-
- lib/dalli/protocol/
|
|
58
|
-
- lib/dalli/protocol/
|
|
59
|
-
- lib/dalli/protocol/
|
|
60
|
-
- lib/dalli/protocol/
|
|
61
|
-
- lib/dalli/protocol/
|
|
62
|
-
- lib/dalli/protocol/
|
|
63
|
-
- lib/dalli/protocol/
|
|
64
|
-
- lib/dalli/protocol/
|
|
65
|
-
- lib/dalli/protocol/
|
|
66
|
-
- lib/dalli/protocol/
|
|
67
|
-
- lib/dalli/
|
|
68
|
-
- lib/dalli/
|
|
69
|
-
- lib/dalli/
|
|
70
|
-
- lib/dalli/
|
|
71
|
-
- lib/
|
|
72
|
-
|
|
37
|
+
- CHANGELOG.md
|
|
38
|
+
- Gemfile
|
|
39
|
+
- LICENSE
|
|
40
|
+
- README.md
|
|
41
|
+
- lib/dalli.rb
|
|
42
|
+
- lib/dalli/cache_result.rb
|
|
43
|
+
- lib/dalli/cas/client.rb
|
|
44
|
+
- lib/dalli/client.rb
|
|
45
|
+
- lib/dalli/compressor.rb
|
|
46
|
+
- lib/dalli/flags.rb
|
|
47
|
+
- lib/dalli/instrumentation.rb
|
|
48
|
+
- lib/dalli/json_serializer.rb
|
|
49
|
+
- lib/dalli/key_grouping.rb
|
|
50
|
+
- lib/dalli/key_manager.rb
|
|
51
|
+
- lib/dalli/options.rb
|
|
52
|
+
- lib/dalli/pipelined_deleter.rb
|
|
53
|
+
- lib/dalli/pipelined_getter.rb
|
|
54
|
+
- lib/dalli/pipelined_setter.rb
|
|
55
|
+
- lib/dalli/protocol.rb
|
|
56
|
+
- lib/dalli/protocol/base.rb
|
|
57
|
+
- lib/dalli/protocol/connection_manager.rb
|
|
58
|
+
- lib/dalli/protocol/held_replies.rb
|
|
59
|
+
- lib/dalli/protocol/key_regularizer.rb
|
|
60
|
+
- lib/dalli/protocol/meta.rb
|
|
61
|
+
- lib/dalli/protocol/request_formatter.rb
|
|
62
|
+
- lib/dalli/protocol/response_buffer.rb
|
|
63
|
+
- lib/dalli/protocol/response_processor.rb
|
|
64
|
+
- lib/dalli/protocol/server_config_parser.rb
|
|
65
|
+
- lib/dalli/protocol/string_marshaller.rb
|
|
66
|
+
- lib/dalli/protocol/ttl_sanitizer.rb
|
|
67
|
+
- lib/dalli/protocol/value_compressor.rb
|
|
68
|
+
- lib/dalli/protocol/value_marshaller.rb
|
|
69
|
+
- lib/dalli/protocol/value_serializer.rb
|
|
70
|
+
- lib/dalli/ring.rb
|
|
71
|
+
- lib/dalli/servers_arg_normalizer.rb
|
|
72
|
+
- lib/dalli/socket.rb
|
|
73
|
+
- lib/dalli/version.rb
|
|
74
|
+
- lib/rack/session/dalli.rb
|
|
75
|
+
homepage: "https://github.com/petergoldstein/dalli"
|
|
73
76
|
licenses:
|
|
74
|
-
- MIT
|
|
77
|
+
- MIT
|
|
75
78
|
metadata:
|
|
76
|
-
bug_tracker_uri: https://github.com/petergoldstein/dalli/issues
|
|
77
|
-
changelog_uri: https://github.com/petergoldstein/dalli/blob/main/CHANGELOG.md
|
|
78
|
-
rubygems_mfa_required:
|
|
79
|
+
bug_tracker_uri: "https://github.com/petergoldstein/dalli/issues"
|
|
80
|
+
changelog_uri: "https://github.com/petergoldstein/dalli/blob/main/CHANGELOG.md"
|
|
81
|
+
rubygems_mfa_required: "true"
|
|
79
82
|
rdoc_options: []
|
|
80
83
|
require_paths:
|
|
81
|
-
- lib
|
|
84
|
+
- lib
|
|
82
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
86
|
requirements:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
-
|
|
88
|
+
- ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: "3.3"
|
|
87
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
92
|
requirements:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
-
|
|
94
|
+
- ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: "0"
|
|
92
97
|
requirements: []
|
|
93
|
-
rubygems_version: 4.0
|
|
98
|
+
rubygems_version: 4.1.0
|
|
94
99
|
specification_version: 4
|
|
95
100
|
summary: High performance memcached client for Ruby
|
|
96
101
|
test_files: []
|