use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class ZoneShrinkageClientTest method testZoneAffinityClient.
@Test
public void testZoneAffinityClient() {
ZoneAffinity zoneAffinity = new ZoneAffinity(true, true, true);
ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(sourceCluster.getNodeById(0).getSocketUrl().toString()).setClientZoneId(DROP_ZONE_ID).setZoneAffinity(zoneAffinity);
SocketStoreClientFactory factory = new SocketStoreClientFactory(clientConfig);
StoreClient<String, String> client = factory.getStoreClient(sourceStoreDefs.get(sourceStoreDefs.size() - 1).getName());
// do some operations against the stores from zone 0.
for (int i = 0; i < 10; i++) {
try {
client.put("key" + i, "val" + i);
assertEquals("Must read value back", "val" + i, client.get("key" + i).getValue());
} catch (Exception e) {
fail("Should be not see any failures");
}
}
// shrink the cluster, by dropping zone 0
String clusterXmlString = new ClusterMapper().writeCluster(targetCluster);
String storesXmlString = new StoreDefinitionsMapper().writeStoreList(targetStoreDefs);
int[] remoteNodeList = new int[sourceCluster.getNumberOfNodes()];
int ni = 0;
for (Integer nodeId : sourceCluster.getNodeIds()) {
remoteNodeList[ni++] = nodeId;
}
adminClient.metadataMgmtOps.updateRemoteMetadataPair(new ArrayList<Integer>(sourceCluster.getNodeIds()), "cluster.xml", new Versioned<String>(clusterXmlString, TestUtils.getClock(remoteNodeList)), "stores.xml", new Versioned<String>(storesXmlString, TestUtils.getClock(remoteNodeList)));
try {
Thread.sleep(clientConfig.getAsyncMetadataRefreshInMs() * 2);
} catch (InterruptedException e) {
e.printStackTrace();
}
// do more operations, the client should fail.
for (int i = 0; i < 10; i++) {
long startMs = System.currentTimeMillis();
try {
client.put("key" + i, "val" + i);
assertEquals("Must read value back", "val" + i, client.get("key" + i).getValue());
fail("Should be not see any successes");
} catch (Exception e) {
e.printStackTrace();
long elapsedMs = System.currentTimeMillis() - startMs;
assertTrue("Operation took longer than timeout to fail :" + elapsedMs + " ms.", elapsedMs < clientConfig.getRoutingTimeout(TimeUnit.MILLISECONDS));
}
}
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class DynamicTimeoutStoreClientTest method setUp.
/**
* Setup a one node Voldemort cluster with a 'slow' store
* (SlowStorageEngine) with a delay of 500 ms for get and put.
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
int numServers = 1;
servers = new VoldemortServer[numServers];
int[][] partitionMap = { { 0, 2, 4, 6, 1, 3, 5, 7 } };
Properties props = new Properties();
props.setProperty("storage.configs", "voldemort.store.bdb.BdbStorageConfiguration,voldemort.store.slow.SlowStorageConfiguration");
props.setProperty("testing.slow.queueing.get.ms", SLOW_STORE_DELAY);
props.setProperty("testing.slow.queueing.put.ms", SLOW_STORE_DELAY);
cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, partitionMap, socketStoreFactory, // useNio
true, null, STORES_XML, props);
socketUrl = servers[0].getIdentityNode().getSocketUrl().toString();
String bootstrapUrl = socketUrl;
ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(bootstrapUrl).setEnableCompressionLayer(false).setEnableSerializationLayer(false).enableDefaultClient(true).setEnableLazy(false);
String storesXml = FileUtils.readFileToString(new File(STORES_XML), "UTF-8");
ClusterMapper mapper = new ClusterMapper();
this.dynamicTimeoutClient = new DynamicTimeoutStoreClient<ByteArray, byte[]>(STORE_NAME, new SocketStoreClientFactory(clientConfig), 1, storesXml, mapper.writeCluster(cluster));
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class EndToEndRebootstrapTest method testEndToEndRebootstrap.
/*
* Test to validate that the client bootstraps on metadata change.
* 1. Do some operations to validate that the client is correctly initialized.
* 2. Update the cluster.xml using the Admin Tool (which should update the
* metadata version as well).
* 3. Verify that the client bootstraps after this update.
* 4. Whether the client has automatically bootstrapped is verified by checking
* the new bootstrap time in the client registry.
*/
@Test
public void testEndToEndRebootstrap() {
try {
sanityTestClientOps();
// Get bootstraptime at start
String bootstrapTime = getPropertyFromClientInfo("bootstrapTime");
// Update cluster.xml metadata
ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(bootStrapUrls).setClientZoneId(CLIENT_ZONE_ID);
AdminClient adminClient = new AdminClient(clientConfig);
for (Node node : cluster.getNodes()) {
VoldemortAdminTool.executeSetMetadata(node.getId(), adminClient, CLUSTER_KEY, new ClusterMapper().writeCluster(cluster));
}
// Wait for about 15 seconds to be sure
try {
Thread.sleep(15000);
} catch (Exception e) {
fail("Interrupted .");
}
// Get bootstraptime again
String newBootstrapTime = getPropertyFromClientInfo("bootstrapTime");
assertFalse(bootstrapTime.equals(newBootstrapTime));
long origTime = Long.parseLong(bootstrapTime);
long newTime = Long.parseLong(newBootstrapTime);
assertTrue(newTime > origTime);
} catch (Exception e) {
fail("Error in validating end to end client rebootstrap : " + e);
}
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class EndToEndRebootstrapTest method testEndToEndRebootstrapWithSetMetadataPair.
/*
* Test to validate that the client bootstraps on metadata change.
* 1. Do some operations to validate that the client is correctly initialized.
* 2. Update the <cluster.xml, stores.xml> pair using the Admin Tool.
* 3. Verify that the client bootstraps after this update.
* 4. Whether the client has automatically bootstrapped is verified by checking
* the new bootstrap time in the client registry.
*/
@Test
public void testEndToEndRebootstrapWithSetMetadataPair() {
try {
sanityTestClientOps();
// Get bootstraptime at start
String bootstrapTime = getPropertyFromClientInfo("bootstrapTime");
// Update cluster.xml metadata
ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(bootStrapUrls).setClientZoneId(CLIENT_ZONE_ID);
AdminClient adminClient = new AdminClient(clientConfig);
StoreDefinitionsMapper storeDefsMapper = new StoreDefinitionsMapper();
List<StoreDefinition> storeDefs = storeDefsMapper.readStoreList(new File(storesXmlfile));
for (Node node : cluster.getNodes()) {
VoldemortAdminTool.executeSetMetadataPair(node.getId(), adminClient, CLUSTER_KEY, new ClusterMapper().writeCluster(cluster), STORES_KEY, storeDefsMapper.writeStoreList(storeDefs));
}
// Wait for about 15 seconds to be sure
try {
Thread.sleep(15000);
} catch (Exception e) {
fail("Interrupted .");
}
// Get bootstraptime again
String newBootstrapTime = getPropertyFromClientInfo("bootstrapTime");
assertFalse(bootstrapTime.equals(newBootstrapTime));
long origTime = Long.parseLong(bootstrapTime);
long newTime = Long.parseLong(newBootstrapTime);
assertTrue(newTime > origTime);
} catch (Exception e) {
fail("Error in validating end to end client rebootstrap : " + e);
}
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class RebalanceMetadataConsistencyTest method setUp.
@Before
public void setUp() {
currentCluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0 }, { 1, 3 }, { 2 } });
finalCluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0 }, { 1 }, { 2 }, { 3 } });
rwStoreDefWithReplication = new StoreDefinitionBuilder().setName(testStoreNameRW).setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
Store<String, String, String> innerStore = new InMemoryStorageEngine<String, String, String>("inner-store");
innerStore.put(MetadataStore.CLUSTER_KEY, new Versioned<String>(new ClusterMapper().writeCluster(currentCluster)), null);
innerStore.put(MetadataStore.STORES_KEY, new Versioned<String>(new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(rwStoreDefWithReplication))), null);
rwStoreDefWithReplication2 = new StoreDefinitionBuilder().setName(testStoreNameRW2).setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
metadataStore = MetadataStore.createInMemoryMetadataStore(innerStore, 0);
rebalancer = new Rebalancer(null, metadataStore, null, null);
}
Aggregations