mirror of https://github.com/apache/cassandra
Check between num_tokens and initial_token only applies to vnodes usage
patch by Stefan Miklosovic; reviewed by Mick Semb Wever for CASSANDRA-14477
This commit is contained in:
parent
8ef5a88631
commit
bfd5d20a13
2
NEWS.txt
2
NEWS.txt
|
|
@ -47,7 +47,7 @@ using the provided 'sstableupgrade' tool.
|
|||
|
||||
Upgrading
|
||||
---------
|
||||
- In cassandra.yaml, num_tokens must be defined if initial_token is defined.
|
||||
- In cassandra.yaml, when using vnodes num_tokens must be defined if initial_token is defined.
|
||||
If it is not defined, or not equal to the numbers of tokens defined in initial_tokens,
|
||||
the node will not start. See CASSANDRA-14477 for details.
|
||||
|
||||
|
|
|
|||
|
|
@ -300,7 +300,10 @@ public class DatabaseDescriptor
|
|||
Collection<String> tokens = tokensFromString(config.initial_token);
|
||||
if (config.num_tokens == null)
|
||||
{
|
||||
throw new ConfigurationException("initial_token was set but num_tokens is not!", false);
|
||||
if (tokens.size() == 1)
|
||||
config.num_tokens = 1;
|
||||
else
|
||||
throw new ConfigurationException("initial_token was set but num_tokens is not!", false);
|
||||
}
|
||||
|
||||
if (tokens.size() != config.num_tokens)
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ public class DatabaseDescriptorTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyInitialTokensInitialTokensSetNumTokensSetAndDoesMatch() throws Exception
|
||||
public void testApplyTokensConfigInitialTokensSetNumTokensSetAndDoesMatch() throws Exception
|
||||
{
|
||||
Config config = DatabaseDescriptor.loadConfig();
|
||||
config.initial_token = "0,256,1024";
|
||||
|
|
@ -337,7 +337,7 @@ public class DatabaseDescriptorTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyInitialTokensInitialTokensSetNumTokensSetAndDoesntMatch() throws Exception
|
||||
public void testApplyTokensConfigInitialTokensSetNumTokensSetAndDoesntMatch() throws Exception
|
||||
{
|
||||
Config config = DatabaseDescriptor.loadConfig();
|
||||
config.initial_token = "0,256,1024";
|
||||
|
|
@ -349,7 +349,7 @@ public class DatabaseDescriptorTest
|
|||
{
|
||||
DatabaseDescriptor.applyTokensConfig(config);
|
||||
|
||||
Assert.fail("initial_token = 0,256,1024 and num_tokens = 10 but applyInitialTokens() did not fail!");
|
||||
Assert.fail("initial_token = 0,256,1024 and num_tokens = 10 but applyTokensConfig() did not fail!");
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
|
|
@ -363,7 +363,7 @@ public class DatabaseDescriptorTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyInitialTokensInitialTokensSetNumTokensNotSet() throws Exception
|
||||
public void testApplyTokensConfigInitialTokensSetNumTokensNotSet() throws Exception
|
||||
{
|
||||
Config config = DatabaseDescriptor.loadConfig();
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ public class DatabaseDescriptorTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyInitialTokensInitialTokensNotSetNumTokensSet() throws Exception
|
||||
public void testApplyTokensConfigInitialTokensNotSetNumTokensSet() throws Exception
|
||||
{
|
||||
Config config = DatabaseDescriptor.loadConfig();
|
||||
config.num_tokens = 3;
|
||||
|
|
@ -408,7 +408,7 @@ public class DatabaseDescriptorTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testApplyInitialTokensInitialTokensNotSetNumTokensNotSet() throws Exception
|
||||
public void testApplyTokensConfigInitialTokensNotSetNumTokensNotSet() throws Exception
|
||||
{
|
||||
Config config = DatabaseDescriptor.loadConfig();
|
||||
|
||||
|
|
@ -427,6 +427,28 @@ public class DatabaseDescriptorTest
|
|||
Assert.assertTrue(DatabaseDescriptor.tokensFromString(config.initial_token).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyTokensConfigInitialTokensOneNumTokensNotSet() throws Exception
|
||||
{
|
||||
Config config = DatabaseDescriptor.loadConfig();
|
||||
config.initial_token = "123";
|
||||
config.num_tokens = null;
|
||||
|
||||
unregisterSnitchesForTokenConfigTest();
|
||||
|
||||
try
|
||||
{
|
||||
DatabaseDescriptor.applyTokensConfig(config);
|
||||
}
|
||||
finally
|
||||
{
|
||||
unregisterSnitchesForTokenConfigTest();
|
||||
}
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(1), config.num_tokens);
|
||||
Assert.assertEquals(1, DatabaseDescriptor.tokensFromString(config.initial_token).size());
|
||||
}
|
||||
|
||||
private void unregisterSnitchesForTokenConfigTest() throws Exception
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in New Issue