Issue Details (XML | Word | Printable)

Key: JCR-245
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jukka Zitting
Reporter: Jukka Zitting
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Jackrabbit Content Repository

Automatic repository shutdown

Created: 06/Oct/05 08:05 PM   Updated: 08/Mar/06 01:24 AM
Return to search
Component/s: jackrabbit-core
Affects Version/s: None
Fix Version/s: 1.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works TransientRepository.patch 2005-12-07 08:38 AM Jukka Zitting 9 kB
Issue Links:
Reference
 

Resolution Date: 09/Dec/05 06:53 PM


 Description  « Hide
Currently Jackrabbit relies on two mechanisms for safely shutting down a repository:

    1) client application invoking RepositoryImpl.shutdown(), or
    2) the shutdown hook installed by RepositoryImpl being run

Both of these mechanisms have problems:

    1) The shutdown() method is not a part of the JCR API, thus making the client application depend on a Jackrabbit-specific feature
    2) In some cases the shutdown hook is not properly run (see issues JCR-120 and JCR-233)

I think the JCR spec thinks of the Repository and Session interfaces as being somewhat similar to the JDBC DataSource and Connection interfaces. The Repository instances have no real lifecycle methods while the Session instances have clearly specified login and logout steps. (DataSource.getConnection() = Repository.login(), Session.logout() = Connection.close()) However the Jackrabbit implementation defines an explicit lifecycle for the RepositoryImpl instances.

This causes problems especially for container environments (JNDI, Spring) where it is hard or even impossible to specify a shutdown mechanism for resource factories like the Repository instances. The current solution for such environments is to use a shutdown hook, but as reported this solution does not work perfectly in all cases.

How about if we bound the RepositoryImpl lifecycle to the lifecycles of the instantiated Sessions. A RepositoryImpl instance could initialize (and lock) the repository when the first session is opened and automatically shut down when the last session has logged out. As long as the sessions are properly logged out (or finalized by the garbage collector) there would be no need for an explicitly RepositoryImpl.shutdown() call. The current behaviour of pre-initializing the repository and shutting down during a shutdown hook could be enabled with a configuration option for environments (like global JNDI resources) in which the shutdown hooks work well.


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jukka Zitting made changes - 06/Oct/05 08:18 PM
Field Original Value New Value
Link This issue relates to JCR-233 [ JCR-233 ]
Jukka Zitting made changes - 06/Oct/05 09:45 PM
Link This issue relates to JCR-243 [ JCR-243 ]
Jukka Zitting made changes - 07/Oct/05 11:05 PM
Link This issue relates to JCR-120 [ JCR-120 ]
Günther Humer added a comment - 06/Dec/05 07:16 PM
What about sth. like implementing the Repository as a Singleton?
But not in the common term of singleton, more like one instance for each Repository-Home directory.

RepositoryImpl.getRepository(homeDir1) provides the same instance as.
RepositoryImpl.getRepository(homeDir1)

But
RepositoryImpl.getRepository(homeDir2) provides a new instance.

The repository is still shutdown, with the shutdown hook and initialized, when the user creates a Session or gets the Repository.

Alexandru Popescu added a comment - 06/Dec/05 07:40 PM
The solution with singletons is still problematic considering the classloaders.

./alex
--
.w( the_mindstorm )p.

Jukka Zitting added a comment - 07/Dec/05 08:38 AM
The attached patch contains org.apache.jackrabbit.core.TransientRepository, a proxy repository class that automatically initializes and shuts down the underlying RepositoryImpl instance when sessions are opened or closed. I implemented this as a separate class to avoid overloading the already heavy RepositoryImpl class. The implementation is quite clean except for two things: 1) it loads the default repository descriptors directly from repository.properties, and 2) it messes with RepositoryImpl.loggedOut(SessionImpl) to avoid a nasty infinite loop in RepositoryImpl.shutdown().

The class is quite easy to use and works very well with component containers like Spring where setting up an explicit shutdown call is difficult and cumbersome. If it weren't for the repository initialization and shutdown overhead, it would also make a fine candidate for solving the deployment model 2 shutdown issues discussed lately on the mailing list. The implementation also relies on all clients properly closing all the sessions they've opened. If needed, the implementation could be modified to use a WeakHashMap to cope with lost sessions.

Example code:

    RepositoryConfig config = RepositoryConfig.create("...", "...");
    Repository repository = new TransientRepository(config);
    Session session = repository.login(); // Repository gets initialized
    try {
        // Use the session
    } finally {
        session.logout(); // Repository gets shut down
    }

Any problems with this approach that I haven't noticed? I've been quite happy using a class like this in my Spring-based projects, so unless anyone objects I'll go ahead and commit it so others can use it too.

Jukka Zitting made changes - 07/Dec/05 08:38 AM
Attachment TransientRepository.patch [ 12321191 ]
Jukka Zitting added a comment - 07/Dec/05 08:53 AM
Günther Humer asked:
> What about sth. like implementing the Repository as a Singleton?

I think that's a solution looking for a problem. It's a different issue than the one raised here, and besides I think that guarding against duplicate repository configuration is better done at the application or container level. See also http://c2.com/cgi/wiki?SingletonGlobalProblems

Stefan Guggisberg added a comment - 07/Dec/05 06:33 PM
jukka's patch:
> Any problems with this approach that I haven't noticed? I've been quite happy using a class
> like this in my Spring-based projects, so unless anyone objects I'll go ahead and commit it
> so others can use it too.

+1

i think that TransientRepository is a very useful alternative for certain use-cases.

Repository Revision Date User Message
ASF #355430 Fri Dec 09 09:48:18 UTC 2005 jukka JCR-245: Added the TransientRepository utility class and an initial test case.
Files Changed
MODIFY /incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/TestAll.java
ADD /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
ADD /incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/TransientRepositoryTest.java

Repository Revision Date User Message
ASF #355439 Fri Dec 09 10:27:47 UTC 2005 jukka JCR-245: Removed the Java 5 Collections.addAll() call.
Files Changed
MODIFY /incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/TransientRepositoryTest.java

Jukka Zitting made changes - 09/Dec/05 06:09 PM
Assignee Jukka Zitting [ jukkaz ]
Jukka Zitting added a comment - 09/Dec/05 06:53 PM
Committed the proposed TransientRepository class in revision 355430 with the following changes:
* Added a simple TransientRepository.RepositoryFactory interface to allow greater control over the repository initialization process
* Added a two utility constructors
* Added an initial test case for the TransientRepository class (more complete unit testing would require a separate test repository or setting up mock RepositoryImpl instances)

Jukka Zitting made changes - 09/Dec/05 06:53 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 1.0 [ 12310154 ]
Jukka Zitting made changes - 08/Mar/06 01:24 AM
Status Resolved [ 5 ] Closed [ 6 ]
Jukka Zitting made changes - 07/Jul/09 01:04 PM
Workflow jira [ 12330850 ] no-reopen-closed, patch-avail [ 12469565 ]