pgtk 0.32.3 → 0.32.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/lib/pgtk/stash.rb +32 -15
- data/lib/pgtk/version.rb +1 -1
- 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: 72cdeed11d9faa8c9097c01256603b2ce77a507b936c983ab623b9e1d6e7d364
|
|
4
|
+
data.tar.gz: ab60b5670e87009e1eb47983bd8d729eb403d78a9c6a20c82ea14d70d4a7d18f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 691ea0c8b5ca6002b72ab4b66487b3dbf489feaedbc8e80cc772fe69cfc1ad966fa836e13298b561cadb38c75290ed8a533a389751a7d6b0454da23b87afcb74
|
|
7
|
+
data.tar.gz: 8a04b05ad839b935ac3f8e5362bb957eb64e8e70e1b963c5713a7c7755f8184e6c1e8c806a4d03467bba80e3ce5af0cf9c1a1a50c4d73f11e79d46dc9569fc2f
|
data/lib/pgtk/stash.rb
CHANGED
|
@@ -61,7 +61,7 @@ class Pgtk::Stash
|
|
|
61
61
|
# @param [Concurrent::ReentrantReadWriteLock] entrance Read-write lock for thread-safe access
|
|
62
62
|
def initialize(
|
|
63
63
|
pool,
|
|
64
|
-
stash: { queries: {}, tables: {}, table_mod: {} },
|
|
64
|
+
stash: { queries: {}, tables: {}, table_mod: {}, table_inflight: {} },
|
|
65
65
|
loog: Loog::NULL,
|
|
66
66
|
entrance: Concurrent::ReentrantReadWriteLock.new,
|
|
67
67
|
refill: 16,
|
|
@@ -76,6 +76,7 @@ class Pgtk::Stash
|
|
|
76
76
|
@pool = pool
|
|
77
77
|
@stash = stash
|
|
78
78
|
@stash[:table_mod] ||= {}
|
|
79
|
+
@stash[:table_inflight] ||= {}
|
|
79
80
|
@loog = loog
|
|
80
81
|
@entrance = entrance
|
|
81
82
|
@refill = refill
|
|
@@ -221,22 +222,33 @@ class Pgtk::Stash
|
|
|
221
222
|
def modify(pure, params, result)
|
|
222
223
|
tables = pure.scan(ALTS_RE).flatten
|
|
223
224
|
tables.uniq!
|
|
224
|
-
ret = @pool.exec(pure, params, result)
|
|
225
|
-
now = Time.now
|
|
226
225
|
affected = (tables + tables.flat_map { |t| @cascades&.fetch(t, []) || [] }).uniq
|
|
227
226
|
@entrance.with_write_lock do
|
|
228
|
-
affected.each
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
227
|
+
affected.each { |t| @stash[:table_inflight][t] = (@stash[:table_inflight][t] || 0) + 1 }
|
|
228
|
+
end
|
|
229
|
+
begin
|
|
230
|
+
ret = @pool.exec(pure, params, result)
|
|
231
|
+
now = Time.now
|
|
232
|
+
@entrance.with_write_lock do
|
|
233
|
+
affected.each do |t|
|
|
234
|
+
@stash[:table_inflight][t] -= 1
|
|
235
|
+
old = @stash[:table_mod][t]
|
|
236
|
+
stamp = old && old > now ? old : now
|
|
237
|
+
@stash[:table_mod][t] = stamp
|
|
238
|
+
@stash[:tables][t]&.each do |q|
|
|
239
|
+
@stash[:queries][q]&.each_key do |key|
|
|
240
|
+
@stash[:queries][q][key][:stale] = stamp
|
|
241
|
+
end
|
|
235
242
|
end
|
|
236
243
|
end
|
|
237
244
|
end
|
|
245
|
+
ret
|
|
246
|
+
rescue StandardError
|
|
247
|
+
@entrance.with_write_lock do
|
|
248
|
+
affected.each { |t| @stash[:table_inflight][t] -= 1 }
|
|
249
|
+
end
|
|
250
|
+
raise
|
|
238
251
|
end
|
|
239
|
-
ret
|
|
240
252
|
end
|
|
241
253
|
|
|
242
254
|
def select(pure, params, result)
|
|
@@ -380,8 +392,12 @@ class Pgtk::Stash
|
|
|
380
392
|
end
|
|
381
393
|
|
|
382
394
|
def replenish(query)
|
|
395
|
+
tables = query.scan(READS_RE).flatten
|
|
396
|
+
tables.uniq!
|
|
397
|
+
pinned = nil
|
|
383
398
|
snapshot =
|
|
384
399
|
@entrance.with_read_lock do
|
|
400
|
+
pinned = tables.to_h { |t| [t, @stash[:table_mod][t]] }
|
|
385
401
|
@stash[:queries][query]&.filter_map do |k, h|
|
|
386
402
|
next unless h[:stale]
|
|
387
403
|
next if h[:stale] > Time.now - @delay
|
|
@@ -396,10 +412,11 @@ class Pgtk::Stash
|
|
|
396
412
|
@entrance.with_write_lock do
|
|
397
413
|
h = @stash[:queries][query]&.dig(k)
|
|
398
414
|
next unless h
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
415
|
+
next unless h[:stale] == mark
|
|
416
|
+
next if pinned.any? { |t, m| @stash[:table_mod][t] != m }
|
|
417
|
+
next if tables.any? { |t| (@stash[:table_inflight][t] || 0).positive? }
|
|
418
|
+
h[:ret] = ret
|
|
419
|
+
h.delete(:stale)
|
|
403
420
|
end
|
|
404
421
|
end
|
|
405
422
|
end
|
data/lib/pgtk/version.rb
CHANGED