Search in sources :

Example 1 with IEndpointSnitch

use of org.apache.cassandra.locator.IEndpointSnitch in project cassandra by apache.

the class StorageServiceServerTest method setUp.

@BeforeClass
public static void setUp() throws ConfigurationException {
    DatabaseDescriptor.daemonInitialization();
    IEndpointSnitch snitch = new PropertyFileSnitch();
    DatabaseDescriptor.setEndpointSnitch(snitch);
    Keyspace.setInitialized();
}
Also used : PropertyFileSnitch(org.apache.cassandra.locator.PropertyFileSnitch) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) BeforeClass(org.junit.BeforeClass)

Example 2 with IEndpointSnitch

use of org.apache.cassandra.locator.IEndpointSnitch in project eiger by wlloyd.

the class StorageProxy method findSuitableEndpoint.

/**
     * Find a suitable replica as leader for counter update.
     * For now, we pick a random replica in the local DC (or ask the snitch if
     * there is no replica alive in the local DC).
     * TODO: if we track the latency of the counter writes (which makes sense
     * contrarily to standard writes since there is a read involved), we could
     * trust the dynamic snitch entirely, which may be a better solution. It
     * is unclear we want to mix those latencies with read latencies, so this
     * may be a bit involved.
     */
private static InetAddress findSuitableEndpoint(String table, ByteBuffer key, String localDataCenter) throws UnavailableException {
    IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
    List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(table, key);
    if (endpoints.isEmpty())
        throw new UnavailableException();
    List<InetAddress> localEndpoints = new ArrayList<InetAddress>();
    for (InetAddress endpoint : endpoints) {
        if (snitch.getDatacenter(endpoint).equals(localDataCenter))
            localEndpoints.add(endpoint);
    }
    if (localEndpoints.isEmpty()) {
        // No endpoint in local DC, pick the closest endpoint according to the snitch
        snitch.sortByProximity(FBUtilities.getBroadcastAddress(), endpoints);
        return endpoints.get(0);
    } else {
        return localEndpoints.get(FBUtilities.threadLocalRandom().nextInt(localEndpoints.size()));
    }
}
Also used : InetAddress(java.net.InetAddress) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch)

Example 3 with IEndpointSnitch

use of org.apache.cassandra.locator.IEndpointSnitch in project cassandra by apache.

the class ViewUtilsTest method setUp.

@BeforeClass
public static void setUp() throws ConfigurationException {
    DatabaseDescriptor.daemonInitialization();
    IEndpointSnitch snitch = new PropertyFileSnitch();
    DatabaseDescriptor.setEndpointSnitch(snitch);
    Keyspace.setInitialized();
}
Also used : PropertyFileSnitch(org.apache.cassandra.locator.PropertyFileSnitch) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) BeforeClass(org.junit.BeforeClass)

Example 4 with IEndpointSnitch

use of org.apache.cassandra.locator.IEndpointSnitch in project cassandra by apache.

the class BootStrapperTest method testAllocateTokensNetworkStrategy.

public void testAllocateTokensNetworkStrategy(int rackCount, int replicas) throws UnknownHostException {
    IEndpointSnitch oldSnitch = DatabaseDescriptor.getEndpointSnitch();
    try {
        DatabaseDescriptor.setEndpointSnitch(new RackInferringSnitch());
        int vn = 16;
        String ks = "BootStrapperTestNTSKeyspace" + rackCount + replicas;
        String dc = "1";
        // Register peers with expected DC for NetworkTopologyStrategy.
        TokenMetadata metadata = StorageService.instance.getTokenMetadata();
        metadata.clearUnsafe();
        metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.1.0.99"));
        metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.15.0.99"));
        SchemaLoader.createKeyspace(ks, KeyspaceParams.nts(dc, replicas, "15", 15), SchemaLoader.standardCFMD(ks, "Standard1"));
        TokenMetadata tm = StorageService.instance.getTokenMetadata();
        tm.clearUnsafe();
        for (int i = 0; i < rackCount; ++i) generateFakeEndpoints(tm, 10, vn, dc, Integer.toString(i));
        InetAddress addr = InetAddress.getByName("127." + dc + ".0.99");
        allocateTokensForNode(vn, ks, tm, addr);
    // Note: Not matching replication factor in second datacentre, but this should not affect us.
    } finally {
        DatabaseDescriptor.setEndpointSnitch(oldSnitch);
    }
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) RackInferringSnitch(org.apache.cassandra.locator.RackInferringSnitch)

Example 5 with IEndpointSnitch

use of org.apache.cassandra.locator.IEndpointSnitch in project cassandra by apache.

the class SystemKeyspace method persistLocalMetadata.

public static void persistLocalMetadata() {
    String req = "INSERT INTO system.%s (" + "key," + "cluster_name," + "release_version," + "cql_version," + "native_protocol_version," + "data_center," + "rack," + "partitioner," + "rpc_address," + "broadcast_address," + "listen_address" + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
    executeOnceInternal(format(req, LOCAL), LOCAL, DatabaseDescriptor.getClusterName(), FBUtilities.getReleaseVersionString(), QueryProcessor.CQL_VERSION.toString(), String.valueOf(ProtocolVersion.CURRENT.asInt()), snitch.getDatacenter(FBUtilities.getBroadcastAddress()), snitch.getRack(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getPartitioner().getClass().getName(), DatabaseDescriptor.getRpcAddress(), FBUtilities.getBroadcastAddress(), FBUtilities.getLocalAddress());
}
Also used : IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch)

Aggregations

IEndpointSnitch (org.apache.cassandra.locator.IEndpointSnitch)10 InetAddress (java.net.InetAddress)6 PropertyFileSnitch (org.apache.cassandra.locator.PropertyFileSnitch)2 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)2 BeforeClass (org.junit.BeforeClass)2 IOException (java.io.IOException)1 AbstractEndpointSnitch (org.apache.cassandra.locator.AbstractEndpointSnitch)1 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)1 DynamicEndpointSnitch (org.apache.cassandra.locator.DynamicEndpointSnitch)1 RackInferringSnitch (org.apache.cassandra.locator.RackInferringSnitch)1 Test (org.junit.Test)1