Class: OllamaAgent::Runtime::CompensationEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/runtime/compensation_engine.rb

Overview

Replays recorded compensations (blob restore or unlink) for a manifest_id.

Instance Method Summary collapse

Constructor Details

#initialize(blob_store:, compensation_manifest:, atomic_mutator:, fencing_allocator:) ⇒ CompensationEngine

Returns a new instance of CompensationEngine.



9
10
11
12
13
14
# File 'lib/ollama_agent/runtime/compensation_engine.rb', line 9

def initialize(blob_store:, compensation_manifest:, atomic_mutator:, fencing_allocator:)
  @blob_store = blob_store
  @compensation_manifest = compensation_manifest
  @atomic_mutator = atomic_mutator
  @fencing_allocator = fencing_allocator
end

Instance Method Details

#compensate(manifest_id:, logical_stamp:) ⇒ Hash

Returns :restored, :missing, :errors (Array of error hashes).

Returns:

  • (Hash)

    :restored, :missing, :errors (Array of error hashes)

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
# File 'lib/ollama_agent/runtime/compensation_engine.rb', line 17

def compensate(manifest_id:, logical_stamp:)
  raise ArgumentError, "kernel wiring incomplete" unless coordinator_wired?

  tallies = { restored: 0, missing: 0 }
  errors = []
  @compensation_manifest.each_unapplied(manifest_id: manifest_id) do |row|
    apply_one(row, tallies, errors, logical_stamp)
  end
  { restored: tallies[:restored], missing: tallies[:missing], errors: errors }
end