You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Kief Morris <ki...@bitbull.com> on 2001/01/13 05:13:46 UTC

[PATCHES] Catalina 4.1 Session Persistence

These patches are my proposal for session persistence in Catalina 4.1. Please
look these over and give me your comments, and commit them if they look OK.

The main change is the addition of a PersistentManager class, an optional replacement
for StandardManager, providing the following configurable functionality:

- Saves sessions to a Store on shutdown, loads on restart. This is currently implemented 
  in StandardManager, but PersistentManager makes use of the Store interface.
- Swaps sessions out to a Store if the number in memory exceeds maxActiveSessions,
  to better manage resources. A minIdleSwap property prevents sessions from being
  swapped out if they haven't been idle for very long, to avoid thrashing.
- Swaps sessions out to a Store if they are idle for too long. With this feature, an app
  can have very long session expiration times without over-burdening memory.
- Backs sessions up to Store (but keeps them in memory) if they are idle for too long.
  This provides basic fault tolerance, since the sessions will be read in from the Store
  when the server starts after a crash. NOT IMPLEMENTED YET! There is an issue
  regarding the Servlet 2.3 specification which I will discuss below.

To test this out, see the server.xml file - there is a section to uncomment and tweak
the configuration.

ISSUES:
----------------------------------------

- Backing up Sessions: I believe that HttpSessionActivationListeners should be notified
  when sessions are being backed up and restored. However, application developers
  reading the Servlet 2.3 specification [PFD] might not expect a session to remain
  in active use after the sessionWillPassivate() method is called. I would like to get 
  some feedback on this.

- I still have not figured out how to get Catalina to instantiate the Store class for me,
  this patch hard-codes the use of FileStore in PersistentManager. I've tried mucking
  around in startup/Catalina.java, to no avail. Can anyone help me out with this?

- There is a lot of duplication of code between PersistentManager and StandardManager.
  Maybe this should be moved to ManagerBase?

- The use of Session/StandardSession is very messy in ManagerBase, StandardManager, 
  and now PersistentManager. Although some code uses the Session interface and executes
  StandardSession-specific code only after testing, much of this code will break if an
  alternative implementation is used (essential properties aren't set, etc.), and some
  code has StandardSession hard-coded without tests. 
      It looks as if someone had good intentions to make it possible to replace StandardSession 
  with a different implementation, but it hasn't been followed through, so it's just a mess.
  This means I can't create a PersistentSession class and keep persistence-related code
  out of StandardSession, which is too bad. 
      Fixing this will require a fair amount of refactoring.

- While developing apps you would sometimes like to wipe out all of the sessions,
  which is a bit awkward to do with persistence enabled because the server saves
  and restores them on restarts. Currently you would have to change the server.xml 
  configuration for PersistentManager to disable all persistence and backups, and then 
  it will clear out the Store when you restart. You can manually delete them from the 
  directory used by FileStore, but this won't work with other Store implementations.
      Ideally there should be a command line argument which causes the Store to be 
  cleared.

PATCH COMMENTS
----------------------------------------

Store.java
----------------------------------------
- Added getManager(), setManager(), and clear() methods.

FileStore.java
----------------------------------------
- Implemented Store functionality, sessions are serialized one per file.

PersistentManager
----------------------------------------
- Implemented persistence across server restarts
- Implemented swapping out of sessions to manage resources, based on
  the number of sessions in memory and idle times.
- Stubs for backing up of sessions based on idle times, not yet implemented.

server.xml
----------------------------------------
- Added a commented out section to enable and configure PersistentManager

LocalStrings.properties
----------------------------------------
- Added strings for logging by FileStore and PersistentManager.


Regards,
Kief