cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1172717 - in /cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra: dht/BootStrapper.java service/StorageService.java
Date Mon, 19 Sep 2011 17:20:59 GMT
Author: jbellis
Date: Mon Sep 19 17:20:58 2011
New Revision: 1172717

URL: http://svn.apache.org/viewvc?rev=1172717&view=rev
Log:
unbreak build from #3219

Modified:
    cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/dht/BootStrapper.java
    cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/service/StorageService.java

Modified: cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/dht/BootStrapper.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/dht/BootStrapper.java?rev=1172717&r1=1172716&r2=1172717&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/dht/BootStrapper.java
(original)
+++ cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/dht/BootStrapper.java
Mon Sep 19 17:20:58 2011
@@ -127,6 +127,24 @@ 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, ConfigurationException
+    {
+        if (DatabaseDescriptor.getInitialToken() != null)
+        {
+            logger.debug("token manually specified as " + 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);
+    }
+
     public static Token getBalancedToken(TokenMetadata metadata, Map<InetAddress, Double>
load)
     {
         InetAddress maxEndpoint = getBootstrapSource(metadata, load);

Modified: cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/service/StorageService.java?rev=1172717&r1=1172716&r2=1172717&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/service/StorageService.java
(original)
+++ cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/service/StorageService.java
Mon Sep 19 17:20:58 2011
@@ -495,7 +495,9 @@ public class StorageService implements I
         // first startup is only chance to bootstrap
         Token<?> token;
         if (DatabaseDescriptor.isAutoBootstrap()
-            && !(DatabaseDescriptor.getSeeds().contains(FBUtilities.getBroadcastAddress())
|| SystemTable.isBootstrapped()))
+            && !(SystemTable.isBootstrapped()
+                 || DatabaseDescriptor.getSeeds().contains(FBUtilities.getBroadcastAddress())
+                 || Schema.instance.getNonSystemTables().isEmpty()))
         {
             setMode("Joining: waiting for ring and schema information", true);
             try
@@ -517,7 +519,7 @@ public class StorageService implements I
                     throw new UnsupportedOperationException(s);
                 }
                 setMode("Joining: getting bootstrap token", true);
-                token = getNewToken();
+                token = BootStrapper.getBootstrapToken(tokenMetadata_, LoadBroadcaster.instance.getLoadInfo());
             }
             else
             {
@@ -539,55 +541,37 @@ public class StorageService implements I
                 setMode("Joining: Replacing a node with token: " + token, true);
             }
 
-            // don't bootstrap if there are no tables defined.
-            if (Schema.instance.getNonSystemTables().size() > 0)
-            {
-                bootstrap(token);
-                assert !isBootstrapMode; // bootstrap will block until finished
-            }
-            // Else: nothing to bootstrap, go directly to participating in ring
+            bootstrap(token);
+            assert !isBootstrapMode; // bootstrap will block until finished
         }
         else
         {
             token = SystemTable.getSavedToken();
             if (token == null)
-                token = getNewToken();
+            {
+                String initialToken = DatabaseDescriptor.getInitialToken();
+                if (initialToken == null)
+                {
+                    token = partitioner.getRandomToken();
+                    logger_.warn("Generated random token " + token + ". Random tokens will
result in an unbalanced ring; see http://wiki.apache.org/cassandra/Operations");
+                }
+                else
+                {
+                    token = partitioner.getTokenFactory().fromString(initialToken);
+                    logger_.info("Saved token not found. Using " + token + " from configuration");
+                }
+            }
             else
+            {
                 logger_.info("Using saved token " + token);
-        }
-
-        // start participating in the ring.
-        SystemTable.setBootstrapped(true);
-        setToken(token);
-        logger_.info("Bootstrap/Replace/Move completed! Now serving reads.");
-        assert tokenMetadata_.sortedTokens().size() > 0;
-    }
+            }
 
-    /**
-     * Return a new token for this node.
-     */
-    private Token getNewToken() throws ConfigurationException
-    {
-        Token token;
-        if (DatabaseDescriptor.getInitialToken() != null)
-        {
-            logger_.debug("token manually specified as {}", DatabaseDescriptor.getInitialToken());
-            token = StorageService.getPartitioner().getTokenFactory().fromString(DatabaseDescriptor.getInitialToken());
+            // start participating in the ring.
+            SystemTable.setBootstrapped(true);
+            setToken(token);
+            logger_.info("Bootstrap/Replace/Move completed! Now serving reads.");
+            assert tokenMetadata_.sortedTokens().size() > 0;
         }
-        else if (Schema.instance.getNonSystemTables().size() > 0)
-        {
-            // We are not bootstrapping, we are an initial node, getBalancedToken is not
safe.
-            token = partitioner.getRandomToken();
-            logger_.warn("Generated random token " + token + ". Random tokens will result
in an unbalanced ring; see http://wiki.apache.org/cassandra/Operation");
-        }
-        else
-        {
-            token = BootStrapper.getBalancedToken(tokenMetadata_, LoadBroadcaster.instance.getLoadInfo());
-        }
-
-        if (tokenMetadata_.getEndpoint(token) != null)
-            throw new ConfigurationException("Bootstraping to existing token " + token +
" is not allowed (decommission/removetoken the old node first)");
-        return token;
     }
 
     public synchronized void joinRing() throws IOException, org.apache.cassandra.config.ConfigurationException



Mime
View raw message