티스토리 뷰
http://www.mastertheboss.com/en/jboss-application-server/82-jboss-datasource-ha.html
http://www.jboss.org/community/wiki/JBossJCADatabaseFailover
에서 참조.
This tutorial has been updated for the new release of JBoss Application Server. We'll discuss about High availability Datasources.
A High availability data source is an abstraction around a group of data sources that provides failover processing between a list of data source. High availability data sources are bound to the JNDI tree or local application context just like data sources are bound to the JNDI tree.
When you configure an HA Datasource you can choose a list of Connection URL- when the Connection you are using is not available anymore, the connection factory will (transparently to the user) choose another database connection URL, try to allocate a connection using it and, in case of success, return the connection back to the user.
Configuring an HA Datasource is a matter of a few steps:
1. Check that resource adapters are deployed
In order to use HA Datasource you need a specialized version of the Connection factory: depending if you use local or XA transaction you would need the files jboss-ha-local-jdbc.rar and jboss-ha-xa-jdbc.rar packages.
In recent versions of JBoss this files are already deployed under the "default" configuration. In older release you can find the Resource Adapters under JBOSS_HOME/docs/examples/jca
2. Create the DataSource Configuration file.
The configuration file for an HA datasource isnot much different from an ordinary datasource file, what makes the trick is the "<url-delimiter>" which separates the list of Connection-urls.
So here's a configuration for a Local HA Datasource with an Oracle driver class:
- <?xml version="1.0" encoding="UTF-8"?>
- <datasources>
- <ha-local-tx-datasource>
- <jndi-name>HADefaultDS</jndi-name>
- <!-- list of connection URLs -->
- <connection-url>jdbc:oracle:thin:@oraclehost:1521:SID|jdbc:oracle:thin:@oraclehost:1521:SID2
- </connection-url>
- <url-delimiter>|</url-delimiter>
- <!-- The driver class -->
- <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
- <user-name>user</user-name>
- <password>password</password>
- <!-- this will be run before a managed connection is removed from the pool for use by a client-->
- <check-valid-connection-sql>select count(*) from testable</check-valid-connection-sql>
- </ha-local-tx-datasource>
- </datasources>
<?xml version="1.0" encoding="UTF-8"?> <datasources> <ha-local-tx-datasource> <jndi-name>HADefaultDS</jndi-name> <!-- list of connection URLs --> <connection-url>jdbc:oracle:thin:@oraclehost:1521:SID|jdbc:oracle:thin:@oraclehost:1521:SID2 </connection-url> <url-delimiter>|</url-delimiter> <!-- The driver class --> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <user-name>user</user-name> <password>password</password> <!-- this will be run before a managed connection is removed from the pool for use by a client--> <check-valid-connection-sql>select count(*) from testable</check-valid-connection-sql> </ha-local-tx-datasource> </datasources>
If on the other hand you need to configure an XA HA Datasource, you can use the following template:
- <ha-xa-datasource>
- <jndi-name>XaHADefaultDS</jndi-name>
- <!-- This disables transaction interleaving (which BTW,most DB vendors don't support) --> <track-connection-by-tx></track-connection-by-tx>
- <isSameRM-override-value>false</isSameRM-override-value>
- <xa-datasource-class>org.jboss.test.jca.adapter.MockedXADataSource</xa-datasource-class>
- <!-- list of connection URLs -->
- <xa-datasource-property name="URL">jdbc:oracle:thin:@oraclehost:1521:SID|jdbc:oracle:thin:@oraclehost:1521:SID2</xa-datasource-property>
- <url-property>URL</url-property>
- <url-delimeter>|</url-delimeter>
- <check-valid-connection-sql>VALUES CURRENT TIMESTAMP</check-valid-connection-sql>
- </ha-xa-datasource>
<ha-xa-datasource> <jndi-name>XaHADefaultDS</jndi-name> <!-- This disables transaction interleaving (which BTW,most DB vendors don't support) --> <track-connection-by-tx></track-connection-by-tx> <isSameRM-override-value>false</isSameRM-override-value> <xa-datasource-class>org.jboss.test.jca.adapter.MockedXADataSource</xa-datasource-class> <!-- list of connection URLs --> <xa-datasource-property name="URL">jdbc:oracle:thin:@oraclehost:1521:SID|jdbc:oracle:thin:@oraclehost:1521:SID2</xa-datasource-property> <url-property>URL</url-property> <url-delimeter>|</url-delimeter> <check-valid-connection-sql>VALUES CURRENT TIMESTAMP</check-valid-connection-sql> </ha-xa-datasource>
What happens if one connection fails ?
When a Connection is no longer available JBoss warns you about it and picks up the next Connection from the list using the Round-Robin Algorithm.
15:20:01,234 WARN [HALocalManagedConnectionFactory] Failed to create connection for jdbc:oracle:thin:@oraclehost:1521:SID: IO Exception : The Network Adapter could not establish the connection |
JBoss 5 High Availability Datasource
JBoss 5 has changed the configuration for HA Datasources. You don't have anymore
<ha-local-tx-datasource> or <ha-xa-datasource> Element. Simply use a Connection URL with a list of Connections separated by an URL Delimiter.
Here's an example for an XA-Datasource:
- <datasources>
- <ha-local-tx-datasource>
- <jndi-name>jdbc/DBConnection</jndi-name>
- <connection-url>jdbc:oracle:thin:@host1:1521:db1|jdbc:oracle:thin:@host2:1521:db2</connection-url>
- <url-delimiter>|</url-delimiter>
- <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
- <user-name>scott</user-name>
- <password>tiger</password>
- <min-pool-size>5</min-pool-size>
- <max-pool-size>20</max-pool-size>
- <check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
- <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
- <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
- </ha-local-tx-datasource>
- </datasources>
<datasources> <ha-local-tx-datasource> <jndi-name>jdbc/DBConnection</jndi-name> <connection-url>jdbc:oracle:thin:@host1:1521:db1|jdbc:oracle:thin:@host2:1521:db2</connection-url> <url-delimiter>|</url-delimiter> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <user-name>scott</user-name> <password>tiger</password> <min-pool-size>5</min-pool-size> <max-pool-size>20</max-pool-size> <check-valid-connection-sql>select 1 from dual</check-valid-connection-sql> <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> </ha-local-tx-datasource> </datasources>
Also, in the new Application Server release you don't have any more jboss-ha-local-jdbc.rar and jboss-ha-xa-jdbc.rar.
The logic contained in Classes HALocalManagedConnectionFactory and HAXAManagedConnectionFactory has been transferred directly in the standard XA/Local ManagedConnectionFactory
Database Failover
Overview
Since version 4.0.2, JBoss supports database failover for local and XA datasources. What does that actually mean? It means that when a user calls javax.sql.DataSource.getConnection() and the connection to the database could not be allocated (or it was pooled and became invalid), the connection factory will (transparently to the user) choose another database connection URL, try to allocate a connection using it and, in case of success, return the connection back to the user.
This functionality is supported for both local datasources and datasources that implement XA interface.
What policy is used to select the next URL during failover?
It's sticky round-robin. It means that first we try the first connection URL in the list. If it worked, we stick to it until it fails. When it fails, we try the second one and if it worked, we stick to it. And so on. When the last URL in the list was tried and it failed, we will come back to the first URL again, then the second and so on. If for a connection request we tried all the URLs in the list and none worked, an exception will be thrown with a message saying that none of the URLs worked.
How to deploy
1. Deploy HA managed connection factories
There are special managed connection factories for datasources that support failover. These connection factories are deployed as resource adapters (RAR packaged). So, the first step is to deploy these resource adapters that are not deployed in the default configuration.
In jboss-4.0.2/docs/examples/jca directory you will find jboss-ha-local-jdbc.rar and jboss-ha-xa-jdbc.rar packages that contain resource adapters for local and XA datasources that support failover. Depending on whether you are going to use local or XA datasources, or both of them, just copy one or both of the packages to the server's deploy directory.
2. Configure the datasource for failover
Both, local and XA datasources, are configured in a -ds.xml file.
2.1. Configure local datasource for failover
The root element for local datasources that support failover is ha-local-tx-datasource which has only one new element that is not present in local-tx-datasource: url-delimeter which contains a string that is used as a delimeter between URLs in connection-url element.
For example:
<ha-local-tx-datasource>
<jndi-name>HADefaultDS</jndi-name>
<!-- list of connection URLs -->
<connection-url>jdbc:hsqldb:hsql://host1:1702|jdbc:hsqldb:hsql://host2:1703|...</connection-url>
<url-delimeter>|</url-delimeter>
<!-- The driver class -->
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<!-- The login and password -->
<user-name>sa</user-name>
<password></password>
<!-- this will be run before a managed connection is removed from the pool for use by a client-->
<check-valid-connection-sql>select count(*) from a</check-valid-connection-sql>
</ha-local-tx-datasource>
2.2. Configure XA datasource for failover
The root element for XA datasources that support failover is ha-xa-datasource. This element has two additional elements not present in xa-datasource. The first is url-property which defines the name of an xa-datasource-property that contains the list of URLs. And the second one is url-delimeter the definition of which is exactly the same as for the ha-local-tx-datasource.
For example:
<ha-xa-datasource>
<jndi-name>MockedHaXaDS</jndi-name>
<track-connection-by-tx></track-connection-by-tx>
<isSameRM-override-value>false</isSameRM-override-value>
<xa-datasource-class>org.jboss.test.jca.adapter.MockedXADataSource</xa-datasource-class>
<!-- list of connection URLs -->
<xa-datasource-property name="URL">haXaUrl1|haXaUrl2</xa-datasource-property>
<url-property>URL</url-property>
<url-delimeter>|</url-delimeter>
<check-valid-connection-sql>VALUES CURRENT TIMESTAMP</check-valid-connection-sql>
</ha-xa-datasource>
Note: both examples include <check-valid-connection-sql>. Checking whether the connection is valid before it is given to the caller is required for transparent failover.
Tests
Testcases for this functionality can be found in JBoss' testsuite in org.jboss.test.jca.test.HAConnectionFactoryUnitTestCase.
4.2 Changes
As of JBoss 4.2.x the url-delimeter property has been updated to fix the typo. The property is now correctly named url-delimiter.
'데이터베이스 > CUBRID FAQ' 카테고리의 다른 글
CUBRID cast 주의 사항 (0) | 2010.01.14 |
---|---|
데이터 타입 테스트 케이스 (0) | 2010.01.07 |
auto increment 사용시 주의 사항 (0) | 2009.12.22 |
glo 사용시 loaddb 주의 사항 (0) | 2009.11.12 |
- Total
- Today
- Yesterday
- 퇴사
- oracle
- 튜닝
- shared all
- getGeneratedKeys
- Datapump
- 오라클
- shared everything
- 브레인피드백
- 바이오해킹
- 일본전산
- 구조주의 인류학
- 꿈
- 디자인패턴
- 아웃라이어
- 성공의길
- 구글
- 습관의힘
- 프로젝트
- 커뮤니케이션의 7가지 나쁜 습관들
- 셀프 조인
- 카이에 소바주 시리즈
- auto increment
- 데이터과학
- ChatGPT
- 다짐
- NHN 면접
- CUBRID
- DB
- 큐브리드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |