Class: ZeroRuby::LmidStore
- Inherits:
-
Object
- Object
- ZeroRuby::LmidStore
- Defined in:
- lib/zero_ruby/lmid_store.rb
Overview
Abstract base class for LMID (Last Mutation ID) storage backends. Implementations must provide thread-safe access to client mutation IDs.
This follows the same atomic increment pattern as Zero’s TypeScript implementation.
Direct Known Subclasses
Instance Method Summary collapse
-
#delete_mutation_results(args) ⇒ Object
Delete mutation results, called by _zero_cleanupResults to remove acknowledged results.
-
#fetch_and_increment(client_group_id, client_id) ⇒ Integer
Atomically increment and return the last mutation ID for a client.
-
#transaction { ... } ⇒ Object
Execute a block within a transaction.
-
#write_mutation_result(client_group_id, client_id, mutation_id, result) ⇒ Object
Persist a mutation result so clients can read it via replication.
Instance Method Details
#delete_mutation_results(args) ⇒ Object
Delete mutation results, called by _zero_cleanupResults to remove acknowledged results.
59 60 61 |
# File 'lib/zero_ruby/lmid_store.rb', line 59 def delete_mutation_results(args) raise NotImplementedError, "#{self.class}#delete_mutation_results must be implemented" end |
#fetch_and_increment(client_group_id, client_id) ⇒ Integer
Atomically increment and return the last mutation ID for a client. Creates the record with ID 1 if it doesn’t exist.
This must be atomic to prevent race conditions - the increment and return should happen in a single operation.
30 31 32 |
# File 'lib/zero_ruby/lmid_store.rb', line 30 def fetch_and_increment(client_group_id, client_id) raise NotImplementedError, "#{self.class}#fetch_and_increment must be implemented" end |
#transaction { ... } ⇒ Object
Execute a block within a transaction. The transaction should support rollback on error.
39 40 41 |
# File 'lib/zero_ruby/lmid_store.rb', line 39 def transaction(&block) raise NotImplementedError, "#{self.class}#transaction must be implemented" end |
#write_mutation_result(client_group_id, client_id, mutation_id, result) ⇒ Object
Persist a mutation result so clients can read it via replication. Used to surface error results back to the client.
50 51 52 |
# File 'lib/zero_ruby/lmid_store.rb', line 50 def write_mutation_result(client_group_id, client_id, mutation_id, result) raise NotImplementedError, "#{self.class}#write_mutation_result must be implemented" end |