Sun GlassFish Enterprise Server v2.1.1 High Availability Administration Guide

Chapter 9 Configuring High Availability Session Persistence and Failover

This chapter explains how to enable and configure high availability session persistence.

Overview of Session Persistence and Failover

Enterprise Server provides high availability session persistence through failover of HTTP session data and stateful session bean (SFSB) session data. Failover means that in the event of an server instance or hardware failure, another server instance takes over a distributed session.

Requirements

A distributed session can run in multiple Sun GlassFish Enterprise Server instances, if:

Restrictions

When a session fails over, any references to open files or network connections are lost. Applications must be coded with this restriction in mind.

You can only bind certain objects to distributed sessions that support failover. Contrary to the Servlet 2.4 specification, Sun GlassFish Enterprise Server does not throw an IllegalArgumentException if an object type not supported for failover is bound into a distributed session.

You can bind the following objects into a distributed session that supports failover:

You cannot bind the following object types into sessions that support failover:

In general, for these objects, failover will not work. However, failover might work in some cases, if for example the object is serializable.

Setting Up High Availability Session Persistence

This section explains how to set up high availability session persistence, with the following topics:

ProcedureTo Set Up High Availability Session Persistence

Before You Begin

High availability session persistence is incompatible with dynamic deployment, dynamic reloading, and autodeployment. These features are for development, not production environments, so you must disable them before enabling HA session persistence. For information about how to disable these features, see Sun GlassFish Enterprise Server v2.1.1 Application Deployment Guide.

  1. Create an Enterprise Server cluster.

    For more information, see To Create a Cluster .

  2. If you are using HADB to store session state data, create an HADB database for the cluster.


    Note –

    The HADB software is supplied with the Enterprise Server standalone distribution of Sun GlassFish Enterprise Server. For information about available distributions of Sun GlassFish Enterprise Server, see Distribution Types and Their Components in Sun GlassFish Enterprise Server v2.1.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server v2.1.1 Administration Guide.


    If you are using in-memory replication on other servers in the cluster for session state data, omit this step.

    For more information about creating an HADB database, see configure-ha-cluster(1).

  3. Set up load balancing for the cluster.

    For more information , see Setting Up HTTP Load Balancing .

  4. Enable availability for the desired application server instances and web or EJB containers.

    Then configure the session persistence settings. Choose one of these approaches:

  5. Restart each server instance in the cluster.

    If the instance is currently serving requests, quiesce the instance before restarting it so that the instance gets enough time to serve the requests it is handling. For more information, see Disabling (Quiescing) a Server Instance or Cluster

  6. Enable availability for any specific SFSB that requires it.

    Select methods for which checkpointing the session state is necessary. See Configuring Availability for an Individual Bean

  7. Make each web module distributable if you want it to be highly available.

  8. Enable availability for individual applications, web modules, or EJB modules during deployment.

    See Configuring Availability for an Individual Application or EJB Module

    In the Administration Console, check the Availability Enabled box, or use the asadmin deploy command with the --availabilityenabled option set to true.

Enabling Session Availability

You can enable session availability at five different scopes (from highest to lowest):

  1. Server instance, enabled by default. Enabling session availability for the server instance means that all applications running on the server instance can have high-availability session persistence. For instructions, see next section, Enabling Availability for a Server Instance .

  2. Container (web or EJB), enabled by default. For information on enabling availability at the container level, see:

  3. Application, disabled by default.

  4. Standalone web or EJB module, disabled by default.

  5. Individual SFSB, disabled by default.

To enable availability at a given scope, you must enable it at all higher levels as well. For example, to enable availability at the application level, you must also enable it at the server instance and container levels.

The default for a given level is the setting at the next level up. For example, if availability is enabled at the container level, it is enabled by default at the application level.

When availability is disabled at the server instance level, enabling it at any other level has no effect. When availability is enabled at the server instance level, it is enabled at all levels unless explicitly disabled.

Enabling Availability for a Server Instance

To enable availability for a server instance, use the asadmin set command to set the configuration’s availability-service.availability-enabled property to true.

For example, if config1 is the configuration name:


asadmin set --user admin --passwordfile password.txt 
--host localhost 
--port 4849 
config1.availability-service.availability-enabled="true"

