Search in sources :

Example 46 with Cluster

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()));
}
Also used : Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Cluster(voldemort.cluster.Cluster)

Example 47 with Cluster

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;
}
Also used : Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster)

Example 48 with Cluster

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);
}
Also used : Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Cluster(voldemort.cluster.Cluster)

Example 49 with Cluster

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("=========================================================");
    }
}
Also used : Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster)

Example 50 with Cluster

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;
}
Also used : StringReader(java.io.StringReader) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper)

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