Search in sources :

Example 21 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project javaee7-samples by javaee-samples.

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    //        // start embedded
    //        VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
    //        VoldemortServer server = new VoldemortServer(config);
    //        server.start();
    // bootstrap
    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    // create a client that executes operations on a single store
    client = factory.getStoreClient("test");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) PostConstruct(javax.annotation.PostConstruct)

Example 22 with SocketStoreClientFactory

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

the class VoldemortClient method init.

/**
   * Initialize the DB layer. This accepts all properties allowed by the
   * Voldemort client. A store maps to a table. Required : bootstrap_urls
   * Additional property : store_name -> to preload once, should be same as -t
   * {@link ClientConfig}
   */
public void init() throws DBException {
    ClientConfig clientConfig = new ClientConfig(getProperties());
    socketFactory = new SocketStoreClientFactory(clientConfig);
    // Retrieve store name
    storeName = getProperties().getProperty("store_name", "usertable");
    // Use store name to retrieve client
    storeClient = socketFactory.getStoreClient(storeName);
    if (storeClient == null) {
        throw new DBException("Unable to instantiate store client");
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig)

Example 23 with SocketStoreClientFactory

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

the class ClusterForkLiftToolTest method setUpClusters.

@Before
public void setUpClusters() {
    // setup four nodes with one store and one partition
    final SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    try {
        int[][] srcPartitionMap = { { 0 }, { 1 }, { 2 }, { 3 } };
        srcServers = new VoldemortServer[4];
        srcCluster = ServerTestUtils.startVoldemortCluster(4, srcServers, srcPartitionMap, socketStoreFactory, true, null, SRC_STORES_XML, new Properties());
        Node node = srcCluster.getNodeById(0);
        srcBootStrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
        int[][] dstPartitionMap = { { 0 }, { 1 }, { 2 } };
        dstServers = new VoldemortServer[3];
        dstCluster = ServerTestUtils.startVoldemortCluster(3, dstServers, dstPartitionMap, socketStoreFactory, true, null, DST_STORES_XML, new Properties());
        node = dstCluster.getNodeById(0);
        dstBootStrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
        kvPairs = ServerTestUtils.createRandomKeyValueString(100);
        int keyCount = 0;
        for (String key : kvPairs.keySet()) {
            if (keyCount == 0)
                firstKey = key;
            if (keyCount == kvPairs.size() - 1)
                lastKey = key;
            if (keyCount == kvPairs.size() / 2)
                conflictKey = key;
            keyCount++;
        }
        srcAdminClient = new AdminClient(srcCluster);
        List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new File(SRC_STORES_XML));
        primaryResolvingStoreDef = StoreUtils.getStoreDef(storeDefs, PRIMARY_RESOLVING_STORE_NAME);
        globallyResolvingStoreDef = StoreUtils.getStoreDef(storeDefs, GLOBALLY_RESOLVING_STORE_NAME);
        nonResolvingStoreDef = StoreUtils.getStoreDef(storeDefs, MULTIPLE_VERSIONS_STORE_NAME);
        srcfactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(srcBootStrapUrl).setSelectors(1).setRoutingTimeout(1000, java.util.concurrent.TimeUnit.MILLISECONDS).setSocketTimeout(1000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionTimeout(1000, java.util.concurrent.TimeUnit.MILLISECONDS).setMaxConnectionsPerNode(1));
        srcPrimaryResolvingStoreClient = srcfactory.getStoreClient(PRIMARY_RESOLVING_STORE_NAME);
        srcGloballyResolvingStoreClient = srcfactory.getStoreClient(GLOBALLY_RESOLVING_STORE_NAME);
        dstfactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(dstBootStrapUrl).setSelectors(1).setRoutingTimeout(1000, java.util.concurrent.TimeUnit.MILLISECONDS).setSocketTimeout(1000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionTimeout(1000, java.util.concurrent.TimeUnit.MILLISECONDS).setMaxConnectionsPerNode(1));
        dstPrimaryResolvingStoreClient = dstfactory.getStoreClient(PRIMARY_RESOLVING_STORE_NAME);
        dstGloballyResolvingStoreClient = dstfactory.getStoreClient(GLOBALLY_RESOLVING_STORE_NAME);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
    }
}
Also used : Node(voldemort.cluster.Node) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) IOException(java.io.IOException) Properties(java.util.Properties) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreDefinition(voldemort.store.StoreDefinition) ClientConfig(voldemort.client.ClientConfig) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient) Before(org.junit.Before)

Example 24 with SocketStoreClientFactory

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

the class ZoneShrinkageCLITest method testZoneShrinkageCLI.

@Test
public void testZoneShrinkageCLI() throws Exception {
    cluster = ClusterTestUtils.getZZZCluster();
    oldStores = ClusterTestUtils.getZZZStoreDefsInMemory();
    setup();
    String[] argv = ("--url " + bsURL + " --drop-zoneid 0 --real-run").split(" ");
    ZoneShrinkageCLI.main(argv);
    AdminClient adminClient = new AdminClient(bsURL);
    assertEquals(2, adminClient.getAdminClientCluster().getZoneIds().size());
    String bootstrapUrl = adminClient.getAdminClientCluster().getNodes().iterator().next().getSocketUrl().toString();
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    StoreClient<String, String> client = factory.getStoreClient(oldStores.get(0).getName());
    client.put("k1", "v1");
    assertEquals("v1", client.get("k1").getValue());
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) AdminClient(voldemort.client.protocol.admin.AdminClient) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) Test(org.junit.Test)

Example 25 with SocketStoreClientFactory

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

the class ClientExample method stringStoreExample.

public static void stringStoreExample() {
    System.out.println("==============String store example=================");
    // In production environment, the StoreClient instantiation should be done using factory pattern
    // through a Framework such as Spring
    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    StoreClient<String, String> client = factory.getStoreClient("test");
    // put initial value
    System.out.println("Putting an initial value");
    client.put("some_key", "initial value");
    // get the value
    System.out.println("Getting Initial value");
    Versioned<String> versioned = client.get("some_key");
    System.out.println("Initial Versioned Object: " + String.valueOf(versioned));
    System.out.println("           Initial Value: " + String.valueOf(versioned.getValue()));
    // modify the value
    System.out.println("Modifying the value");
    versioned.setObject("new_value");
    // update the value
    System.out.println("Putting the new value");
    client.put("some_key", versioned);
    // get again and print
    System.out.println("Getting the new value");
    versioned = client.get("some_key");
    System.out.println("Putting the value");
    System.out.println("    New Versioned Object: " + String.valueOf(versioned));
    System.out.println("               New Value: " + String.valueOf(versioned.getValue()));
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

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