Module: Gouda::FiberDatabaseSupport

Defined in:
lib/gouda.rb

Overview

Database configuration helpers for fiber mode

Class Method Summary collapse

Class Method Details

.check_fiber_isolation_levelObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/gouda.rb', line 168

def self.check_fiber_isolation_level
  return unless defined?(Rails) && Rails.respond_to?(:application) && Rails.application

  begin
    current_isolation = ActiveSupport.isolation_level

    # Check if we're using PostgreSQL
    using_postgresql = false
    begin
      if defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
        using_postgresql = true
      end
    rescue
      # If we can't determine the adapter, assume we might be using PostgreSQL to be safe
      using_postgresql = true
    end

    if current_isolation != :fiber && using_postgresql
      logger.warn("=" * 80)
      logger.warn("FIBER SCHEDULER CONFIGURATION WARNING")
      logger.warn("=" * 80)
      logger.warn("Gouda fiber mode is enabled with PostgreSQL but Rails isolation level is set to: #{current_isolation}")
      logger.warn("For optimal fiber-based performance and to avoid potential issues with PostgreSQL,")
      logger.warn("you should set the Rails isolation level to :fiber")
      logger.warn("")
      logger.warn("Add this to your config/application.rb:")
      logger.warn("  config.active_support.isolation_level = :fiber")
      logger.warn("")
      logger.warn("This ensures ActiveRecord connection pools work correctly with fibers")
      logger.warn("and PostgreSQL connections, and can prevent segfaults with Ruby 3.4+.")
      logger.warn("=" * 80)
    elsif current_isolation == :fiber
      logger.info("Rails isolation level correctly set to :fiber for fiber-based execution")
    elsif !using_postgresql
      logger.info("Non-PostgreSQL database detected - isolation level configuration may not be required")
    end
  rescue => e
    logger.warn("Could not check Rails isolation level: #{e.message}")
  end
end

.loggerObject



209
210
211
# File 'lib/gouda.rb', line 209

def self.logger
  Gouda.logger
end