Search in sources :

Example 66 with Cluster

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

the class RepartitionerCLI method main.

public static void main(String[] args) throws Exception {
    setupParser();
    OptionSet options = getValidOptions(args);
    // Required args
    String currentClusterXML = (String) options.valueOf("current-cluster");
    String currentStoresXML = (String) options.valueOf("current-stores");
    String interimClusterXML = new String(currentClusterXML);
    if (options.has("interim-cluster")) {
        interimClusterXML = (String) options.valueOf("interim-cluster");
    }
    String finalStoresXML = new String(currentStoresXML);
    if (options.has("final-stores")) {
        finalStoresXML = (String) options.valueOf("final-stores");
    }
    Cluster currentCluster = new ClusterMapper().readCluster(new File(currentClusterXML));
    List<StoreDefinition> currentStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(currentStoresXML));
    RebalanceUtils.validateClusterStores(currentCluster, currentStoreDefs);
    Cluster interimCluster = new ClusterMapper().readCluster(new File(interimClusterXML));
    List<StoreDefinition> finalStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(finalStoresXML));
    RebalanceUtils.validateClusterStores(interimCluster, finalStoreDefs);
    RebalanceUtils.validateCurrentInterimCluster(currentCluster, interimCluster);
    // Optional administrivia args
    int attempts = CmdUtils.valueOf(options, "attempts", Repartitioner.DEFAULT_REPARTITION_ATTEMPTS);
    String outputDir = null;
    if (options.has("output-dir")) {
        outputDir = (String) options.valueOf("output-dir");
    }
    // Optional repartitioning args
    boolean disableNodeBalancing = options.has("disable-node-balancing");
    boolean disableZoneBalancing = options.has("disable-zone-balancing");
    boolean enableRandomSwaps = options.has("enable-random-swaps");
    int randomSwapAttempts = CmdUtils.valueOf(options, "random-swap-attempts", Repartitioner.DEFAULT_RANDOM_SWAP_ATTEMPTS);
    int randomSwapSuccesses = CmdUtils.valueOf(options, "random-swap-successes", Repartitioner.DEFAULT_RANDOM_SWAP_SUCCESSES);
    List<Integer> randomSwapZoneIds = CmdUtils.valuesOf(options, "random-swap-zoneids", Repartitioner.DEFAULT_RANDOM_SWAP_ZONE_IDS);
    boolean enableGreedySwaps = options.has("enable-greedy-swaps");
    int greedySwapAttempts = CmdUtils.valueOf(options, "greedy-swap-attempts", Repartitioner.DEFAULT_GREEDY_SWAP_ATTEMPTS);
    int greedyMaxPartitionsPerNode = CmdUtils.valueOf(options, "greedy-max-partitions-per-node", Repartitioner.DEFAULT_GREEDY_MAX_PARTITIONS_PER_NODE);
    int greedyMaxPartitionsPerZone = CmdUtils.valueOf(options, "greedy-max-partitions-per-zone", Repartitioner.DEFAULT_GREEDY_MAX_PARTITIONS_PER_ZONE);
    List<Integer> greedySwapZoneIds = CmdUtils.valuesOf(options, "greedy-swap-zoneids", Repartitioner.DEFAULT_GREEDY_SWAP_ZONE_IDS);
    int maxContiguousPartitionsPerZone = CmdUtils.valueOf(options, "max-contiguous-partitions", Repartitioner.DEFAULT_MAX_CONTIGUOUS_PARTITIONS);
    // Sanity check optional repartitioning args
    if (disableNodeBalancing && !enableRandomSwaps && !enableGreedySwaps && maxContiguousPartitionsPerZone == 0) {
        printUsageAndDie("Did not enable any forms for repartitioning.");
    }
    if ((options.has("random-swap-attempts") || options.has("random-swap-successes")) && !enableRandomSwaps) {
        printUsageAndDie("Provided arguments for generate random swaps but did not enable the feature");
    }
    if ((options.has("greedy-swap-attempts") || options.has("greedy-max-partitions-per-node") || options.has("greedy-max-partitions-per-zone")) && !enableGreedySwaps) {
        printUsageAndDie("Provided arguments for generate greedy swaps but did not enable the feature");
    }
    Repartitioner.repartition(currentCluster, currentStoreDefs, interimCluster, finalStoreDefs, outputDir, attempts, disableNodeBalancing, disableZoneBalancing, enableRandomSwaps, randomSwapAttempts, randomSwapSuccesses, randomSwapZoneIds, enableGreedySwaps, greedySwapAttempts, greedyMaxPartitionsPerNode, greedyMaxPartitionsPerZone, greedySwapZoneIds, maxContiguousPartitionsPerZone);
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 67 with Cluster

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

