Channels ▼
RSS

Design

JDBC Fast Connection Failover with Oracle RAC


Michael Pilone is a senior software engineer for Vangent where he is currently working on Java-based web service technologies and large scale geographical data indexing and searching.


It wasn't too long ago when it would be common to see a notice on your favorite website that it is "Currently Down for Scheduled Maintenance". However, with the push toward all data in the cloud and more web "applications" over the past few years, users are demanding constant availability and access to data and resources. Just look at the Internet outcries when Twitter or Google gmail goes down for more than a few minutes and you can understand the importance of building highly available systems. In this article, I present examples of how to configure and test Java web service and enterprise applications to leverage Oracle Real Application Clusters (RAC), Oracle Universal Connection Pool (UCP), and Fast Connection Failover (FCF) to provide high availability.

Oracle RAC is a clustering solution that allows you to present multiple interconnected Oracle databases as one server to the end user or applications. Oracle RAC uses Oracle Clusterware to link together multiple servers to create one large single database. Normally there is a one-to-one relationship of an Oracle database to an instance when running on a single server; however in a RAC environment, there is a one-to-many relationship where a single database is simultaneously hosted on multiple instances. The obvious advantage is that any one of the instances could fail while the database remains available on the other instances in the cluster. There are other advantages to RAC, including performance scaling and workload distribution, however a full discussion of RAC is beyond the scope of this article. For more information, refer to the Oracle Real Application Clusters Administration and Deployment Guide.

With Oracle RAC in place, database client applications can leverage a number of high availability features including:

  • Fast Connection Failover (FCF): Allows a client application to be immediately notified of a planned or unplanned database service outage by subscribing to Fast Application Notification (FAN) events.
  • Run-time Connection Load-Balancing: Uses the Oracle RAC Load Balancing Advisory events to distribute work appropriately across the cluster nodes and to quickly react to changes in cluster configuration, overworked nodes, or hangs.
  • Connection Affinity (11g recommended/required): Routes connections to the same database instance based on previous connections to an instance to limit performance impacts of switching between instances. RAC supports web session and transaction-based affinity for different client scenarios.

These features are enabled in a Java application through the use of the Oracle Universal Connection Pool (UCP) and, other than configuration, require no special support code.

Oracle Server Environment

Before any high availability (HA) work can be done on the client side, a few key Oracle server components must be in place. This article is not meant to be a guide to installing and configuring Oracle RAC (there are many books on the subject) but there are a few key features that must be enabled by your database administrator (DBA).

Obviously the RAC environment must have at least two nodes available for testing. Your DBA will give you the hostnames for these nodes but you can assume that they will be something like "sales1node1" and "sales1node2". These are the two hosts that your Java client will connect to and therefore need to be running the standard Oracle listener process. Your DBA should be able to tell you the port number that the listeners are bound to (usually 1521).

Oracle databases are represented to clients as a service. A single database can have multiple services associated with it which are defined by service names, such as sales.foo.com or finance.foo.com. The service names should not be confused with the listener host names even though a service name may look like a host or domain name. In a RAC environment, different instances in the cluster can offer the same service to clients which allows for failover if one instance goes down, distribution of load based on the capabilities of the hardware, and service migration for planned downtime. Therefore it is important that the service name and not the instance name (i.e., Oracle System Identifier (SID)) is used when configuring the client. Figure 1 shows how two different instances (sales 1 and sales 2) can both offer the same service (sales.foo.com) while only one instance (sales 2) is offers a second service (finance.foo.com).

Figure 1: Oracle RAC attempts to distribute the load by sending Runtime Load-Balance Advisory FAN events to clients. The UCP will rebalance the pooled connections based on the advisory events

The Oracle RAC Load Balancing Advisory must be configured with service-level goals for each service for which load balancing is enabled. Enabling the advisory allows the RAC nodes to advise clients on how to distribute work across the cluster to ensure optimal use of resources and to avoid slow, hung, or down nodes. The Oracle Real Application Clusters Administration and Deployment Guide contains the details for configuring the advisory but the basic process is to execute a SQL statement that associates a load balancing goal with a service such as:


EXECUTE DBMS_SERVICE.MODIFY_SERVICE (service_name => 'sales' -, goal =>  
   DBMS_SERVICE.GOAL_THROUGHPUT -, clb_goal =>  DBMS_SERVICE.CLB_GOAL_SHORT);

The final server side piece is the setup of the Oracle Notification Service (ONS) which propagates Fast Application Notification (FAN) events between the Oracle RAC database and the JDBC connection pool. On the client side, ONS can be configured in a local or remote configuration with remote being preferred because it eliminates the need for a local ONS server process on the client machine. To support remote connections to the ONS server, the DBA must modify the ons.config file on the database servers to set the remoteport and the list of ONS nodes. Your DBA should be able to tell you the remote port to use when configuring remote ONS support on the client side.

Now that the Oracle server side setup is complete and you obtained all the needed information from a DBA, you can test the FCF and ONS setups and configure the JDBC clients.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video