Class: CDC::Core::OrderingPolicy
- Inherits:
-
Object
- Object
- CDC::Core::OrderingPolicy
- Defined in:
- lib/cdc/core/ordering_policy.rb
Overview
Immutable description of how ordered CDC work should be grouped.
OrderingPolicy defines the vocabulary for ordering guarantees without performing any scheduling itself. Runtime layers can consume the policy to route events into ordered lanes.
Constant Summary collapse
- SUPPORTED_POSITIONS =
Position strategies supported by the core contract.
Ractor.make_shareable( %i[commit_lsn transaction_id sequence_number occurred_at].freeze )
Instance Attribute Summary collapse
- #position ⇒ Symbol, Boolean readonly
- #scope ⇒ Symbol, Boolean readonly
- #transaction_aware ⇒ Symbol, Boolean readonly
Instance Method Summary collapse
-
#initialize(scope:, position: :commit_lsn, transaction_aware: true) ⇒ OrderingPolicy
constructor
Build an ordering policy.
-
#key_for(event) ⇒ OrderingKey?
Derive an ordering key for an event.
-
#position_for(event) ⇒ EventPosition
Derive an event position for an event.
-
#to_h ⇒ Hash{String=>Object}
Convert the policy into a Ractor-shareable hash.
-
#transaction_aware? ⇒ Boolean
Whether transaction boundaries should be preserved.
Constructor Details
#initialize(scope:, position: :commit_lsn, transaction_aware: true) ⇒ OrderingPolicy
Build an ordering policy.
26 27 28 29 30 31 |
# File 'lib/cdc/core/ordering_policy.rb', line 26 def initialize(scope:, position: :commit_lsn, transaction_aware: true) @scope = OrderingScope.normalize(scope) @position = normalize_position(position) @transaction_aware = transaction_aware == true Ractor.make_shareable(self) end |
Instance Attribute Details
#position ⇒ Symbol, Boolean (readonly)
19 20 21 |
# File 'lib/cdc/core/ordering_policy.rb', line 19 def position @position end |
#scope ⇒ Symbol, Boolean (readonly)
19 20 21 |
# File 'lib/cdc/core/ordering_policy.rb', line 19 def scope @scope end |
#transaction_aware ⇒ Symbol, Boolean (readonly)
19 20 21 |
# File 'lib/cdc/core/ordering_policy.rb', line 19 def transaction_aware @transaction_aware end |
Instance Method Details
#key_for(event) ⇒ OrderingKey?
Derive an ordering key for an event.
42 43 44 45 46 |
# File 'lib/cdc/core/ordering_policy.rb', line 42 def key_for(event) return nil if scope == OrderingScope::NONE OrderingKey.new(scope: scope, components: key_components(event)) end |
#position_for(event) ⇒ EventPosition
Derive an event position for an event.
52 53 54 55 56 57 58 59 60 |
# File 'lib/cdc/core/ordering_policy.rb', line 52 def position_for(event) EventPosition.new( strategy: position, value: event.public_send(position), transaction_id: event.transaction_id, sequence_number: event.sequence_number, occurred_at: event.occurred_at ) end |
#to_h ⇒ Hash{String=>Object}
Convert the policy into a Ractor-shareable hash.
65 66 67 68 69 70 71 |
# File 'lib/cdc/core/ordering_policy.rb', line 65 def to_h Ractor.make_shareable({ 'scope' => scope, 'position' => position, 'transaction_aware' => transaction_aware }.freeze) end |
#transaction_aware? ⇒ Boolean
Whether transaction boundaries should be preserved.
36 |
# File 'lib/cdc/core/ordering_policy.rb', line 36 def transaction_aware? = transaction_aware |