the class ReplaceNodeCLI method getClusterXML.

private String getClusterXML() {
    ClusterMapper clusterMapper = new ClusterMapper();
    Cluster existingCluster = null;
    String clusterXML = null;
    Map<Integer, String> clusterXMLInNodes = getMetadataXML(MetadataStore.CLUSTER_KEY);
    for (Map.Entry<Integer, String> clusterNodeId : clusterXMLInNodes.entrySet()) {
        String xml = clusterNodeId.getValue();
        Cluster cluster = clusterMapper.readCluster(new StringReader(xml), false);
        if (existingCluster == null) {
            existingCluster = cluster;
            clusterXML = xml;
        } else if (existingCluster.equals(cluster) == false) {
            throw new VoldemortApplicationException("Cluster XMLs are different across nodes, fix that before the node swap...aborting " + clusterNodeId.getKey());
        }
    }
    return clusterXML;
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) StringReader(java.io.StringReader) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 68 with Cluster

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

the class RebalanceControllerCLI method main.

public static void main(String[] args) throws Exception {
    setupParser();
    OptionSet options = getValidOptions(args);
    // Bootstrap & fetch current cluster/stores
    String bootstrapURL = (String) options.valueOf("url");
    int parallelism = RebalanceController.MAX_PARALLEL_REBALANCING;
    if (options.has("parallelism")) {
        parallelism = (Integer) options.valueOf("parallelism");
    }
    long proxyPauseSec = RebalanceController.PROXY_PAUSE_IN_SECONDS;
    if (options.has("proxy-pause")) {
        proxyPauseSec = (Long) options.valueOf("proxy-pause");
    }
    RebalanceController rebalanceController = new RebalanceController(bootstrapURL, parallelism, proxyPauseSec);
    Cluster currentCluster = rebalanceController.getCurrentCluster();
    List<StoreDefinition> currentStoreDefs = rebalanceController.getCurrentStoreDefs();
    // If this test doesn't pass, something is wrong in prod!
    RebalanceUtils.validateClusterStores(currentCluster, currentStoreDefs);
    // Determine final cluster/stores and validate them
    String finalClusterXML = (String) options.valueOf("final-cluster");
    Cluster finalCluster = new ClusterMapper().readCluster(new File(finalClusterXML));
    List<StoreDefinition> finalStoreDefs = currentStoreDefs;
    if (options.has("final-stores")) {
        String storesXML = (String) options.valueOf("final-stores");
        finalStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXML));
    }
    RebalanceUtils.validateClusterStores(finalCluster, finalStoreDefs);
    RebalanceUtils.validateCurrentFinalCluster(currentCluster, finalCluster);
    // Process optional "planning" arguments
    int batchSize = CmdUtils.valueOf(options, "batch-size", RebalancePlan.BATCH_SIZE);
    String outputDir = null;
    if (options.has("output-dir")) {
        outputDir = (String) options.valueOf("output-dir");
    }
    RebalancePlan rebalancePlan = new RebalancePlan(currentCluster, currentStoreDefs, finalCluster, finalStoreDefs, batchSize, outputDir);
    boolean resetQuota = !options.has("no-reset-quota");
    Set<String> storeNames = Sets.newHashSet();
    for (StoreDefinition storeDef : finalStoreDefs) {
        storeNames.add(storeDef.getName());
    }
    QuotaResetter quotaResetter = new QuotaResetter(bootstrapURL, storeNames, rebalancePlan.getFinalCluster().getNodeIds());
    // before rebalance, remember and disable quota enforcement settings
    if (resetQuota) {
        quotaResetter.rememberAndDisableQuota();
    }
    // Plan & execute rebalancing.
    rebalanceController.rebalance(rebalancePlan);
    // after rebalance, reset quota values and recover quota enforcement
    if (resetQuota) {
        quotaResetter.resetQuotaAndRecoverEnforcement();
    }
}
Also used : RebalancePlan(voldemort.client.rebalance.RebalancePlan) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) RebalanceController(voldemort.client.rebalance.RebalanceController) StoreDefinition(voldemort.store.StoreDefinition) QuotaResetter(voldemort.client.rebalance.QuotaResetter) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 69 with Cluster

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

