Yanni Mac wrote:
I have an application that is load balanced. I have a master database which I update once a day. Then I push the raw mysql files to all other servers so they are the same as the master. This works fine, but there are a few situations where I need all databases to update in real-time. What would be the best way to achieve this in rails?
Here is an example of what I am trying to do. I want to update the name of a product on my website. Here is the controller:
def update_product_name product = Product.find(params[:id]) product.name = params[:name] product.save #Say I want to save this to 3 other databases #can I do this with activerecord? #PSUEDO CODE... I know it cant do this product.save(mysql_host2) product.save(mysql_host3) product.save(mysql_host4) end
Any ideas? Alternative ways to do this?
Before we have an adapter capable of supporting two-phase commit distributed transaction, it will be difficult to have a single transaction to commit changes to more than one database.
One alternative is to use message queuing. Essentially you generate messages destined to each DB and each DB will process its queue. Of course, you might have to devise some additional messages to compensate any actions rolled back in the master/slave due to some reasons like errors etc.
Regards,
rp8