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;
}
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];
}
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);
}
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;
}
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));
}
Aggregations