JDBC THIN DRIVER 사용시 CONNECT TIME FAIL-OVER를 고찰(TAF, 오라클 DB failover)
Web service 2009. 4. 10. 12:13N = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = krtest1) (PORT = 1521))
(ADDRESS = (PROTOCOL = TCP) (HOST = krtest2) (PORT = 1521))) (CONNECT_DATA =
(SERVICE_NAME = MIKE.us.oracle.com))) ", "scott", "tiger");
(출처: http://blog.empas.com/myungho/read.html?a=18405273)
<중략>
JDBC 1.0 스펙상에는 DB Connection Pooling 기능에 대한 언급이 존재하지 않았습니다.
<중략>
그러나 최근 JDBC 2.0 Specifiaction 이 SunmicroSystem 의해 발표된 후 대부분의 DB Vendor들을 이를 지원하게 되었으며, Oracle의 경우 Version 8.1.6 부터 JDBC 2.0을 지원하고 있습니다.
따라서, DB Connection Pool기능과 그것의 구현과정에서 transparent하게 DB Connection Recovery 기능을 제공해야 하는 책임을 갖고 있는 곳은 이젠 DB Vendor에 달려 있게 됩니다.
<중략>
Oracle의 경우 Oracle 8i Release 2 ( 8.1.6 ) 부터 JDBC 2.0 을 지원하고 있습니다. 그러나, 현재 H은행에서 사용되고 있는 형태인 JDBC Type 4 Thin Driver는 Transparent한 FailOver 기능을 아직 제공하지 않고 있습니다.
<중략>
Transparent한 DB Connection Recovery 기능을 구현하려면 매 호출시마다, Pool에 기연결되어 있는 Connection이 가용한 것인지를 확인하기 위해 SQL Query를 날려보아야 합니다.
Yes. When you are connecting to a RAC server, Fast Connection Failover provides rapid response to failure events. This new High-Availability feature is driver independent and works in conjunction with the Implicit connection cache and RAC to provide maximum availability of connections in the cache. This is achieved by processing RAC's down events to remove invalid connections and up events to load balance existing connections.
If you are using the OCI driver and all you need is query fail-over, you might consider TAF. TAF primarily facilitates query failover in an application. It is not a general fail-over mechanism. Note that Fast Connection Failover and TAF can't be used together. Only one may be enabled and used at a time.
아래 내용을 보자.
JDBC OCI Application Failover Callbacks--OCIFailOver.java
This sample demonstrates the registration and operation of JDBC OCI application failover callbacks.
For information on Transparent Application Failover (TAF) and failover events, see "OCI Driver Transparent Application Failover".
/* * This sample demonstrates the registration and operation of * JDBC OCI application failover callbacks * * Note: Before you run this sample, set up the following * service in tnsnames.ora: * inst_primary=(DESCRIPTION= * (ADDRESS=(PROTOCOL=tcp)(Host=hostname)(Port=1521)) * (CONNECT_DATA=(SERVICE_NAME=ORCL) * (FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)) * ) * ) * Please see the Oracle Net Administrator's Guide for more detail about * failover_mode * * To demonstrate the the functionality, first compile and start up the sample, * then log into sqlplus and connect /as sysdba. While the sample is still * running, shutdown the database with "shutdown abort;". At this moment, * the failover callback functions should be invoked. Now, the database can * be restarted, and the interupted query will be continued. */ // You need to import java.sql and oracle.jdbc packages to use // JDBC OCI failover callback import java.sql.*; import java.net.*; import java.io.*; import java.util.*; import oracle.jdbc.OracleConnection; import oracle.jdbc.OracleOCIFailover; public class OCIFailOver { static final String user = "scott"; static final String password = "tiger"; static final String driver_class = "oracle.jdbc.OracleDriver"; static final String URL = "jdbc:oracle:oci8:@inst_primary"; public static void main (String[] args) throws Exception { Connection conn = null; CallBack fcbk= new CallBack(); String msg = null; Statement stmt = null; ResultSet rset = null; // Load JDBC driver try { Class.forName(driver_class); } catch(Exception e) { System.out.println(e); } // Connect to the database conn = DriverManager.getConnection(URL, user, password); // register TAF callback function ((OracleConnection) conn).registerTAFCallback(fcbk, msg); // Create a Statement stmt = conn.createStatement (); for (int i=0; i<30; i++) { // Select the ENAME column from the EMP table rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1)); // Sleep one second to make it possible to shutdown the DB. Thread.sleep(1000); } // End for // Close the RseultSet rset.close(); // Close the Statement stmt.close(); // Close the connection conn.close(); } // End Main() } // End class jdemofo /* * Define class CallBack */ class CallBack implements OracleOCIFailover { // TAF callback function public int callbackFn (Connection conn, Object ctxt, int type, int event) { /********************************************************************* * There are 7 possible failover event * FO_BEGIN = 1 indicates that failover has detected a * lost conenction and faiover is starting. * FO_END = 2 indicates successful completion of failover. * FO_ABORt = 3 indicates that failover was unsuccessful, * and there is no option of retrying. * FO_REAUTH = 4 indicates that a user handle has been re- * authenticated. * FO_ERROR = 5 indicates that failover was temporarily un- * successful, but it gives the apps the opp- * ortunity to handle the error and retry failover. * The usual method of error handling is to issue * sleep() and retry by returning the value FO_RETRY * FO_RETRY = 6 * FO_EVENT_UNKNOWN = 7 It is a bad failover event *********************************************************************/ String failover_type = null; switch (type) { case FO_SESSION: failover_type = "SESSION"; break; case FO_SELECT: failover_type = "SELECT"; break; default: failover_type = "NONE"; } switch (event) { case FO_BEGIN: System.out.println(ctxt + ": "+ failover_type + " failing over..."); break; case FO_END: System.out.println(ctxt + ": failover ended"); break; case FO_ABORT: System.out.println(ctxt + ": failover aborted."); break; case FO_REAUTH: System.out.println(ctxt + ": failover."); break; case FO_ERROR: System.out.println(ctxt + ": failover error gotten. Sleeping..."); // Sleep for a while try { Thread.sleep(100); } catch (InterruptedException e) { System.out.println("Thread.sleep has problem: " + e.toString()); } return FO_RETRY; default: System.out.println(ctxt + ": bad failover event."); break; } return 0; } }
Oracle® Database JDBC Developer's Guide and Reference
10g Release 2
(10.2)
http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/fstconfo.htm#CIHJBFFC
Application-level connection retries
Fast Connection Failover supports application-level connection retries. This gives the application control of responding to connection failovers. The application can choose whether to retry the connection or to rethrow the exception. TAF supports connection retries only at the OCI/Net layer.
How It Works
Under Fast Connection Failover, each connection in the cache maintains a mapping to a service, instance, database, and hostname.
When a database generates a RAC event, that event is forwarded to the JVM in which JDBC is running. A daemon thread inside the JVM receives the RAC event and passes it on to the Connection Cache Manager. The Connection Cache Manager then throws SQL exceptions to the applications affected by the RAC event.
A typical failover scenario may work like this:
-
A database instance fails, leaving several stale connections in the cache.
-
The RAC mechanism in the database generates a RAC event which is sent to the JVM containing JDBC.
-
The daemon thread inside the JVM finds all the connections affected by the RAC event, notifies them of the closed connection through SQL exceptions, and rolls back any open transactions.
-
Each individual connection receives a SQL exception and must retry.
'Web service' 카테고리의 다른 글
SelectKey in insert statement in mysql (0) | 2009.06.05 |
---|---|
Weakness of Java Web Start (0) | 2009.04.27 |
<img src="http://blogimgs.naver.com/nblog/ico_scrap01.gif" class="i_scrap" width="50" height="15" alt="본문스크랩" /> 내 Custum Tags 에서 EL을 지원하게 하기~ (0) | 2007.06.08 |
build.xml for deploying java servlet on tomcat container (0) | 2006.05.17 |
SOA & Web Services Tutorials (0) | 2006.05.16 |