Implementing a Failover Mechanism for Your Clustered Servlets and JSPs


A clustered WebLogic Server provides high availability for servlets and JSPs (in the Presentation tier ) by transparently replicating client session data contained in HttpSession objects via in-memory replication or file-based or JDBC-based persistence. The following sections discuss each of these HTTP session state failover mechanisms.

In-Memory Replication

With in-memory replication, a primary HttpSession object is created on the clustered managed server to which the client first connects and accesses a servlet or JSP. To support automatic failover for HTTP session states, a clustered managed server replicates the primary HttpSession object in memory to a secondary managed server in the same WebLogic cluster. The replicated HttpSession object is known as the replica or backup HttpSession object. As session data is modified in the primary HttpSession object, the managed server ensures the replica is kept up to date so that it may be used if the clustered managed server that hosts the primary HttpSession object fails.

If the managed server hosting a primary HttpSession object were to fail, the mechanism that a WebLogic cluster uses to provide transparent session state failover is dependent on the type of load-balancing solution that is being used: a WebLogic proxy plug-in or hardware appliance.

In the case of a load-balancing solution that uses a WebLogic proxy plug-in and client-side WebLogic Server cookies, the proxy plug-in uses the cookie information to automatically redirect subsequent HTTP requests to the clustered server hosting the replica HttpSession object. The replica HttpSession object is then upgraded to the primary HttpSession object, and a replica HttpSession object is created on another managed server in the WebLogic cluster. In the HTTP response, the proxy server updates the client's cookie to reflect the new primary and secondary servers as a safeguard for subsequent HttpSession object failovers.

Note

If URL rewriting is used, the proxy server extracts the session ID and the primary and secondary HttpSession object servers from the inbound client URL.


In the case of a load-balancing solution that uses a hardware appliance, the primary and replica HttpSession object locations in a cookie or URL serve only as a history for a client's session state locations. Because the hardware appliance will redirect the failed HTTP request to any available managed server in a WebLogic cluster based on a certain algorithm, the WebLogic cluster uses the replica to create a new primary HttpSession object on the newly targeted managed server. Hence, the replica HttpSession object remains as the replica. The new information about the primary HttpSession object location is updated in the client's cookie, or via URL rewriting.

Configuring In-Memory Replication

The type of session state persistence you are going to implement is specified in the WebLogic Deployment Descriptor ( weblogic.xml ) file for a deployed Web application via the PersistentStoreType parameter. To specify in-memory replication for a Web application, edit the weblogic.xml file using an XML editor and set the value of this parameter to replicated as follows :

 
 <session-descriptor> <session-param> <param-name>PersistentStoreType</param- name > <param-value>replicated</param-value> </session-param> </session-descriptor> 

Tip

You can also use the Administration Console to modify the weblogic.xml file for a deployed Web application.


Configuring Replication Groups to Specify Replica Object Servers

When a primary HttpSession object is created, it is the responsibility of the hosting managed server to rank other managed servers within the same WebLogic cluster to determine which server will host the replica HttpSession object. By default, a managed server will attempt to create the replica HttpSession object on a different machine than the one that hosts the primary HttpSession object.

Through the configuration of replication groups, however, you can influence the location of the replica HttpSession objects. A replication group is a list of clustered managed servers within the same WebLogic cluster that serve as preferred locations for replica HttpSession objects.

You can use the Administration Console, as shown in Figure 25.19, to assign a clustered managed server to

Figure 25.19. Configuring replication groups using the Administration Console.

graphics/25fig19.gif

  • A replication group, which defines a preferred logical group of clustered managed servers for hosting the replica HttpSession objects

  • A preferred secondary group, which defines a secondary logical group of clustered managed servers that can be considered for hosting the replica HttpSession objects

How a managed server ranks other managed servers in a WebLogic cluster is described in Table 25.2.

Table 25.2. The Ranking Rules for Selecting a Host for a Replica HttpSession Object

Server Rank

Managed Server Resides Physically on Another Machine

Managed Server Is a Member of the Preferred Replication Group

1

Yes

Yes

2

No

Yes

3

Yes

No

4

No

No

Using the rules described in Table 25.2, the primary managed server ranks other members of the cluster and selects the highest-ranked server to host the replica HttpSession object.

Demonstrating the In-Memory Replication of Session State

The quickest way to verify whether your WebLogic cluster is providing session state failover using in-memory replication in conjunction with your load-balancing solution is to build and deploy the inmemrep Web application, which comes bundled with WebLogic Server if you opted to install the WebLogic Server examples during the server's installation process.

Note

You need to install the WebLogic Server examples to deploy the inmemrep Web application code.


