use of voldemort.client.ClientConfig 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.ClientConfig 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()));
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class VoldemortClientShell method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
OptionParser parser = new OptionParser();
parser.accepts("client-zone-id", "Client zone id for zone routing").withRequiredArg().describedAs("zone-id").ofType(Integer.class);
parser.accepts("config-file", "A properties file that contains client config properties").withRequiredArg().describedAs("file");
parser.accepts("help", "Print this help message").isForHelp();
parser.accepts("voldemort-shell", "Suffix of shell script; used to format help output." + " Examples of script suffixes: sh, bat, app").withRequiredArg().describedAs("script_suffix");
OptionSet options = parser.parse(args);
List<String> nonOptions = (List<String>) options.nonOptionArguments();
if (nonOptions.size() < 2 || nonOptions.size() > 3 || options.has("help")) {
if (options.has("voldemort-shell")) {
System.err.println("Usage: voldemort-shell." + options.valueOf("voldemort-shell") + " store_name bootstrap_url [command_file] [options]");
} else {
System.err.println("Usage: java VoldemortClientShell store_name bootstrap_url [command_file] [options]");
}
parser.printHelpOn(System.err);
System.exit(-1);
}
String storeName = nonOptions.get(0);
String bootstrapUrl = nonOptions.get(1);
String configFile = (String) options.valueOf("config-file");
ClientConfig clientConfig = null;
BufferedReader inputReader = null;
boolean fileInput = false;
try {
if (nonOptions.size() == 3) {
inputReader = new BufferedReader(new FileReader(nonOptions.get(2)));
fileInput = true;
} else {
inputReader = new BufferedReader(new InputStreamReader(System.in));
}
} catch (IOException e) {
Utils.croak("Failure to open input stream: " + e.getMessage());
}
if (configFile != null) {
clientConfig = new ClientConfig(new File(configFile));
} else {
clientConfig = new ClientConfig();
}
clientConfig.setBootstrapUrls(bootstrapUrl).setEnableLazy(false).setRequestFormatType(RequestFormatType.VOLDEMORT_V3);
if (options.has("client-zone-id")) {
clientConfig.setClientZoneId((Integer) options.valueOf("client-zone-id"));
}
VoldemortClientShell shell = new VoldemortClientShell(clientConfig, storeName, inputReader, System.out, System.err);
shell.process(fileInput);
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class ExceededQuotaSlopTest method testAsyncWritesSloppedOnQuotaExceeed.
@Test
public void testAsyncWritesSloppedOnQuotaExceeed() throws Exception {
// Set quotas on each server
setGetPutQuotasForEachServer();
/**
* Look at the comment on this method
*
* @see voldemort.utils.pool.QueuedKeyedResourcePool.processQueueLoop(K)
* to see why bumping the number generateKeysForMasterNode will
* fail this test.
*/
// This test is non-deterministic.
// 1) The QuotaException is thrown by SerialPut, but parallelPut ignores
// QuotaException and throws InsufficientOperationalNodesException
// as the QuotaExceptions are silently (warning logs) eaten away.
// 2) When you increase the key/value pairs beyond 100, slops start
// randomly failing as there are only 2 nodes and backlog of slops on
// other node causes the slop to be dropped
// But when you set this <= 100, no Put receives a QuotaException
// Correct way is creating a mock SocketStore which can inject
// failures of QuotaException and test the pipeline actions and handling
// by node. The Server side needs a mock time where you can freeze the
// time and see if it fails after the quota. But saving these ones for
// later.
HashMap<String, String> keyValuePairsToMasterNode = generateKeysForMasterNode(100);
String bootStrapUrl = "tcp://" + cluster.getNodeById(0).getHost() + ":" + cluster.getNodeById(0).getSocketPort();
factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootStrapUrl));
storeClient = factory.getStoreClient(storeName);
int numPutExceptions = 0;
ArrayList<String> putKeysThatSucceeded = new ArrayList<String>();
for (Entry<String, String> entry : keyValuePairsToMasterNode.entrySet()) {
try {
// do a put on node 0
storeClient.put(entry.getKey(), entry.getValue());
putKeysThatSucceeded.add(entry.getValue());
} catch (VoldemortException e) {
logger.warn(e, e);
numPutExceptions++;
}
}
logger.info("#Puts that failed due to Exception: " + numPutExceptions);
// wait for the slop pushed to finish its job
Thread.sleep(2 * SLOP_FREQUENCY_MS);
// keys exist
for (String val : putKeysThatSucceeded) {
int nodeId = 1;
// do a get on node 1
List<Versioned<byte[]>> valueBytes = adminClient.storeOps.getNodeKey(storeName, nodeId, new ByteArray(ByteUtils.getBytes(val, encodingType)));
assertEquals("Expect 1 value from PUT " + val, 1, valueBytes.size());
assertEquals("GET returned different value than put", val, ByteUtils.getString(valueBytes.get(0).getValue(), encodingType));
}
int numDeleteExceptions = 0;
ArrayList<String> deleteKeysThatSucceeded = new ArrayList<String>();
for (Entry<String, String> entry : keyValuePairsToMasterNode.entrySet()) {
try {
// do a put on node 0
storeClient.delete(entry.getKey());
deleteKeysThatSucceeded.add(entry.getValue());
} catch (VoldemortException e) {
logger.warn(e, e);
numDeleteExceptions++;
}
}
logger.info("#Deletes that failed due to Exceptions: " + numDeleteExceptions);
// wait for the slop pushed to finish its job
Thread.sleep(2 * SLOP_FREQUENCY_MS);
for (String val : deleteKeysThatSucceeded) {
for (int nodeId : cluster.getNodeIds()) {
// do a get on node 1
List<Versioned<byte[]>> valueBytes = adminClient.storeOps.getNodeKey(storeName, nodeId, new ByteArray(ByteUtils.getBytes(val, encodingType)));
assertTrue("Deleted value should be null or zero on node " + nodeId, valueBytes == null || valueBytes.size() == 0);
}
}
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class QuotaLimitingStoreTest method setup.
@Before
public void setup() throws IOException {
Properties props = new Properties();
props.put("enable.quota.limiting", "true");
server = ServerTestUtils.startStandAloneVoldemortServer(props, "test/common/voldemort/config/single-store.xml");
adminClient = new AdminClient(server.getMetadataStore().getCluster());
String bootStrapUrl = "tcp://" + server.getIdentityNode().getHost() + ":" + server.getIdentityNode().getSocketPort();
factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootStrapUrl));
storeClient = factory.getStoreClient("test");
}
Aggregations