Search in sources :

Example 26 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class TestDistribution method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2)
        Utils.croak("USAGE: java TestDistribution cluster.xml replication_factor max_id");
    long start = System.currentTimeMillis();
    File file = new File(args[0]);
    int repFactor = Integer.parseInt(args[1]);
    int maxVal = Integer.parseInt(args[2]);
    ClusterMapper mapper = new ClusterMapper();
    Cluster cluster = mapper.readCluster(file);
    RoutingStrategy strategy = new ConsistentRoutingStrategy(cluster, repFactor);
    JsonTypeSerializer serializer = new JsonTypeSerializer(JsonTypeDefinition.INT32);
    Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
    for (int i = 0; i < maxVal; i++) {
        for (Node node : strategy.routeRequest(serializer.toBytes(i))) {
            int newCount = 1;
            if (counts.get(node.getId()) != null) {
                newCount = counts.get(node.getId()) + 1;
            }
            counts.put(node.getId(), newCount);
        }
    }
    int sum = 0;
    int totalCounts = 0;
    for (int countVal : counts.values()) {
        sum += countVal;
        totalCounts++;
    }
    int avg = sum / totalCounts;
    NumberFormat percent = NumberFormat.getPercentInstance();
    percent.setMaximumFractionDigits(2);
    System.out.println("Node\tKeys\tPercent\tVariation");
    for (int nodeId : counts.keySet()) {
        System.out.println(nodeId + "\t" + counts.get(nodeId) + "\t" + percent.format(counts.get(nodeId) / (double) sum) + "\t" + percent.format((counts.get(nodeId) - avg) / (double) counts.get(nodeId)));
    }
    double msPerHash = (System.currentTimeMillis() - start) / ((double) repFactor * maxVal);
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(10);
    System.out.println(nf.format(msPerHash) + " ms per hash");
}
Also used : JsonTypeSerializer(voldemort.serialization.json.JsonTypeSerializer) HashMap(java.util.HashMap) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) RoutingStrategy(voldemort.routing.RoutingStrategy) ConsistentRoutingStrategy(voldemort.routing.ConsistentRoutingStrategy) ConsistentRoutingStrategy(voldemort.routing.ConsistentRoutingStrategy) File(java.io.File) NumberFormat(java.text.NumberFormat)

Example 27 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class ServerTestUtils method createServerConfigWithDefs.

public static VoldemortConfig createServerConfigWithDefs(boolean useNio, int nodeId, String baseDir, Cluster cluster, List<StoreDefinition> stores, Properties properties) throws IOException {
    File clusterXml = new File(TestUtils.createTempDir(), "cluster.xml");
    File storesXml = new File(TestUtils.createTempDir(), "stores.xml");
    ClusterMapper clusterMapper = new ClusterMapper();
    StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper();
    FileWriter writer = new FileWriter(clusterXml);
    writer.write(clusterMapper.writeCluster(cluster));
    writer.close();
    writer = new FileWriter(storesXml);
    writer.write(storeDefMapper.writeStoreList(stores));
    writer.close();
    return createServerConfig(useNio, nodeId, baseDir, clusterXml.getAbsolutePath(), storesXml.getAbsolutePath(), properties);
}
Also used : FileWriter(java.io.FileWriter) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper) File(java.io.File)

Example 28 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class ServerJVMTestUtils method createAndInitializeVoldemortHome.

public static String createAndInitializeVoldemortHome(boolean useNio, int node, String storesXmlfile, Cluster cluster) throws IOException {
    VoldemortConfig config = ServerTestUtils.createServerConfig(useNio, node, TestUtils.createTempDir().getAbsolutePath(), null, storesXmlfile, new Properties());
    // Initialize voldemort config dir with all required files.
    // cluster.xml
    File clusterXml = new File(config.getMetadataDirectory() + File.separator + "cluster.xml");
    FileUtils.writeStringToFile(clusterXml, new ClusterMapper().writeCluster(cluster));
    // stores.xml
    File storesXml = new File(config.getMetadataDirectory() + File.separator + "stores.xml");
    FileUtils.copyFile(new File(storesXmlfile), storesXml);
    // server.properties
    File serverProperties = new File(config.getMetadataDirectory() + File.separator + "server.properties");
    FileUtils.writeLines(serverProperties, Arrays.asList("node.id=" + node, "bdb.cache.size=" + 1024 * 1024, "enable.metadata.checking=" + false, "enable.network.classloader=" + false));
    return config.getVoldemortHome();
}
Also used : ClusterMapper(voldemort.xml.ClusterMapper) Properties(java.util.Properties) File(java.io.File) VoldemortConfig(voldemort.server.VoldemortConfig)

