mirror of https://github.com/apache/cassandra
allow specifying initial token. patch by Jun Rao; reviewed by jbellis for CASSANDRA-181
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@775203 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1fdfad82b3
commit
324c3c32a1
|
|
@ -32,6 +32,18 @@
|
||||||
-->
|
-->
|
||||||
<Partitioner>org.apache.cassandra.dht.RandomPartitioner</Partitioner>
|
<Partitioner>org.apache.cassandra.dht.RandomPartitioner</Partitioner>
|
||||||
|
|
||||||
|
<!-- If you are using the OrderPreservingPartitioner and you know your key
|
||||||
|
distribution, you can specify the token for this node to use.
|
||||||
|
(Keys are sent to the node with the "closest" token, so distributing
|
||||||
|
your tokens equally along the key distribution space will spread
|
||||||
|
keys evenly across your cluster.) This setting is only checked the
|
||||||
|
first time a node is started.
|
||||||
|
|
||||||
|
This can also be useful with RandomPartitioner to force equal
|
||||||
|
spacing of tokens around the hash space, especially for
|
||||||
|
clusters with a small number of nodes. -->
|
||||||
|
<InitialToken></InitialToken>
|
||||||
|
|
||||||
<!-- RackAware: Setting this to true instructs Cassandra to try and place the replicas in
|
<!-- RackAware: Setting this to true instructs Cassandra to try and place the replicas in
|
||||||
a different rack in the same datacenter and one in a different datacenter
|
a different rack in the same datacenter and one in a different datacenter
|
||||||
-->
|
-->
|
||||||
|
|
|
||||||
|
|
@ -119,12 +119,15 @@ public class DatabaseDescriptor
|
||||||
|
|
||||||
// the path qualified config file (storage-conf.xml) name
|
// the path qualified config file (storage-conf.xml) name
|
||||||
private static String configFileName_;
|
private static String configFileName_;
|
||||||
|
/* initial token in the ring */
|
||||||
|
private static String initialToken_ = null;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
configFileName_ = System.getProperty("storage-config") + System.getProperty("file.separator") + "storage-conf.xml";
|
configFileName_ = System.getProperty("storage-config") + System.getProperty("file.separator") + "storage-conf.xml";
|
||||||
|
logger_.debug("Loading settings from " + configFileName_);
|
||||||
XMLUtils xmlUtils = new XMLUtils(configFileName_);
|
XMLUtils xmlUtils = new XMLUtils(configFileName_);
|
||||||
|
|
||||||
/* Cluster Name */
|
/* Cluster Name */
|
||||||
|
|
@ -164,6 +167,8 @@ public class DatabaseDescriptor
|
||||||
if ( gcGrace != null )
|
if ( gcGrace != null )
|
||||||
gcGraceInSeconds_ = Integer.parseInt(gcGrace);
|
gcGraceInSeconds_ = Integer.parseInt(gcGrace);
|
||||||
|
|
||||||
|
initialToken_ = xmlUtils.getNodeValue("/Storage/InitialToken");
|
||||||
|
|
||||||
/* Zookeeper's session timeout */
|
/* Zookeeper's session timeout */
|
||||||
String zkSessionTimeout = xmlUtils.getNodeValue("/Storage/ZookeeperSessionTimeout");
|
String zkSessionTimeout = xmlUtils.getNodeValue("/Storage/ZookeeperSessionTimeout");
|
||||||
if ( zkSessionTimeout != null )
|
if ( zkSessionTimeout != null )
|
||||||
|
|
@ -536,6 +541,11 @@ public class DatabaseDescriptor
|
||||||
return memtableLifetime_;
|
return memtableLifetime_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getInitialToken()
|
||||||
|
{
|
||||||
|
return initialToken_;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getMemtableSize()
|
public static int getMemtableSize()
|
||||||
{
|
{
|
||||||
return memtableSize_;
|
return memtableSize_;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import java.util.Comparator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||||
|
|
||||||
public class OrderPreservingPartitioner implements IPartitioner
|
public class OrderPreservingPartitioner implements IPartitioner
|
||||||
{
|
{
|
||||||
// TODO make locale configurable. But don't just leave it up to the OS or you could really screw
|
// TODO make locale configurable. But don't just leave it up to the OS or you could really screw
|
||||||
|
|
@ -65,6 +67,11 @@ public class OrderPreservingPartitioner implements IPartitioner
|
||||||
|
|
||||||
public StringToken getDefaultToken()
|
public StringToken getDefaultToken()
|
||||||
{
|
{
|
||||||
|
String initialToken = DatabaseDescriptor.getInitialToken();
|
||||||
|
if (initialToken != null)
|
||||||
|
return new StringToken(initialToken);
|
||||||
|
|
||||||
|
// generate random token
|
||||||
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package org.apache.cassandra.dht;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||||
import org.apache.cassandra.utils.FBUtilities;
|
import org.apache.cassandra.utils.FBUtilities;
|
||||||
import org.apache.cassandra.utils.GuidGenerator;
|
import org.apache.cassandra.utils.GuidGenerator;
|
||||||
|
|
||||||
|
|
@ -74,6 +75,11 @@ public class RandomPartitioner implements IPartitioner
|
||||||
|
|
||||||
public BigIntegerToken getDefaultToken()
|
public BigIntegerToken getDefaultToken()
|
||||||
{
|
{
|
||||||
|
String initialToken = DatabaseDescriptor.getInitialToken();
|
||||||
|
if (initialToken != null)
|
||||||
|
return new BigIntegerToken(new BigInteger(initialToken));
|
||||||
|
|
||||||
|
// generate random token
|
||||||
String guid = GuidGenerator.guid();
|
String guid = GuidGenerator.guid();
|
||||||
BigInteger token = FBUtilities.hash(guid);
|
BigInteger token = FBUtilities.hash(guid);
|
||||||
if ( token.signum() == -1 )
|
if ( token.signum() == -1 )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue