Is Your Java Application FailoverProof (i.e., RAC Aware)?
Why in the world should a Java developer care about failover and what does it mean to be failoverproof?
Well, failure is inevitable however, in mission critical (i.e., web) deployments, all applications including the Java ones must sustain resource manager (i.e., RDBMS) failure, or connection failure, or transaction failure without disrupting the service.
How exactly?
For the sake of simplicity, let's take a JDBC program. Best practices mandate that Java/JDBC programs capture exceptions and deal with these; here is a skeleton of a failoverproof program using Oracle JDBC in RAC environment:
...
try
{
conn = getConnection();
// do some work
} catch (SQLException e) {
handleSQLException(e); }
...
handleSQLException (SQLException e)
{
if (OracleConnectionCacheManager.isFatalConnectionError(e))
ConnRetry = true; // Fatal Connection error detected
}
Capturing SQL exceptons and re-trying to get a connection are all good JDBC programming so the burden is not really at the Java application level (it has to be somewhat portable), rather at the driver or framework level. Up to these (the driver, the OR Mapping framework, servlet engine, Java EE container) to furnish, under the covers, a failoverproof environment.
Do all drivers and Java frameworks are failoverproof?
You wish! The reality is that very few JDBC drivers or Java frameworks furnish true/reliable connection or transaction failover mechanisms.
From database access point of view, what does it take for a JDBC Driver or a Java framework to be failoverproof?
First of all, a JDBC driver or a Java EE ccontainer by itself cannot furnish a complete failoverproof environment, it more importantly requires the resource manager, in this case the RDBMS to be failoverproof as well. In the Oracle RDBMS case, instance/node failover as well as scalability is furnished by the RAC framework.
What is RAC?
An Oracle database is managed by a database instance which is made of a shared memory (a.k.a. SGA)and a set of database server processes. A database is usually accessed and managed by a single instance. However, an Oracle database can also be concurrently accessed and managed by multiple instances up to 64 nodes and beyond; this technology is known as Real Application Clusters (RAC).
How Does RAC Furnish Failover?
Starting with release 10g, RAC generates events that indicate the health or status of each RAC components including SERVICE, SERVICE_MEMBER,DATABASE, INSTANCE, NODE, ASM, and SRV_PRECONNECT.
The possible status are: UP, DOWN, NOT_RESTARTING, PRECONN_UP, PRECON_DOWN, and UNKNOWN.
Example of events can be: "Instance1 UP", "Node2 Down".
RAC furnishes failover by design in the sense that when a service/instance/node fails, a well written application can be redirected to the surviving node/instance provided these furnish the same service and proceed against the same database.
How Does JDBC Leverages RAC Failover?
The Oracle JDBC 10g drivers, more specifically it's connection cache (a.k.a. Implicit Connection Cache) leverages RAC by subscribing to the following events and status (as described in RAC documentation and in chapter 7 of my book):
- Service Up: The connection pool starts establishing connections in small batches to the newly added service.
- Instance (of Service) Up: The connection pool gradually releases idle connections associated with existing instances and reallocates these onto the new instance.
- Instance (of Service) Down: The connections associated with theinstance are aborted and cleaned up, leaving the connection pool with sound and valid connections.
- Node Down: The connections associated with the instance are aborted and cleaned up, leaving the connection pool with good connections.
But to be reliable, these events must be propagated to interested parties as fast as possible because the timeout mechanisms(tcp_keepalive, tcp_ip_interval, and so on) are unreliable and may take a long (tens of minutes) to indefinite time to be kick-in.
Orale furnishes ONS (Orale Notification Services) and Advanced Queue as publish/subscribe and predictable notification mechanisms which detects and propagates quasi-instantaneously (sub-seconds) those events to components that have subscribed to these mechanisms.
Setting up JDBC for Failover
- Set up a multinstance Oracle Database 10g RAC database (see RAC documentation).
- Virtualize the database host through a service name (see JDBC URL in chapter 7 of my book).
- Configure ONS on each RAC server node (see the RAC Administrator Guide or chapter 7 in my book).
- Configure ONS on each client node (10g Release 1) or use simpler remote subscription (10g Release 2). Ensure ons.jar file is in the CLASSPATH then programmatically set the ONS configuration string for remote ONS subscription at the data source level (unfortunately this cannot yet be set through system property): ods.setONSConfiguration("nodes=node1:4200,node2:4200"); The Java virtual machine (JVM) in which the JDBC driver is running must have oracle.ons.oraclehome set to point to ORACLE_HOME -Doracle.ons.oraclehome=
- Enable the Connection Cache and Fast Connection Failover through system property: -Doracle.jdbc.FastConnectionFailover = true Alternatively, the Connection Cache and Fast Connection Failover can be enabled programmatically using OracleDataSource properties: ods.setConnectionCachingEnabled(true); ods.setFastConnectionFailoverEnabled(true);
Oracle JDBC: Handling of DOWN events (Under the covers) Upon the notification of Service Down event, a worker thread (one per pool instance) processes the event in two passes:First pass: Connections are marked as down first, to efficiently disable bad connectionsSecond pass: Aborts and removes connections that are marked as downNote: active connections that may be in the middle of a transaction receive a SQLException instantly
Oracle JDBC: Hanlding of UP Events (under the covers)
A Service UP event initiates connections to be load balanced to all active RAC instances Connection creation depends on Listener’s placement of connections. Starting with 10g release 2,load balancing advisory events enabled Runtime Connection Load Balancing (covered in chapter 7 of my book).
Object-relational Mapping frameworks as well as any Java EE containers may either leverage Oracle JDBC (bypassing their own connection pool) or subscribe diretly to RAC events using the ONS APIs and processing these (i.e., handle connection retry). To my knowledge, only Oracle's Java EE containers (OC4J) has integrated Fast Connection Failover and ONS at datasource level.
How does Oracle JDBC Fast Connection Failover (FCF) compares with TAF?
Fast Connection Fail-over and TAF differ from each other in the followingways:
- Driver-type dependency: TAF is in fact a OCI failover mechanism exposed to Java through JDBC-OCI. FCF is driver-type independent (i.e., works for both JDBC-Thin and JDBC-OCI).
- Application-Level Connection Retries: FCF supports application-level connection retries (i.e., the application may retry the connection or rethrow the exception). TAF on the other hand retries connection transparently at the OCI/Net out of the control ofthe application or Java framework.
- Integration with the Connection Cache: FCF is integrated with the Implicit Connection Cache and invalidates failed connections automatically in the cache. TAF on the other hand works on a per-connection basis at the network level; it does not notify the connection cache of failures.
- Load Balancing: unlike TAF, FCF and runtime connection load balancing (RCLB) support UP event load-balancing of connections and runtime distribution of work across active RAC instances.
- Transaction Management: FCF automatically rolls back in-flight transations; TAF, on the other hand, requires the application to roll back the transaction and send an acknowledgment to TAF to proceed with the failover.
- TAF does not protect or fail-over codes that have server-side states such as Java or PL/SQL stored procedures; however, the application can register a callback function that will be called upon failure to reestablish the session states.
// register TAF callback function “cbk”
((OracleConnection) conn).registerTAFCallback(cbk,msg);
Voila, you now have a Java plateform with connection pool failover, on top of which you can code and deploy JDBC applications or Java EE components.
For more details, see chapter 7 of my book: http://db360.blogspot.com/2006/08/oracle-database-programming-using-java_01.html