ProcedureTo Enable Availability for the Server Instance with Admin Console

  1. In the tree component, expand the Configurations node.

  2. Expand the node for the configuration you want to edit.

  3. Select the Availability Service node.

  4. In the Availability Service page, enable instance level availability by checking the Availability Service box.

    To disable it, uncheck the box.

    Additionally, you can change the Store Pool Name if you changed the JDBC resource used for connections to the HADB for session persistence. For details, see configure-ha-cluster(1).


    Note –

    The HADB software is supplied with the Enterprise Server standalone distribution of Sun GlassFish Enterprise Server. For information about available distributions of Sun GlassFish Enterprise Server, see Distribution Types and Their Components in Sun GlassFish Enterprise Server v2.1.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server v2.1.1 Administration Guide.


  5. Click on the Save button.

  6. Stop and restart the server instance.

HTTP Session Failover

Java EE applications typically have significant amounts of session state data. A web shopping cart is the classic example of session state. Also, an application can cache frequently-needed data in the session object. In fact, almost all applications with significant user interactions need to maintain session state.

Configuring Availability for the Web Container


Note –

The HADB software is supplied with the Enterprise Server standalone distribution of Sun GlassFish Enterprise Server. For information about available distributions of Sun GlassFish Enterprise Server, see Distribution Types and Their Components in Sun GlassFish Enterprise Server v2.1.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server v2.1.1 Administration Guide.


If you are using HADB, enable and configure web container availability by using the asadmin configure-ha-persistence. For more information about this command, see configure-ha-persistence(1).

Alternatively, use the asadmin set command to set the configuration’s availability-service.web-container-availability.availability-enabled property to true and then configure-ha-persistence to set properties as desired.


Note –

If you are using in-memory replication to store session state data, you must use the asadmin set command to enable web container availability and to set properties. You can use the configure-ha-persistence command only with HADB.


For example, use the set command as follows, where config1 is the configuration name:


asadmin set 
config1.availability-service.web-container-availability.availability-enabled="true"

asadmin set 
config1.availability-service.web-container-availability.persistence-frequency="time-based"

Or use the set and configure-ha-persistence commands as follows, where config1 is the configuration name:


asadmin set 
config1.availability-service.web-container-availability.availability-enabled="true"
asadmin configure-ha-persistence --user admin --passwordfile secret.txt 
--type ha 
--frequency web-method 
--scope modified-session 
--store jdbc/hastore 
--property maxSessions=1000:reapIntervalSeconds=60 cluster1

ProcedureTo Enable Availability for the Web Container with Admin Console

  1. In the tree component, select the desired configuration.

  2. Click on Availability Service.

  3. Select the Web Container Availability tab.

    Check the Availability Service box to enable availability. To disable it, uncheck the box.

  4. Change other settings, as described in the following section, Web Container Availability Settings

  5. Restart the server instance.

Web Container Availability Settings


Note –

The HADB software is supplied with the Enterprise Server standalone distribution of Sun GlassFish Enterprise Server. For information about available distributions of Sun GlassFish Enterprise Server, see Distribution Types and Their Components in Sun GlassFish Enterprise Server v2.1.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server v2.1.1 Administration Guide.


The Web Container Availability tab of the Availability Service enables you to change these availability settings:

Persistence Type: Specifies the session persistence mechanism for web applications that have availability enabled. Allowed values are memory (no persistence) file (the file system), ha (HADB), and replicated (memory on other servers).

HADB must be configured and enabled before you can use ha session persistence. For configuration details, see configure-ha-cluster(1).

If web container availability is enabled, the default persistence type depends on the profile, as shown in the following table.

Profile 

Persistence Type 

Developer 

memory

Cluster 

replicated

Enterprise 

ha

For production environments that require session persistence, use ha or replicated. The memory persistence type and the file persistence type do not provide high availability session persistence.

If web container availability is disabled, the default persistence type memory.

Persistence Frequency: Specifies how often the session state is stored. Applicable only if the Persistence Type is ha or replicated. Allowed values are:

Persistence Scope : Specifies how much of the session object and how often session state is stored. Applicable only if the Persistence Type is ha or replicated. Allowed values are as follows:

Single Sign-On State: Check this box to enable persistence of the single sign-on state. To disable it, uncheck the box. For more information, see Using Single Sign-on with Session Failover

HTTP Session Store: You can change the HTTP Session Store if you changed the JDBC resource used for connections to the HADB for session persistence. For details, see configure-ha-cluster(1).

Configuring Availability for Individual Web Applications

To enable and configure availability for an individual web application, edit the application deployment descriptor file, sun-web.xml. The settings in an application’s deployment descriptor override the web container’s availability settings.

The session-manager element’s persistence-type attribute determines the type of session persistence an application uses. It must be set to ha or replicated to enable high availability session persistence.

For more information about the sun-web.xml file, see The sun-web.xml File in Sun GlassFish Enterprise Server v2.1.1 Application Deployment Guide.

Example

