litebucket 0.2.0-aarch64-linux → 0.2.1-aarch64-linux
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/lib/litebucket/native/aarch64-linux/liblitebucket.so +0 -0
- data/lib/litebucket/railtie.rb +1 -1
- data/lib/litebucket/version.rb +1 -1
- data/lib/litebucket/write_forwarding_middleware.rb +162 -19
- data/lib/litebucket.rb +173 -0
- data/lib/puma/plugin/litebucket.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1891569c57de1c82ab544664cc4473f7a05e6e934798e233246f4864ac92802a
|
|
4
|
+
data.tar.gz: cd1d79e7baf48673e43a56105285a9288c63265a67f966c98cca35b5b6cfa5f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8af3083a501d74355e899cacc56b72fbb07511aad726808bb277d8fe57edb04395b5ded1f8b863d2f6c32afe5236f31a9dfdfaff44c10613e43649943d687d59
|
|
7
|
+
data.tar.gz: ca79e015ed2b2dd396c72c9bbb867058adb75eb52432050476a5d86e64c7089958c83b648f8f31f7425fd6c7d71d58990daca00730b6efecc1b9266cc9450d47
|
|
Binary file
|
data/lib/litebucket/railtie.rb
CHANGED
data/lib/litebucket/version.rb
CHANGED
|
@@ -42,7 +42,9 @@ module LiteBucket
|
|
|
42
42
|
open_timeout: 3,
|
|
43
43
|
read_timeout: 30,
|
|
44
44
|
max_body_bytes: DEFAULT_MAX_BODY_BYTES,
|
|
45
|
-
forward_secret: nil
|
|
45
|
+
forward_secret: nil,
|
|
46
|
+
ryw_cookie: nil,
|
|
47
|
+
ryw_max_wait_ms: 500
|
|
46
48
|
)
|
|
47
49
|
@app = app
|
|
48
50
|
@prefix = prefix
|
|
@@ -53,6 +55,8 @@ module LiteBucket
|
|
|
53
55
|
@read_timeout = read_timeout
|
|
54
56
|
@max_body_bytes = max_body_bytes.to_i
|
|
55
57
|
@forward_secret = forward_secret
|
|
58
|
+
@ryw_cookie = ryw_cookie
|
|
59
|
+
@ryw_max_wait_ms = ryw_max_wait_ms.to_i
|
|
56
60
|
@pool_mutex = Mutex.new
|
|
57
61
|
@http_pools = {}
|
|
58
62
|
end
|
|
@@ -60,38 +64,61 @@ module LiteBucket
|
|
|
60
64
|
def call(env)
|
|
61
65
|
method = env["REQUEST_METHOD"].to_s.upcase
|
|
62
66
|
is_mut = MUTATING_METHODS.include?(method)
|
|
67
|
+
is_read = (method == "GET" || method == "HEAD")
|
|
63
68
|
is_forwarded_in = valid_forwarded_header?(env["HTTP_X_LITEBUCKET_FORWARDED"])
|
|
69
|
+
target_prefix = (is_mut || is_read) ? resolve_target_prefix(env) : nil
|
|
70
|
+
|
|
71
|
+
# Cross-replica read-your-writes: when a browser writes directly to Primary A and its
|
|
72
|
+
# follow-up GET lands on Standby B milliseconds later, the signed `_lb_txid` watermark
|
|
73
|
+
# cookie lets Standby B catch up cleanly (and is 100% inert when LITEBUCKET_ADVERTISE_ADDR
|
|
74
|
+
# is unset, and ~50 ns RAM fast-path when already caught up!).
|
|
75
|
+
if is_read && ryw_cookie_enabled?
|
|
76
|
+
maybe_catch_up_from_txid_cookie(env["HTTP_COOKIE"], target_prefix)
|
|
77
|
+
end
|
|
64
78
|
|
|
65
79
|
if is_mut && !is_forwarded_in
|
|
66
|
-
target_prefix = resolve_target_prefix(env)
|
|
67
80
|
owner_url = resolve_owner_url(env, target_prefix)
|
|
68
81
|
if owner_url && !owner_url.empty?
|
|
69
82
|
result = forward_request(env, owner_url)
|
|
70
83
|
if result != :peer_unreachable
|
|
71
|
-
status, headers, body = result
|
|
84
|
+
status, headers, body, upstream_txid = result
|
|
72
85
|
if status >= 200 && status < 400
|
|
73
86
|
# Read-your-writes across horizontally scaled replicas: pull the freshly committed
|
|
74
87
|
# LTX frame from S3/R2 into local L1 RAM right before returning so an immediate
|
|
75
88
|
# browser `302 -> GET` on this replica sees the write in < 1 ms!
|
|
76
|
-
LiteBucket.catch_up_prefix!(target_prefix)
|
|
89
|
+
caught = LiteBucket.catch_up_prefix!(target_prefix)
|
|
90
|
+
if ryw_cookie_enabled?
|
|
91
|
+
mark = [upstream_txid.to_i, caught.to_i].max
|
|
92
|
+
append_txid_cookie(headers, mark, target_prefix) if mark > 0
|
|
93
|
+
end
|
|
77
94
|
end
|
|
78
95
|
return [status, headers, body]
|
|
79
96
|
end
|
|
80
97
|
# Peer refused connection before receiving the request (e.g. primary pod SIGKILLed or
|
|
81
|
-
# restarting): fall through to local execution so
|
|
82
|
-
# the expired lease seamlessly with zero 502 errors!
|
|
98
|
+
# restarting): evict any cached cold-owner entry and fall through to local execution so
|
|
99
|
+
# SQLite's write-lease takeover claims the expired lease seamlessly with zero 502 errors!
|
|
100
|
+
LiteBucket.invalidate_cached_owner(target_prefix) if target_prefix && !target_prefix.empty?
|
|
83
101
|
end
|
|
84
102
|
end
|
|
85
103
|
|
|
86
104
|
status, headers, body = @app.call(env)
|
|
87
|
-
if is_mut &&
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
if is_mut && status >= 200 && status < 400
|
|
106
|
+
if is_forwarded_in
|
|
107
|
+
# Primary handling a forwarded write: flush staged frames to S3/R2 (keeping our write
|
|
108
|
+
# lease hot!) so the forwarding replica's catch-up observes the new LTX immediately.
|
|
109
|
+
txid = LiteBucket.flush_staged!(target_prefix)
|
|
110
|
+
if txid && txid > 0
|
|
111
|
+
headers = headers.dup
|
|
112
|
+
headers["x-litebucket-txid"] = txid.to_s
|
|
113
|
+
end
|
|
114
|
+
elsif ryw_cookie_enabled?
|
|
115
|
+
# Direct Primary write in multi-replica mode: stamp effective txid (~50 ns RAM, zero R2
|
|
116
|
+
# blocking!) so a follow-up GET hitting ANY Standby replica catches up automatically!
|
|
117
|
+
eff = LiteBucket.effective_txid(target_prefix)
|
|
118
|
+
if eff && eff > 0
|
|
119
|
+
headers = headers.dup
|
|
120
|
+
append_txid_cookie(headers, eff, target_prefix)
|
|
121
|
+
end
|
|
95
122
|
end
|
|
96
123
|
end
|
|
97
124
|
[status, headers, body]
|
|
@@ -115,16 +142,127 @@ module LiteBucket
|
|
|
115
142
|
return @owner_resolver.arity == 0 ? @owner_resolver.call : @owner_resolver.call(env)
|
|
116
143
|
end
|
|
117
144
|
|
|
118
|
-
LiteBucket.write_owner_addr(target_prefix)
|
|
145
|
+
addr = LiteBucket.write_owner_addr(target_prefix)
|
|
146
|
+
return addr if addr && !addr.empty?
|
|
147
|
+
|
|
148
|
+
# Cold multi-tenant DB not yet open locally: probe write_lock.json via 3s RAM cache
|
|
149
|
+
# (completely inert when LITEBUCKET_ADVERTISE_ADDR is unset).
|
|
150
|
+
if horizontal_mode_enabled? && target_prefix && !target_prefix.empty? &&
|
|
151
|
+
LiteBucket.effective_txid(target_prefix).nil?
|
|
152
|
+
return LiteBucket.write_owner_addr_or_probe(target_prefix)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
nil
|
|
119
156
|
end
|
|
120
157
|
|
|
121
|
-
def
|
|
122
|
-
|
|
158
|
+
def horizontal_mode_enabled?
|
|
159
|
+
!ENV["LITEBUCKET_ADVERTISE_ADDR"].to_s.strip.empty?
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def ryw_cookie_enabled?
|
|
163
|
+
return @ryw_cookie unless @ryw_cookie.nil?
|
|
164
|
+
|
|
165
|
+
horizontal_mode_enabled?
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def forward_secret_value
|
|
169
|
+
@forward_secret || %w[
|
|
123
170
|
LITEBUCKET_FORWARD_SECRET
|
|
124
171
|
LITEBUCKET_ENCRYPTION_KEY
|
|
125
172
|
AWS_SECRET_ACCESS_KEY
|
|
126
173
|
FILESYSTEM_SECRET_ACCESS_KEY
|
|
127
174
|
].map { |k| ENV[k] }.find { |v| v && !v.strip.empty? }
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def safe_cookie_prefix?(prefix)
|
|
178
|
+
return false if prefix.nil? || prefix.empty? || prefix.bytesize > 192
|
|
179
|
+
|
|
180
|
+
prefix.match?(/\A[A-Za-z0-9._\/-]+\z/)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def sign_txid_cookie(txid, prefix)
|
|
184
|
+
secret = forward_secret_value
|
|
185
|
+
clean_p = prefix ? prefix.to_s.gsub(%r{\A/+|/+\z}, "") : nil
|
|
186
|
+
clean_p = nil unless safe_cookie_prefix?(clean_p)
|
|
187
|
+
payload = clean_p ? "#{txid}@#{clean_p}" : txid.to_s
|
|
188
|
+
val = if secret && !secret.empty?
|
|
189
|
+
sig = OpenSSL::HMAC.hexdigest("SHA256", secret, "lb-txid-v1:#{payload}")[0, 16]
|
|
190
|
+
clean_p ? "#{txid}.#{sig}@#{clean_p}" : "#{txid}.#{sig}"
|
|
191
|
+
else
|
|
192
|
+
payload
|
|
193
|
+
end
|
|
194
|
+
"_lb_txid=#{val}; Path=/; Max-Age=10; HttpOnly; SameSite=Lax"
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def parse_txid_cookie(cookie_header)
|
|
198
|
+
return nil if cookie_header.nil? || cookie_header.empty?
|
|
199
|
+
|
|
200
|
+
secret = forward_secret_value
|
|
201
|
+
cookie_header.split(";").each do |part|
|
|
202
|
+
trimmed = part.strip
|
|
203
|
+
next unless trimmed.start_with?("_lb_txid=")
|
|
204
|
+
|
|
205
|
+
raw = trimmed.delete_prefix("_lb_txid=")
|
|
206
|
+
head, raw_prefix = raw.split("@", 2)
|
|
207
|
+
clean_p = nil
|
|
208
|
+
if raw_prefix
|
|
209
|
+
clean_p = raw_prefix.gsub(%r{\A/+|/+\z}, "")
|
|
210
|
+
return nil unless safe_cookie_prefix?(clean_p)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
txid_str, sig = head.split(".", 2)
|
|
214
|
+
return nil unless txid_str && txid_str.match?(/\A[0-9]+\z/)
|
|
215
|
+
|
|
216
|
+
txid = txid_str.to_i
|
|
217
|
+
return nil if txid <= 0
|
|
218
|
+
|
|
219
|
+
if secret && !secret.empty?
|
|
220
|
+
return nil if sig.nil? || sig.empty?
|
|
221
|
+
|
|
222
|
+
payload = clean_p ? "#{txid}@#{clean_p}" : txid.to_s
|
|
223
|
+
expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "lb-txid-v1:#{payload}")[0, 16]
|
|
224
|
+
return nil unless sig.bytesize == expected.bytesize &&
|
|
225
|
+
OpenSSL.fixed_length_secure_compare(sig, expected)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
return [txid, clean_p]
|
|
229
|
+
end
|
|
230
|
+
nil
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def append_txid_cookie(headers, txid, prefix)
|
|
234
|
+
return if txid.nil? || txid <= 0
|
|
235
|
+
|
|
236
|
+
cookie_str = sign_txid_cookie(txid, prefix)
|
|
237
|
+
existing_key = headers.keys.find { |k| k.to_s.downcase == "set-cookie" } || "set-cookie"
|
|
238
|
+
existing = headers[existing_key]
|
|
239
|
+
headers[existing_key] = if existing.nil?
|
|
240
|
+
cookie_str
|
|
241
|
+
elsif existing.is_a?(Array)
|
|
242
|
+
existing + [cookie_str]
|
|
243
|
+
else
|
|
244
|
+
[existing, cookie_str]
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def maybe_catch_up_from_txid_cookie(cookie_header, target_prefix)
|
|
249
|
+
parsed = parse_txid_cookie(cookie_header)
|
|
250
|
+
return unless parsed
|
|
251
|
+
|
|
252
|
+
target_txid, cookie_prefix = parsed
|
|
253
|
+
if target_prefix && !target_prefix.empty? && cookie_prefix && !cookie_prefix.empty?
|
|
254
|
+
return unless target_prefix.gsub(%r{\A/+|/+\z}, "") == cookie_prefix
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
lookup_prefix = (target_prefix && !target_prefix.empty?) ? target_prefix : cookie_prefix
|
|
258
|
+
eff = LiteBucket.effective_txid(lookup_prefix)
|
|
259
|
+
return unless eff && eff < target_txid
|
|
260
|
+
|
|
261
|
+
LiteBucket.catch_up_to_txid!(lookup_prefix, target_txid, max_wait_ms: @ryw_max_wait_ms)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def forward_loop_token
|
|
265
|
+
secret = forward_secret_value
|
|
128
266
|
return nil if secret.nil? || secret.empty?
|
|
129
267
|
|
|
130
268
|
OpenSSL::HMAC.hexdigest("SHA256", secret, "litebucket-write-forward-v1")[0, 32]
|
|
@@ -287,16 +425,21 @@ module LiteBucket
|
|
|
287
425
|
end
|
|
288
426
|
checkin_http(pool_key, http)
|
|
289
427
|
|
|
428
|
+
upstream_txid = nil
|
|
290
429
|
headers = {}
|
|
291
430
|
res.each_header do |k, v|
|
|
292
431
|
lower = k.downcase
|
|
293
|
-
|
|
432
|
+
if lower == "x-litebucket-txid"
|
|
433
|
+
upstream_txid = v.to_i if v.to_s.match?(/\A[0-9]+\z/)
|
|
434
|
+
next
|
|
435
|
+
end
|
|
436
|
+
next if HOP_BY_HOP_HEADERS.include?(lower)
|
|
294
437
|
|
|
295
438
|
headers[k] = v
|
|
296
439
|
end
|
|
297
440
|
# Signal forwarding occurred without leaking internal peer pod IP/URL to public clients.
|
|
298
441
|
headers["x-litebucket-forwarded"] = "1"
|
|
299
|
-
[res.code.to_i, headers, [res.body.to_s]]
|
|
442
|
+
[res.code.to_i, headers, [res.body.to_s], upstream_txid]
|
|
300
443
|
rescue StandardError
|
|
301
444
|
http.finish rescue nil
|
|
302
445
|
[502, { "content-type" => "text/plain" }, ["LiteBucket write-forwarding to primary failed"]]
|
data/lib/litebucket.rb
CHANGED
|
@@ -375,6 +375,65 @@ module LiteBucket
|
|
|
375
375
|
nil
|
|
376
376
|
end
|
|
377
377
|
|
|
378
|
+
# Return the highest effective `txid` (including staged/in-flight batched commits) for open
|
|
379
|
+
# DB(s) matching `prefix` (or all open DBs when `nil`), or `nil` if no matching DB is open.
|
|
380
|
+
def effective_txid(prefix = nil)
|
|
381
|
+
return nil unless @loaded
|
|
382
|
+
|
|
383
|
+
fn = fiddle_effective_txid_fn
|
|
384
|
+
return nil unless fn
|
|
385
|
+
|
|
386
|
+
ptr = prefix ? Fiddle::Pointer[prefix.to_s] : Fiddle::NULL
|
|
387
|
+
txid = fn.call(ptr)
|
|
388
|
+
txid >= 0 ? txid : nil
|
|
389
|
+
rescue StandardError
|
|
390
|
+
nil
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
# Ensure open read-replica DB(s) matching `prefix` (or all open DBs when `nil`) are caught up
|
|
394
|
+
# to at least `target_txid`, waiting up to `max_wait_ms` (default 500 ms) for Primary's
|
|
395
|
+
# background batched flush to land in S3/R2. Fast-paths in ~50 ns with 0 S3 calls when warm.
|
|
396
|
+
def catch_up_to_txid!(prefix, target_txid, max_wait_ms: 500)
|
|
397
|
+
return nil unless @loaded
|
|
398
|
+
|
|
399
|
+
fn = fiddle_catch_up_to_txid_fn
|
|
400
|
+
return catch_up_prefix!(prefix) unless fn
|
|
401
|
+
|
|
402
|
+
ptr = prefix ? Fiddle::Pointer[prefix.to_s] : Fiddle::NULL
|
|
403
|
+
txid = fn.call(ptr, target_txid.to_i, max_wait_ms.to_i)
|
|
404
|
+
txid >= 0 ? txid : nil
|
|
405
|
+
rescue StandardError
|
|
406
|
+
nil
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# Returns `true` once `begin_shutdown_drain!` has been called (SIGTERM / worker shutdown).
|
|
410
|
+
# Wire into `/up` or `/ready` health checks so load balancers drain traffic cleanly.
|
|
411
|
+
def draining?
|
|
412
|
+
return false unless @loaded
|
|
413
|
+
|
|
414
|
+
fn = fiddle_is_draining_fn
|
|
415
|
+
return false unless fn
|
|
416
|
+
|
|
417
|
+
fn.call == 1
|
|
418
|
+
rescue StandardError
|
|
419
|
+
false
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
# Engage the process-wide `DRAINING` write barrier (promoting any late in-flight batched
|
|
423
|
+
# commits to synchronous S3/R2 flushes) and drain all open DBs + release write leases in
|
|
424
|
+
# parallel (up to 16 concurrent HTTP/2 workers). Falls back to `flush_all!` on older `.so`.
|
|
425
|
+
def begin_shutdown_drain!
|
|
426
|
+
return 0 unless @loaded
|
|
427
|
+
|
|
428
|
+
if (fn = fiddle_begin_shutdown_drain_fn)
|
|
429
|
+
return fn.call
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
flush_all!
|
|
433
|
+
rescue StandardError
|
|
434
|
+
flush_all!
|
|
435
|
+
end
|
|
436
|
+
|
|
378
437
|
# Flush all open LiteBucket DBs in-process AND release distributed write leases cleanly
|
|
379
438
|
# (safe for at_exit / SIGTERM). Falls back to per-pool `PRAGMA litebucket_flush;` when
|
|
380
439
|
# running against an older `liblitebucket.so` without `litebucket_flush_all`.
|
|
@@ -424,6 +483,34 @@ module LiteBucket
|
|
|
424
483
|
nil
|
|
425
484
|
end
|
|
426
485
|
|
|
486
|
+
# Like `write_owner_addr`, but when `prefix` is not yet open locally (cold multi-tenant DB)
|
|
487
|
+
# and `LITEBUCKET_ADVERTISE_ADDR` is configured, performs a cached (3s TTL) `write_lock.json`
|
|
488
|
+
# probe via the shared HTTP/2 S3 client to prevent multi-tenant lease ping-pong.
|
|
489
|
+
# Completely inert (returns `nil`) when `LITEBUCKET_ADVERTISE_ADDR` is unset.
|
|
490
|
+
def write_owner_addr_or_probe(prefix)
|
|
491
|
+
return nil unless @loaded_path && prefix && !prefix.to_s.empty?
|
|
492
|
+
|
|
493
|
+
fn = fiddle_write_owner_or_probe_fn
|
|
494
|
+
return write_owner_addr(prefix) unless fn
|
|
495
|
+
|
|
496
|
+
buf = +"\0" * 512
|
|
497
|
+
n = fn.call(Fiddle::Pointer[prefix.to_s], buf, buf.bytesize)
|
|
498
|
+
n > 0 ? buf.byteslice(0, n) : nil
|
|
499
|
+
rescue StandardError
|
|
500
|
+
nil
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
# Evict the 3s cached cold-tenant write-owner entry for `prefix` after a dead-peer connect error.
|
|
504
|
+
def invalidate_cached_owner(prefix)
|
|
505
|
+
return nil unless @loaded_path && prefix && !prefix.to_s.empty?
|
|
506
|
+
|
|
507
|
+
fn = fiddle_invalidate_cached_owner_fn
|
|
508
|
+
fn&.call(Fiddle::Pointer[prefix.to_s])
|
|
509
|
+
nil
|
|
510
|
+
rescue StandardError
|
|
511
|
+
nil
|
|
512
|
+
end
|
|
513
|
+
|
|
427
514
|
# Render Prometheus metrics (`text/plain; version=0.0.4`) for all open LiteBucket DBs in-process.
|
|
428
515
|
def prometheus_metrics
|
|
429
516
|
return "" unless @loaded_path
|
|
@@ -608,6 +695,92 @@ module LiteBucket
|
|
|
608
695
|
end
|
|
609
696
|
end
|
|
610
697
|
|
|
698
|
+
def fiddle_begin_shutdown_drain_fn
|
|
699
|
+
return @fiddle_begin_shutdown_drain_fn if defined?(@fiddle_begin_shutdown_drain_fn)
|
|
700
|
+
|
|
701
|
+
@fiddle_begin_shutdown_drain_fn = begin
|
|
702
|
+
return nil unless fiddle_handle
|
|
703
|
+
|
|
704
|
+
sym = fiddle_handle["litebucket_begin_shutdown_drain"]
|
|
705
|
+
Fiddle::Function.new(sym, [], Fiddle::TYPE_SIZE_T)
|
|
706
|
+
rescue StandardError
|
|
707
|
+
nil
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
|
|
711
|
+
def fiddle_is_draining_fn
|
|
712
|
+
return @fiddle_is_draining_fn if defined?(@fiddle_is_draining_fn)
|
|
713
|
+
|
|
714
|
+
@fiddle_is_draining_fn = begin
|
|
715
|
+
return nil unless fiddle_handle
|
|
716
|
+
|
|
717
|
+
sym = fiddle_handle["litebucket_is_draining"]
|
|
718
|
+
Fiddle::Function.new(sym, [], Fiddle::TYPE_INT)
|
|
719
|
+
rescue StandardError
|
|
720
|
+
nil
|
|
721
|
+
end
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
def fiddle_effective_txid_fn
|
|
725
|
+
return @fiddle_effective_txid_fn if defined?(@fiddle_effective_txid_fn)
|
|
726
|
+
|
|
727
|
+
@fiddle_effective_txid_fn = begin
|
|
728
|
+
return nil unless fiddle_handle
|
|
729
|
+
|
|
730
|
+
sym = fiddle_handle["litebucket_effective_txid"]
|
|
731
|
+
Fiddle::Function.new(sym, [Fiddle::TYPE_VOIDP], Fiddle::TYPE_LONG_LONG)
|
|
732
|
+
rescue StandardError
|
|
733
|
+
nil
|
|
734
|
+
end
|
|
735
|
+
end
|
|
736
|
+
|
|
737
|
+
def fiddle_catch_up_to_txid_fn
|
|
738
|
+
return @fiddle_catch_up_to_txid_fn if defined?(@fiddle_catch_up_to_txid_fn)
|
|
739
|
+
|
|
740
|
+
@fiddle_catch_up_to_txid_fn = begin
|
|
741
|
+
return nil unless fiddle_handle
|
|
742
|
+
|
|
743
|
+
sym = fiddle_handle["litebucket_catch_up_to_txid"]
|
|
744
|
+
Fiddle::Function.new(
|
|
745
|
+
sym,
|
|
746
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG_LONG, Fiddle::TYPE_LONG_LONG],
|
|
747
|
+
Fiddle::TYPE_LONG_LONG
|
|
748
|
+
)
|
|
749
|
+
rescue StandardError
|
|
750
|
+
nil
|
|
751
|
+
end
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
def fiddle_write_owner_or_probe_fn
|
|
755
|
+
return @fiddle_write_owner_or_probe_fn if defined?(@fiddle_write_owner_or_probe_fn)
|
|
756
|
+
|
|
757
|
+
@fiddle_write_owner_or_probe_fn = begin
|
|
758
|
+
return nil unless fiddle_handle
|
|
759
|
+
|
|
760
|
+
sym = fiddle_handle["litebucket_write_owner_addr_or_probe"]
|
|
761
|
+
Fiddle::Function.new(
|
|
762
|
+
sym,
|
|
763
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T],
|
|
764
|
+
Fiddle::TYPE_SSIZE_T
|
|
765
|
+
)
|
|
766
|
+
rescue StandardError
|
|
767
|
+
nil
|
|
768
|
+
end
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
def fiddle_invalidate_cached_owner_fn
|
|
772
|
+
return @fiddle_invalidate_cached_owner_fn if defined?(@fiddle_invalidate_cached_owner_fn)
|
|
773
|
+
|
|
774
|
+
@fiddle_invalidate_cached_owner_fn = begin
|
|
775
|
+
return nil unless fiddle_handle
|
|
776
|
+
|
|
777
|
+
sym = fiddle_handle["litebucket_invalidate_cached_owner"]
|
|
778
|
+
Fiddle::Function.new(sym, [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID)
|
|
779
|
+
rescue StandardError
|
|
780
|
+
nil
|
|
781
|
+
end
|
|
782
|
+
end
|
|
783
|
+
|
|
611
784
|
def read_c_string_from_fn(fn, initial_cap: 1024)
|
|
612
785
|
buf = +"\0" * initial_cap
|
|
613
786
|
len = fn.call(Fiddle::Pointer[buf], buf.bytesize)
|
|
@@ -18,11 +18,11 @@ Puma::Plugin.create do
|
|
|
18
18
|
|
|
19
19
|
if c.respond_to?(:on_worker_shutdown)
|
|
20
20
|
c.on_worker_shutdown do
|
|
21
|
-
LiteBucket.
|
|
21
|
+
LiteBucket.begin_shutdown_drain!
|
|
22
22
|
end
|
|
23
23
|
elsif c.respond_to?(:before_worker_shutdown)
|
|
24
24
|
c.before_worker_shutdown do
|
|
25
|
-
LiteBucket.
|
|
25
|
+
LiteBucket.begin_shutdown_drain!
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -30,7 +30,7 @@ Puma::Plugin.create do
|
|
|
30
30
|
def start(launcher)
|
|
31
31
|
if launcher.respond_to?(:events) && launcher.events.respond_to?(:on_stopped)
|
|
32
32
|
launcher.events.on_stopped do
|
|
33
|
-
LiteBucket.
|
|
33
|
+
LiteBucket.begin_shutdown_drain!
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|