Search in sources :

Example 76 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class VoldemortServletContextListener method contextDestroyed.

public void contextDestroyed(ServletContextEvent event) {
    logger.info("Calling application shutdown...");
    VoldemortServer server = (VoldemortServer) event.getServletContext().getAttribute(SERVER_KEY);
    if (server != null)
        server.stop();
    logger.info("Destroying application...");
    event.getServletContext().removeAttribute(SERVER_KEY);
    event.getServletContext().removeAttribute(SERVER_CONFIG_KEY);
    event.getServletContext().removeAttribute(VELOCITY_ENGINE_KEY);
}
Also used : VoldemortServer(voldemort.server.VoldemortServer)

Example 77 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class StoreSwapperTest method tearDown.

@After
public void tearDown() throws IOException {
    adminClient.close();
    for (VoldemortServer server : servers) {
        ServerTestUtils.stopVoldemortServer(server);
    }
    socketStoreFactory.close();
}
Also used : VoldemortServer(voldemort.server.VoldemortServer) After(org.junit.After)

Example 78 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class AbstractZoneAffinityTest method setup.

@Before
public void setup() throws IOException {
    byte[] v1_bytes = { (byte) 'V', (byte) '1' };
    byte[] v2_bytes = { (byte) 'V', (byte) '2' };
    byte[] k1_bytes = { (byte) 'K', (byte) '1' };
    byte[] k2_bytes = { (byte) 'K', (byte) '2' };
    byte[] k3_bytes = { (byte) 'K', (byte) '3' };
    clientConfig = new ClientConfig();
    clientConfig.setBootstrapUrls(cluster.getNodes().iterator().next().getSocketUrl().toString());
    clientConfig.setClientZoneId(clientZoneId);
    setupZoneAffinitySettings();
    SocketStoreClientFactory socketStoreClientFactory = new SocketStoreClientFactory(clientConfig);
    for (Integer nodeId : cluster.getNodeIds()) {
        SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
        VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, stores, new Properties());
        VoldemortServer vs = ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster);
        vservers.put(nodeId, vs);
        socketStoreFactories.put(nodeId, socketStoreFactory);
        Store<ByteArray, byte[], byte[]> store = vs.getStoreRepository().getLocalStore(storeDef.getName());
        Node node = cluster.getNodeById(nodeId);
        VectorClock version1 = new VectorClock();
        version1.incrementVersion(0, System.currentTimeMillis());
        VectorClock version2 = version1.incremented(0, System.currentTimeMillis());
        if (node.getZoneId() == clientZoneId) {
            // local zone
            store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
            store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
        } else {
            // remote zone
            store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v2_bytes, version2), null);
            store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
            store.put(new ByteArray(k3_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
        }
    }
    client = socketStoreClientFactory.getRawStore(storeDef.getName(), null);
}
Also used : Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) VoldemortConfig(voldemort.server.VoldemortConfig) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) ClientConfig(voldemort.client.ClientConfig) Before(org.junit.Before)

Example 79 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class AbstractZoneAffinityTest method tearDown.

@After
public void tearDown() throws IOException {
    client.close();
    for (VoldemortServer vs : this.vservers.values()) {
        ServerTestUtils.stopVoldemortServer(vs);
    }
    for (SocketStoreFactory ssf : this.socketStoreFactories.values()) {
        ssf.close();
    }
    ClusterTestUtils.reset();
}
Also used : SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) VoldemortServer(voldemort.server.VoldemortServer) After(org.junit.After)

Example 80 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class ServerTestUtils method startVoldemortServer.

/**
     * Starts a Voldemort server for testing purposes.
     *
     * Unless the ports passed in via cluster are guaranteed to be available,
     * this method is susceptible to BindExceptions in VoldemortServer.start().
     * (And, there is no good way of guaranteeing that ports will be available,
     * so...)
     *
     * The method {@link ServerTestUtils#startVoldemortCluster} should be used
     * in preference to this method.}
     *
     * @param socketStoreFactory
     * @param config
     * @param cluster
     * @param testConnection
     * @return
     */
public static VoldemortServer startVoldemortServer(SocketStoreFactory socketStoreFactory, VoldemortConfig config, Cluster cluster, boolean testConnection) throws BindException {
    // TODO: Some tests that use this method fail intermittently with the
    // following output:
    //
    // A successor version version() to this version() exists for key
    // cluster.xml
    // voldemort.versioning.ObsoleteVersionException: A successor version
    // version() to this version() exists for key cluster.xml"
    //
    // Need to trace through the constructor VoldemortServer(VoldemortConfig
    // config, Cluster cluster) to understand how this error is possible,
    // and why it only happens intermittently.
    final int MAX_NUMBER_OF_ATTEMPTS = 120;
    // 5 minutes
    final long MAX_RETRY_TIME_IN_MS = 5 * Time.MS_PER_MINUTE;
    VoldemortException lastVE = null;
    long startTime = System.currentTimeMillis(), currentTime = System.currentTimeMillis();
    for (int i = 1; (i <= MAX_NUMBER_OF_ATTEMPTS) && (currentTime - startTime < MAX_RETRY_TIME_IN_MS); i++, currentTime = System.currentTimeMillis()) {
        VoldemortServer server = null;
        boolean success = false;
        try {
            if (cluster != null) {
                server = new VoldemortServer(config, cluster);
            } else {
                server = new VoldemortServer(config);
            }
            server.start();
            if (testConnection)
                ServerTestUtils.waitForServerStart(socketStoreFactory, server.getIdentityNode());
            // wait till server starts or throw exception
            success = true;
            return server;
        } catch (VoldemortException ve) {
            if (ve.getCause() instanceof BindException) {
                ve.printStackTrace();
                trySleep(Math.min(100 * i, 1000));
                lastVE = ve;
            } else {
                throw ve;
            }
        } finally {
            if (!success && server != null) {
                // This is in case new VoldemortServer() worked but ServerTestUtils.waitForServerStart() failed.
                try {
                    server.stop();
                } catch (Exception e) {
                    logger.error("Got an exception while trying to close a VoldemortServer", e);
                }
            }
        }
    }
    throw new BindException(lastVE.getMessage());
}
Also used : BindException(java.net.BindException) VoldemortServer(voldemort.server.VoldemortServer) UnreachableStoreException(voldemort.store.UnreachableStoreException) BindException(java.net.BindException) IOException(java.io.IOException)

Aggregations

VoldemortServer (voldemort.server.VoldemortServer)86 Properties (java.util.Properties)36 VoldemortConfig (voldemort.server.VoldemortConfig)24 Test (org.junit.Test)23 Node (voldemort.cluster.Node)23 Before (org.junit.Before)21 SocketStoreFactory (voldemort.store.socket.SocketStoreFactory)20 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)18 ClientConfig (voldemort.client.ClientConfig)17 ByteArray (voldemort.utils.ByteArray)17 ArrayList (java.util.ArrayList)16 After (org.junit.After)15 StoreDefinition (voldemort.store.StoreDefinition)15 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)14 Cluster (voldemort.cluster.Cluster)14 IOException (java.io.IOException)11 HashMap (java.util.HashMap)11 AdminClient (voldemort.client.protocol.admin.AdminClient)11 VectorClock (voldemort.versioning.VectorClock)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9