[jbosscache-commits] JBoss Cache SVN: r6233 - in core/trunk/src/main/java/org/jboss/cache: mvcc and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Jul 9 08:47:56 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-07-09 08:47:56 -0400 (Wed, 09 Jul 2008)
New Revision: 6233

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
   core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
   core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java
   core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
   core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
Log:
Minor updates and renaming

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java	2008-07-09 12:25:00 UTC (rev 6232)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java	2008-07-09 12:47:56 UTC (rev 6233)
@@ -309,7 +309,7 @@
             {
                // for each of these, swap refs
                ReadCommittedNode rcn = (ReadCommittedNode) ctx.lookUpNode(fqnsToUnlock[i]);
-               if (rcn != null) rcn.commitUpdate(dataContainer, nodeFactory, ctx); // could be null with read-committed
+               if (rcn != null) rcn.commitUpdate(ctx, dataContainer, nodeFactory); // could be null with read-committed
                // and then unlock
                if (trace) log.trace("Releasing lock on [" + fqnsToUnlock[i] + "] for thread " + owner);
                lockManager.unlock(fqnsToUnlock[i], owner);
@@ -348,7 +348,7 @@
                   if (commit)
                   {
                      // for each of these, swap refs
-                     rcn.commitUpdate(dataContainer, nodeFactory, ctx);
+                     rcn.commitUpdate(ctx, dataContainer, nodeFactory);
                   }
                   else
                   {

Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java	2008-07-09 12:25:00 UTC (rev 6232)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java	2008-07-09 12:47:56 UTC (rev 6233)
@@ -172,7 +172,7 @@
          if (lockForWriting && acquireLock(context, fqn))
          {
             // create a copy of the underlying node
-            n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+            n.markForUpdate(context, dataContainer, nodeFactory, allowWriteSkew);
          }
          if (trace) log.trace("Retrieving wrapped node " + fqn);
          if (n.isDeleted() && createIfAbsent)
@@ -197,7 +197,7 @@
             }
             n = nodeFactory.createMvccNode(in);
             context.putLookedUpNode(fqn, n);
-            if (needToCopy) n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+            if (needToCopy) n.markForUpdate(context, dataContainer, nodeFactory, allowWriteSkew);
          }
          else if (createIfAbsent) // else, do we need to create one?
          {
@@ -209,7 +209,7 @@
             if (parentLockNeeded && acquireLock(context, parentFqn))
             {
                ReadCommittedNode parentRCN = (ReadCommittedNode) context.lookUpNode(parentFqn);
-               parentRCN.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+               parentRCN.markForUpdate(context, dataContainer, nodeFactory, allowWriteSkew);
             }
 
             // now to lock and create the node.
@@ -223,7 +223,7 @@
             n = nodeFactory.createMvccNode(in);
             n.setCreated(true);
             context.putLookedUpNode(fqn, n);
-            n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+            n.markForUpdate(context, dataContainer, nodeFactory, allowWriteSkew);
          }
       }
 
@@ -269,7 +269,7 @@
       ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(fqn);
 
       // update child ref on parent to point to child as this is now a copy.
