[jboss-cvs] JBossCache/src/org/jboss/cache ...
Galder Zamarreno
gzamarreno at belmont.prod.atl2.jboss.com
Tue Aug 29 16:00:35 EDT 2006
User: gzamarreno
Date: 06/08/29 16:00:35
Modified: src/org/jboss/cache Tag:
Branch_JBossCache_1_2_4_SP2_JBCACHE-753
TreeCache.java
Log:
[JBCACHE-753] Port the fix for JBCACHE-650 to 1.2.4SP2
Revision Changes Path
No revision
No revision
1.56.2.11.4.6.6.1 +72 -1 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.56.2.11.4.6
retrieving revision 1.56.2.11.4.6.6.1
diff -u -b -r1.56.2.11.4.6 -r1.56.2.11.4.6.6.1
--- TreeCache.java 21 Feb 2006 18:33:13 -0000 1.56.2.11.4.6
+++ TreeCache.java 29 Aug 2006 20:00:35 -0000 1.56.2.11.4.6.6.1
@@ -17,6 +17,7 @@
import org.jboss.cache.loader.AsyncExtendedCacheLoader;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.ExtendedCacheLoader;
+import org.jboss.cache.loader.SingletonCacheLoader;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockStrategyFactory;
import org.jboss.cache.lock.LockingException;
@@ -61,7 +62,7 @@
* @author Ben Wang
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
- * @version $Id: TreeCache.java,v 1.56.2.11.4.6 2006/02/21 18:33:13 bstansberry Exp $
+ * @version $Id: TreeCache.java,v 1.56.2.11.4.6.6.1 2006/08/29 20:00:35 gzamarreno Exp $
* <p/>
*/
public class TreeCache extends ServiceMBeanSupport implements TreeCacheMBean, Cloneable, MembershipListener {
@@ -217,6 +218,15 @@
/** specifies whether the cache loader needs to be wrapped in the AsyncCacheLoader decorator */
protected boolean cache_loader_asynchronous=false;
+ /** specifies whether the cache loader is Singleton one */
+ protected boolean cache_loader_singleton=false;
+
+ /** This only applies to SingletonCacheLoader. When the singleton (coordinator)
+ * goes down and a new coordinator is elected, this becomes the singleton and depending on this attribute
+ * , it will dump the in memory state to the cache loader, in case any cache updates have been missed in the mean
+ * time */
+ protected boolean cache_loader_push_when_coordinator=false;
+
/** synchronous or asynchrous commit phase ? */
protected boolean sync_commit_phase=false;
@@ -607,6 +617,41 @@
this.cache_loader_passivate = passivate;
}
+ /**
+ *
+ * @return
+ */
+ public boolean getCacheLoaderSingleton()
+ {
+ return cache_loader_singleton;
+ }
+
+ /**
+ *
+ * @param singleton
+ */
+ public void setCacheLoaderSingleton(boolean singleton)
+ {
+ this.cache_loader_singleton = singleton;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean getCacheLoaderPushWhenCoordinator()
+ {
+ return cache_loader_push_when_coordinator;
+ }
+
+ /**
+ *
+ * @param cache_loader_push_when_coordinator
+ */
+ public void setCacheLoaderPushWhenCoordinator(boolean pushWhenCoordinator)
+ {
+ this.cache_loader_push_when_coordinator = pushWhenCoordinator;
+ }
/**
* @param list
@@ -1292,6 +1337,8 @@
* Lifecycle method. Same thing as calling <code>stop</code>.
*/
public void stopService() {
+ waitForSingletonStatePush();
+
if(channel != null) {
log.info("stopService(): closing the channel");
channel.close();
@@ -1733,6 +1780,11 @@
cache_loader = new AsyncCacheLoader( concreteCacheLoader );
}
}
+ else if (cache_loader_singleton && concreteCacheLoader != null)
+ {
+ cache_loader = new SingletonCacheLoader(concreteCacheLoader, cache_loader_push_when_coordinator);
+ addTreeCacheListener((SingletonCacheLoader)cache_loader);
+ }
else
{
cache_loader = concreteCacheLoader;
@@ -4440,6 +4492,25 @@
return -1;
}
+ private void waitForSingletonStatePush() {
+ /* We are waiting for the Singleton state push thread in case is still in progress. Otherwise, the cache loader
+ could end up in a inconsistent state that would destroy the data permanently (i.e. if the last node in the
+ cluster (which is of course the coordinator) fails to pass the in-memory state to the cache loader). We can only
+ avoid normal shutdowns, JVM crashes or computer switch down could not be avoided. */
+ if (cache_loader != null && cache_loader instanceof SingletonCacheLoader) {
+ SingletonCacheLoader loader = (SingletonCacheLoader)cache_loader;
+ try
+ {
+ if (loader.getPushStateThread() != null) {
+ log.debug("waiting for the in-memory state to be pushed to the cache loader");
+ loader.getPushStateThread().join();
+ }
+ } catch (InterruptedException e)
+ {
+ log.error("joining with the in-memory state pusher to cache loader was interrupted", e);
+ }
+ }
+ }
/*-------------------- ActionOrigin ----------------------*/
private static class ActionOrigin {
More information about the jboss-cvs-commits
mailing list