23 Comments:
Is it safe to say, that when using the BC4J/ADF Framework? my application must be FailoverProof/RAC Awar?
Hi,
Fast Connection Failover is based on RAC events. ADFBC provides a failover mode, but it does not depend on RAC.
Kuassi
Kuassi,
The question I have is what does the application code have to do to use TAF vs FCF? We have in our requirements to our client identified to use TAF, however I am questioning whether TAF is the right way to go or FCF would be a better option. We are in a J2EE environment with an Oracle 10.2.0.2 application server cluster and 10.2.0.2 RAC database behind it. From our management perspective since we are well into development what impact would using FCF have, i.e. additional code to our application or just enabling ONS and setting some system configuration properties within the application servers and or database servers? Any assistance you could provide or direction would be greatly appreciated.
Thanks,
Brad
Hi Brad,
Simply put:
- with TAF, connection failover is transparent (in case of node failure) however, you have to programmatically rollback ongoing transactions (TAF requires an ACK from the application, in order to proceed)
- with FCF, you need to retry getConnection() programmatically in case of node faiure (you might not need to do anything if your JDBC code has already done the right thing - i.e., catch SQL exception and retry), ongoing transactions are automatically rolled back.
From JDBC perspective, we recommend FCF and it's future incarnation as these are driver independent (as you know, TAF is an OCI feature which only works for JDBC-OCI).
Hope this helps, Kuassi
Does anyone know if the Spring framework handles this? There is a spring thread at http://forum.springframework.org/showthread.php?t=16931
Cheers
Neil
Nice and knowledgeable sites for everyone-
booksshelf
knowledge
books
liberary
kitaben
Books and references
books
tutorial books
Kuassi,
Our application is not using RAC but using DataGuard as per client requirements. In this case how do we manage the failover when standby databse becomes master? We are using hibernate and c3p0. Please advice.
Thanks
Sri.
Kuassi,
I am an oracle DBA implementing 10gR2 RAC. I have implemented TAF in the past but never had a chance to implement FCF so far. But now our requirement is to implement FCF using ONS. I see that our app team will need to use Oracle JDBC drivers in their code so that we can achieve this. What does the app team need to use/do to ensure that our FCF will work? Thanks much in advance.
Don
Don,
Assuming RAC, ONS, and the services have been confugured and working (see Setting up JDBC for Failover in the blog) , the application team needs to do 2 things.
1) enable FCF either programmatically or using system property
(-Doracle.jdbc.FastConnectionFailover = true)
2) catch SQLException and if this is indeed a FataConnectionError then retry getConnection. See the pseudo-code above in the blog.
That's it, Kuassi
Hi Kuassi,
We are currently using our own connection pooling mechanism, and would like to continue using this pool. We are also moving to a RAC environment, and need to support RAC in our application.
Is it possible to use the RAC type db connection properties with our existing connection pool. (No FCF, and no Implicit Connection Cache)
If so, what is the behavior of the JDBC driver when getConnection is called and one of the nodes in the RAC are down? Does it return a connection failure?
Hi,
Right now, the subscription to RAC events ( using ONS) is handled by our connection pool, not by the JDBC itself. There is no public API that you can use to subscribe to RAC events and manage these in your custom connection pool but we are looking into furnishing a JDBC API which will allow you to do that, in a near future.
KUassi
情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,按摩棒,震動按摩棒,微調按摩棒,情趣按摩棒,逼真按摩棒,G點,跳蛋,跳蛋,跳蛋,性感內衣,飛機杯,充氣娃娃,情趣娃娃,角色扮演,性感睡衣,SM,潤滑液,威而柔,香水,精油,芳香精油,自慰套,自慰,性感吊帶襪,吊帶襪,情趣用品加盟AIO交友愛情館,情人歡愉用品,美女視訊,情色交友,視訊交友,辣妹視訊,美女交友,嘟嘟成人網,成人網站,A片,A片下載,免費A片,免費A片下載愛情公寓,情色,舊情人,情色貼圖,情色文學,情色交友,色情聊天室,色情小說,一葉情貼圖片區,情色小說,色情,色情遊戲,情色視訊,情色電影,aio交友愛情館,色情a片,一夜情,辣妹視訊,視訊聊天室,免費視訊聊天,免費視訊,視訊,視訊美女,美女視訊,視訊交友,視訊聊天,免費視訊聊天室,情人視訊網,影音視訊聊天室,視訊交友90739,成人影片,成人交友,美女交友,微風成人,嘟嘟成人網,成人貼圖,成人電影,A片,豆豆聊天室,聊天室,UT聊天室,尋夢園聊天室,男同志聊天室,UT男同志聊天室,聊天室尋夢園,080聊天室,080苗栗人聊天室,6K聊天室,女同志聊天室,小高聊天室,上班族聊天室,080中部人聊天室,同志聊天室,聊天室交友,中部人聊天室,成人聊天室,一夜情聊天室,情色聊天室,寄情築園小遊戲情境坊歡愉用品,情趣用品,成人網站,情人節禮物,情人節,AIO交友愛情館,情色,情色貼圖,情色文學,情色交友,色情聊天室,色情小說,七夕情人節,色情,情色電影,色情網站,辣妹視訊,視訊聊天室,情色視訊,免費視訊聊天,美女視訊,視訊美女,美女交友,美女,情色交友,成人交友,自拍,本土自拍,情人視訊網,視訊交友90739,生日禮物,情色論壇,正妹牆,免費A片下載,AV女優,成人影片,色情A片,成人論壇,情趣,免費成人影片,成人電影,成人影城,愛情公寓,成人影片,保險套,舊情人,微風成人,成人,成人遊戲,成人光碟,色情遊戲,跳蛋,按摩棒,一夜情,男同志聊天室,肛交,口交,性交,援交,免費視訊交友,視訊交友,一葉情貼圖片區,性愛,視訊,視訊聊天,A片,A片下載,免費A片,嘟嘟成人網,寄情築園小遊戲,女同志聊天室,免費視訊聊天室,一夜情聊天室,聊天室
Kuassi,
First of all it is not clear to me if retrying is mandatory in order to change servers and allow for fail over. If it *is* mandatory, then
I don't see why Oracle's Data Source driver does not automatically retries the connection (i.e. via configuration parameters); given the fact that there is a RAC configured retrying in case of error would seem the most logical thing to do.
Additionally, I am not aware if commonly used frameworks (like Spring) actually retry a connection on failure (do you happen to know this is the case?).
Thanks a lot,
Regards
AB
Hi,
Yes, when a RAC node fails, it is mandatory to get a new connection belonging to surviving nodes; and the only programmatic way is to rety getConnection(). Having said that, if you were using a container that can intersperse the retry then your own code does not have to do it.
A plain data source cannot intersperse the retry. I know that TAF does that at the network layer but TAF has lot of shortages (not counting that is depends on OCI) that makes it not fully general purpose.
We have had interacion with the Spring folks but i don't know if they have achieved the integration with RAC or not.
Regards, Kuassi
We specialize in laptop battery,laptop AC adapters. All our products are brand new, with the excellent service from our laptop battery of customer service team.
the most convenient and cheap replacement battery online shop in uk. We specialize in laptop batteries, laptop AC adapters.
All our laptop AC adapters are brand new, with the excellent service from our customer service team.
the most convenient and cheap battery online shop in uk.
You can find some battery and adapter from here is very cool.
情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,情趣,情趣,按摩棒,跳蛋,充氣娃娃,情境坊歡愉用品,情趣用品,情人節禮物,情惑用品性易購
免費A片,AV女優,美女視訊,情色交友,免費AV,色情網站,辣妹視訊,美女交友,色情影片,成人影片,成人網站,A片,H漫,18成人,成人圖片,成人漫畫,情色網,日本A片,免費A片下載,性愛
A片,色情,成人,做愛,情色文學,A片下載,色情遊戲,色情影片,色情聊天室,情色電影,免費視訊,免費視訊聊天,免費視訊聊天室,一葉情貼圖片區,情色,情色視訊,免費成人影片,視訊交友,視訊聊天,視訊聊天室,言情小說,愛情小說,AIO,AV片,A漫,av dvd,聊天室,自拍,情色論壇,視訊美女,AV成人網,色情A片,SEX
情趣用品,A片,免費A片,AV女優,美女視訊,情色交友,色情網站,免費AV,辣妹視訊,美女交友,色情影片,成人網站,H漫,18成人,成人圖片,成人漫畫,成人影片,情色網
情趣用品,A片,免費A片,日本A片,A片下載,線上A片,成人電影,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,微風成人區,成人文章,成人影城,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,臺灣情色網,色情,情色電影,色情遊戲,嘟嘟情人色網,麗的色遊戲,情色論壇,色情網站,一葉情貼圖片區,做愛,性愛,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,美女交友,做愛影片
av,情趣用品,a片,成人電影,微風成人,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,愛情公寓,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,aio,av女優,AV,免費A片,日本a片,美女視訊,辣妹視訊,聊天室,美女交友,成人光碟
情趣用品.A片,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,色情遊戲,色情網站,聊天室,ut聊天室,豆豆聊天室,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,免費A片,日本a片,a片下載,線上a片,av女優,av,成人電影,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,成人網站,自拍,尋夢園聊天室
---------------------------------------------------------------------------------------------------------------------------------
A片,A片,成人網站,成人漫畫,色情,情色網,情色,AV,AV女優,成人影城,成人,色情A片,日本AV,免費成人影片,成人影片,SEX,免費A片,A片下載,免費A片下載,做愛,情色A片,色情影片,H漫,A漫,18成人
a片,色情影片,情色電影,a片,色情,情色網,情色,av,av女優,成人影城,成人,色情a片,日本av,免費成人影片,成人影片,情色a片,sex,免費a片,a片下載,免費a片下載
情趣用品,情趣用品,情趣,情趣,情趣用品,情趣用品,情趣,情趣,情趣用品,情趣用品,情趣,情趣
A片,A片,A片下載,做愛,成人電影,.18成人,日本A片,情色小說,情色電影,成人影城,自拍,情色論壇,成人論壇,情色貼圖,情色,免費A片,成人,成人網站,成人圖片,AV女優,成人光碟,色情,色情影片,免費A片下載,SEX,AV,色情網站,本土自拍,性愛,成人影片,情色文學,成人文章,成人圖片區,成人貼圖
情色,AV女優,UT聊天室,聊天室,A片,視訊聊天室
I am having a trouble to implement FCF using Oracle OracleDataSource JDBC class in my plain Java application.
But I don't have this problem in my Java web application deployed to WebLogic app server since WebLogic takes of this. The one big difference between my Java and Web app is providing database connection information. In my Java application, to connect a database, I use Oracle OracleDataSource methods such as setServerName(), setUser(), setFastConnectionFailoverEnabled(), etc. However, in my Web application, I use standard DataSource JDBC class and provide the following connection information to WebLogic configuration file:
url tag jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.199.1.144)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.199.1.145)(PORT = 1521))
(FAILOVER=on)(LOAD_BALANCE=yes))
(CONNECT_DATA=(SERVER=DEDICATED)
(SERVICE_NAME = my.ractest.com)
(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5))
)
)
As I said before, my Web App works with Oracle RAC but not my plain Java app.
My questions are below:
1. For my java app, do I have to provide the above url to OracleDataSource class to connect database as I did to WebLogic?
2. If yes, how do I pass these information?
I mean which OracleDataSource methods I have to use. I can't find a method that takes the entire url string a single call.
3. Can you take a look at my code snippet and tell what is wrong with my code?
Note: This code works fine in NOT RAC environment.
OracleDataSource conPds = new OracleDataSource();
conPds.setUser( user );
conPds.setPassword( password );
conPds.setDriverType( THIN );
conPds.setPortNumber( port );
conPds.setDatabaseName( databaseName );
conPds.setServerName( serverName );
if ( serviceName != null && serviceName.length() != 0 )
{
conPds.setServiceName( serviceName );
}
Properties cacheProp = new Properties();
cacheProp.setProperty( INITIAL_LIMIT, initConLimit );
ms_initConLimit = initConLimit; // for debugging info
cacheProp.setProperty( MAX_LIMIT_STATEMENTS_LIMIT, "30" );
conPds.setConnectionCachingEnabled( true );
conPds.setFastConnectionFailoverEnabled( true );
conPds.setConnectionCacheProperties( cacheProp );
conPds.setONSConfiguration( "nodes=192.168.1.155:6200,192.168.1.156:6200" ); // hard-coded now
conPds.setConnectionCacheName( CONNECTION_CACHE_NAME );
OracleConnectionCacheManager conCacheMgr = OracleConnectionCacheManager.getConnectionCacheManagerInstance();
conCacheMgr.createCache( CONNECTION_CACHE_NAME, conPds, cacheProp );
I appreciate your help in advance.
Sun
Hi,
The Weblogic data source does on your behalf what your JDBC code needs to do.
Yes, you need to provide the same URL either directly in your Java code or in tnsnames.ora as a service and use the service name in your JDBC URL.
HOpe this helps
(法新社倫敦四日電) 英國情色大亨芮孟的成人公司昨天說色情,芮孟a片下載日前部落格去世,享壽八十二歲;成人網站這位身價上億的房地產開情色電影發商,曾經a片在倫敦推出av女優第色情一場脫色情衣舞情色表演。
芮孟的財產估計達六億五千萬英色情影片鎊(台幣將近四百億),由日本av於他名a片下事業大多分布部落格在倫敦夜av生活區蘇活區成人電影,因此擁有「蘇活之王」的稱號。sex
他的公司「保羅芮a片孟集團」旗下發行多種情色雜誌情色視訊,包括「Razzle成人影片」、「男性世界」以及「Mayfair」。av女優
成人光碟芮孟a片下載本名av女優傑a片福瑞成人影片.av安東尼.奎恩,父成人影片親為搬運承包商。芮孟十五歲離開學校,矢言要在表演事業留成人網站名AV片,起先表成人網站演讀心成人術,後來成為巡迴歌舞avdvd雜耍表演的製作人。
情色電影
許多評論家認為,他把情色表演帶進主流社會,一九五九年主部落格持破天荒的av脫衣舞表演,後來更靠情色著在蘇活區與倫敦西區開發房地成人電影產賺得大筆財富。av
有人形容芮孟是英國的海夫納色情a片,地位等同美國的「花花公子」創辦人海夫納。
Does two-phase commit (XA) work with Fast Connection Failover?
Yes but you have to use the new connection pool (UCP) it comes with 11.1.0.7.
Post a Comment
Links to this post:
Create a Link
<< Home