How to build an ActiveRecord Adapter — Introduction

datePosted on 14:18, August 19th, 2009 by Peter Fitzgibbons

Well, I don’t know how many parts this will have… so lets just say 5 until I re-edit the introduction.

Inspiration and Perspiration

Thomas Edison told us how to invent.  So let’s get to it.  The Adapter we’ll build will assist in handling the problem of database-failover in Rails 2.3.2 applications

Inspired – Seamless Database Pool

Seamless Database Pool gem provides us with a template to follow.  The SDP is focused purely on connection logic.  The true db adapter is used within the pool connections.  Our Adapter, like SDP, will simply serve as a proxy to handle the event when an ActiveRecord method (#select, #create, #update, #delete) encounters a DatabaseConnectionError.

Perspired – Activerecord Failover Adapter

Ok, we’re going to have to work for it this time.  Event though we have SDP as a template, there is A LOT of logic in there that is really not useful to us.  SDP is a load-balancing pool based upon a weighted one-write/many-read database cluster / replication group.

Requirements

Ahh, the real meat of our cookout.

  1. Configure Master + Slaves(multiple) in database.yml just like SDP
  2. Use Master Always.  Well, until failover.
  3. Use periodic timeouts to attempt re-connect to master
  4. Retry db queries on alternate connection
  5. Rollback transactions upon connection failure… then retry them?
    1. Re-try the transaction in the alternate connection
  6. Allow #establish_connection to target master/slave (especially needed for targeted migrations)
  7. Allow db:migrate to target master/slave through use of RAILS_ENV

In my next post, we’ll start with #1 Configure Master + Slavees in database.yml

categoryPosted in Uncategorized | printPrint
Related Posts:

Leave a Reply

Name: (required)
Email: (required) (will not be published)
Website:
Comment: