Search in sources :

Example 16 with SocketStoreFactory

use of voldemort.store.socket.SocketStoreFactory in project voldemort by voldemort.

the class ServerTestUtils method restartServer.

public static VoldemortServer restartServer(VoldemortServer oldServer, int nodeId, Cluster cluster, Properties serverProps) throws Exception {
    ServerTestUtils.stopVoldemortServer(oldServer);
    String baseDirPath = oldServer.getVoldemortConfig().getVoldemortHome();
    String parentDirPath = Paths.get(baseDirPath).getParent().toString();
    List<StoreDefinition> storeDefs = oldServer.getMetadataStore().getStoreDefList();
    final boolean ENABLE_NIO = true;
    VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(ENABLE_NIO, nodeId, parentDirPath, cluster, storeDefs, serverProps);
    SocketStoreFactory socketStoreFactory = getSocketStoreFactory();
    try {
        return startVoldemortServer(socketStoreFactory, config, cluster);
    } finally {
        socketStoreFactory.close();
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) VoldemortConfig(voldemort.server.VoldemortConfig)

Example 17 with SocketStoreFactory

use of voldemort.store.socket.SocketStoreFactory in project voldemort by voldemort.

the class ServerTestUtils method startVoldemortCluster.

public static Cluster startVoldemortCluster(VoldemortServer[] voldemortServers, int[][] partitionMap, String clusterFile, String storeFile, Properties properties, Cluster customCluster) throws IOException {
    boolean started = false;
    Cluster cluster = null;
    SocketStoreFactory socketStoreFactory = getSocketStoreFactory();
    try {
        while (!started) {
            try {
                cluster = internalStartVoldemortCluster(voldemortServers.length, voldemortServers, partitionMap, socketStoreFactory, true, clusterFile, storeFile, properties, customCluster);
                started = true;
            } catch (BindException be) {
                logger.debug("Caught BindException when starting cluster. Will retry.");
            }
        }
    } finally {
        socketStoreFactory.close();
    }
    return cluster;
}
Also used : Cluster(voldemort.cluster.Cluster) BindException(java.net.BindException) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory)

Example 18 with SocketStoreFactory

use of voldemort.store.socket.SocketStoreFactory in project voldemort by voldemort.

the class HintedHandoffTestEnvironment method startServer.

/**
 * Start a server How it works:
 *
 * 1. create a server using test utilities
 *
 * 2.Inject prepared test store and storage engine
 *
 * 3. Inject prepared slop store and storage engine
 *
 * @param nodeId The node of server to start
 * @throws IOException
 */
public void startServer(int nodeId) throws IOException {
    if (logger.isInfoEnabled())
        logger.info("Starting server of node [" + nodeId + "]");
    SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
    List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
    stores.add(storeDef);
    // start a voldemort server
    VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, stores, new Properties());
    config.setNioAdminConnectorSelectors(1);
    config.setNioConnectorSelectors(5);
    config.setSlopFrequencyMs(DEFAULT_SLOP_PUSH_INTERVAL_S * 1000);
    config.setSlopStoreType("memory");
    config.setFailureDetectorAsyncRecoveryInterval(DEFAULT_ASYNC_RECOVERY_INTERVAL_S * 1000);
    VoldemortServer vs = ServerTestUtils.startVoldemortServer(socketStoreFactory, config);
    socketStoreFactory.close();
    voldemortServers.put(nodeId, vs);
    VoldemortService vsrv = vs.getService(ServiceType.STORAGE);
    StoreRepository sr = ((StorageService) vsrv).getStoreRepository();
    // storage engine injection
    sr.removeLocalStore(STORE_NAME);
    sr.addLocalStore(sleepyStores.get(nodeId));
    sr.removeStorageEngine(STORE_NAME);
    sr.addStorageEngine((StorageEngine<ByteArray, byte[], byte[]>) realStores.get(nodeId));
    // slop stores caching and injection
    if (!slopStorageEngines.containsKey(nodeId)) {
        SlopStorageEngine slopStorageEngine = sr.getSlopStore();
        slopStorageEngines.put(nodeId, slopStorageEngine);
    } else {
        sr.removeStorageEngine("slop");
        sr.removeLocalStore("slop");
        sr.addStorageEngine(slopStorageEngines.get(nodeId));
        sr.addLocalStore(slopStorageEngines.get(nodeId));
        sr.setSlopStore(slopStorageEngines.get(nodeId));
    }
}
Also used : ArrayList(java.util.ArrayList) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) StoreRepository(voldemort.server.StoreRepository) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) VoldemortConfig(voldemort.server.VoldemortConfig) StorageService(voldemort.server.storage.StorageService) VoldemortService(voldemort.common.service.VoldemortService) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray)

Example 19 with SocketStoreFactory

use of voldemort.store.socket.SocketStoreFactory in project voldemort by voldemort.

the class RemoteStoreComparisonTest method main.

