[jboss-cvs] JBossCache/src/org/jboss/cache/buddyreplication ...

Manik Surtani msurtani at jboss.com
Fri Nov 10 15:03:34 EST 2006


  User: msurtani
  Date: 06/11/10 15:03:34

  Modified:    src/org/jboss/cache/buddyreplication   Tag:
                        Branch_JBossCache_1_4_0 BuddyManager.java
  Added:       src/org/jboss/cache/buddyreplication   Tag:
                        Branch_JBossCache_1_4_0 BuddyNotInitException.java
  Log:
  fixed concurrency deadlocks when buddies start up
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.33.2.6  +88 -21    JBossCache/src/org/jboss/cache/buddyreplication/BuddyManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/buddyreplication/BuddyManager.java,v
  retrieving revision 1.33.2.5
  retrieving revision 1.33.2.6
  diff -u -b -r1.33.2.5 -r1.33.2.6
  --- BuddyManager.java	5 Oct 2006 16:49:59 -0000	1.33.2.5
  +++ BuddyManager.java	10 Nov 2006 20:03:34 -0000	1.33.2.6
  @@ -16,12 +16,12 @@
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.TreeCacheListener;
   import org.jboss.cache.lock.TimeoutException;
  +import org.jboss.cache.marshall.JBCMethodCall;
   import org.jboss.cache.marshall.MethodCallFactory;
   import org.jboss.cache.marshall.MethodDeclarations;
   import org.jboss.cache.marshall.Region;
   import org.jboss.cache.marshall.RegionManager;
   import org.jboss.cache.marshall.VersionAwareMarshaller;
  -import org.jboss.cache.marshall.JBCMethodCall;
   import org.jboss.cache.xml.XmlHelper;
   import org.jgroups.View;
   import org.jgroups.blocks.MethodCall;
  @@ -29,7 +29,14 @@
   import org.w3c.dom.Element;
   
   import java.io.IOException;
  -import java.util.*;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
  +import java.util.Properties;
  +import java.util.Vector;
   
   /**
    * Class that manages buddy replication groups.
  @@ -99,6 +106,14 @@
       public static final Fqn BUDDY_BACKUP_SUBTREE_FQN = Fqn.fromString(BUDDY_BACKUP_SUBTREE);
   
       int buddyCommunicationTimeout = 10000;
  +   /**
  +    *  number of times to retry communicating with a selected buddy if the buddy has not been initialised.
  +    */
  +   private static int UNINIT_BUDDIES_RETRIES = 3;
  +   /**
  +    * wait time between retries
  +    */
  +   private static final long UNINIT_BUDDIES_RETRY_NAPTIME = 500;
   
       /**
        * Flag to prevent us receiving and processing remote calls before we've started
  @@ -383,9 +398,10 @@
        * Called by TreeCache._remoteRemoveFromBuddyGroup(String groupName)
        * when a method call for this is received from a remote cache.
        */
  -    public void handleRemoveFromBuddyGroup(String groupName)
  +    public void handleRemoveFromBuddyGroup(String groupName) throws BuddyNotInitException
       {
  -        waitForInit();
  +        //waitForInit();
  +       if (!initialised) throw new BuddyNotInitException("Not yet initialised");
           if (log.isInfoEnabled()) log.info("Removing self from buddy group " + groupName);
           buddyGroupsIParticipateIn.remove(groupName);
   
  @@ -411,7 +427,9 @@
        */
       public void handleAssignToBuddyGroup(BuddyGroup newGroup, Map state) throws Exception
       {
  -        waitForInit();
  +       // if we haven't initialised, throw an exception.
  +       if (!initialised) throw new BuddyNotInitException("Not yet initialised");
  +
           if (log.isInfoEnabled()) log.info("Assigning self to buddy group " + newGroup);
           buddyGroupsIParticipateIn.put(newGroup.getGroupName(), newGroup);
   
  @@ -433,6 +451,7 @@
              {
                 ClassLoader cl = (marshaller == null) ? null : marshaller.getClassLoader(fqnS);
                 Fqn integrationRoot = new Fqn(integrationBase, fqn);
  +              log.fatal("***** Cache is " + cache + " and entry is " + entry);
                 cache._setState((byte[]) entry.getValue(), integrationRoot, cl);
              }
           }
  @@ -511,7 +530,7 @@
   
       // -------------- internal helpers methods --------------------
   
  -    private void removeFromGroup(List buddies)
  +    private void removeFromGroup(List buddies) throws Exception
       {
           if (log.isInfoEnabled())
           {
  @@ -522,14 +541,37 @@
           MethodCall membershipCall = MethodCallFactory.create(MethodDeclarations.remoteRemoveFromBuddyGroupMethod, new Object[]{buddyGroup.getGroupName()});
           MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, new Object[]{membershipCall});
   
  +
  +       int attemptsLeft = UNINIT_BUDDIES_RETRIES;
  +
  +     while (attemptsLeft-- > 0)
  +     {
           try
           {
               makeRemoteCall(buddies, replicateCall);
  +            break;
           }
           catch (Exception e)
           {
  -            log.error("Problems broadcasting removeFromGroup to specific buddies", e);
  +            if (e instanceof BuddyNotInitException || e.getCause() instanceof BuddyNotInitException)
  +            {
  +               if (attemptsLeft > 0)
  +               {
  +                  log.info("One of the buddies have not been initialised.  Will retry after a short nap.");
  +                  Thread.sleep(UNINIT_BUDDIES_RETRY_NAPTIME);
  +               }
  +               else
  +               {
  +                  throw new BuddyNotInitException("Unable to contact buddy after " + UNINIT_BUDDIES_RETRIES + " retries");
  +               }
  +            }
  +            else
  +            {
  +                log.error("Unable to communicate with Buddy for some reason", e);
  +            }
  +         }
           }
  +
           log.trace("removeFromGroup notification complete");
       }
   
  @@ -591,14 +633,37 @@
           MethodCall membershipCall = MethodCallFactory.create(MethodDeclarations.remoteAssignToBuddyGroupMethod, new Object[]{buddyGroup, stateMap});
           MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, new Object[]{membershipCall});
   
  +         int attemptsLeft = UNINIT_BUDDIES_RETRIES;
  +
  +       while (attemptsLeft-- > 0)
  +       {
           try
           {
               makeRemoteCall(buddies, replicateCall);
  +              break;
           }
           catch (Exception e)
           {
  -            log.error("Problems broadcasting assignToGroup to specific buddies", e);
  +              if (e instanceof BuddyNotInitException || e.getCause() instanceof BuddyNotInitException)
  +              {
  +                 if (attemptsLeft > 0)
  +                 {
  +                    log.info("One of the buddies have not been initialised.  Will retry after a short nap.");
  +                    Thread.sleep(UNINIT_BUDDIES_RETRY_NAPTIME);
           }
  +                 else
  +                 {
  +                    throw new BuddyNotInitException("Unable to contact buddy after " + UNINIT_BUDDIES_RETRIES + " retries");
  +                 }                 
  +              }
  +              else
  +              {
  +                 log.error("Unable to communicate with Buddy for some reason", e);
  +              }
  +           }
  +       }
  +
  +
           log.trace("addToGroup notification complete");
       }
   
  @@ -805,6 +870,8 @@
   
           public void run()
           {
  +           // don't start this thread until the Buddy Manager has initialised as it cocks things up.
  +           waitForInit();
               while (!Thread.interrupted())
               {
                   try
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +27 -0     JBossCache/src/org/jboss/cache/buddyreplication/Attic/BuddyNotInitException.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyNotInitException.java
  ===================================================================
  RCS file: BuddyNotInitException.java
  diff -N BuddyNotInitException.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BuddyNotInitException.java	10 Nov 2006 20:03:34 -0000	1.1.2.1
  @@ -0,0 +1,27 @@
  +package org.jboss.cache.buddyreplication;
  +
  +import org.jboss.cache.CacheException;
  +
  +/**
  + * Exception to depict that a buddy has not been initialised to participate in any comms
  + *
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  + * @since 1.4.1
  + */
  +public class BuddyNotInitException extends CacheException
  +{
  +
  +   public BuddyNotInitException()
  +   {
  +   }
  +
  +   public BuddyNotInitException(String msg)
  +   {
  +      super(msg);
  +   }
  +
  +   public BuddyNotInitException(String msg, Throwable cause)
  +   {
  +      super(msg, cause);
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list