auto_retry setup for all connection instances ?

214 views
Skip to first unread message

George Ardeleanu

unread,
Nov 8, 2011, 6:57:07 PM11/8/11
to Oracle enhanced adapter for ActiveRecord
I noticed there is an auto_retry attribute on several classes that
seems to reconnect the connection, however i am not clear on the
correct way to set it up.

I would think this is something that can be set in database.yml and
then carried thru to the connection instance.

I did notice in the specs this option is enabled by running the line
below but wasn't sure if this was the best approach :
ActiveRecord::Base.connection.auto_retry = true

Is it as simple as running the above line in an initializer ?


Here is the code reference for the v1.3.1 (which is the version i am
currently using):

https://github.com/rsim/oracle-enhanced/blob/v1.3.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L386

https://github.com/rsim/oracle-enhanced/blob/v1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb#L33

https://github.com/rsim/oracle-enhanced/blob/v1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb#L339


thanks,
george .

Raimonds Simanovskis

unread,
Nov 13, 2011, 8:44:56 AM11/13/11
to oracle-...@googlegroups.com
If database connection will be lost then it will be reestablished by ActiveRecord by default. This additional auto_retry option turns on functionality that if SQL statement will fail due to lost connection then it will reestablish connection and retry the same SQL statement again.

Do you have any real need for that? I have not actually used this option by myself in real projects as loosing connection is quite rare situation and that's not a big issue if then corresponding web transaction will fail as well.

Raimonds

George Ardeleanu

unread,
Nov 13, 2011, 9:29:39 AM11/13/11
to oracle-...@googlegroups.com
I see my Oracle connection being reestablished in my Rails app (running with nginx and passenger), however in my delayed_job daemon the connection is never reestablished.  I was assuming passenger is simply killing the Rails process and starting up a new one, and this was how the Oracle connection was being reestablished.
where does activerecord perform the reconnect logic you are referring to ?  i only was able to find it for the MySQL Adapter.

this is the exact scenario i am running :
delayed_job starts up with a Oracle connection, processing jobs with no problem. 
then we have a blip in the network and delayed_job cannot communicate with Oracle for a few seconds.
then the job is tried again a few minutes later with Oracle communication restored, however the job still fails with an error that it cannot communicate with Oracle.

once i set ActiveRecord::Base.connection.auto_retry = true in my delayed_job startup script,  the Oracle connection is established.

george .



Raimonds

--
You received this message because you are subscribed to the Google Groups "Oracle enhanced adapter for ActiveRecord" group.
To view this discussion on the web visit https://groups.google.com/d/msg/oracle-enhanced/-/Hj8R_DyrAbcJ.
To post to this group, send email to oracle-...@googlegroups.com.
To unsubscribe from this group, send email to oracle-enhanc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/oracle-enhanced?hl=en.

ukyov...@gmail.com

unread,
Feb 3, 2013, 6:57:23 AM2/3/13
to oracle-...@googlegroups.com
Hi, 

I found your post after googling around. I'm at the same spot. My rails app's main db is MySQL but there are some classes whose data is stored on Oracle. Whenever the app needs an active record object residing on Oracle I see in the logs that rails tries to reconnect to Oracle and everything is fine within the app. However delayed_job after losing the connection complains about not being connected. I tried to require 'active_record' and set ActiveRecord::Base.connection.auto_retry = true  in delayed_job start up script but I got the following error
ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'

Actually that makes total sense. So I wonder where you've put the line
ActiveRecord::Base.connection.auto_retry = true

in an initializer or in the method being executed by the delayed_job worker?

Thanks in advance,
Ukyo
Reply all
Reply to author
Forward
0 new messages