Author: jbellis
Date: Tue Nov 3 02:24:12 2009
New Revision: 832268
URL: http://svn.apache.org/viewvc?rev=832268&view=rev
Log:
fix NPE caused by getToken on endpoint that isn't member of ring yet. add
assert to prevent in the future.
patch by jbellis for CASSANDRA-522
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/BootStrapper.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/TokenMetadata.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/BootStrapper.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/BootStrapper.java?rev=832268&r1=832267&r2=832268&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/BootStrapper.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/BootStrapper.java
Tue Nov 3 02:24:12 2009
@@ -110,7 +110,7 @@
}).start();
}
- public static void guessTokenIfNotSpecified() throws IOException
+ public static void guessTokenIfNotSpecified(TokenMetadata metadata) throws
IOException
{
StorageService ss = StorageService.instance();
StorageLoadBalancer slb = StorageLoadBalancer.instance();
@@ -122,8 +122,10 @@
{
double maxLoad = 0;
InetAddress maxEndpoint = null;
- for (Map.Entry<InetAddress,Double> entry :
slb.getLoadInfo().entrySet())
+ for (Map.Entry<InetAddress, Double> entry :
slb.getLoadInfo().entrySet())
{
+ if (!metadata.isMember(entry.getKey()))
+ continue;
if (maxEndpoint == null || entry.getValue() > maxLoad)
{
maxEndpoint = entry.getKey();
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/TokenMetadata.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/TokenMetadata.java?rev=832268&r1=832267&r2=832268&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/TokenMetadata.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/TokenMetadata.java
Tue Nov 3 02:24:12 2009
@@ -114,7 +114,8 @@
public Token getToken(InetAddress endpoint)
{
assert endpoint != null;
-
+ assert isMember(endpoint); // don't want to return nulls
+
lock.readLock().lock();
try
{
@@ -126,7 +127,7 @@
}
}
- public boolean isKnownEndPoint(InetAddress endpoint)
+ public boolean isMember(InetAddress endpoint)
{
assert endpoint != null;
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=832268&r1=832267&r2=832268&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
Tue Nov 3 02:24:12 2009
@@ -272,7 +272,7 @@
{
logger_.info("Starting in bootstrap mode (first, sleeping to get
load information)");
Gossiper.instance().addApplicationState(MODE, new
ApplicationState(MODE_MOVING));
- BootStrapper.guessTokenIfNotSpecified();
+ BootStrapper.guessTokenIfNotSpecified(tokenMetadata_);
new BootStrapper(replicationStrategy_,
FBUtilities.getLocalAddress(), getLocalToken(),
tokenMetadata_).startBootstrap(); // handles token update
}
else
@@ -373,20 +373,21 @@
Token newToken =
getPartitioner().getTokenFactory().fromString(nodeIdState.getState());
if (logger_.isDebugEnabled())
logger_.debug("CHANGE IN STATE FOR " + endpoint + " - has token
" + nodeIdState.getState());
- Token oldToken = tokenMetadata_.getToken(endpoint);
- if ( oldToken != null )
+ if (tokenMetadata_.isMember(endpoint))
{
+ 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
* the newToken this means that the node is being relocated
* to another position in the ring.
*/
- if ( !oldToken.equals(newToken) )
+ if (!oldToken.equals(newToken))
{
if (logger_.isDebugEnabled())
- logger_.debug("Relocation for endpoint " + endpoint);
+ logger_.debug("Relocation for endpoint " + endpoint);
updateForeignToken(newToken, endpoint);
}
else
@@ -396,7 +397,7 @@
* Deliver the hints that we have for this endpoint.
*/
if (logger_.isDebugEnabled())
- logger_.debug("Sending hinted data to " + endpoint);
+ logger_.debug("Sending hinted data to " + endpoint);
deliverHints(endpoint);
}
}
@@ -414,10 +415,10 @@
* 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_.isKnownEndPoint(endpoint)
)
+ if (epState.isAlive() && tokenMetadata_.isMember(endpoint))
{
if (logger_.isDebugEnabled())
- logger_.debug("InetAddress " + endpoint + " just recovered
from a partition. Sending hinted data.");
+ logger_.debug("InetAddress " + endpoint + " just recovered
from a partition. Sending hinted data.");
deliverHints(endpoint);
}
}