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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Another thing.. I don''t want to do this per model. This would happen in very few situations, so I would like to code this in the controller if possible (I will probably add a method to application.rb and call it in the controller when appropriate). 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?-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? >You could use MySQL''s built-in replication support. -- Jack Christensen jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jack Christensen wrote:> 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? >> > You could use MySQL''s built-in replication support. >What if I want it on other SQL server? davi -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkltDOUACgkQ76Bs0E5RGKO3twCePRLi1tyfJM1FTGgQX3jiT7Co BDgAnilihvAKaFQE+17ifR4RaASgLqjV =a/a+ -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
A "not so easy" way to solve this is to write your own database adapter, that would send the real SQL code to many different databases (your adapter would contain an array of other adapters that would receive the real SQL). That''s how tools like C-JDBC do it. But if you need this for MySQL only, you should try to use the database replication mechanism. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Tue, Jan 13, 2009 at 6:51 PM, Davi Vidal <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Jack Christensen wrote: >> 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? >>> >> You could use MySQL''s built-in replication support. >> > > > What if I want it on other SQL server? > > davi > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.9 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAkltDOUACgkQ76Bs0E5RGKO3twCePRLi1tyfJM1FTGgQX3jiT7Co > BDgAnilihvAKaFQE+17ifR4RaASgLqjV > =a/a+ > -----END PGP SIGNATURE----- > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 13 Jan 2009, at 23:08, Maurício Linhares wrote:> > A "not so easy" way to solve this is to write your own database > adapter, that would send the real SQL code to many different databases > (your adapter would contain an array of other adapters that would > receive the real SQL). That''s how tools like C-JDBC do it.Doesn''t that boil down to reinventing replication ? Fred> > > But if you need this for MySQL only, you should try to use the > database replication mechanism. > > - > Maurício Linhares > http://alinhavado.wordpress.com/ (pt-br) | http:// > blog.codevader.com/ (en) > > > > On Tue, Jan 13, 2009 at 6:51 PM, Davi Vidal <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org > > wrote: >> >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Jack Christensen wrote: >>> 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? >>>> >>> You could use MySQL''s built-in replication support. >>> >> >> >> What if I want it on other SQL server? >> >> davi >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v2.0.9 (GNU/Linux) >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org >> >> iEYEARECAAYFAkltDOUACgkQ76Bs0E5RGKO3twCePRLi1tyfJM1FTGgQX3jiT7Co >> BDgAnilihvAKaFQE+17ifR4RaASgLqjV >> =a/a+ >> -----END PGP SIGNATURE----- >> >>> >> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The problem is that I don''t want to replicate everything. The way I understand it, and correct me if I am wrong b/c I have never set up master/slave replication in MySQL, every time there is a insert/update/delete to the database, it will replicate to the others automatically in real-time. I don''t want this to happen, because I am running a script that updates 16 million rows and takes 20 hours to complete... replication would affect performance on the live slaves. In parallel to this script running I am making live changes to the data in my app via a web interface. These changes (small portion compared to the script running) will need to write to all 4 databases at the same time. I am assuming mysql replication is all or none and can''t do this... meaning replicate some times and not others?? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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?I would like to know what their connection are already configured to your applications? because to connect multiple databases are different configuration or you can do manually connection in your AR (if this is a false solution, please give me issues and resolution ): require "activerecord" def update_product_name // i am not sure about this script is put in Class AR // Maybe it is suitable to put out of class AR ActiveRecord::Base.establish_connection( :adapter=>"mysql", :database=>"theSame", :username=>"theSame_theSame", :password=>"1234567890" :host=>"theSame-2.com") saving_name(params[:id],params[:name]) end // you can make array to descript your multiple login then loop it. end def saving_name(id,name) product = Product.find(id) product.name = name product.save ActiveRecord::Base.remove_connection end - Ruby Servant - -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 ======================http://competo.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rails Terrorist wrote:> >> 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? > > I would like to know what their connection are already configured to > your applications? because to connect multiple databases are different > configuration or you can do manually connection in your AR (if this is a > false solution, please give me issues and resolution ): > > require "activerecord" > > def update_product_name > > > // i am not sure about this script is put in Class AR > // Maybe it is suitable to put out of class AR > ActiveRecord::Base.establish_connection( > :adapter=>"mysql", > :database=>"theSame", > :username=>"theSame_theSame", > :password=>"1234567890" > :host=>"theSame-2.com") > > saving_name(params[:id],params[:name]) > end > > // you can make array to descript your multiple login then loop it. > > end > > > def saving_name(id,name) > product = Product.find(id) > product.name = name > product.save > ActiveRecord::Base.remove_connection > end > > > - Ruby Servant -Yeah.. I think this is sort of what I am looking for. I was playing around with something like this (still tweaking it after getting some errors) slaves = ["host2","host3","host4"] for slave in slaves ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV].merge(''host'' => slave)) unique_product.save end #set back to original host ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV].merge(''host'' => original_host)) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- rid and ad backends differences
- rid and ad backends differences
- (SOLVED ) you have been logged on with a temporary profile_win7, client+samba 4+WinServ2012
- (SOLVED ) you have been logged on with a temporary profile_win7, client+samba 4+WinServ2012
- Don''t Shout at your JBODs