instacart / makara

A Read-Write Proxy for Connections; Also provides an ActiveRecord adapter.
http://tech.taskrabbit.com/
MIT License
923 stars 170 forks source link

Check decorated connection responds to open_transactions before invoking #341

Open lewispb opened 2 years ago

lewispb commented 2 years ago

An ActiveRecord::Base.connection responds to open_transactions but other connections such as a Redis client do not.

Continues from and closes https://github.com/instacart/makara/pull/324, I've also added the specs as discussed there.

As per @rosa's original PR:

We have an instance of a Makara proxy we use for Redis, for read-write splitting. It looks like this:

class RedisProxy < Makara::Proxy

  # ...

  def connection_for(config)
    Redis.new(config)
  end

  # ...
end

The connection returned is an instance of a Redis client, which doesn't respond to open_transactions, so after updating to v0.5.1, any errors on Redis that would result in a Makara::Errors::BlacklistConnection, now result in a Redis::CommandError: ERR unknown command 'open_transactions'.