<sun-web-app> ... 
  <session-config> 
    <session-manager persistence-type="replicated"> 
      <manager-properties> 
        <property name="persistenceFrequency" value="web-method" /> 
      </manager-properties> 
      <store-properties> 
        <property name="persistenceScope" value="session" /> 
      </store-properties> 
    </session-manager> ... 
</session-config> ...

Using Single Sign-on with Session Failover

In a single application server instance, once a user is authenticated by an application, the user is not required to re-authenticate individually to other applications running on the same instance. This is called single sign-on. For more information, see User Authentication for Single Sign-on in Sun GlassFish Enterprise Server v2.1.1 Developer’s Guide.

For this feature to continue to work even when an HTTP session fails over to another instance in a cluster, single sign-on information must be persisted using in-memory replication or the HADB. To persist single sign-on information, first, enable availability for the server instance and the web container, then enable single-sign-on state failover.


Note –

The HADB software is supplied with the Enterprise Server standalone distribution of Sun GlassFish Enterprise Server. For information about available distributions of Sun GlassFish Enterprise Server, see Distribution Types and Their Components in Sun GlassFish Enterprise Server v2.1.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server v2.1.1 Administration Guide.


You can enable single sign-on state failover with the Admin Console in the Web Container Availability tab of the Availability Service, as described in Configuring Availability for the Web Container. You can also use the asadmin set command to set the configuration’s availability-service.web-container-availability.sso-failover-enabled property to true.

For example, use the set command as follows, where config1 is the configuration name:

asadmin set --user admin --passwordfile password.txt 
--host localhost --port 4849 
config1.availability-service.web-container-availability.
sso-failover-enabled="true"

Single Sign-On Groups

Applications that can be accessed through a single name and password combination constitute a single sign-on group. For HTTP sessions corresponding to applications that are part of a single sign-on group, if one of the sessions times out, other sessions are not invalidated and continue to be available. This is because time out of one session should not affect the availability of other sessions.

As a corollary of this behavior, if a session times out and you try to access the corresponding application from the same browser window that was running the session, you are not required to authenticate again. However, a new session is created.

Take the example of a shopping cart application that is a part of a single sign-on group with two other applications. Assume that the session time out value for the other two applications is higher than the session time out value for the shopping cart application. If your session for the shopping cart application times out and you try to run the shopping cart application from the same browser window that was running the session, you are not required to authenticate again. However, the previous shopping cart is lost, and you have to create a new shopping cart. The other two applications continue to run as usual even though the session running the shopping cart application has timed out.

Similarly, suppose a session corresponding to any of the other two applications times out. You are not required to authenticate again while connecting to the application from the same browser window in which you were running the session.


Note –

This behavior applies only to cases where the session times out. If single sign-on is enabled and you invalidate one of the sessions using HttpSession.invalidate() , the sessions for all applications belonging to the single sign-on group are invalidated. If you try to access any application belonging to the single sign-on group, you are required to authenticate again, and a new session is created for the client accessing the application.


Stateful Session Bean Failover

Stateful session beans (SFSBs) contain client-specific state. There is a one-to-one relationship between clients and the stateful session beans. At creation, the EJB container gives each SFSB a unique session ID that binds it to a client.

An SFSB’s state can be saved in a persistent store in case a server instance fails. The state of an SFSB is saved to the persistent store at predefined points in its life cycle. This is called checkpointing. If enabled, checkpointing generally occurs after the bean completes any transaction, even if the transaction rolls back.

However, if an SFSB participates in a bean-managed transaction, the transaction might be committed in the middle of the execution of a bean method. Since the bean’s state might be undergoing transition as a result of the method invocation, this is not an appropriate time to checkpoint the bean’s state. In this case, the EJB container checkpoints the bean’s state at the end of the corresponding method, provided the bean is not in the scope of another transaction when that method ends. If a bean-managed transaction spans across multiple methods, checkpointing is delayed until there is no active transaction at the end of a subsequent method.

The state of an SFSB is not necessarily transactional and might be significantly modified as a result of non-transactional business methods. If this is the case for an SFSB, you can specify a list of checkpointed methods, as described in Specifying Methods to Be Checkpointed

If a distributable web application references an SFSB, and the web application’s session fails over, the EJB reference is also failed over.

If an SFSB that uses session persistence is undeployed while the Enterprise Server instance is stopped, the session data in the persistence store might not be cleared. To prevent this, undeploy the SFSB while the Enterprise Server instance is running.

Configuring Availability for the EJB Container

ProcedureTo Enable Availability for the EJB Container

  1. Select the EJB Container Availability tab.

  2. Check the Availability Service box.

    To disable availability, uncheck the box.

  3. Change other settings as described in Availability Settings

  4. Click on the Save button.

  5. Restart the server instance.

