Search in sources :

Example 41 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class ServerTestUtils method startVoldemortCluster.

/**
     * This method wraps up all of the work that is done in many different tests
     * to set up some number of Voldemort servers in a cluster. This method
     * masks an intermittent TOCTOU problem with the ports identified by
     * {@link #findFreePorts(int)} not actually being free when a server needs
     * to bind to them. If this method returns, it will return a non-null
     * cluster. This method is not guaranteed to return, but will likely
     * eventually do so...
     *
     * @param numServers
     * @param voldemortServers
     * @param partitionMap
     * @param socketStoreFactory
     * @param useNio
     * @param clusterFile
     * @param storeFile
     * @param properties
     * @param customCluster Use this specified cluster object
     * @return Cluster object that was used to successfully start all of the
     *         servers.
     * @throws IOException
     */
// TODO: numServers is likely not needed. If this method is refactored in
// the future, then try and drop the numServers argument.
// So, is the socketStoreFactory argument.. It should be entirely hidden
// within the helper method
private static Cluster startVoldemortCluster(int numServers, VoldemortServer[] voldemortServers, int[][] partitionMap, SocketStoreFactory socketStoreFactory, boolean useNio, String clusterFile, String storeFile, Properties properties, Cluster customCluster) throws IOException {
    boolean started = false;
    Cluster cluster = null;
    while (!started) {
        try {
            cluster = internalStartVoldemortCluster(numServers, voldemortServers, partitionMap, socketStoreFactory, useNio, clusterFile, storeFile, properties, customCluster);
            started = true;
        } catch (BindException be) {
            logger.debug("Caught BindException when starting cluster. Will retry.");
        }
    }
    return cluster;
}
Also used : Cluster(voldemort.cluster.Cluster) BindException(java.net.BindException)

Example 42 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class ServerTestUtils method startStandAloneVoldemortServer.

public static VoldemortServer startStandAloneVoldemortServer(Properties serverProperties, String storesXmlFile) throws IOException {
    VoldemortServer[] servers = new VoldemortServer[1];
    int[][] partitionMap = { { 0, 1, 2, 3 } };
    SocketStoreFactory socketStoreFactory = getSocketStoreFactory();
    try {
        Cluster cluster = ServerTestUtils.startVoldemortCluster(1, servers, partitionMap, socketStoreFactory, true, null, storesXmlFile, serverProperties);
    } finally {
        socketStoreFactory.close();
    }
    return servers[0];
}
Also used : Cluster(voldemort.cluster.Cluster) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) VoldemortServer(voldemort.server.VoldemortServer)

Example 43 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class ServerTestUtils method updateClusterWithNewHost.

/**
     * Update a cluster by replacing the specified server with a new host, i.e.
     * new ports since they are all localhost
     *
     * @param original The original cluster to be updated
     * @param serverIds The ids of the server to be replaced with new hosts
     * @return updated cluster
     */
public static Cluster updateClusterWithNewHost(Cluster original, int... serverIds) {
    int highestPortInuse = 0;
    for (Node node : original.getNodes()) {
        int nodeMaxPort = 0;
        nodeMaxPort = Math.max(nodeMaxPort, node.getAdminPort());
        nodeMaxPort = Math.max(nodeMaxPort, node.getHttpPort());
        nodeMaxPort = Math.max(nodeMaxPort, node.getSocketPort());
        highestPortInuse = Math.max(highestPortInuse, nodeMaxPort);
    }
    Set<Integer> newNodesSet = new HashSet<Integer>(serverIds.length);
    for (int id : serverIds) {
        newNodesSet.add(id);
    }
    List<Node> newNodeList = new ArrayList<Node>(serverIds.length);
    for (Node node : original.getNodes()) {
        if (newNodesSet.contains(node.getId())) {
            node = new Node(node.getId(), "localhost", ++highestPortInuse, ++highestPortInuse, ++highestPortInuse, node.getPartitionIds());
        }
        newNodeList.add(node);
    }
    return new Cluster(original.getName(), newNodeList);
}
Also used : Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Cluster(voldemort.cluster.Cluster) HashSet(java.util.HashSet)

Example 44 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class ServerTestUtils method internalStartVoldemortCluster.

protected static Cluster internalStartVoldemortCluster(int numServers, VoldemortServer[] voldemortServers, int[][] partitionMap, SocketStoreFactory socketStoreFactory, boolean useNio, String clusterFile, String storeFile, Properties properties, Cluster customCluster) throws IOException {
    Cluster cluster = null;
    if (customCluster != null) {
        cluster = customCluster;
    } else {
        cluster = ServerTestUtils.getLocalCluster(numServers, partitionMap);
    }
    int count = 0;
    for (int nodeId : cluster.getNodeIds()) {
        voldemortServers[count] = ServerTestUtils.startVoldemortServer(socketStoreFactory, ServerTestUtils.createServerConfig(useNio, nodeId, TestUtils.createTempDir().getAbsolutePath(), clusterFile, storeFile, properties), cluster);
        count++;
    }
    return cluster;
}
Also used : Cluster(voldemort.cluster.Cluster)

Example 45 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class RebalanceUtils method dropZone.

/**
     * Given a interim cluster with a previously vacated zone, constructs a new
     * cluster object with the drop zone completely removed
     * 
     * @param intermediateCluster
     * @param dropZoneId
     * @return adjusted cluster with the zone dropped
     */
public static Cluster dropZone(Cluster intermediateCluster, int dropZoneId) {
    // Filter out nodes that don't belong to the zone being dropped
    Set<Node> survivingNodes = new HashSet<Node>();
    for (int nodeId : intermediateCluster.getNodeIds()) {
        if (intermediateCluster.getNodeById(nodeId).getZoneId() != dropZoneId) {
            survivingNodes.add(intermediateCluster.getNodeById(nodeId));
        }
    }
    // Filter out dropZoneId from all zones
    Set<Zone> zones = new HashSet<Zone>();
    for (int zoneId : intermediateCluster.getZoneIds()) {
        if (zoneId == dropZoneId) {
            continue;
        }
        List<Integer> proximityList = intermediateCluster.getZoneById(zoneId).getProximityList();
        proximityList.remove(new Integer(dropZoneId));
        zones.add(new Zone(zoneId, proximityList));
    }
    return new Cluster(intermediateCluster.getName(), Utils.asSortedList(survivingNodes), Utils.asSortedList(zones));
}
Also used : Zone(voldemort.cluster.Zone) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) HashSet(java.util.HashSet)

Aggregations

Cluster (voldemort.cluster.Cluster)197 Test (org.junit.Test)74 StoreDefinition (voldemort.store.StoreDefinition)74 Node (voldemort.cluster.Node)72 ArrayList (java.util.ArrayList)51 HashMap (java.util.HashMap)47 ByteArray (voldemort.utils.ByteArray)33 AdminClient (voldemort.client.protocol.admin.AdminClient)26 ClusterTestUtils (voldemort.ClusterTestUtils)25 VoldemortException (voldemort.VoldemortException)24 List (java.util.List)23 ClusterMapper (voldemort.xml.ClusterMapper)23 File (java.io.File)20 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)18 Zone (voldemort.cluster.Zone)17 Versioned (voldemort.versioning.Versioned)17 Properties (java.util.Properties)16 IOException (java.io.IOException)15 VoldemortServer (voldemort.server.VoldemortServer)15 RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)14