Class: OllamaAgent::Runtime::AtomicMutator
- Inherits:
-
Object
- Object
- OllamaAgent::Runtime::AtomicMutator
- Defined in:
- lib/ollama_agent/runtime/atomic_mutator.rb
Overview
POSIX-oriented atomic write (temp → fsync → rename → parent fsync).
Directory fd fsync after rename is required on Linux for crash-safe metadata durability. When File#fsync on a directory file descriptor is unsupported (Errno::EINVAL, ENOTSUP, or NotImplementedError), the step is skipped (see mutation_step payload dir_fsync_status). rubocop:disable Metrics/ClassLength – single orchestrator; helpers are private below
Instance Method Summary collapse
-
#delete_file(path:, mode:, fencing_token:, expected_pre_hash:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) ⇒ :deleted, ...
rubocop:disable Metrics/ParameterLists.
-
#initialize(workspace_root:, ownership_index:, fencing_allocator:, wal:, blob_store: nil) ⇒ AtomicMutator
constructor
A new instance of AtomicMutator.
- #rename_file(from_path:, to_path:, mode:, fencing_token_from:, fencing_token_to:, expected_pre_hash_from:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) ⇒ :renamed, ...
-
#write(path:, content:, mode:, fencing_token:, expected_pre_hash:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) ⇒ :written, ...
Atomically replace
pathunder the configured workspace root.
Constructor Details
#initialize(workspace_root:, ownership_index:, fencing_allocator:, wal:, blob_store: nil) ⇒ AtomicMutator
Returns a new instance of AtomicMutator.
22 23 24 25 26 27 28 |
# File 'lib/ollama_agent/runtime/atomic_mutator.rb', line 22 def initialize(workspace_root:, ownership_index:, fencing_allocator:, wal:, blob_store: nil) @workspace_root = File.(workspace_root) @ownership_index = ownership_index @fencing_allocator = fencing_allocator @wal = wal @blob_store = blob_store end |
Instance Method Details
#delete_file(path:, mode:, fencing_token:, expected_pre_hash:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) ⇒ :deleted, ...
rubocop:disable Metrics/ParameterLists
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ollama_agent/runtime/atomic_mutator.rb', line 56 def delete_file(path:, mode:, fencing_token:, expected_pre_hash:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) outcome = guard_and_ownership(path, mode, manifest_id, logical_stamp, owner_required, supervisor_lease) return outcome if outcome absolute = (path.to_s) outcome = cas_delete_and_wal(absolute, fencing_token, expected_pre_hash, intent_hash, manifest_id, logical_stamp) return outcome if outcome != :continue two_step_unlink!(absolute, manifest_id, logical_stamp) track_step(manifest_id, logical_stamp, "complete") :deleted end |
#rename_file(from_path:, to_path:, mode:, fencing_token_from:, fencing_token_to:, expected_pre_hash_from:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) ⇒ :renamed, ...
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ollama_agent/runtime/atomic_mutator.rb', line 73 def rename_file(from_path:, to_path:, mode:, fencing_token_from:, fencing_token_to:, expected_pre_hash_from:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) o1 = guard_and_ownership(from_path, mode, manifest_id, logical_stamp, owner_required, supervisor_lease) return o1 if o1 o2 = guard_and_ownership(to_path, mode, manifest_id, logical_stamp, owner_required, supervisor_lease) return o2 if o2 from_abs = (from_path.to_s) to_abs = (to_path.to_s) outcome = cas_rename_and_wal(from_abs, to_abs, fencing_token_from, fencing_token_to, expected_pre_hash_from, intent_hash, manifest_id, logical_stamp) return outcome if outcome != :continue persist_rename(from_abs, to_abs, manifest_id, logical_stamp) :renamed end |
#write(path:, content:, mode:, fencing_token:, expected_pre_hash:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) ⇒ :written, ...
Atomically replace path under the configured workspace root.
rubocop:disable Metrics/ParameterLists – public mutation envelope matches kernel contract
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ollama_agent/runtime/atomic_mutator.rb', line 39 def write(path:, content:, mode:, fencing_token:, expected_pre_hash:, intent_hash:, manifest_id:, logical_stamp:, owner_required: nil, supervisor_lease: false) outcome = guard_and_ownership(path, mode, manifest_id, logical_stamp, owner_required, supervisor_lease) return outcome if outcome absolute = (path.to_s) outcome = cas_and_wal(absolute, content, fencing_token, expected_pre_hash, intent_hash, manifest_id, logical_stamp) return outcome if outcome != :continue persist_atomic_swap(absolute, content, manifest_id, logical_stamp) end |