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");
}
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");
}
}
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");
}
}
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());
}
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()));
}
Aggregations