Equivalent asadmin command

To enable availability for the EJB container use the asadmin set command to set the following three properties for the configuration:

For example, if config1 is the configuration name, use the following commands:

asadmin set --user admin --passwordfile password.txt --host localhost --port 4849config1.availability-service.ejb-container-availability.availability-enabled="true"

asadmin set --user admin --passwordfile password.txt --host localhost --port 4849config1.availability-service.ejb-container-availability.sfsb-persistence-type="file"

asadmin set --user admin --passwordfile password.txt --host localhost --port 4849config1.availability-service.ejb-container-availability.sfsb-ha-persistence-type="replicated"

Availability Settings


Note –

The HADB software is supplied with the Enterprise Server standalone distribution of Sun GlassFish Enterprise Server. For information about available distributions of Sun GlassFish Enterprise Server, see Distribution Types and Their Components in Sun GlassFish Enterprise Server v2.1.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server v2.1.1 Administration Guide.


The EJB Container Availability tab of the Availability Service enables you to change these settings:

HA Persistence Type: Specifies the session persistence and passivation mechanism for SFSBs that have availability enabled. Allowed values are file (the file system), ha (HADB), and replicated (memory on other servers). The default value is ha if HADB is installed, and otherwise replicated. For production environments that require session persistence, use ha or replicated.

SFSB Persistence Type: Specifies the passivation mechanism for SFSBs that do not have availability enabled. Allowed values are file (the default), ha, and replicated.

If either Persistence Type is set to file, the EJB container specifies the file system location where the passivated session bean state is stored. Checkpointing to the file system is useful for testing but is not for production environments. For information about configuring store properties, see the Admin Console online help.

HA persistence enables a cluster of server instances to recover the SFSB state if any server instance fails. The HA store is also used as the passivation and activation store. Use this option in a production environment that requires SFSB state persistence. For more information about HADB, see configure-ha-cluster(1).

SFSB Store Pool Name: You can change the SFSB Store Pool Name if you changed the JDBC resource used for connections to the HADB for session persistence. For details, see configure-ha-cluster(1).

Configuring the SFSB Session Store When Availability Is Disabled

If availability is disabled, the local file system is used for SFSB state passivation, but not persistence. To change where the SFSB state is stored, change the Session Store Location setting in the EJB container. For information about configuring store properties, see the Admin Console online help.

Configuring Availability for an Individual Application or EJB Module

You can enable SFSB availability for an individual application or EJB module during deployment:

Configuring Availability for an Individual Bean

To enable availability and select methods to be checkpointed for an individual SFSB, use the sun-ejb-jar.xml deployment descriptor file. .

To enable high availability session persistence, set availability-enabled="true" in the ejb element. To control the size and behavior of the SFSB cache, use the following elements:

For more information about sun-ejb-jar.xml, see The sun-ejb-jar.xml File in Sun GlassFish Enterprise Server v2.1.1 Application Deployment Guide.


Example 9–1 Example of an EJB Deployment Descriptor With Availability Enabled

<sun-ejb-jar>
    ...
    <enterprise-beans>
        ...
        <ejb availability-enabled="true">
            <ejb-name>MySFSB</ejb-name>
        </ejb>
        ...
    </enterprise-beans>
</sun-ejb-jar>

Specifying Methods to Be Checkpointed

If enabled, checkpointing generally occurs after the bean completes any transaction, even if the transaction rolls back. To specify additional optional checkpointing of SFSBs at the end of non-transactional business methods that cause important modifications to the bean’s state, use the checkpoint-at-end-of-method element in the ejb element of the sun-ejb-jar.xml deployment descriptor file.

The non-transactional methods in the checkpoint-at-end-of-method element can be:


Note –

If an SFSB does not participate in any transaction, and if none of its methods are explicitly specified in the checkpoint-at-end-of-method element, the bean’s state is not checkpointed at all even if availability-enabled="true" for this bean.

For better performance, specify a small subset of methods. The methods should accomplish a significant amount of work or result in important modification to the bean’s state.



Example 9–2 Example of EJB Deployment Descriptor Specifying Methods Checkpointing

<sun-ejb-jar>
    ...
    <enterprise-beans>
        ...
        <ejb availability-enabled="true">
            <ejb-name>ShoppingCartEJB</ejb-name>
            <checkpoint-at-end-of-method>
                <method>
                    <method-name>addToCart</method-name>
                </method>
            </checkpoint-at-end-of-method>
        </ejb>
        ...
    </enterprise-beans>
</sun-ejb-jar>