The following steps describe how to build and deploy the inmemrep Web application to the WebLogic cluster (mycluster) you configured earlier in this chapter:

  1. Open a new command shell and set up your WebLogic environment by executing the setEnv command from the root of your domain's (objectmind) directory.

  2. Change directories to the following:

       
      %  wl_home  %\samples\server\src\examples\cluster\sessionrep\inmemrep  
  3. Use the build script to compile the Web application by executing the ant command. This process builds both the JSP and deployment descriptors and packages them in a WAR file named InMemRepClient.war .

  4. From the Administration Console, click the Application link under the Deployments node in the left pane and click the Configure a New Application link.

  5. Use the links at the bottom of the page to navigate to the location of the InMemRepClient.war file and click the Select link next to the InMemRepClient.war filename.

  6. Select the cluster that was previously created (mycluster) as your target for deployment and click Configure and Deploy.

When the InMemRepClient Web application is deployed, you can access it by navigating to the following URL in a Web browser:

 
 http://  ip_address_of_proxy  :  port_of_proxy  /InMemRepClient/Session.jsp. 

You can add some values to the JSP, as shown in Figure 25.20, and bring down the clustered server from which you just requested the JSP. Now you can refresh the browser to demonstrate in-memory session persistence. You will notice the session is now hosted on another machine.

Figure 25.20. The InMemRepClient Web application demonstrating in-memory session persistence.

graphics/25fig20.jpg

File-Based Persistent Storage

File-based persistence implies that you will be using a system directory to store all the session information related to your Web application. The requirements for using this type of session persistence mechanism are as follows:

  • The system directory must be shared and available to each managed server in the WebLogic cluster.

  • You must have enough disk space to store the session information (the number of valid sessions multiplied by the size of each session).

To specify file-based persistent session storage for a Web application, edit the associated weblogic.xml file using an XML editor and set the value of the PersistentStoreType and PersistentStoreDir parameters as follows:

 
 <session-descriptor> <session-param> <param-name>PersistentStoreType</param-name> <param-value>file</param-value> <param-name>PersistentStoreDir</param-name> <param-value>  your  _  shared  _  folder_name  </param-value> </session-param> </session-descriptor> 

Here, your_shared_folder_name specifies the directory path where the clustered managed servers will write and retrieve their respective session's data.

Using the file-based persistence approach allows all managed server instances in a WebLogic cluster to have access to all the generated session data. Hence, client HTTP requests can be serviced by any managed server in a WebLogic cluster. The HttpSession object can fail over to any clustered server in a WebLogic cluster and still have access to its session state data.

However, there is a significant reduction in the WebLogic cluster's performance using this approach because session state is continuously being written to the disk system, and session data needs to be retrieved from the disk upon session failover. Also, an added concern is that if you lose the disk system where the session is persisted , you also lose all your session data.

JDBC-Based Persistent Storage

JDBC-based persistence is similar to file-based persistence because it also allows all managed server instances in a WebLogic cluster to have access to all the generated session data, with the exception that the session data is now persisted to database instead of a file system. The advantage of using a database for storing persistent session storage is that you can leverage the high-availability, scalability, and high-performance features of a database to safeguard as well as provide performance-based writing and retrieval of session data. However, this method of session persistence is still not as fast as in-memory replication.

To specify JDBC-based persistent session storage for a Web application, follow these steps:

  1. Create a table named wl_servlet_sessions in the database using the column and data type information described in Table 25.3.

    Table 25.3. The Column and Data Type Information for the wl_servlet_sessions Table

    Column Name

    Data Type

    wl_id (primary key)

    Variable-width alphanumeric column, up to 100 characters

    wl_context_path (primary key)

    Variable-width alphanumeric column, up to 100 characters

    wl_is_new

    Single-character column

    wl_create_time

    20-digit numeric column

    wl_is_valid

    Single-character column

    wl_session_values

    Large binary column

    wl_access_time

    20-digit numeric column

    wl_max_inactive_interval

    Integer column

  2. Assign a connection pool that has read/write permissions to the wl_servlet_sessions database table to your WebLogic cluster.

  3. Assign the connection pool's associated data source to the same cluster.

  4. Edit the associated weblogic.xml file using an XML editor and set the value of the PersistentStoreType and PersistentStorePool parameters as follows:

       
      <session-descriptor> <session-param> <param-name>PersistentStoreType</param-name> <param-value>jdbc</param-value> <param-name>PersistentStorePool</param-name> <param-value>  Connection_Pool_Name  </param-value> </session-param> </session-descriptor>  

Here, Connection_Pool_Name specifies the JDBC connection pool to be used for persistence storage.

Caution

When connection pools are targeted to a WebLogic cluster, the number of database connections will be multiplied, because the connection pool will exist on each managed server in the cluster.




BEA WebLogic Platform 7
BEA WebLogic Platform 7
ISBN: 0789727129
EAN: 2147483647
Year: 2003
Pages: 360

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net