Search in sources :

Example 36 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class CompressingStoreTest method testPutGetWithSocketService.

@Test
public void testPutGetWithSocketService() throws Exception {
    int freePort = ServerTestUtils.findFreePort();
    String clusterXml = VoldemortTestConstants.getOneNodeClusterXml();
    clusterXml = clusterXml.replace("<socket-port>6666</socket-port>", "<socket-port>" + freePort + "</socket-port>");
    AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, clusterXml, VoldemortTestConstants.getCompressedStoreDefinitionsXml(), "test", freePort);
    socketService.start();
    Thread.sleep(1000);
    SocketStoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls("tcp://localhost:" + freePort).setMaxBootstrapRetries(10));
    StoreClient<String, String> storeClient = storeClientFactory.getStoreClient("test");
    storeClient.put("someKey", "someValue");
    assertEquals(storeClient.getValue("someKey"), "someValue");
    socketService.stop();
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) AbstractSocketService(voldemort.server.AbstractSocketService) ClientConfig(voldemort.client.ClientConfig) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 37 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory 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 38 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class TestClientShutdown method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2 || args.length > 3)
        Utils.croak("USAGE: java VoldemortClientShell store_name bootstrap_url [command_file]");
    String storeName = args[0];
    String bootstrapUrl = args[1];
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setEnableLazy(false).setBootstrapUrls(bootstrapUrl));
    DefaultStoreClient<Object, Object> client = null;
    try {
        client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
    } catch (Exception e) {
        Utils.croak("Could not connect to server: " + e.getMessage());
    }
    System.out.println("Established connection to " + storeName + " via " + bootstrapUrl);
    client.get("hello");
    System.out.println("Got value");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 39 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class RemoteDataGenerator method generateData.

/**
     * Populate the store with
     * 
     * @param requests key-value pairs with key of size, appending
     * @param postfix for uniqueness.
     * 
     * @param keySize bytes and value of size
     * @param valueSize bytes
     * @param requests How many key-value pairs to generate
     * @param keySize Size (in bytes) of the key
     * @param valueSize Size (in bytes) of the value
     * @param postfix Postfix to append (for uniqueness)
     */
public void generateData(int requests, int keySize, int valueSize, String postfix) {
    StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url).setMaxThreads(workers));
    StoreClient<String, String> client = storeClientFactory.getStoreClient(storeName);
    for (int i = 0; i < requests; i++) {
        StringBuilder keyBuilder = new StringBuilder(makeString(keySize)).append(i);
        StringBuilder valueBuilder = new StringBuilder(makeString(valueSize)).append(i);
        if (postfix != null) {
            keyBuilder.append(postfix);
        }
        try {
            client.put(keyBuilder.toString(), valueBuilder.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 40 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class HintedHandoffTestEnvironment method run.

@Override
public void run() {
    Random random = new Random(System.currentTimeMillis());
    cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
    storeDef = storeDefBuilder.build();
    // setup store engines
    for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
        // do only once
        createInnerStore(nodeId);
    }
    for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
        try {
            startServer(nodeId);
        } catch (IOException e) {
            logger.error("Server " + nodeId + "failed to start", e);
        }
    }
    // setup client factory
    String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
    factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    // wait for start of servers
    startFinishLatch.countDown();
    try {
        boolean wrapUpSignal = false;
        while (!wrapUpSignal) {
            if (logger.isInfoEnabled()) {
                logger.info("Will sleep for a while or until seeing wrapUpSignal. sleep time: " + statusRefreshIntervalSecond + " Seconds");
            }
            wrapUpSignal = wrapUpRequestLatch.await(statusRefreshIntervalSecond, TimeUnit.SECONDS);
            if (logger.isInfoEnabled()) {
                if (wrapUpSignal) {
                    logger.info("Wake Up and wrap up. Make all servers NORMAL");
                    minNodesAvailable = NUM_NODES_TOTAL;
                } else {
                    logger.info("Wake Up and decide new failure statuses");
                }
                for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> entry : realStores.entrySet()) {
                    InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]> engine = (InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) entry.getValue();
                    logger.info("Outstanding Put Assertions of node [" + entry.getKey() + "]: " + engine.getFailedAssertions().size());
                }
            }
            // decide random number of cluster nodes(at least 1 alive) with
            // random ids to fail
            Integer numNodesToFail = random.nextInt(NUM_NODES_TOTAL - minNodesAvailable + 1);
            Set<Integer> nodesToFail = getUniqueRandomNumbers(NUM_NODES_TOTAL, numNodesToFail);
            if (logger.isInfoEnabled()) {
                logger.info("Setting nodes to Fail: " + nodesToFail.toString());
            }
            for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
                if (nodesToFail.contains(nodeId)) {
                    // fail a node if it's normal
                    if (nodesStatus.get(nodeId) == NodeStatus.NORMAL) {
                        // random pick one failure node
                        Integer failureMode = random.nextInt(3);
                        switch(failureMode) {
                            case 0:
                                makeNodeDown(nodeId);
                                break;
                            case 1:
                                makeNodeSlow(nodeId);
                                break;
                            case 2:
                                makeNodeBdbError(nodeId);
                                break;
                        }
                    }
                // otherwise, leave unchanged
                } else {
                    // make node normal if not normal
                    if (nodesStatus.get(nodeId) != NodeStatus.NORMAL) {
                        makeNodeNormal(nodeId);
                    }
                // otherwise, leave unchanged
                }
            }
        }
    } catch (InterruptedException e) {
    } finally {
        wrapUpFinishLatch.countDown();
    }
}
Also used : Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) ForceFailStore(voldemort.store.ForceFailStore) IOException(java.io.IOException) Random(java.util.Random) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) ClientConfig(voldemort.client.ClientConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)40 ClientConfig (voldemort.client.ClientConfig)37 IOException (java.io.IOException)14 VoldemortServer (voldemort.server.VoldemortServer)14 ByteArray (voldemort.utils.ByteArray)13 Properties (java.util.Properties)12 Before (org.junit.Before)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 StoreClientFactory (voldemort.client.StoreClientFactory)9 Cluster (voldemort.cluster.Cluster)8 HashMap (java.util.HashMap)7 ExecutorService (java.util.concurrent.ExecutorService)7 Node (voldemort.cluster.Node)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ClusterTestUtils (voldemort.ClusterTestUtils)6 DefaultStoreClient (voldemort.client.DefaultStoreClient)6 InvalidMetadataException (voldemort.store.InvalidMetadataException)6