pg_eventstore 1.13.2 → 1.13.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 +11 -3
- data/lib/pg_eventstore/event.rb +2 -0
- data/lib/pg_eventstore/queries/event_queries.rb +4 -3
- data/lib/pg_eventstore/queries/partition_queries.rb +71 -6
- data/lib/pg_eventstore/query_builders/events_filtering.rb +1 -5
- data/lib/pg_eventstore/query_builders/partitions_filtering.rb +26 -16
- data/lib/pg_eventstore/sql_builder.rb +30 -12
- data/lib/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rb +8 -3
- data/lib/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rb +9 -0
- data/lib/pg_eventstore/subscriptions/events_processor.rb +7 -3
- data/lib/pg_eventstore/subscriptions/queries/service_queries.rb +73 -0
- data/lib/pg_eventstore/subscriptions/queries/subscription_queries.rb +1 -0
- data/lib/pg_eventstore/subscriptions/subscription.rb +11 -1
- data/lib/pg_eventstore/subscriptions/subscription_feeder.rb +7 -1
- data/lib/pg_eventstore/subscriptions/subscription_position_evaluation.rb +195 -0
- data/lib/pg_eventstore/subscriptions/subscription_runner.rb +18 -2
- data/lib/pg_eventstore/subscriptions/subscription_runners_feeder.rb +1 -1
- data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +13 -1
- data/lib/pg_eventstore/subscriptions/synchronized_array.rb +41 -0
- data/lib/pg_eventstore/version.rb +1 -1
- data/lib/pg_eventstore/web/paginator/events_collection.rb +1 -1
- data/lib/pg_eventstore/web/paginator/stream_ids_collection.rb +2 -2
- data/rbs_collection.lock.yaml +9 -1
- data/rbs_collection.yaml +2 -0
- data/sig/manifest.yaml +3 -0
- data/sig/pg_eventstore/event.rbs +3 -1
- data/sig/pg_eventstore/queries/partition_queries.rbs +5 -1
- data/sig/pg_eventstore/query_builders/partitions_filtering.rbs +9 -5
- data/sig/pg_eventstore/sql_builder.rbs +8 -2
- data/sig/pg_eventstore/subscriptions/callback_handlers/events_processor_handlers.rbs +2 -1
- data/sig/pg_eventstore/subscriptions/callback_handlers/subscription_runner_handlers.rbs +3 -0
- data/sig/pg_eventstore/subscriptions/queries/service_queries.rbs +15 -0
- data/sig/pg_eventstore/subscriptions/subscription.rbs +2 -0
- data/sig/pg_eventstore/subscriptions/subscription_feeder.rbs +2 -0
- data/sig/pg_eventstore/subscriptions/subscription_position_evaluation.rbs +53 -0
- data/sig/pg_eventstore/subscriptions/subscription_runner.rbs +3 -2
- data/sig/pg_eventstore/subscriptions/subscriptions_manager.rbs +2 -0
- data/sig/pg_eventstore/subscriptions/synchronized_array.rbs +4 -0
- metadata +8 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PgEventstore
|
|
4
|
+
# When subscription pulls events at the edge of the events list and several events arrives concurrently - there is a
|
|
5
|
+
# chance some events will never be picked. Example:
|
|
6
|
+
# - event1 has been assigned global_position#9
|
|
7
|
+
# - event2 has been assigned global_position#10
|
|
8
|
+
# - event1 and event2 are currently in concurrent transactions, but those transactions does not block each other
|
|
9
|
+
# - transaction holding event2 commits first
|
|
10
|
+
# - a subscription picks event2 and sets next position to 11
|
|
11
|
+
# - transaction holding event1 commits
|
|
12
|
+
# Illustration:
|
|
13
|
+
# Time → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → → →
|
|
14
|
+
#
|
|
15
|
+
# T1: BEGIN
|
|
16
|
+
# INSERT INTO events(...);
|
|
17
|
+
# --------------------global_position#9------------------->
|
|
18
|
+
# COMMIT
|
|
19
|
+
# T2: BEGIN
|
|
20
|
+
# INSERT INTO events(...);
|
|
21
|
+
# --------------global_position#10-------->
|
|
22
|
+
# COMMIT
|
|
23
|
+
# Query events: SELECT * FROM event WHERE global_position >= 8
|
|
24
|
+
# --------------Picks #8, #10, but never #9-------->
|
|
25
|
+
#
|
|
26
|
+
# To solve this problem we can:
|
|
27
|
+
# 1. pause events fetching for the subscription
|
|
28
|
+
# 2. fetch latest global position that matches subscription's filter
|
|
29
|
+
# 3. wait for all currently running transactions that affects on the subscription to finish
|
|
30
|
+
# 4. unpause events fetching and use this position as a right hand limiter, because we can now confidently say there
|
|
31
|
+
# are no uncommited events that would be lost otherwise
|
|
32
|
+
# This class is responsible for the step 2 and step 3, and persists the last safe position to be used in step 4.
|
|
33
|
+
# @!visibility private
|
|
34
|
+
class SubscriptionPositionEvaluation
|
|
35
|
+
# Determines how often to check the list of currently running transactions
|
|
36
|
+
# @return [Float]
|
|
37
|
+
TRANSACTIONS_STATUS_REFRESH_INTERVAL = 0.05 # seconds
|
|
38
|
+
private_constant :TRANSACTIONS_STATUS_REFRESH_INTERVAL
|
|
39
|
+
|
|
40
|
+
# @param config_name [Symbol]
|
|
41
|
+
# @param filter_options [Hash]
|
|
42
|
+
def initialize(config_name:, filter_options:)
|
|
43
|
+
@config_name = config_name
|
|
44
|
+
@stream_filters = QueryBuilders::PartitionsFiltering.extract_streams_filter(filter: filter_options)
|
|
45
|
+
@event_type_filters = QueryBuilders::PartitionsFiltering.extract_event_types_filter(filter: filter_options)
|
|
46
|
+
@position_to_evaluate = nil
|
|
47
|
+
@position_is_safe = nil
|
|
48
|
+
@last_safe_position = nil
|
|
49
|
+
@runner = nil
|
|
50
|
+
@relation_ids_cache = {}
|
|
51
|
+
@mutex = Mutex.new
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @param position_to_evaluate [Integer]
|
|
55
|
+
# @return [self]
|
|
56
|
+
def evaluate(position_to_evaluate)
|
|
57
|
+
unless self.position_to_evaluate == position_to_evaluate
|
|
58
|
+
stop_evaluation
|
|
59
|
+
self.position_to_evaluate = position_to_evaluate
|
|
60
|
+
calculate_safe_position
|
|
61
|
+
end
|
|
62
|
+
self
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @return [Boolean]
|
|
66
|
+
def safe?
|
|
67
|
+
@mutex.synchronize { @position_is_safe } || false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @return [Integer, nil]
|
|
71
|
+
def last_safe_position
|
|
72
|
+
@mutex.synchronize { @last_safe_position }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @return [Thread, nil] a runner who is being stopped if any
|
|
76
|
+
def stop_evaluation
|
|
77
|
+
_stop_evaluation(@runner)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
# @param runner [Thread, nil]
|
|
83
|
+
# @return [Thread, nil]
|
|
84
|
+
def _stop_evaluation(runner)
|
|
85
|
+
runner&.exit
|
|
86
|
+
self.position_is_safe = nil
|
|
87
|
+
self.last_safe_position = nil
|
|
88
|
+
self.position_to_evaluate = nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @return [Integer, nil]
|
|
92
|
+
def position_to_evaluate
|
|
93
|
+
@mutex.synchronize { @position_to_evaluate }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# @return [Boolean, nil]
|
|
97
|
+
def position_is_safe
|
|
98
|
+
@mutex.synchronize { @position_is_safe }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# @param val [Integer, nil]
|
|
102
|
+
# @return [Integer, nil]
|
|
103
|
+
def last_safe_position=(val)
|
|
104
|
+
@mutex.synchronize { @last_safe_position = val }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# @param val [Integer, nil]
|
|
108
|
+
# @return [Integer, nil]
|
|
109
|
+
def position_to_evaluate=(val)
|
|
110
|
+
@mutex.synchronize { @position_to_evaluate = val }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @param val [Boolean, nil]
|
|
114
|
+
# @return [Boolean, nil]
|
|
115
|
+
def position_is_safe=(val)
|
|
116
|
+
@mutex.synchronize { @position_is_safe = val }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# @return [Array<String>]
|
|
120
|
+
def affected_tables
|
|
121
|
+
if @stream_filters.empty? && @event_type_filters.empty?
|
|
122
|
+
[Event::PRIMARY_TABLE_NAME]
|
|
123
|
+
else
|
|
124
|
+
partition_queries.partitions(@stream_filters, @event_type_filters, scope: :auto).map(&:table_name)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @return [void]
|
|
129
|
+
def calculate_safe_position
|
|
130
|
+
@runner = Thread.new do
|
|
131
|
+
tables_to_track = affected_tables
|
|
132
|
+
update_relation_ids_cache(tables_to_track)
|
|
133
|
+
safe_position = service_queries.max_global_position(tables_to_track)
|
|
134
|
+
trx_ids = transaction_queries.transaction do
|
|
135
|
+
service_queries.relation_transaction_ids(@relation_ids_cache.values)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
loop do
|
|
139
|
+
transactions_in_progress = service_queries.transactions_in_progress?(
|
|
140
|
+
relation_ids: @relation_ids_cache.values, transaction_ids: trx_ids
|
|
141
|
+
)
|
|
142
|
+
break unless transactions_in_progress
|
|
143
|
+
|
|
144
|
+
sleep TRANSACTIONS_STATUS_REFRESH_INTERVAL
|
|
145
|
+
end
|
|
146
|
+
@mutex.synchronize do
|
|
147
|
+
if safe_position >= @position_to_evaluate
|
|
148
|
+
# We progressed forward. New position can be persisted
|
|
149
|
+
@last_safe_position = safe_position
|
|
150
|
+
@position_is_safe = true
|
|
151
|
+
else
|
|
152
|
+
# safe_position is less than the current position to fetch the events from. This means that no new events
|
|
153
|
+
# are present at this point. We will need to re-evaluate the safe position during next attempts. Until that
|
|
154
|
+
# we can't progress.
|
|
155
|
+
@position_to_evaluate = nil
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
rescue
|
|
159
|
+
# Clean up the state immediately in case of error
|
|
160
|
+
_stop_evaluation(nil)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# @param tables_to_track [Array<String>]
|
|
165
|
+
# @return [void]
|
|
166
|
+
def update_relation_ids_cache(tables_to_track)
|
|
167
|
+
missing_relation_ids = tables_to_track - @relation_ids_cache.keys
|
|
168
|
+
deleted_relations = @relation_ids_cache.keys - tables_to_track
|
|
169
|
+
@relation_ids_cache = @relation_ids_cache.except(*deleted_relations)
|
|
170
|
+
return if missing_relation_ids.empty?
|
|
171
|
+
|
|
172
|
+
@relation_ids_cache.merge!(service_queries.relation_ids_by_names(missing_relation_ids))
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# @return [PgEventstore::PartitionQueries]
|
|
176
|
+
def partition_queries
|
|
177
|
+
PartitionQueries.new(connection)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# @return [PgEventstore::TransactionQueries]
|
|
181
|
+
def transaction_queries
|
|
182
|
+
TransactionQueries.new(connection)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# @return [PgEventstore::ServiceQueries]
|
|
186
|
+
def service_queries
|
|
187
|
+
ServiceQueries.new(connection)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# @return [PgEventstore::Connection]
|
|
191
|
+
def connection
|
|
192
|
+
PgEventstore.connection(@config_name)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
@@ -28,17 +28,23 @@ module PgEventstore
|
|
|
28
28
|
# @param stats [PgEventstore::SubscriptionHandlerPerformance]
|
|
29
29
|
# @param events_processor [PgEventstore::EventsProcessor]
|
|
30
30
|
# @param subscription [PgEventstore::Subscription]
|
|
31
|
-
|
|
31
|
+
# @param position_evaluation [PgEventstore::SubscriptionPositionEvaluation]
|
|
32
|
+
def initialize(stats:, events_processor:, subscription:, position_evaluation:)
|
|
32
33
|
@stats = stats
|
|
33
34
|
@events_processor = events_processor
|
|
34
35
|
@subscription = subscription
|
|
36
|
+
@position_evaluation = position_evaluation
|
|
35
37
|
|
|
36
38
|
attach_callbacks
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
# @return [Hash]
|
|
40
42
|
def next_chunk_query_opts
|
|
41
|
-
@subscription.options.merge(
|
|
43
|
+
@subscription.options.merge(
|
|
44
|
+
from_position: next_chunk_global_position,
|
|
45
|
+
max_count: estimate_events_number,
|
|
46
|
+
to_position: @position_evaluation.last_safe_position
|
|
47
|
+
)
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
# @return [Boolean]
|
|
@@ -46,6 +52,11 @@ module PgEventstore
|
|
|
46
52
|
@subscription.last_chunk_fed_at + @subscription.chunk_query_interval <= Time.now.utc
|
|
47
53
|
end
|
|
48
54
|
|
|
55
|
+
# @return [Boolean]
|
|
56
|
+
def next_chunk_safe?
|
|
57
|
+
estimate_events_number == 0 ? false : @position_evaluation.evaluate(next_chunk_global_position).safe?
|
|
58
|
+
end
|
|
59
|
+
|
|
49
60
|
private
|
|
50
61
|
|
|
51
62
|
# @return [Integer]
|
|
@@ -97,6 +108,11 @@ module PgEventstore
|
|
|
97
108
|
:change_state, :after,
|
|
98
109
|
SubscriptionRunnerHandlers.setup_handler(:update_subscription_state, @subscription)
|
|
99
110
|
)
|
|
111
|
+
# Prevent dangling position evaluation runner when subscription changes the state to something except 'running'
|
|
112
|
+
@events_processor.define_callback(
|
|
113
|
+
:change_state, :after,
|
|
114
|
+
SubscriptionRunnerHandlers.setup_handler(:stop_position_evaluation, @position_evaluation)
|
|
115
|
+
)
|
|
100
116
|
end
|
|
101
117
|
end
|
|
102
118
|
end
|
|
@@ -12,7 +12,7 @@ module PgEventstore
|
|
|
12
12
|
# @param runners [Array<PgEventstore::SubscriptionRunner>]
|
|
13
13
|
# @return [void]
|
|
14
14
|
def feed(runners)
|
|
15
|
-
runners = runners.select(&:running?).select(&:time_to_feed?)
|
|
15
|
+
runners = runners.select(&:running?).select(&:time_to_feed?).select(&:next_chunk_safe?)
|
|
16
16
|
return if runners.empty?
|
|
17
17
|
|
|
18
18
|
runners_query_options = runners.to_h { |runner| [runner.id, runner.next_chunk_query_opts] }
|
|
@@ -6,9 +6,11 @@ require_relative 'basic_runner'
|
|
|
6
6
|
require_relative 'runner_recovery_strategy'
|
|
7
7
|
require_relative 'runner_recovery_strategies'
|
|
8
8
|
require_relative 'subscription'
|
|
9
|
+
require_relative 'synchronized_array'
|
|
9
10
|
require_relative 'events_processor'
|
|
10
11
|
require_relative 'subscription_handler_performance'
|
|
11
12
|
require_relative 'subscription_runner'
|
|
13
|
+
require_relative 'subscription_position_evaluation'
|
|
12
14
|
require_relative 'subscriptions_set'
|
|
13
15
|
require_relative 'subscription_runners_feeder'
|
|
14
16
|
require_relative 'subscriptions_set_lifecycle'
|
|
@@ -26,6 +28,7 @@ require_relative 'queries/subscription_command_queries'
|
|
|
26
28
|
require_relative 'queries/subscription_queries'
|
|
27
29
|
require_relative 'queries/subscriptions_set_command_queries'
|
|
28
30
|
require_relative 'queries/subscriptions_set_queries'
|
|
31
|
+
require_relative 'queries/service_queries'
|
|
29
32
|
require_relative 'commands_handler'
|
|
30
33
|
|
|
31
34
|
module PgEventstore
|
|
@@ -108,7 +111,11 @@ module PgEventstore
|
|
|
108
111
|
graceful_shutdown_timeout: graceful_shutdown_timeout,
|
|
109
112
|
recovery_strategies: recovery_strategies(subscription, restart_terminator, failed_subscription_notifier)
|
|
110
113
|
),
|
|
111
|
-
subscription: subscription
|
|
114
|
+
subscription: subscription,
|
|
115
|
+
position_evaluation: SubscriptionPositionEvaluation.new(
|
|
116
|
+
config_name: config.name,
|
|
117
|
+
filter_options: options[:filter] || {}
|
|
118
|
+
)
|
|
112
119
|
)
|
|
113
120
|
|
|
114
121
|
@subscriptions_lifecycle.runners.push(runner)
|
|
@@ -185,5 +192,10 @@ module PgEventstore
|
|
|
185
192
|
),
|
|
186
193
|
]
|
|
187
194
|
end
|
|
195
|
+
|
|
196
|
+
# @return [PgEventstore::Connection]
|
|
197
|
+
def connection
|
|
198
|
+
PgEventstore.connection(config_name)
|
|
199
|
+
end
|
|
188
200
|
end
|
|
189
201
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'monitor'
|
|
4
|
+
|
|
5
|
+
module PgEventstore
|
|
6
|
+
# @!visibility private
|
|
7
|
+
class SynchronizedArray < Array
|
|
8
|
+
include MonitorMixin
|
|
9
|
+
|
|
10
|
+
alias old_shift shift
|
|
11
|
+
alias old_unshift unshift
|
|
12
|
+
alias old_push push
|
|
13
|
+
alias old_clear clear
|
|
14
|
+
alias old_size size
|
|
15
|
+
alias old_empty? empty?
|
|
16
|
+
|
|
17
|
+
def shift(...)
|
|
18
|
+
synchronize { old_shift(...) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def unshift(...)
|
|
22
|
+
synchronize { old_unshift(...) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def push(...)
|
|
26
|
+
synchronize { old_push(...) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def clear(...)
|
|
30
|
+
synchronize { old_clear(...) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def size(...)
|
|
34
|
+
synchronize { old_size(...) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def empty?(...)
|
|
38
|
+
synchronize { old_empty?(...) }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -58,7 +58,7 @@ module PgEventstore
|
|
|
58
58
|
options.merge(from_position: from_position, max_count: per_page, direction: order == :asc ? :desc : :asc)
|
|
59
59
|
).to_sql_builder.unselect.select('global_position').offset(1)
|
|
60
60
|
sql, params = sql_builder.to_exec_params
|
|
61
|
-
sql = "SELECT * FROM (#{sql})
|
|
61
|
+
sql = "SELECT * FROM (#{sql}) #{Event::PRIMARY_TABLE_NAME} ORDER BY global_position #{order} LIMIT 1"
|
|
62
62
|
connection.with do |conn|
|
|
63
63
|
conn.exec_params(sql, params)
|
|
64
64
|
end.to_a.dig(0, 'global_position')
|
|
@@ -11,7 +11,7 @@ module PgEventstore
|
|
|
11
11
|
def collection
|
|
12
12
|
@collection ||=
|
|
13
13
|
begin
|
|
14
|
-
sql_builder = SQLBuilder.new.select('stream_id').from(
|
|
14
|
+
sql_builder = SQLBuilder.new.select('stream_id').from(Event::PRIMARY_TABLE_NAME)
|
|
15
15
|
sql_builder.where('context = ? and stream_name = ?', options[:context], options[:stream_name])
|
|
16
16
|
sql_builder.where('stream_id like ?', "#{options[:query]}%")
|
|
17
17
|
sql_builder.where("stream_id #{direction_operator} ?", starting_id) if starting_id
|
|
@@ -27,7 +27,7 @@ module PgEventstore
|
|
|
27
27
|
return unless collection.size == per_page
|
|
28
28
|
|
|
29
29
|
starting_id = collection.first['stream_id']
|
|
30
|
-
sql_builder = SQLBuilder.new.select('stream_id').from(
|
|
30
|
+
sql_builder = SQLBuilder.new.select('stream_id').from(Event::PRIMARY_TABLE_NAME)
|
|
31
31
|
sql_builder.where("stream_id #{direction_operator} ?", starting_id)
|
|
32
32
|
sql_builder.where('stream_id like ?', "#{options[:query]}%")
|
|
33
33
|
sql_builder.where('context = ? and stream_name = ?', options[:context], options[:stream_name])
|
data/rbs_collection.lock.yaml
CHANGED
|
@@ -6,9 +6,17 @@ gems:
|
|
|
6
6
|
source:
|
|
7
7
|
type: git
|
|
8
8
|
name: ruby/gem_rbs_collection
|
|
9
|
-
revision:
|
|
9
|
+
revision: 0cb6351d218704700cf4df797ff8966b3a418fcd
|
|
10
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
11
11
|
repo_dir: gems
|
|
12
|
+
- name: forwardable
|
|
13
|
+
version: '0'
|
|
14
|
+
source:
|
|
15
|
+
type: stdlib
|
|
16
|
+
- name: monitor
|
|
17
|
+
version: '0'
|
|
18
|
+
source:
|
|
19
|
+
type: stdlib
|
|
12
20
|
- name: timeout
|
|
13
21
|
version: '0'
|
|
14
22
|
source:
|
data/rbs_collection.yaml
CHANGED
data/sig/manifest.yaml
ADDED
data/sig/pg_eventstore/event.rbs
CHANGED
|
@@ -39,7 +39,8 @@ module PgEventstore
|
|
|
39
39
|
# _@return_ — partition attributes
|
|
40
40
|
def context_partition: (PgEventstore::Stream stream) -> ::Hash[untyped, untyped]?
|
|
41
41
|
|
|
42
|
-
def partitions: (Array[Hash[Symbol, String | nil]] stream_filters, Array[String] event_filters
|
|
42
|
+
def partitions: (Array[Hash[Symbol, String | nil]] stream_filters, Array[String] event_filters,
|
|
43
|
+
?scope: Symbol) -> Array[Partition]
|
|
43
44
|
|
|
44
45
|
# _@param_ `stream`
|
|
45
46
|
#
|
|
@@ -76,5 +77,8 @@ module PgEventstore
|
|
|
76
77
|
private
|
|
77
78
|
|
|
78
79
|
def deserialize: (Hash[untyped, untyped] attrs)-> Partition
|
|
80
|
+
|
|
81
|
+
def set_partitions_scope: (QueryBuilders::PartitionsFiltering partitions_filter, Array[untyped] stream_filters,
|
|
82
|
+
Array[untyped] event_filters, Symbol scope) -> SQLBuilder
|
|
79
83
|
end
|
|
80
84
|
end
|
|
@@ -7,15 +7,19 @@ module PgEventstore
|
|
|
7
7
|
|
|
8
8
|
def self.extract_streams_filter: (Hash[untyped, untyped] options) -> Array[Hash[untyped, untyped]]
|
|
9
9
|
|
|
10
|
-
def
|
|
10
|
+
def self.correct_stream_filter?: (::Hash[untyped, untyped] stream_attrs) -> bool
|
|
11
11
|
|
|
12
|
-
def
|
|
12
|
+
def add_event_types: (::Array[String] event_types) -> SQLBuilder
|
|
13
13
|
|
|
14
|
-
def
|
|
14
|
+
def add_stream_attrs: (?context: String?, ?stream_name: String?) -> SQLBuilder
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
def with_event_types: -> SQLBuilder
|
|
17
17
|
|
|
18
|
-
def
|
|
18
|
+
def with_stream_names: -> SQLBuilder
|
|
19
|
+
|
|
20
|
+
def without_event_types: -> SQLBuilder
|
|
21
|
+
|
|
22
|
+
def without_stream_names: -> SQLBuilder
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
end
|
|
@@ -2,6 +2,8 @@ module PgEventstore
|
|
|
2
2
|
class SQLBuilder
|
|
3
3
|
def initialize: () -> void
|
|
4
4
|
|
|
5
|
+
def from_sql: -> String
|
|
6
|
+
|
|
5
7
|
# _@param_ `sql`
|
|
6
8
|
def select: (String sql) -> self
|
|
7
9
|
|
|
@@ -18,7 +20,7 @@ module PgEventstore
|
|
|
18
20
|
def where_or: (String sql, *Object arguments) -> self
|
|
19
21
|
|
|
20
22
|
# _@param_ `table_name`
|
|
21
|
-
def from: (String table_name) -> self
|
|
23
|
+
def from: (String | SQLBuilder table_name) -> self
|
|
22
24
|
|
|
23
25
|
# _@param_ `sql`
|
|
24
26
|
#
|
|
@@ -53,7 +55,7 @@ module PgEventstore
|
|
|
53
55
|
# _@param_ `val`
|
|
54
56
|
def positional_values_size=: (Integer val) -> Integer
|
|
55
57
|
|
|
56
|
-
def _to_exec_params: () ->
|
|
58
|
+
def _to_exec_params: () -> [String, ::Array[untyped]]
|
|
57
59
|
|
|
58
60
|
def single_query_sql: () -> String
|
|
59
61
|
|
|
@@ -70,5 +72,9 @@ module PgEventstore
|
|
|
70
72
|
|
|
71
73
|
# _@param_ `sql`
|
|
72
74
|
def extract_positional_args: (String sql, *untyped arguments) -> String
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def merge: (SQLBuilder builder)-> String
|
|
73
79
|
end
|
|
74
80
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module PgEventstore
|
|
2
2
|
class EventsProcessorHandlers
|
|
3
|
-
def self.process_event: (PgEventstore::Callbacks callbacks, _RawEventHandler handler,
|
|
3
|
+
def self.process_event: (PgEventstore::Callbacks callbacks, _RawEventHandler handler, SynchronizedArray raw_events,
|
|
4
|
+
MonitorMixin::ConditionVariable raw_events_cond) -> void
|
|
4
5
|
|
|
5
6
|
def self.after_runner_died: (PgEventstore::Callbacks callbacks, StandardError error) -> void
|
|
6
7
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
module PgEventstore
|
|
2
2
|
class SubscriptionRunnerHandlers
|
|
3
|
+
def self.stop_position_evaluation: (SubscriptionPositionEvaluation subscription_position_evaluation,
|
|
4
|
+
String state) -> void
|
|
5
|
+
|
|
3
6
|
def self.track_exec_time: (PgEventstore::SubscriptionHandlerPerformance stats, ^() -> void, Integer _current_position) -> void
|
|
4
7
|
|
|
5
8
|
def self.update_subscription_stats: (PgEventstore::Subscription subscription, PgEventstore::SubscriptionHandlerPerformance stats, Integer current_position) -> void
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module PgEventstore
|
|
2
|
+
class ServiceQueries
|
|
3
|
+
@connection: Connection
|
|
4
|
+
|
|
5
|
+
def initialize: (Connection connection) -> void
|
|
6
|
+
|
|
7
|
+
def max_global_position: (Array[String] table_names) -> Integer
|
|
8
|
+
|
|
9
|
+
def relation_ids_by_names: (Array[String] table_names) -> Hash[String, Integer]
|
|
10
|
+
|
|
11
|
+
def relation_transaction_ids: (Array[Integer] relation_oids) -> Array[String]
|
|
12
|
+
|
|
13
|
+
def transactions_in_progress?: (relation_ids: Array[Integer], transaction_ids: Array[String]) -> bool
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module PgEventstore
|
|
2
|
+
class SubscriptionPositionEvaluation
|
|
3
|
+
TRANSACTIONS_STATUS_REFRESH_INTERVAL: Float
|
|
4
|
+
|
|
5
|
+
@config_name: Symbol
|
|
6
|
+
@event_type_filters: Array[String]
|
|
7
|
+
@last_safe_position: Integer?
|
|
8
|
+
@mutex: Mutex
|
|
9
|
+
@position_is_safe: bool?
|
|
10
|
+
@position_to_evaluate: Integer?
|
|
11
|
+
@relation_ids_cache: Hash[String, Integer]
|
|
12
|
+
@runner: Thread?
|
|
13
|
+
@stream_filters: Array[Hash[untyped, untyped]]
|
|
14
|
+
|
|
15
|
+
def initialize: (config_name: Symbol, filter_options: Hash[untyped, untyped]) -> void
|
|
16
|
+
|
|
17
|
+
def evaluate: (Integer position_to_evaluate) -> self
|
|
18
|
+
|
|
19
|
+
def last_safe_position: -> Integer?
|
|
20
|
+
|
|
21
|
+
def safe?: -> bool
|
|
22
|
+
|
|
23
|
+
def stop_evaluation: -> void
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def _stop_evaluation: (Thread? runner)-> void
|
|
28
|
+
|
|
29
|
+
def affected_tables: -> Array[String]
|
|
30
|
+
|
|
31
|
+
def calculate_safe_position: -> void
|
|
32
|
+
|
|
33
|
+
def connection: -> Connection
|
|
34
|
+
|
|
35
|
+
def last_safe_position=: (Integer? val) -> Integer?
|
|
36
|
+
|
|
37
|
+
def partition_queries: -> PartitionQueries
|
|
38
|
+
|
|
39
|
+
def position_is_safe: -> bool?
|
|
40
|
+
|
|
41
|
+
def position_is_safe=: (bool? val) -> bool?
|
|
42
|
+
|
|
43
|
+
def position_to_evaluate: -> Integer?
|
|
44
|
+
|
|
45
|
+
def position_to_evaluate=: (Integer? val) -> Integer?
|
|
46
|
+
|
|
47
|
+
def service_queries: -> ServiceQueries
|
|
48
|
+
|
|
49
|
+
def transaction_queries: -> TransactionQueries
|
|
50
|
+
|
|
51
|
+
def update_relation_ids_cache: (Array[String] tables_to_track) -> void
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -12,12 +12,13 @@ module PgEventstore
|
|
|
12
12
|
stats: SubscriptionHandlerPerformance,
|
|
13
13
|
events_processor: EventsProcessor,
|
|
14
14
|
subscription: Subscription,
|
|
15
|
-
|
|
16
|
-
?failed_subscription_notifier: _FailedSubscriptionNotifier?
|
|
15
|
+
position_evaluation: SubscriptionPositionEvaluation,
|
|
17
16
|
) -> void
|
|
18
17
|
|
|
19
18
|
def next_chunk_query_opts: () -> ::Hash[untyped, untyped]
|
|
20
19
|
|
|
20
|
+
def next_chunk_safe?: -> bool
|
|
21
|
+
|
|
21
22
|
def time_to_feed?: () -> bool
|
|
22
23
|
|
|
23
24
|
def next_chunk_global_position: () -> Integer
|