the class RebalancePlanCLI method main.

public static void main(String[] args) throws Exception {
    setupParser();
    OptionSet options = getValidOptions(args);
    // Required args
    String currentClusterXML = (String) options.valueOf("current-cluster");
    String currentStoresXML = (String) options.valueOf("current-stores");
    String finalClusterXML = (String) options.valueOf("final-cluster");
    // Required args for some use cases
    String finalStoresXML = new String(currentStoresXML);
    if (options.has("final-stores")) {
        finalStoresXML = (String) options.valueOf("final-stores");
    }
    Cluster currentCluster = new ClusterMapper().readCluster(new File(currentClusterXML));
    List<StoreDefinition> currentStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(currentStoresXML));
    Cluster finalCluster = new ClusterMapper().readCluster(new File(finalClusterXML));
    List<StoreDefinition> finalStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(finalStoresXML));
    // Optional args
    int batchSize = CmdUtils.valueOf(options, "batch-size", RebalancePlan.BATCH_SIZE);
    String outputDir = null;
    if (options.has("output-dir")) {
        outputDir = (String) options.valueOf("output-dir");
    }
    new RebalancePlan(currentCluster, currentStoreDefs, finalCluster, finalStoreDefs, batchSize, outputDir);
}
Also used : RebalancePlan(voldemort.client.rebalance.RebalancePlan) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 70 with Cluster

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

the class ValidateNodeIdCLI method main.

public static void main(String[] args) throws IOException {
    OptionParser parser = null;
    OptionSet options = null;
    try {
        parser = setupParser();
        options = parser.parse(args);
    } catch (OptionException oe) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        return;
    }
    /* validate options */
    if (options.has("help")) {
        printUsage();
        return;
    }
    if (!options.hasArgument("id") || !options.hasArgument("path")) {
        printUsageAndDie("Missing a required argument.");
        return;
    }
    String id = (String) options.valueOf("id");
    int expectedNodeId = Integer.parseInt(id);
    String clusterPaths = getFilePath(options, "path");
    String[] allPaths = clusterPaths.split(",");
    boolean isMatch = false;
    for (String path : allPaths) {
        path = path.replace("~", System.getProperty("user.home"));
        File filePath = new File(path);
        if (filePath.exists()) {
            isMatch = true;
            Cluster cluster = getCluster(filePath);
            Properties properties = new Properties();
            properties.setProperty(VoldemortConfig.ENABLE_NODE_ID_DETECTION, Boolean.toString(true));
            properties.setProperty(VoldemortConfig.VOLDEMORT_HOME, getTempDirPath());
            VoldemortConfig config = new VoldemortConfig(properties);
            int actualNodeId = VoldemortServer.getNodeId(config, cluster);
            if (actualNodeId != expectedNodeId) {
                throw new VoldemortApplicationException("Mismatch detected. Computed Node Id " + actualNodeId + " Expected " + expectedNodeId);
            } else {
                System.out.println("Expected and Computed node Id matched " + expectedNodeId);
            }
            config.setNodeId(actualNodeId);
            VoldemortServer.validateNodeId(config, cluster);
            System.out.println("Validation of node Id passed");
        }
    }
    if (!isMatch) {
        throw new VoldemortApplicationException("None of the paths matched the cluster.xml");
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) OptionException(joptsimple.OptionException) Cluster(voldemort.cluster.Cluster) OptionSet(joptsimple.OptionSet) Properties(java.util.Properties) OptionParser(joptsimple.OptionParser) File(java.io.File) VoldemortConfig(voldemort.server.VoldemortConfig)

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