class TableLock
A lock held while an execution runs against a table, preventing concurrent executions from racing on the same table.
Public Class Methods
Source
# File app/models/table_lock.rb, line 8 def self.acquire(execution) create!(iceberg_table_id: execution.iceberg_table_id, execution_history: execution, acquired_at: Time.current) true rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid false end
The uniqueness constraint is the real guarantee; the rescue only translates it.
Source
# File app/models/table_lock.rb, line 24 def self.reap_stale! joins(:execution_history) .where.not(execution_histories: { status: %w[pending running] }) .delete_all end
A lock whose owner finished or disappeared is garbage: free it.
Source
# File app/models/table_lock.rb, line 19 def self.release(execution) where(execution_history_id: execution.id).delete_all end
Releases the lock held by the given execution. @param execution [ExecutionHistory] the execution releasing its lock