cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r832996 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: gms/Gossiper.java gms/IEndPointStateChangeSubscriber.java service/StorageLoadBalancer.java service/StorageService.java
Date Thu, 05 Nov 2009 05:33:48 GMT
Author: jbellis
Date: Thu Nov  5 05:33:47 2009
New Revision: 832996

URL: http://svn.apache.org/viewvc?rev=832996&view=rev
Log:
add onAlive, onDead methods to gossiper listener interface so listeners don't have to try
to infer that by less accurate circumstantial evidence
patch by jbellis; reviewed by Jaakko Laine for CASSANDRA-527

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/IEndPointStateChangeSubscriber.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageLoadBalancer.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java?rev=832996&r1=832995&r2=832996&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java Thu Nov  5 05:33:47
2009
@@ -198,22 +198,15 @@
     public void convict(InetAddress endpoint)
     {
         EndPointState epState = endPointStateMap_.get(endpoint);
-        if ( epState != null )
+        if (epState != null)
         {
-            if ( !epState.isAlive() && epState.isAGossiper() )
+            if (!epState.isAlive() && epState.isAGossiper())
             {
-                /*
-                 * just to be sure - is invoked just to make sure that
-                 * it was called at least once.
-                */
-                if ( liveEndpoints_.contains(endpoint) )
+                // just to be sure - should already have been done by suspect()
+                if (liveEndpoints_.contains(endpoint))
                 {
                     logger_.info("InetAddress " + endpoint + " is now dead.");
                     isAlive(endpoint, epState, false);
-
-                    /* Notify an endpoint is dead to interested parties. */
-                    EndPointState deltaState = new EndPointState(epState.getHeartBeatState());
-                    doNotifications(endpoint, deltaState);
                 }
                 epState.isAGossiper(false);
             }
@@ -229,14 +222,10 @@
     public void suspect(InetAddress endpoint)
     {
         EndPointState epState = endPointStateMap_.get(endpoint);
-        if ( epState.isAlive() )
+        if (epState.isAlive())
         {
             logger_.info("InetAddress " + endpoint + " is now dead.");
             isAlive(endpoint, epState, false);
-
-            /* Notify an endpoint is dead to interested parties. */
-            EndPointState deltaState = new EndPointState(epState.getHeartBeatState());
-            doNotifications(endpoint, deltaState);
         }
     }
 
@@ -771,17 +760,21 @@
     synchronized void isAlive(InetAddress addr, EndPointState epState, boolean value)
     {
         epState.isAlive(value);
-        if ( value )
+        if (value)
         {
             liveEndpoints_.add(addr);
             unreachableEndpoints_.remove(addr);
+            for (IEndPointStateChangeSubscriber subscriber : subscribers_)
+                subscriber.onAlive(addr, epState);
         }
         else
         {
             liveEndpoints_.remove(addr);
             unreachableEndpoints_.add(addr);
+            for (IEndPointStateChangeSubscriber subscriber : subscribers_)
+                subscriber.onDead(addr, epState);
         }
-        if ( epState.isAGossiper() )
+        if (epState.isAGossiper())
             return;
         epState.isAGossiper(true);
     }
@@ -920,10 +913,8 @@
     public synchronized void addApplicationState(String key, ApplicationState appState)
     {
         EndPointState epState = endPointStateMap_.get(localEndPoint_);
-        if ( epState != null )
-        {
-            epState.addApplicationState(key, appState);
-        }
+        assert epState != null;
+        epState.addApplicationState(key, appState);
     }
 
     public void stop()

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/IEndPointStateChangeSubscriber.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/IEndPointStateChangeSubscriber.java?rev=832996&r1=832995&r2=832996&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/IEndPointStateChangeSubscriber.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/IEndPointStateChangeSubscriber.java
Thu Nov  5 05:33:47 2009
@@ -39,4 +39,8 @@
      * @param epState state that actually changed for the above endpoint.
      */
     public void onChange(InetAddress endpoint, EndPointState epState);
+
+    public void onAlive(InetAddress endpoint, EndPointState state);
+
+    public void onDead(InetAddress endpoint, EndPointState state);
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageLoadBalancer.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageLoadBalancer.java?rev=832996&r1=832995&r2=832996&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageLoadBalancer.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageLoadBalancer.java
Thu Nov  5 05:33:47 2009
@@ -227,7 +227,11 @@
         }       
     }
 
-    /*
+    public void onAlive(InetAddress endpoint, EndPointState state) {}
+
+    public void onDead(InetAddress endpoint, EndPointState state) {}
+
+/*
     private boolean isMoveable()
     {
         if ( !isMoveable_.get() )

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=832996&r1=832995&r2=832996&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java Thu
Nov  5 05:33:47 2009
@@ -370,20 +370,7 @@
             tokenMetadata_.setBootstrapping(endpoint,  bootstrapState);
         }
 
-        if (nodeIdState == null)
-        {
-            /*
-             * If we are here and if this node is UP and already has an entry
-             * in the token map. It means that the node was behind a network partition.
-            */
-            if (epState.isAlive() && tokenMetadata_.isMember(endpoint))
-            {
-                if (logger_.isDebugEnabled())
-                    logger_.debug("InetAddress " + endpoint + " just recovered from a partition.
Sending hinted data.");
-                deliverHints(endpoint);
-            }
-        }
-        else
+        if (nodeIdState != null)
         {
             Token newToken = getPartitioner().getTokenFactory().fromString(nodeIdState.getState());
             if (logger_.isDebugEnabled())
@@ -394,8 +381,7 @@
                 Token oldToken = tokenMetadata_.getToken(endpoint);
 
                 /*
-                 * If oldToken equals the newToken then the node had crashed
-                 * and is coming back up again. If oldToken is not equal to
+                 * If oldToken is not equal to
                  * the newToken this means that the node is being relocated
                  * to another position in the ring.
                 */
@@ -405,16 +391,6 @@
                         logger_.debug("Relocation for endpoint " + endpoint);
                     updateForeignToken(newToken, endpoint);
                 }
-                else
-                {
-                    /*
-                     * This means the node crashed and is coming back up.
-                     * Deliver the hints that we have for this endpoint.
-                    */
-                    if (logger_.isDebugEnabled())
-                        logger_.debug("Sending hinted data to " + endpoint);
-                    deliverHints(endpoint);
-                }
             }
             else
             {
@@ -426,6 +402,13 @@
         }
     }
 
+    public void onAlive(InetAddress endpoint, EndPointState state)
+    {
+        deliverHints(endpoint);
+    }
+
+    public void onDead(InetAddress endpoint, EndPointState state) {}
+
     /** raw load value */
     public double getLoad()
     {



Mime
View raw message