Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#setEndpointSnitch()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#setEndpointSnitch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void updateSnitch(String epSnitchClassName, Boolean dynamic, Integer dynamicUpdateInterval, Integer dynamicResetInterval, Double dynamicBadnessThreshold) throws ClassNotFoundException
{
    IEndpointSnitch oldSnitch = DatabaseDescriptor.getEndpointSnitch();

    // new snitch registers mbean during construction
    IEndpointSnitch newSnitch;
    try
    {
        newSnitch = FBUtilities.construct(epSnitchClassName, "snitch");
    }
    catch (ConfigurationException e)
    {
        throw new ClassNotFoundException(e.getMessage());
    }
    if (dynamic)
    {
        DatabaseDescriptor.setDynamicUpdateInterval(dynamicUpdateInterval);
        DatabaseDescriptor.setDynamicResetInterval(dynamicResetInterval);
        DatabaseDescriptor.setDynamicBadnessThreshold(dynamicBadnessThreshold);
        newSnitch = new DynamicEndpointSnitch(newSnitch);
    }

    // point snitch references to the new instance
    DatabaseDescriptor.setEndpointSnitch(newSnitch);
    for (String ks : Schema.instance.getKeyspaces())
    {
        Keyspace.open(ks).getReplicationStrategy().snitch = newSnitch;
    }

    if (oldSnitch instanceof DynamicEndpointSnitch)
        ((DynamicEndpointSnitch)oldSnitch).unregisterMBean();
}
 
Example 2
Source File: StorageServiceServerTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws ConfigurationException
{
    IEndpointSnitch snitch = new PropertyFileSnitch();
    DatabaseDescriptor.setEndpointSnitch(snitch);
    Keyspace.setInitialized();
}
 
Example 3
Source File: NetworkTopologyStrategyTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testLargeCluster() throws UnknownHostException, ConfigurationException
{
    int[] dcRacks = new int[]{2, 4, 8};
    int[] dcEndpoints = new int[]{128, 256, 512};
    int[] dcReplication = new int[]{2, 6, 6};

    IEndpointSnitch snitch = new RackInferringSnitch();
    DatabaseDescriptor.setEndpointSnitch(snitch);
    TokenMetadata metadata = new TokenMetadata();
    Map<String, String> configOptions = new HashMap<String, String>();
    Multimap<InetAddress, Token> tokens = HashMultimap.create();

    int totalRF = 0;
    for (int dc = 0; dc < dcRacks.length; ++dc)
    {
        totalRF += dcReplication[dc];
        configOptions.put(Integer.toString(dc), Integer.toString(dcReplication[dc]));
        for (int rack = 0; rack < dcRacks[dc]; ++rack)
        {
            for (int ep = 1; ep <= dcEndpoints[dc]/dcRacks[dc]; ++ep)
            {
                byte[] ipBytes = new byte[]{10, (byte)dc, (byte)rack, (byte)ep};
                InetAddress address = InetAddress.getByAddress(ipBytes);
                StringToken token = new StringToken(String.format("%02x%02x%02x", ep, rack, dc));
                logger.debug("adding node " + address + " at " + token);
                tokens.put(address, token);
            }
        }
    }
    metadata.updateNormalTokens(tokens);

    NetworkTopologyStrategy strategy = new NetworkTopologyStrategy(keyspaceName, metadata, snitch, configOptions);

    for (String testToken : new String[]{"123456", "200000", "000402", "ffffff", "400200"})
    {
        List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(new StringToken(testToken), metadata);
        Set<InetAddress> epSet = new HashSet<InetAddress>(endpoints);

        Assert.assertEquals(totalRF, endpoints.size());
        Assert.assertEquals(totalRF, epSet.size());
        logger.debug(testToken + ": " + endpoints.toString());
    }
}