Author: genman
Date: 2008-11-05 13:39:35 -0500 (Wed, 05 Nov 2008)
New Revision: 7086
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java
Log:
JBCACHE-1438 - Optimize state transfer; batch modifications
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-11-05
18:36:58 UTC (rev 7085)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-11-05
18:39:35 UTC (rev 7086)
@@ -29,6 +29,7 @@
import org.jboss.cache.Modification;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.Modification.ModificationType;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.marshall.Marshaller;
@@ -39,6 +40,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -126,6 +128,7 @@
protected void storeStateHelper(Fqn subtree, List nodeData, boolean moveToBuddy)
throws Exception
{
+ List<Modification> mod = new ArrayList<Modification>(nodeData.size());
for (Object aNodeData : nodeData)
{
NodeData nd = (NodeData) aNodeData;
@@ -144,15 +147,9 @@
fqn = nd.getFqn();
}
if (trace) log.trace("Storing state in Fqn " + fqn);
- if (nd.getAttributes() != null)
- {
- this.put(fqn, nd.getAttributes(), true);// creates a node with 0 or more
attributes
- }
- else
- {
- this.put(fqn, null);// creates a node with null attributes
- }
+ mod.add(new Modification(ModificationType.PUT_DATA_ERASE, fqn,
nd.getAttributes()));
}
+ prepare(null, mod, true);
}
public void loadEntireState(ObjectOutputStream os) throws Exception
@@ -313,8 +310,8 @@
remove(m.getFqn());
break;
case MOVE:
- // involve moving all children too,
- _move(m.getFqn(), m.getFqn2());
+ // involve moving all children too
+ move(m.getFqn(), m.getFqn2());
break;
default:
throw new CacheException("Unknown modification " +
m.getType());
@@ -322,7 +319,7 @@
}
}
- private void _move(Fqn fqn, Fqn parent) throws Exception
+ protected void move(Fqn fqn, Fqn parent) throws Exception
{
Object name = fqn.getLastElement();
Fqn newFqn = Fqn.fromRelativeElements(parent, name);
@@ -333,7 +330,7 @@
{
for (Object c : childrenNames)
{
- _move(Fqn.fromRelativeElements(fqn, c), newFqn);
+ move(Fqn.fromRelativeElements(fqn, c), newFqn);
}
}
// get data for node.
Modified: core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java 2008-11-05
18:36:58 UTC (rev 7085)
+++ core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java 2008-11-05
18:39:35 UTC (rev 7086)
@@ -29,6 +29,7 @@
import net.jcip.annotations.ThreadSafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.FqnComparator;
@@ -562,11 +563,39 @@
public void put(List<Modification> modifications)
throws Exception
{
-
checkOpen();
checkNonNull(modifications, "modifications");
- super.put(modifications);
+ for (Modification m : modifications)
+ {
+ switch (m.getType())
+ {
+ case PUT_DATA:
+ put0(m.getFqn(), m.getData());
+ break;
+ case PUT_DATA_ERASE:
+ erase0(m.getFqn(), false);
+ put0(m.getFqn(), m.getData());
+ break;
+ case PUT_KEY_VALUE:
+ put0(m.getFqn(), m.getKey(), m.getValue());
+ break;
+ case REMOVE_DATA:
+ erase0(m.getFqn(), false);
+ break;
+ case REMOVE_KEY_VALUE:
+ eraseKey0(m.getFqn(), m.getKey());
+ break;
+ case REMOVE_NODE:
+ erase0(m.getFqn());
+ break;
+ case MOVE:
+ move(m.getFqn(), m.getFqn2());
+ break;
+ default:
+ throw new CacheException("Unknown modification " +
m.getType());
+ }
+ }
commit();
}