Search in sources :

Example 6 with ClusterMapper

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));
        }
    }
}
Also used : StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ZoneAffinity(voldemort.client.ZoneAffinity) ClusterMapper(voldemort.xml.ClusterMapper) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) ClientConfig(voldemort.client.ClientConfig) Test(org.junit.Test)

Example 7 with ClusterMapper

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));
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) ClusterMapper(voldemort.xml.ClusterMapper) Properties(java.util.Properties) ClientConfig(voldemort.client.ClientConfig) File(java.io.File) Before(org.junit.Before)

Example 8 with ClusterMapper

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);
    }
}
Also used : Node(voldemort.cluster.Node) ClusterMapper(voldemort.xml.ClusterMapper) VoldemortException(voldemort.VoldemortException) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 9 with ClusterMapper

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);
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) Node(voldemort.cluster.Node) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper) File(java.io.File) VoldemortException(voldemort.VoldemortException) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 10 with ClusterMapper

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);
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Rebalancer(voldemort.server.rebalance.Rebalancer) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper) SerializerDefinition(voldemort.serialization.SerializerDefinition) Before(org.junit.Before)

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