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