Author: jbellis Date: Thu Oct 7 15:40:41 2010 New Revision: 1005497 URL: http://svn.apache.org/viewvc?rev=1005497&view=rev Log: Disallow bootstrap to an in-use token. patch by jbellis; reviewed by gdusbabek for CASSANDRA-1561
Modified: cassandra/branches/cassandra-0.6/CHANGES.txt cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/BootStrapper.java cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageProxy.java cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageService.java cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/Util.java cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java Modified: cassandra/branches/cassandra-0.6/CHANGES.txt URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/CHANGES.txt (original) +++ cassandra/branches/cassandra-0.6/CHANGES.txt Thu Oct 7 15:40:41 2010 @@ -44,6 +44,7 @@ data during server startup (CASSANDRA-1526) * add cache save/load ability (CASSANDRA-1417) * Ignore stray files in the commit log directory (CASSANDRA-1547) + * Disallow bootstrap to an in-use token (CASSANDRA-1561) 0.6.5 Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/BootStrapper.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/BootStrapper.java?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/BootStrapper.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/BootStrapper.java Thu Oct 7 15:40:41 2010 @@ -24,6 +24,8 @@ package org.apache.cassandra.dht; import java.io.UnsupportedEncodingException; import java.net.InetAddress; + import javax.naming.ConfigurationException; + import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -86,12 +88,15 @@ public class BootStrapper * if initialtoken was specified, use that. * otherwise, pick a token to assume half the load of the most-loaded node. */ - public static Token getBootstrapToken(final TokenMetadata metadata, final Map<InetAddress, Double> load) throws IOException + public static Token getBootstrapToken(final TokenMetadata metadata, final Map<InetAddress, Double> load) throws IOException, ConfigurationException { if (DatabaseDescriptor.getInitialToken() != null) { logger.debug("token manually specified as " + DatabaseDescriptor.getInitialToken()); - return StorageService.getPartitioner().getTokenFactory().fromString(DatabaseDescriptor.getInitialToken()); + Token token = StorageService.getPartitioner().getTokenFactory().fromString(DatabaseDescriptor.getInitialToken()); + if (metadata.getEndPoint(token) != null) + throw new ConfigurationException("Bootstraping to existing token " + token + " is not allowed (decommission/removetoken the old node first)."); + return token; } return getBalancedToken(metadata, load); Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageProxy.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageProxy.java?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageProxy.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageProxy.java Thu Oct 7 15:40:41 2010 @@ -613,7 +613,7 @@ public class StorageProxy implements Sto * D, but we don't want any other results from it until after the (D, T] range. Unwrapping so that * the ranges we consider are (D, T], (T, MIN], (MIN, D] fixes this. */ - private static List<AbstractBounds> getRestrictedRanges(final AbstractBounds queryRange) + static List<AbstractBounds> getRestrictedRanges(final AbstractBounds queryRange) { TokenMetadata tokenMetadata = StorageService.instance.getTokenMetadata(); Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageService.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageService.java?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageService.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/StorageService.java Thu Oct 7 15:40:41 2010 @@ -28,6 +28,7 @@ import java.util.*; import java.util.concurrent.*; import javax.management.MBeanServer; import javax.management.ObjectName; +import javax.naming.ConfigurationException; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -296,7 +297,7 @@ public class StorageService implements I MessagingService.instance.listen(FBUtilities.getLocalAddress()); } - public synchronized void initServer() throws IOException + public synchronized void initServer() throws IOException, ConfigurationException { if (initialized) { Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java Thu Oct 7 15:40:41 2010 @@ -27,6 +27,8 @@ import java.util.concurrent.SynchronousQ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import javax.naming.ConfigurationException; + import org.apache.cassandra.db.SystemTable; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; @@ -115,8 +117,17 @@ public class CassandraDaemon CompactionManager.instance.checkAllColumnFamilies(); // start server internals - StorageService.instance.initServer(); - + try + { + StorageService.instance.initServer(); + } + catch (ConfigurationException e) + { + logger.error("Fatal error: " + e.getMessage()); + System.err.println("Bad configuration; unable to start server"); + System.exit(1); + } + // now we start listening for clients final CassandraServer cassandraServer = new CassandraServer(); Cassandra.Processor processor = new Cassandra.Processor(cassandraServer); Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/Util.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/Util.java?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/Util.java (original) +++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/Util.java Thu Oct 7 15:40:41 2010 @@ -31,9 +31,7 @@ import org.apache.commons.lang.ArrayUtil import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryPath; -import org.apache.cassandra.dht.Bounds; -import org.apache.cassandra.dht.Range; -import org.apache.cassandra.dht.Token; +import org.apache.cassandra.dht.*; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.thrift.SliceRange; @@ -44,6 +42,21 @@ public class Util return new Column(name.getBytes(), value.getBytes(), timestamp); } + public static Token token(String key) + { + return StorageService.getPartitioner().getToken(key); + } + + public static Range range(String left, String right) + { + return new Range(token(left), token(right)); + } + + public static Bounds bounds(String left, String right) + { + return new Bounds(token(left), token(right)); + } + public static void addMutation(RowMutation rm, String columnFamilyName, String superColumnName, long columnName, String value, long timestamp) { rm.add(new QueryPath(columnFamilyName, superColumnName.getBytes(), getBytes(columnName)), value.getBytes(), timestamp); Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java?rev=1005497&r1=1005496&r2=1005497&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java (original) +++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java Thu Oct 7 15:40:41 2010 @@ -24,6 +24,8 @@ import java.io.IOException; import java.util.Collections; import java.util.List; +import javax.naming.ConfigurationException; + import org.junit.Test; import org.apache.cassandra.dht.Token; @@ -37,7 +39,7 @@ import static org.junit.Assert.assertTru public class StorageServiceServerTest { @Test - public void testRegularMode() throws IOException, InterruptedException + public void testRegularMode() throws IOException, InterruptedException, ConfigurationException { CleanupHelper.mkdirs(); CleanupHelper.cleanup();