public static void main(String[] args) throws Exception {
    if (args.length != 2)
        Utils.croak("USAGE: java " + RemoteStoreComparisonTest.class.getName() + " numRequests numThreads [useNio]");
    int numRequests = Integer.parseInt(args[0]);
    int numThreads = Integer.parseInt(args[1]);
    boolean useNio = args.length > 2 ? args[2].equals("true") : false;
    /**
     * In memory test **
     */
    final Store<byte[], byte[], byte[]> memStore = new InMemoryStorageEngine<byte[], byte[], byte[]>("test");
    PerformanceTest memWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] key = String.valueOf(i).getBytes();
            memStore.put(key, new Versioned<byte[]>(key), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing memory write test.");
    memWriteTest.run(numRequests, numThreads);
    memWriteTest.printStats();
    System.out.println();
    PerformanceTest memReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            try {
                memStore.get(String.valueOf(i).getBytes(), null);
            } catch (Exception e) {
                System.out.println("Failure on i = " + i);
                e.printStackTrace();
            }
        }
    };
    System.out.println("Performing memory read test.");
    memReadTest.run(numRequests, numThreads);
    memReadTest.printStats();
    System.out.println();
    System.out.println();
    /**
     * Do Socket tests **
     */
    String storeName = "test";
    StoreRepository repository = new StoreRepository();
    repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
    SocketStoreFactory storeFactory = new ClientRequestExecutorPool(10, 1000, 1000, 32 * 1024);
    final Store<ByteArray, byte[], byte[]> socketStore = storeFactory.create(storeName, "localhost", 6666, RequestFormatType.VOLDEMORT_V1, RequestRoutingType.NORMAL);
    RequestHandlerFactory factory = ServerTestUtils.getSocketRequestHandlerFactory(repository);
    AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, factory, 6666, 50, 50, 1000);
    socketService.start();
    PerformanceTest socketWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] bytes = String.valueOf(i).getBytes();
            ByteArray key = new ByteArray(bytes);
            socketStore.put(key, new Versioned<byte[]>(bytes), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing socket write test.");
    socketWriteTest.run(numRequests, numThreads);
    socketWriteTest.printStats();
    System.out.println();
    PerformanceTest socketReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            try {
                socketStore.get(TestUtils.toByteArray(String.valueOf(i)), null);
            } catch (Exception e) {
                System.out.println("Failure on i = " + i);
                e.printStackTrace();
            }
        }
    };
    System.out.println("Performing socket read test.");
    socketReadTest.run(numRequests, 1);
    socketReadTest.printStats();
    System.out.println();
    System.out.println();
    socketStore.close();
    storeFactory.close();
    socketService.stop();
    /**
     * Do HTTP tests **
     */
    repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
    HttpService httpService = new HttpService(null, null, repository, RequestFormatType.VOLDEMORT_V0, numThreads, 8080);
    httpService.start();
    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), 10000, TimeUnit.MILLISECONDS);
    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
    HttpParams clientParams = httpClient.getParams();
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
    HttpProtocolParams.setUserAgent(clientParams, "test-agent");
    HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
    HttpConnectionParams.setConnectionTimeout(clientParams, 10000);
    connectionManager.setMaxTotal(numThreads);
    connectionManager.setDefaultMaxPerRoute(numThreads);
    HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
    final HttpStore httpStore = new HttpStore("test", "localhost", 8080, httpClient, new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V0), false);
    Thread.sleep(400);
    PerformanceTest httpWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] key = String.valueOf(i).getBytes();
            httpStore.put(new ByteArray(key), new Versioned<byte[]>(key), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing HTTP write test.");
    httpWriteTest.run(numRequests, numThreads);
    httpWriteTest.printStats();
    System.out.println();
    PerformanceTest httpReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            httpStore.get(new ByteArray(String.valueOf(i).getBytes()), null);
        }
    };
    System.out.println("Performing HTTP read test.");
    httpReadTest.run(numRequests, numThreads);
    httpReadTest.printStats();
    httpService.stop();
    VoldemortIOUtils.closeQuietly(httpClient);
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) RequestHandlerFactory(voldemort.server.protocol.RequestHandlerFactory) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) StoreRepository(voldemort.server.StoreRepository) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) HttpService(voldemort.server.http.HttpService) HttpStore(voldemort.store.http.HttpStore) ByteArray(voldemort.utils.ByteArray) AbstractSocketService(voldemort.server.AbstractSocketService)

Example 20 with SocketStoreFactory

use of voldemort.store.socket.SocketStoreFactory in project voldemort by voldemort.

the class NioStatsJmxTest method setUp.

@Before
public void setUp() throws Exception {
    String storesXmlfile = "test/common/voldemort/config/single-store.xml";
    ClientConfig clientConfig = new ClientConfig().setMaxConnectionsPerNode(1).setMaxThreads(1);
    SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(clientConfig.getSelectors(), clientConfig.getMaxConnectionsPerNode(), clientConfig.getConnectionTimeout(TimeUnit.MILLISECONDS), clientConfig.getSocketTimeout(TimeUnit.MILLISECONDS), clientConfig.getSocketBufferSize(), clientConfig.getSocketKeepAlive());
    Properties props = new Properties();
    props.put("jmx.enable", "true");
    int numServers = 1;
    VoldemortServer[] servers = new VoldemortServer[numServers];
    Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, null, socketStoreFactory, true, null, storesXmlfile, props);
    server = servers[0];
    for (Node node : cluster.getNodes()) {
        socketStore = ServerTestUtils.getSocketStore(socketStoreFactory, "test", node.getSocketPort(), clientConfig.getRequestFormatType());
    }
}
Also used : ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) ClientConfig(voldemort.client.ClientConfig) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) Before(org.junit.Before)

Aggregations

SocketStoreFactory (voldemort.store.socket.SocketStoreFactory)26 VoldemortServer (voldemort.server.VoldemortServer)20 Properties (java.util.Properties)19 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)18 Node (voldemort.cluster.Node)16 Before (org.junit.Before)14 VoldemortConfig (voldemort.server.VoldemortConfig)13 StoreDefinition (voldemort.store.StoreDefinition)10 Cluster (voldemort.cluster.Cluster)8 ClientConfig (voldemort.client.ClientConfig)6 AdminClient (voldemort.client.protocol.admin.AdminClient)6 ByteArray (voldemort.utils.ByteArray)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)4 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)4 RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)3 TestSocketStoreFactory (voldemort.store.socket.TestSocketStoreFactory)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2