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