Example 29 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class AdminServiceBasicTest method testIsClusterModified.

@Test
public void testIsClusterModified() {
    AdminClient client = getAdminClient();
    assertFalse("Newly Created admin client has valid cluster", client.isClusterModified());
    String clusterXml = new ClusterMapper().writeCluster(cluster);
    client.metadataMgmtOps.updateRemoteMetadata(cluster.getNodeIds(), MetadataStore.CLUSTER_KEY, clusterXml);
    assertTrue("After cluster update", client.isClusterModified());
}
Also used : ClusterMapper(voldemort.xml.ClusterMapper) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 30 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class AtomicSetMetadataPairTest method testClusterAndStoresAreSetAtomically.

/**
     * Bug fix: The old approach tried to test store metadata update by
     * replacing an existing stores.xml with a completely different stores.xml.
     * This has been fixed such that, the new stores.xml is the same as the
     * original, except for required replication factor = 2.
     * 
     */
@Test
public void testClusterAndStoresAreSetAtomically() {
    try {
        AdminClient adminClient = new AdminClient(bootStrapUrls[0]);
        StoreDefinitionsMapper storeDefsMapper = new StoreDefinitionsMapper();
        List<StoreDefinition> storeDefs = storeDefsMapper.readStoreList(new File(newStoresXmlfile));
        ClusterMapper clusterMapper = new ClusterMapper();
        for (Node node : oldCluster.getNodes()) {
            VoldemortAdminTool.executeSetMetadataPair(node.getId(), adminClient, CLUSTER_KEY, clusterMapper.writeCluster(newCluster), STORES_KEY, storeDefsMapper.writeStoreList(storeDefs));
        }
        String dirPath = TestUtils.createTempDir().getAbsolutePath();
        for (Node node : newCluster.getNodes()) {
            VoldemortAdminTool.executeGetMetadata(node.getId(), adminClient, CLUSTER_KEY, dirPath);
            // Make sure cluster metadata was updated
            Cluster newClusterFromMetadataRepo = clusterMapper.readCluster(new File(dirPath, CLUSTER_KEY + "_" + node.getId()));
            // All nodes should have this old list
            assertTrue(oldCluster.getNodeById(5).getPartitionIds().equals(oldPartitionIds));
            // As per the new metadata node 5 should have this list
            assertTrue(newClusterFromMetadataRepo.getNodeById(5).getPartitionIds().equals(newPartitionIds));
            // Make sure store metadata was updated
            VoldemortAdminTool.executeGetMetadata(node.getId(), adminClient, STORES_KEY, dirPath);
            List<StoreDefinition> newStoreDefsFromMetadatRepo = storeDefsMapper.readStoreList(new File(dirPath, STORES_KEY + "_" + node.getId()));
            // Check that the required replication factor has been updated
            assertTrue(newStoreDefsFromMetadatRepo.get(1).getRequiredReads() == 2);
            assertTrue(newStoreDefsFromMetadatRepo.get(1).getRequiredWrites() == 2);
        }
    } catch (Exception e) {
        fail("Error in validating end to end client rebootstrap : " + e);
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) Node(voldemort.cluster.Node) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Aggregations

ClusterMapper (voldemort.xml.ClusterMapper)41 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)26 Cluster (voldemort.cluster.Cluster)23 File (java.io.File)18 StoreDefinition (voldemort.store.StoreDefinition)18 StringReader (java.io.StringReader)13 OptionSet (joptsimple.OptionSet)10 Node (voldemort.cluster.Node)10 AdminClient (voldemort.client.protocol.admin.AdminClient)9 VoldemortException (voldemort.VoldemortException)8 Test (org.junit.Test)6 ByteArray (voldemort.utils.ByteArray)6 Versioned (voldemort.versioning.Versioned)6 OptionParser (joptsimple.OptionParser)5 IOException (java.io.IOException)4 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)4 FileNotFoundException (java.io.FileNotFoundException)3 ClientConfig (voldemort.client.ClientConfig)3 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)3 BufferedReader (java.io.BufferedReader)2