-      if (node != null && !(node instanceof NullMarkerNode))
+      if (node != null && !(node.isNullNode()))
       {
          if (parentLockNeeded && (needToCopyNode || needToCopyParent))
          {
@@ -304,7 +304,7 @@
       ReadCommittedNode rcn = wrapNodeForWriting(ctx, fqn, true, false, true, false, false);
       if (rcn != null)
       {
-         rcn.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
+         rcn.markForUpdate(ctx, dataContainer, nodeFactory, allowWriteSkew);
          ReadCommittedNode parent = (ReadCommittedNode) ctx.lookUpNode(fqn.getParent());
          parent.addChildDirect(nodeFactory.createNodeInvocationDelegate((InternalNode) rcn.getDelegationTarget()));
 
@@ -331,7 +331,7 @@
 
       if (needToCopyNode && node != null && !node.isChanged()) // node could be null if using read-committed
       {
-         node.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
+         node.markForUpdate(ctx, dataContainer, nodeFactory, allowWriteSkew);
       }
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java	2008-07-09 12:25:00 UTC (rev 6232)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java	2008-07-09 12:47:56 UTC (rev 6233)
@@ -1,5 +1,6 @@
 package org.jboss.cache.mvcc;
 
+import net.jcip.annotations.ThreadSafe;
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InternalNode;
@@ -13,11 +14,20 @@
 import java.util.Set;
 
 /**
- * // TODO Document this
+ * A node reference that delegates all calls to a different {@link org.jboss.cache.InternalNode}.  Simple indirection
+ * is all this class does, allowing other processes to change the delegate.
+ * <p/>
+ * The delegate is a volatile field so the class is thread safe.
+ * <p/>
+ * This is used to wrap all {@link org.jboss.cache.invocation.NodeInvocationDelegate}s in the {@link org.jboss.cache.DataContainer}
+ * when using {@link org.jboss.cache.config.Configuration.NodeLockingScheme#MVCC} and {@link org.jboss.cache.lock.IsolationLevel#READ_COMMITTED}.
+ * <p/>
  *
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @see org.jboss.cache.mvcc.ReadCommittedNode
  * @since 3.0
  */
+ at ThreadSafe
 public class NodeReference implements InternalNode
 {
    transient volatile InternalNode delegate;
@@ -27,11 +37,19 @@
       this.delegate = delegate;
    }
 
+   /**
+    * @return the InternalNode being delegated to.
+    */
    public InternalNode getDelegate()
    {
       return delegate;
    }
 
+   /**
+    * Sets the internal node to delegate to.
+    *
+    * @param delegate node to delegate to.
+    */
    public void setDelegate(InternalNode delegate)
    {
       this.delegate = delegate;

Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java	2008-07-09 12:25:00 UTC (rev 6232)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java	2008-07-09 12:47:56 UTC (rev 6233)
@@ -6,7 +6,8 @@
 import org.jboss.cache.invocation.InvocationContext;
 
 /**
- * A marker node to represent a null node for repeatable read
+ * A marker node to represent a null node for repeatable read, so that a read that returns a null can continue to return
+ * null.
  *
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 3.0
@@ -18,26 +19,38 @@
       super(node);
    }
 
+   /**
+    * @return always returns true
+    */
    @Override
    public boolean isNullNode()
    {
       return true;
    }
 
+   /**
+    * @return always returns true so that any get commands, upon getting this node, will ignore the node as though it were removed.
+    */
    @Override
    public boolean isDeleted()
    {
       return true;
    }
 
+   /**
+    * @return always returns true so that any get commands, upon getting this node, will ignore the node as though it were invalid.
+    */
    @Override
    public boolean isValid()
    {
       return false;
    }
 
+   /**
+    * A no-op.
+    */
    @Override
-   public void copyNodeForUpdate(DataContainer d, boolean b, InvocationContext ctx, NodeFactory nodeFactory)
+   public void markForUpdate(InvocationContext ctx, DataContainer d, NodeFactory nodeFactory, boolean b)
    {
       // no op
    }

Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java	2008-07-09 12:25:00 UTC (rev 6232)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java	2008-07-09 12:47:56 UTC (rev 6233)
@@ -12,7 +12,7 @@
 import org.jboss.cache.optimistic.DefaultDataVersion;
 
 /**
- * Repeatable read would do a simple delegation to the underlying node.
+ * A node delegate that encapsulates read committed semantics when writes are initiated, committed or rolled back.
  *
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 3.0
@@ -23,7 +23,6 @@
    protected boolean changed;
    protected boolean created;
    protected boolean deleted;
-//   protected Set childrenAdded, childrenRemoved;
 
    public ReadCommittedNode(InternalNode node)
    {
@@ -35,7 +34,16 @@
       return false;
    }
 
-   public void copyNodeForUpdate(DataContainer container, boolean allowWriteSkew, InvocationContext ctx, NodeFactory nodeFactory)
+   /**
+    * Marks a node for updating.  Internally, this creates a copy of the delegate and performs any checks necessary to
+    * maintain isolation level.
+    *
+    * @param ctx            invocation context
+    * @param container      data container
+    * @param nodeFactory    node factory for creating new nodes/copies.
+    * @param allowWriteSkew if true, write skews are allowed.  Only makes sense with repeatable read.
+    */
+   public void markForUpdate(InvocationContext ctx, DataContainer container, NodeFactory nodeFactory, boolean allowWriteSkew)
    {
       if (changed) return; // already copied
 
@@ -47,7 +55,14 @@
       node.setVersion(newVersion);
    }
 
-   public void commitUpdate(DataContainer container, NodeFactory nf, InvocationContext ctx)
+   /**
+    * Commits any updates made on this node to the underlying data structure, making it visible to all other transactions.
+    *
+    * @param ctx         invocation context
+    * @param container   data container
+    * @param nodeFactory node factory
+    */
+   public void commitUpdate(InvocationContext ctx, DataContainer container, NodeFactory nodeFactory)
    {
       if (changed)
       {
@@ -72,16 +87,16 @@
          {
             // add newly created nodes to parents.
             NodeSPI parent = lookupParent(fqn, ctx, container);
-            parent.addChildDirect(nf.createNodeInvocationDelegate(node));
+            parent.addChildDirect(nodeFactory.createNodeInvocationDelegate(node));
          }
          else if (fqn.isRoot())
          {
             // set root node reference in data container.
-            container.setRoot(nf.createNodeInvocationDelegate(node));
+            container.setRoot(nodeFactory.createNodeInvocationDelegate(node));
          }
          else
          {
-            updateNode(container, nf, ctx);
+            updateNode(ctx, container, nodeFactory);
          }
 
          changed = false;
@@ -113,11 +128,11 @@
    /**
     * Updates state changes on the current node in the underlying data structure.
     *
+    * @param ctx           invocation context
     * @param dataContainer data container
     * @param nf            node factory
-    * @param ctx           invocation context
     */
-   protected void updateNode(DataContainer dataContainer, NodeFactory nf, InvocationContext ctx)
+   protected void updateNode(InvocationContext ctx, DataContainer dataContainer, NodeFactory nf)
    {
       // swap refs
       ((NodeReference) backup).setDelegate(((NodeReference) node).getDelegate());
@@ -131,16 +146,17 @@
       changed = false;
    }
 
+   /**
+    * @return true if this node has been marked for update, false otherwise.
+    */
    public boolean isChanged()
    {
       return changed;
    }
 
-   public void setChanged(boolean changed)
-   {
-      this.changed = changed;
-   }
-
+   /**
+    * @return true if this node has been newly created in the current scope.
+    */
    public boolean isCreated()
    {
       return created;
@@ -151,16 +167,6 @@
       this.created = created;
    }
 
-   public InternalNode getNode()
-   {
-      return node;
-   }
-
-   public InternalNode getBackupNode()
-   {
-      return backup;
-   }
-
    // do not propagate deletion flags to the underlying node.
 
    @Override

Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java	2008-07-09 12:25:00 UTC (rev 6232)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java	2008-07-09 12:47:56 UTC (rev 6233)
@@ -11,7 +11,7 @@
 import org.jboss.cache.optimistic.DefaultDataVersion;
 
 /**
- * // TODO Document this
+ * A node delegate that encapsulates repeatable read semantics when writes are initiated, committed or rolled back.
  *
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 3.0
@@ -24,7 +24,7 @@
    }
 
    @Override
-   public void copyNodeForUpdate(DataContainer container, boolean allowWriteSkew, InvocationContext ctx, NodeFactory nodeFactory)
+   public void markForUpdate(InvocationContext ctx, DataContainer container, NodeFactory nodeFactory, boolean allowWriteSkew)
    {
       if (changed) return; // already copied
 
@@ -54,7 +54,7 @@
    }
 
    @Override
-   protected void updateNode(DataContainer dataContainer, NodeFactory nf, InvocationContext ctx)
+   protected void updateNode(InvocationContext ctx, DataContainer dataContainer, NodeFactory nf)
    {
       NodeSPI parent = lookupParent(getFqn(), ctx, dataContainer);
       parent.addChildDirect(nf.createNodeInvocationDelegate(node));




More information about the jbosscache-commits mailing list