cdc-core 0.1.2 → 0.1.3
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 +14 -0
- data/README.md +12 -4
- data/lib/cdc/core/change_event.rb +10 -5
- data/lib/cdc/core/column_change.rb +4 -4
- data/lib/cdc/core/composite_processor.rb +3 -3
- data/lib/cdc/core/event_metadata.rb +14 -9
- data/lib/cdc/core/event_position.rb +1 -1
- data/lib/cdc/core/filter.rb +8 -8
- data/lib/cdc/core/observer.rb +24 -19
- data/lib/cdc/core/ordering_key.rb +8 -3
- data/lib/cdc/core/ordering_policy.rb +12 -9
- data/lib/cdc/core/pipeline.rb +5 -5
- data/lib/cdc/core/processor.rb +7 -7
- data/lib/cdc/core/processor_chain.rb +1 -1
- data/lib/cdc/core/processor_result.rb +18 -14
- data/lib/cdc/core/router.rb +6 -6
- data/lib/cdc/core/source_adapter.rb +2 -2
- data/lib/cdc/core/transaction_envelope.rb +9 -4
- data/lib/cdc/core/version.rb +1 -1
- data/sig/cdc/core/change_event.rbs +34 -216
- data/sig/cdc/core/column_change.rbs +4 -43
- data/sig/cdc/core/composite_processor.rbs +11 -54
- data/sig/cdc/core/errors.rbs +1 -7
- data/sig/cdc/core/event_metadata.rbs +7 -39
- data/sig/cdc/core/event_position.rbs +12 -12
- data/sig/cdc/core/filter.rbs +11 -62
- data/sig/cdc/core/null_observer.rbs +1 -2
- data/sig/cdc/core/observer.rbs +11 -13
- data/sig/cdc/core/operation.rbs +7 -29
- data/sig/cdc/core/ordering_key.rbs +5 -7
- data/sig/cdc/core/ordering_policy.rbs +10 -15
- data/sig/cdc/core/ordering_scope.rbs +7 -5
- data/sig/cdc/core/pipeline.rbs +9 -54
- data/sig/cdc/core/processor.rbs +5 -56
- data/sig/cdc/core/processor_chain.rbs +8 -35
- data/sig/cdc/core/processor_result.rbs +32 -125
- data/sig/cdc/core/router.rbs +12 -13
- data/sig/cdc/core/source_adapter.rbs +2 -4
- data/sig/cdc/core/transaction_envelope.rbs +17 -71
- data/sig/cdc/core/version.rbs +1 -2
- data/sig/cdc/core.rbs +28 -7
- data/sig/cdc_core.rbs +4 -0
- metadata +2 -2
|
@@ -10,6 +10,10 @@ module CDC
|
|
|
10
10
|
class ProcessorResult
|
|
11
11
|
# Allowed result statuses.
|
|
12
12
|
VALID_STATUSES = Ractor.make_shareable(%i[success failure skipped].freeze)
|
|
13
|
+
EMPTY_METADATA = Ractor.make_shareable(
|
|
14
|
+
{} # : Hash[untyped, untyped]
|
|
15
|
+
.freeze
|
|
16
|
+
)
|
|
13
17
|
|
|
14
18
|
# @return [Symbol] result status
|
|
15
19
|
# @return [ChangeEvent, Object, nil] event or input associated with the result
|
|
@@ -23,8 +27,8 @@ module CDC
|
|
|
23
27
|
# @param event [ChangeEvent, nil] processed event
|
|
24
28
|
# @param metadata [Hash, EventMetadata] result metadata
|
|
25
29
|
# @param value [Object, nil] value produced by the processor; defaults to event for compatibility
|
|
26
|
-
# @return [ProcessorResult]
|
|
27
|
-
def self.success(event = nil, metadata:
|
|
30
|
+
# @return [ProcessorResult] successful processor result
|
|
31
|
+
def self.success(event = nil, metadata: EMPTY_METADATA, value: event) = new(:success, event:, metadata:, value:)
|
|
28
32
|
|
|
29
33
|
# Build a failure result.
|
|
30
34
|
#
|
|
@@ -35,7 +39,7 @@ module CDC
|
|
|
35
39
|
# @param processor [String, nil] processor name associated with the failure
|
|
36
40
|
# @param failed_at [String, nil] timestamp for when the failure occurred
|
|
37
41
|
# @param metadata [Hash, EventMetadata] result metadata
|
|
38
|
-
# @return [ProcessorResult]
|
|
42
|
+
# @return [ProcessorResult] failed processor result
|
|
39
43
|
def self.failure(error, event: nil, reason: nil, retryable: nil, processor: nil, failed_at: nil,
|
|
40
44
|
metadata: nil)
|
|
41
45
|
base_metadata = metadata.nil? ? EventMetadata.new.to_h : metadata.to_h
|
|
@@ -53,8 +57,8 @@ module CDC
|
|
|
53
57
|
#
|
|
54
58
|
# @param event [ChangeEvent, nil] skipped event
|
|
55
59
|
# @param metadata [Hash, EventMetadata] result metadata
|
|
56
|
-
# @return [ProcessorResult]
|
|
57
|
-
def self.skipped(event = nil, metadata:
|
|
60
|
+
# @return [ProcessorResult] skipped processor result
|
|
61
|
+
def self.skipped(event = nil, metadata: EMPTY_METADATA) = new(:skipped, event:, metadata:)
|
|
58
62
|
|
|
59
63
|
# Build a processor result with an explicit status.
|
|
60
64
|
#
|
|
@@ -63,7 +67,7 @@ module CDC
|
|
|
63
67
|
# @param error [Exception, nil] associated failure
|
|
64
68
|
# @param metadata [Hash, EventMetadata] result metadata
|
|
65
69
|
# @param value [Object, nil] value produced by the processor
|
|
66
|
-
def initialize(status, event: nil, error: nil, metadata:
|
|
70
|
+
def initialize(status, event: nil, error: nil, metadata: EMPTY_METADATA, value: event)
|
|
67
71
|
@status = normalize_status(status)
|
|
68
72
|
@event = event
|
|
69
73
|
@value = value
|
|
@@ -83,56 +87,56 @@ module CDC
|
|
|
83
87
|
|
|
84
88
|
# Human-readable failure reason, when present.
|
|
85
89
|
#
|
|
86
|
-
# @return [String, nil]
|
|
90
|
+
# @return [String, nil] human-readable failure reason
|
|
87
91
|
def failure_reason
|
|
88
92
|
metadata[:reason]
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
# Whether the failure is retryable.
|
|
92
96
|
#
|
|
93
|
-
# @return [Boolean]
|
|
97
|
+
# @return [Boolean] true when metadata marks the failure retryable
|
|
94
98
|
def retryable?
|
|
95
99
|
metadata[:retryable] == true
|
|
96
100
|
end
|
|
97
101
|
|
|
98
102
|
# Name of the processor associated with the failure, when present.
|
|
99
103
|
#
|
|
100
|
-
# @return [String, nil]
|
|
104
|
+
# @return [String, nil] processor name associated with the failure
|
|
101
105
|
def processor_name
|
|
102
106
|
metadata[:processor]
|
|
103
107
|
end
|
|
104
108
|
|
|
105
109
|
# Timestamp for when the failure occurred, when present.
|
|
106
110
|
#
|
|
107
|
-
# @return [String, nil]
|
|
111
|
+
# @return [String, nil] timestamp for when the failure occurred
|
|
108
112
|
def failed_at
|
|
109
113
|
metadata[:failed_at]
|
|
110
114
|
end
|
|
111
115
|
|
|
112
116
|
# Error class name, when present.
|
|
113
117
|
#
|
|
114
|
-
# @return [String, nil]
|
|
118
|
+
# @return [String, nil] class name of the associated error
|
|
115
119
|
def error_class
|
|
116
120
|
error&.class&.name
|
|
117
121
|
end
|
|
118
122
|
|
|
119
123
|
# Error message, when present.
|
|
120
124
|
#
|
|
121
|
-
# @return [String, nil]
|
|
125
|
+
# @return [String, nil] message from the associated error
|
|
122
126
|
def error_message
|
|
123
127
|
error&.message
|
|
124
128
|
end
|
|
125
129
|
|
|
126
130
|
# Error backtrace, when present.
|
|
127
131
|
#
|
|
128
|
-
# @return [Array<String>]
|
|
132
|
+
# @return [Array<String>] backtrace from the associated error
|
|
129
133
|
def error_backtrace
|
|
130
134
|
Array(error&.backtrace)
|
|
131
135
|
end
|
|
132
136
|
|
|
133
137
|
# Convert the result into a shareable hash.
|
|
134
138
|
#
|
|
135
|
-
# @return [Hash{String=>Object,nil}]
|
|
139
|
+
# @return [Hash{String=>Object,nil}] Ractor-shareable result representation
|
|
136
140
|
def to_h
|
|
137
141
|
payload = {
|
|
138
142
|
'status' => status,
|
data/lib/cdc/core/router.rb
CHANGED
|
@@ -26,8 +26,8 @@ module CDC
|
|
|
26
26
|
|
|
27
27
|
# Process a CDC work item.
|
|
28
28
|
#
|
|
29
|
-
# @param item [ChangeEvent, TransactionEnvelope, Array<ChangeEvent>]
|
|
30
|
-
# @return [Object]
|
|
29
|
+
# @param item [ChangeEvent, TransactionEnvelope, Array<ChangeEvent>] work item to route
|
|
30
|
+
# @return [Object] value returned by the selected handler
|
|
31
31
|
# @raise [UnsupportedWorkItemError] when the item cannot be routed
|
|
32
32
|
def process(item)
|
|
33
33
|
observer.dispatch_started(item)
|
|
@@ -49,8 +49,8 @@ module CDC
|
|
|
49
49
|
|
|
50
50
|
# Route a transaction envelope to the configured transaction processor.
|
|
51
51
|
#
|
|
52
|
-
# @param transaction [TransactionEnvelope]
|
|
53
|
-
# @return [Object]
|
|
52
|
+
# @param transaction [TransactionEnvelope] transaction envelope to route
|
|
53
|
+
# @return [Object] value returned by the transaction processor
|
|
54
54
|
def route_transaction(transaction)
|
|
55
55
|
return transaction_processor.process(transaction) if transaction_processor
|
|
56
56
|
|
|
@@ -60,8 +60,8 @@ module CDC
|
|
|
60
60
|
|
|
61
61
|
# Route many change events through the configured processor.
|
|
62
62
|
#
|
|
63
|
-
# @param items [Array]
|
|
64
|
-
# @return [Object]
|
|
63
|
+
# @param items [Array] change events to route as a batch
|
|
64
|
+
# @return [Object] batch processor result or array of per-event results
|
|
65
65
|
def route_many(items)
|
|
66
66
|
unless items.all?(ChangeEvent)
|
|
67
67
|
raise UnsupportedWorkItemError, "unsupported CDC work item: Array(#{items.first.class})"
|
|
@@ -19,7 +19,7 @@ module CDC
|
|
|
19
19
|
# Subclasses must override this method.
|
|
20
20
|
#
|
|
21
21
|
# @param _input [Object] source-specific payload
|
|
22
|
-
# @return [ChangeEvent,
|
|
22
|
+
# @return [ChangeEvent,TransactionEnvelope, Array<ChangeEvent>, Array<TransactionEnvelope>] normalized core object or objects # rubocop:disable Layout/LineLength
|
|
23
23
|
# @raise [NotImplementedError] when not implemented by a subclass
|
|
24
24
|
def normalize(_input)
|
|
25
25
|
raise NotImplementedError, "#{self.class} must implement #normalize"
|
|
@@ -32,7 +32,7 @@ module CDC
|
|
|
32
32
|
# objects for each payload.
|
|
33
33
|
#
|
|
34
34
|
# @param inputs [Enumerable] source-specific payloads
|
|
35
|
-
# @return [Array]
|
|
35
|
+
# @return [Array] flattened normalized core objects
|
|
36
36
|
def normalize_many(inputs)
|
|
37
37
|
Array(inputs).flat_map { |input| normalize(input) }.freeze
|
|
38
38
|
end
|
|
@@ -8,6 +8,11 @@ module CDC
|
|
|
8
8
|
# boundaries instead of isolated row-level events. The contained events and
|
|
9
9
|
# metadata are Ractor-shareable when construction succeeds.
|
|
10
10
|
class TransactionEnvelope
|
|
11
|
+
EMPTY_METADATA = Ractor.make_shareable(
|
|
12
|
+
{} # : Hash[untyped, untyped]
|
|
13
|
+
.freeze
|
|
14
|
+
)
|
|
15
|
+
|
|
11
16
|
# @return [Object] transaction identifier
|
|
12
17
|
# @return [Array<ChangeEvent>] events committed by the transaction
|
|
13
18
|
# @return [String, nil] commit log sequence number
|
|
@@ -22,7 +27,7 @@ module CDC
|
|
|
22
27
|
# @param commit_lsn [#to_s, nil] commit log sequence number
|
|
23
28
|
# @param committed_at [Time, nil] commit timestamp
|
|
24
29
|
# @param metadata [Hash, EventMetadata] transaction metadata
|
|
25
|
-
def initialize(transaction_id:, events:, commit_lsn: nil, committed_at: nil, metadata:
|
|
30
|
+
def initialize(transaction_id:, events:, commit_lsn: nil, committed_at: nil, metadata: EMPTY_METADATA)
|
|
26
31
|
@transaction_id = transaction_id
|
|
27
32
|
@events = Ractor.make_shareable(events.freeze)
|
|
28
33
|
@commit_lsn = commit_lsn&.to_s&.freeze
|
|
@@ -33,17 +38,17 @@ module CDC
|
|
|
33
38
|
|
|
34
39
|
# Whether the envelope has no events.
|
|
35
40
|
#
|
|
36
|
-
# @return [Boolean]
|
|
41
|
+
# @return [Boolean] true when the envelope has no events
|
|
37
42
|
def empty? = events.empty?
|
|
38
43
|
|
|
39
44
|
# Number of events in the envelope.
|
|
40
45
|
#
|
|
41
|
-
# @return [Integer]
|
|
46
|
+
# @return [Integer] number of events in the envelope
|
|
42
47
|
def size = events.size
|
|
43
48
|
|
|
44
49
|
# Convert the transaction envelope into a Ractor-shareable hash.
|
|
45
50
|
#
|
|
46
|
-
# @return [Hash{String=>Object,nil}]
|
|
51
|
+
# @return [Hash{String=>Object,nil}] Ractor-shareable transaction representation
|
|
47
52
|
def to_h
|
|
48
53
|
Ractor.make_shareable({
|
|
49
54
|
'transaction_id' => transaction_id,
|
data/lib/cdc/core/version.rb
CHANGED
|
@@ -1,226 +1,44 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
# Immutable representation of one logical database change.
|
|
4
|
-
#
|
|
5
|
-
# ChangeEvent is the core data structure passed through filters, pipelines,
|
|
6
|
-
# and processors. It is database-agnostic but carries common CDC fields such
|
|
7
|
-
# as operation, schema, table, before/after values, primary key, LSN, and
|
|
8
|
-
# metadata.
|
|
9
3
|
class ChangeEvent
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@new_values: untyped
|
|
19
|
-
|
|
20
|
-
@primary_key: untyped
|
|
21
|
-
|
|
22
|
-
@transaction_id: untyped
|
|
23
|
-
|
|
24
|
-
@commit_lsn: untyped
|
|
25
|
-
|
|
26
|
-
@sequence_number: untyped
|
|
27
|
-
|
|
28
|
-
@occurred_at: untyped
|
|
29
|
-
|
|
30
|
-
@metadata: untyped
|
|
31
|
-
|
|
32
|
-
# @return [Symbol] normalized CDC operation
|
|
33
|
-
# @return [String] database schema name
|
|
34
|
-
# @return [String] database table name
|
|
35
|
-
# @return [Hash, nil] values before the change
|
|
36
|
-
# @return [Hash, nil] values after the change
|
|
37
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
38
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
39
|
-
# @return [String, nil] commit log sequence number
|
|
40
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
41
|
-
# @return [Time, nil] timestamp associated with the event
|
|
42
|
-
# @return [EventMetadata] additional normalized metadata
|
|
43
|
-
attr_reader operation: untyped
|
|
44
|
-
|
|
45
|
-
# @return [Symbol] normalized CDC operation
|
|
46
|
-
# @return [String] database schema name
|
|
47
|
-
# @return [String] database table name
|
|
48
|
-
# @return [Hash, nil] values before the change
|
|
49
|
-
# @return [Hash, nil] values after the change
|
|
50
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
51
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
52
|
-
# @return [String, nil] commit log sequence number
|
|
53
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
54
|
-
# @return [Time, nil] timestamp associated with the event
|
|
55
|
-
# @return [EventMetadata] additional normalized metadata
|
|
56
|
-
attr_reader schema: untyped
|
|
57
|
-
|
|
58
|
-
# @return [Symbol] normalized CDC operation
|
|
59
|
-
# @return [String] database schema name
|
|
60
|
-
# @return [String] database table name
|
|
61
|
-
# @return [Hash, nil] values before the change
|
|
62
|
-
# @return [Hash, nil] values after the change
|
|
63
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
64
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
65
|
-
# @return [String, nil] commit log sequence number
|
|
66
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
67
|
-
# @return [Time, nil] timestamp associated with the event
|
|
68
|
-
# @return [EventMetadata] additional normalized metadata
|
|
69
|
-
attr_reader table: untyped
|
|
70
|
-
|
|
71
|
-
# @return [Symbol] normalized CDC operation
|
|
72
|
-
# @return [String] database schema name
|
|
73
|
-
# @return [String] database table name
|
|
74
|
-
# @return [Hash, nil] values before the change
|
|
75
|
-
# @return [Hash, nil] values after the change
|
|
76
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
77
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
78
|
-
# @return [String, nil] commit log sequence number
|
|
79
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
80
|
-
# @return [Time, nil] timestamp associated with the event
|
|
81
|
-
# @return [EventMetadata] additional normalized metadata
|
|
82
|
-
attr_reader old_values: untyped
|
|
83
|
-
|
|
84
|
-
# @return [Symbol] normalized CDC operation
|
|
85
|
-
# @return [String] database schema name
|
|
86
|
-
# @return [String] database table name
|
|
87
|
-
# @return [Hash, nil] values before the change
|
|
88
|
-
# @return [Hash, nil] values after the change
|
|
89
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
90
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
91
|
-
# @return [String, nil] commit log sequence number
|
|
92
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
93
|
-
# @return [Time, nil] timestamp associated with the event
|
|
94
|
-
# @return [EventMetadata] additional normalized metadata
|
|
95
|
-
attr_reader new_values: untyped
|
|
96
|
-
|
|
97
|
-
# @return [Symbol] normalized CDC operation
|
|
98
|
-
# @return [String] database schema name
|
|
99
|
-
# @return [String] database table name
|
|
100
|
-
# @return [Hash, nil] values before the change
|
|
101
|
-
# @return [Hash, nil] values after the change
|
|
102
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
103
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
104
|
-
# @return [String, nil] commit log sequence number
|
|
105
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
106
|
-
# @return [Time, nil] timestamp associated with the event
|
|
107
|
-
# @return [EventMetadata] additional normalized metadata
|
|
108
|
-
attr_reader primary_key: untyped
|
|
109
|
-
|
|
110
|
-
# @return [Symbol] normalized CDC operation
|
|
111
|
-
# @return [String] database schema name
|
|
112
|
-
# @return [String] database table name
|
|
113
|
-
# @return [Hash, nil] values before the change
|
|
114
|
-
# @return [Hash, nil] values after the change
|
|
115
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
116
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
117
|
-
# @return [String, nil] commit log sequence number
|
|
118
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
119
|
-
# @return [Time, nil] timestamp associated with the event
|
|
120
|
-
# @return [EventMetadata] additional normalized metadata
|
|
4
|
+
EMPTY_METADATA: metadata_hash
|
|
5
|
+
|
|
6
|
+
attr_reader operation: Symbol
|
|
7
|
+
attr_reader schema: String
|
|
8
|
+
attr_reader table: String
|
|
9
|
+
attr_reader old_values: event_values?
|
|
10
|
+
attr_reader new_values: event_values?
|
|
11
|
+
attr_reader primary_key: event_values?
|
|
121
12
|
attr_reader transaction_id: untyped
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
attr_reader sequence_number: untyped
|
|
148
|
-
|
|
149
|
-
# @return [Symbol] normalized CDC operation
|
|
150
|
-
# @return [String] database schema name
|
|
151
|
-
# @return [String] database table name
|
|
152
|
-
# @return [Hash, nil] values before the change
|
|
153
|
-
# @return [Hash, nil] values after the change
|
|
154
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
155
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
156
|
-
# @return [String, nil] commit log sequence number
|
|
157
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
158
|
-
# @return [Time, nil] timestamp associated with the event
|
|
159
|
-
# @return [EventMetadata] additional normalized metadata
|
|
160
|
-
attr_reader occurred_at: untyped
|
|
161
|
-
|
|
162
|
-
# @return [Symbol] normalized CDC operation
|
|
163
|
-
# @return [String] database schema name
|
|
164
|
-
# @return [String] database table name
|
|
165
|
-
# @return [Hash, nil] values before the change
|
|
166
|
-
# @return [Hash, nil] values after the change
|
|
167
|
-
# @return [Hash, nil] primary key values for the changed row
|
|
168
|
-
# @return [Object, nil] transaction identifier from the upstream source
|
|
169
|
-
# @return [String, nil] commit log sequence number
|
|
170
|
-
# @return [Integer, nil] event sequence within a transaction or stream
|
|
171
|
-
# @return [Time, nil] timestamp associated with the event
|
|
172
|
-
# @return [EventMetadata] additional normalized metadata
|
|
173
|
-
attr_reader metadata: untyped
|
|
174
|
-
|
|
175
|
-
# Build a change event.
|
|
176
|
-
#
|
|
177
|
-
# @param operation [#to_sym] CDC operation
|
|
178
|
-
# @param schema [#to_s] schema name
|
|
179
|
-
# @param table [#to_s] table name
|
|
180
|
-
# @param old_values [Hash, nil] values before the change
|
|
181
|
-
# @param new_values [Hash, nil] values after the change
|
|
182
|
-
# @param primary_key [Hash, nil] primary key values
|
|
183
|
-
# @param transaction_id [Object, nil] source transaction identifier
|
|
184
|
-
# @param commit_lsn [#to_s, nil] commit log sequence number
|
|
185
|
-
# @param sequence_number [Integer, nil] event sequence number
|
|
186
|
-
# @param occurred_at [Time, nil] event timestamp
|
|
187
|
-
# @param metadata [Hash, EventMetadata] additional event metadata
|
|
188
|
-
def initialize: (operation: untyped, schema: untyped, table: untyped, ?old_values: untyped?, ?new_values: untyped?, ?primary_key: untyped?, ?transaction_id: untyped?, ?commit_lsn: untyped?, ?sequence_number: untyped?, ?occurred_at: untyped?, ?metadata: ::Hash[untyped, untyped]) -> void
|
|
189
|
-
|
|
190
|
-
# @return [Boolean] true for insert events
|
|
191
|
-
def insert?: () -> untyped
|
|
192
|
-
|
|
193
|
-
# @return [Boolean] true for update events
|
|
194
|
-
def update?: () -> untyped
|
|
195
|
-
|
|
196
|
-
# @return [Boolean] true for delete events
|
|
197
|
-
def delete?: () -> untyped
|
|
198
|
-
|
|
199
|
-
# Fully qualified table name in schema.table form.
|
|
200
|
-
#
|
|
201
|
-
# @return [String]
|
|
202
|
-
def qualified_table_name: () -> ::String
|
|
203
|
-
|
|
204
|
-
# Compute changed columns by comparing old and new values.
|
|
205
|
-
#
|
|
206
|
-
# Columns with equal old and new values are omitted. Insert and delete
|
|
207
|
-
# events can pass nil for one side; missing values are represented as nil.
|
|
208
|
-
#
|
|
209
|
-
# @return [Array<ColumnChange>] Ractor-shareable changed columns
|
|
210
|
-
def changes: () -> untyped
|
|
211
|
-
|
|
212
|
-
# Convert the event into a Ractor-shareable hash.
|
|
213
|
-
#
|
|
214
|
-
# @return [Hash{String=>Object,nil}]
|
|
215
|
-
def to_h: () -> untyped
|
|
13
|
+
attr_reader commit_lsn: String?
|
|
14
|
+
attr_reader sequence_number: Integer?
|
|
15
|
+
attr_reader occurred_at: ::Time?
|
|
16
|
+
attr_reader metadata: EventMetadata
|
|
17
|
+
|
|
18
|
+
def initialize: (
|
|
19
|
+
operation: Symbol | String,
|
|
20
|
+
schema: String | Symbol,
|
|
21
|
+
table: String | Symbol,
|
|
22
|
+
?old_values: metadata_hash?,
|
|
23
|
+
?new_values: metadata_hash?,
|
|
24
|
+
?primary_key: metadata_hash?,
|
|
25
|
+
?transaction_id: untyped,
|
|
26
|
+
?commit_lsn: String?,
|
|
27
|
+
?sequence_number: Integer?,
|
|
28
|
+
?occurred_at: ::Time?,
|
|
29
|
+
?metadata: EventMetadata | metadata_hash
|
|
30
|
+
) -> void
|
|
31
|
+
|
|
32
|
+
def insert?: () -> bool
|
|
33
|
+
def update?: () -> bool
|
|
34
|
+
def delete?: () -> bool
|
|
35
|
+
def qualified_table_name: () -> String
|
|
36
|
+
def changes: () -> ::Array[ColumnChange]
|
|
37
|
+
def to_h: () -> shareable_hash
|
|
216
38
|
|
|
217
39
|
private
|
|
218
40
|
|
|
219
|
-
|
|
220
|
-
#
|
|
221
|
-
# @param hash [Hash, nil]
|
|
222
|
-
# @return [Hash, nil]
|
|
223
|
-
def freeze_hash_or_nil: (untyped hash) -> (nil | untyped)
|
|
41
|
+
def freeze_hash_or_nil: (metadata_hash? hash) -> event_values?
|
|
224
42
|
end
|
|
225
43
|
end
|
|
226
44
|
end
|
|
@@ -1,55 +1,16 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
# Represents a single column-level value change.
|
|
4
|
-
#
|
|
5
|
-
# ColumnChange is immutable and Ractor-shareable. Values that cannot be made
|
|
6
|
-
# shareable by Ruby are represented by their frozen #inspect string so the
|
|
7
|
-
# enclosing event can still cross Ractor boundaries safely.
|
|
8
3
|
class ColumnChange
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@old_value: untyped
|
|
12
|
-
|
|
13
|
-
@new_value: untyped
|
|
14
|
-
|
|
15
|
-
# @return [String] column name
|
|
16
|
-
# @return [Object, nil] value before the change
|
|
17
|
-
# @return [Object, nil] value after the change
|
|
18
|
-
attr_reader name: untyped
|
|
19
|
-
|
|
20
|
-
# @return [String] column name
|
|
21
|
-
# @return [Object, nil] value before the change
|
|
22
|
-
# @return [Object, nil] value after the change
|
|
4
|
+
attr_reader name: String
|
|
23
5
|
attr_reader old_value: untyped
|
|
24
|
-
|
|
25
|
-
# @return [String] column name
|
|
26
|
-
# @return [Object, nil] value before the change
|
|
27
|
-
# @return [Object, nil] value after the change
|
|
28
6
|
attr_reader new_value: untyped
|
|
29
7
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# @param old_value [Object, nil] previous value
|
|
34
|
-
# @param new_value [Object, nil] new value
|
|
35
|
-
def initialize: (name: untyped, old_value: untyped, new_value: untyped) -> void
|
|
36
|
-
|
|
37
|
-
# Whether the old and new values differ.
|
|
38
|
-
#
|
|
39
|
-
# @return [Boolean]
|
|
40
|
-
def changed?: () -> untyped
|
|
41
|
-
|
|
42
|
-
# Convert the change into a Ractor-shareable hash.
|
|
43
|
-
#
|
|
44
|
-
# @return [Hash{String=>Object,nil}]
|
|
45
|
-
def to_h: () -> untyped
|
|
8
|
+
def initialize: (name: String | Symbol, old_value: untyped, new_value: untyped) -> void
|
|
9
|
+
def changed?: () -> bool
|
|
10
|
+
def to_h: () -> shareable_hash
|
|
46
11
|
|
|
47
12
|
private
|
|
48
13
|
|
|
49
|
-
# Convert a value into a Ractor-shareable representation.
|
|
50
|
-
#
|
|
51
|
-
# @param value [Object, nil]
|
|
52
|
-
# @return [Object, String, nil]
|
|
53
14
|
def make_value_shareable: (untyped value) -> untyped
|
|
54
15
|
end
|
|
55
16
|
end
|
|
@@ -1,64 +1,21 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
# Processor that delegates each event to multiple processors.
|
|
4
|
-
#
|
|
5
|
-
# CompositeProcessor enables fan-out processing while preserving a simple
|
|
6
|
-
# sequential execution model. It normalizes truthy/falsey processor returns
|
|
7
|
-
# into ProcessorResult objects and can stop at the first failure.
|
|
8
3
|
class CompositeProcessor < Processor
|
|
9
|
-
|
|
4
|
+
attr_reader processors: ::Array[_ProcessorLike]
|
|
5
|
+
attr_reader fail_fast: bool
|
|
6
|
+
attr_reader observer: Observer
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# @return [Array<Processor>] processors executed for each event
|
|
16
|
-
# @return [Boolean] whether processing stops on the first failure
|
|
17
|
-
attr_reader processors: untyped
|
|
18
|
-
|
|
19
|
-
# @return [Array<Processor>] processors executed for each event
|
|
20
|
-
# @return [Boolean] whether processing stops on the first failure
|
|
21
|
-
attr_reader fail_fast: untyped
|
|
22
|
-
|
|
23
|
-
# @return [Observer] observer notified of dispatch events
|
|
24
|
-
attr_reader observer: untyped
|
|
25
|
-
|
|
26
|
-
# Build a composite processor.
|
|
27
|
-
#
|
|
28
|
-
# @param processors [Array<#process>] processors to execute
|
|
29
|
-
# @param fail_fast [Boolean] whether to stop after the first failure
|
|
30
|
-
# @param observer [Observer, nil] instrumentation observer
|
|
31
|
-
def initialize: (untyped processors, ?fail_fast: bool, ?observer: untyped?) -> void
|
|
32
|
-
|
|
33
|
-
# Process an event through each configured processor.
|
|
34
|
-
#
|
|
35
|
-
# @param event [ChangeEvent] event to process
|
|
36
|
-
# @return [Array<ProcessorResult>] result from each attempted processor
|
|
37
|
-
def process: (untyped event) -> untyped
|
|
38
|
-
|
|
39
|
-
# Processors that declared Ractor safety.
|
|
40
|
-
#
|
|
41
|
-
# @return [Array<Processor>]
|
|
42
|
-
def ractor_safe_processors: () -> untyped
|
|
43
|
-
|
|
44
|
-
# Processors that should remain sequential in the core runtime.
|
|
45
|
-
#
|
|
46
|
-
# @return [Array<Processor>]
|
|
47
|
-
def sequential_processors: () -> untyped
|
|
8
|
+
def initialize: (::Array[_ProcessorLike] processors, ?fail_fast: bool, ?observer: Observer?) -> void
|
|
9
|
+
def process: (untyped event) -> ::Array[ProcessorResult]
|
|
10
|
+
def ractor_safe_processors: () -> ::Array[_ProcessorLike]
|
|
11
|
+
def sequential_processors: () -> ::Array[_ProcessorLike]
|
|
48
12
|
|
|
49
13
|
private
|
|
50
14
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
# @return [ProcessorResult]
|
|
56
|
-
def normalize_result: (untyped result, untyped event) -> untyped
|
|
57
|
-
|
|
58
|
-
def collect_results: (untyped event) -> untyped
|
|
59
|
-
def process_with: (untyped processor, untyped event) -> untyped
|
|
60
|
-
def observe_results: (untyped results) -> untyped
|
|
61
|
-
def freeze_results: (untyped results) -> untyped
|
|
15
|
+
def normalize_result: (untyped result, untyped event) -> ProcessorResult
|
|
16
|
+
def collect_results: (untyped event) -> ::Array[ProcessorResult]
|
|
17
|
+
def process_with: (_ProcessorLike processor, untyped event) -> ProcessorResult
|
|
18
|
+
def observe_results: (::Array[ProcessorResult] results) -> void
|
|
62
19
|
end
|
|
63
20
|
end
|
|
64
21
|
end
|
data/sig/cdc/core/errors.rbs
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
|
|
4
|
-
class Error < StandardError
|
|
3
|
+
class Error < ::StandardError
|
|
5
4
|
end
|
|
6
5
|
|
|
7
|
-
# Raised when an operation cannot be normalized to a supported CDC action.
|
|
8
6
|
class InvalidOperationError < Error
|
|
9
7
|
end
|
|
10
8
|
|
|
11
|
-
# Raised when an ordering scope cannot be normalized to a supported value.
|
|
12
9
|
class InvalidOrderingScopeError < Error
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
# Raised when an ordering position cannot be normalized to a supported value.
|
|
16
12
|
class InvalidOrderingPositionError < Error
|
|
17
13
|
end
|
|
18
14
|
|
|
19
|
-
# Raised when a router receives an unsupported CDC work item.
|
|
20
15
|
class UnsupportedWorkItemError < Error
|
|
21
16
|
end
|
|
22
17
|
|
|
23
|
-
# Raised by processors when a processor-specific failure needs wrapping.
|
|
24
18
|
class ProcessorError < Error
|
|
25
19
|
end
|
|
26
20
|
end
|