use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class UpdateClusterUtils method updateCluster.
/**
* Concatenates the list of current nodes in the given cluster with the new
* nodes provided and returns an updated cluster metadata. <br>
* If the nodes being updated already exist in the current metadata, we take
* the updated ones
*
* @param currentCluster The current cluster metadata
* @param updatedNodeList The list of new nodes to be added
* @return New cluster metadata containing both the sets of nodes
*/
public static Cluster updateCluster(Cluster currentCluster, List<Node> updatedNodeList) {
List<Node> newNodeList = new ArrayList<Node>(updatedNodeList);
for (Node currentNode : currentCluster.getNodes()) {
if (!updatedNodeList.contains(currentNode))
newNodeList.add(currentNode);
}
Collections.sort(newNodeList);
return new Cluster(currentCluster.getName(), newNodeList, Lists.newArrayList(currentCluster.getZones()));
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class UpdateClusterUtils method createUpdatedCluster.
/**
* Updates the existing cluster such that we remove partitions mentioned
* from the stealer node and add them to the donor node
*
* @param currentCluster Existing cluster metadata. Both stealer and donor
* node should already exist in this metadata
* @param stealerNodeId Id of node for which we are stealing the partitions
* @param donatedPartitions List of partitions we are moving
* @return Updated cluster metadata
*/
public static Cluster createUpdatedCluster(Cluster currentCluster, int stealerNodeId, List<Integer> donatedPartitions) {
Cluster updatedCluster = Cluster.cloneCluster(currentCluster);
// Go over every donated partition one by one
for (int donatedPartition : donatedPartitions) {
// Gets the donor Node that owns this donated partition
Node donorNode = updatedCluster.getNodeForPartitionId(donatedPartition);
Node stealerNode = updatedCluster.getNodeById(stealerNodeId);
if (donorNode == stealerNode) {
// Moving to the same location = No-op
continue;
}
// Update the list of partitions for this node
donorNode = removePartitionFromNode(donorNode, donatedPartition);
stealerNode = addPartitionToNode(stealerNode, donatedPartition);
// Sort the nodes
updatedCluster = updateCluster(updatedCluster, Lists.newArrayList(donorNode, stealerNode));
}
return updatedCluster;
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class ServerTestUtils method getLocalCluster.
public static Cluster getLocalCluster(int numberOfNodes, int[] ports, int[][] partitionMap) {
if (3 * numberOfNodes != ports.length)
throw new IllegalArgumentException(3 * numberOfNodes + " ports required but only " + ports.length + " given.");
List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < numberOfNodes; i++) {
List<Integer> partitions = ImmutableList.of(i);
if (null != partitionMap) {
partitions = new ArrayList<Integer>(partitionMap[i].length);
for (int p : partitionMap[i]) {
partitions.add(p);
}
}
nodes.add(new Node(i, "localhost", ports[3 * i], ports[3 * i + 1], ports[3 * i + 2], partitions));
}
return new Cluster("test-cluster", nodes);
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class ZoneShrinkageCLI method executeShrink.
public void executeShrink(boolean realRun) {
Cluster initialCluster = adminClient.getAdminClientCluster();
Collection<Node> initialClusterNodes = initialCluster.getNodes();
Integer initialClusterFirstNodeId = initialCluster.getNodes().iterator().next().getId();
boolean shouldContinue;
// Get Metadata from one server
logger.info("Start fetching metadata for server " + initialClusterFirstNodeId);
String initialClusterXml = adminClient.metadataMgmtOps.getRemoteMetadata(initialClusterFirstNodeId, CLUSTER_KEY).getValue();
String initialStoresXml = adminClient.metadataMgmtOps.getRemoteMetadata(initialClusterFirstNodeId, STORES_KEY).getValue();
logger.info("End fetching metadata for server " + initialClusterFirstNodeId);
logger.info("Original cluster.xml: \n" + initialClusterXml + "\n");
logger.info("Original stores.xml: \n" + initialStoresXml + "\n");
// Query the servers to see if all have the same XML
shouldContinue = verifyMetadataConsistency(adminClient, initialClusterNodes, initialClusterXml, initialStoresXml);
if (!shouldContinue) {
logAbort();
return;
}
// Calculate and print out the new metadata
String newStoresXml = shrinkStoresXml(initialStoresXml, droppingZoneId);
String newClusterXml = shrinkClusterXml(initialClusterXml, droppingZoneId);
logger.info("New cluster.xml: \n" + newClusterXml + "\n");
logger.info("New stores.xml: \n" + newStoresXml + "\n");
// Verifying Server rebalancing states
shouldContinue = verifyRebalanceState(adminClient, initialClusterNodes);
if (!shouldContinue) {
logAbort();
return;
}
// Run shrinkage
if (realRun) {
logger.info("Updating metadata(cluster.xml, stores.xml) on all nodes");
executeSetMetadataPair(-1, adminClient, MetadataStore.CLUSTER_KEY, newClusterXml, MetadataStore.STORES_KEY, newStoresXml);
} else {
logger.info("(dry-run)Skipping updating metadata");
}
// Check metadata consistency
if (realRun) {
shouldContinue = verifyMetadataConsistency(adminClient, initialClusterNodes, newClusterXml, newStoresXml);
if (!shouldContinue) {
logAbort();
return;
}
} else {
logger.info("(dry-run)Skipping verifying new metadata");
}
// Verifying Server rebalancing states
shouldContinue = verifyRebalanceState(adminClient, initialClusterNodes);
if (!shouldContinue) {
logAbort();
} else {
logger.info("Shrinkage on " + bootstrapUrl + " is completed");
logger.info("=========================================================");
logger.info("|| DDDDDDD OOO NN NN EEEEEEEE ||");
logger.info("|| DD DD OO OO NNN NN EE ||");
logger.info("|| DD DD OO OO NNNN NN EE ||");
logger.info("|| DD DD OO OO NN NN NN EEEEEEEE ||");
logger.info("|| DD DD OO OO NN NNNN EE ||");
logger.info("|| DD DD OO OO NN NNN EE ||");
logger.info("|| DDDDDDD OOO NN NN EEEEEEEE ||");
logger.info("=========================================================");
}
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class ZoneShrinkageCLI method shrinkClusterXml.
protected static String shrinkClusterXml(String clusterXml, int droppingZoneId) {
Cluster initialCluster = new ClusterMapper().readCluster(new StringReader(clusterXml));
Cluster intermediateCluster = RebalanceUtils.vacateZone(initialCluster, droppingZoneId);
Cluster finalCluster = RebalanceUtils.dropZone(intermediateCluster, droppingZoneId);
String newClusterXml = new ClusterMapper().writeCluster(finalCluster);
return newClusterXml;
}
Aggregations