use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class RebootstrappingStoreTest method setUp.
@Before
public void setUp() throws Exception {
SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
int numServers = 2;
VoldemortServer[] voldemortServers = new VoldemortServer[numServers];
int[][] partitionMap = { { 0, 1 }, {} };
cluster = ServerTestUtils.startVoldemortCluster(numServers, voldemortServers, partitionMap, socketStoreFactory, false, null, STORES_XML, new Properties());
servers = Lists.newArrayList();
for (int i = 0; i < numServers; ++i) {
servers.add(voldemortServers[i]);
}
String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
storeClient = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl)).getStoreClient(STORE_NAME);
Map<String, String> entries = Maps.newHashMap();
entries.put("a", "1");
entries.put("b", "2");
for (Map.Entry<String, String> entry : entries.entrySet()) storeClient.put(entry.getKey(), entry.getValue());
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class VersionedPutPruneJobTest method setup.
@Before
public void setup() throws Exception {
socketStoreMap = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
final int numServers = 4;
servers = new VoldemortServer[numServers];
int[][] currentPartitionMap = { { 0, 4 }, { 2, 6 }, { 1, 5 }, { 3, 7 } };
cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, currentPartitionMap, socketStoreFactory, true, null, "test/common/voldemort/config/single-store-322.xml", new Properties());
StringReader reader = new StringReader(VoldemortTestConstants.getSingleStore322Xml());
StoreDefinition storeDef = new StoreDefinitionsMapper().readStoreList(reader).get(0);
currentRoutingPlan = new BaseStoreRoutingPlan(cluster, storeDef);
String bootStrapUrl = "";
for (VoldemortServer server : servers) {
Node node = server.getIdentityNode();
socketStoreMap.put(node.getId(), ServerTestUtils.getSocketStore(socketStoreFactory, "test", node.getHost(), node.getSocketPort(), RequestFormatType.PROTOCOL_BUFFERS, false, true));
bootStrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
}
testEntries = ServerTestUtils.createRandomKeyValueString(100);
int[][] oldPartitionMap = { { 3, 6 }, { 1, 4 }, { 7, 2 }, { 5, 0 } };
oldRoutingPlan = new BaseStoreRoutingPlan(ServerTestUtils.getLocalCluster(numServers, oldPartitionMap), storeDef);
SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootStrapUrl));
storeClient = factory.getStoreClient("test");
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class VoldemortAvroClientShell method main.
public static void main(String[] args) throws IOException {
if (args.length < 2 || args.length > 3) {
System.err.println("Usage: java VoldemortAvroClient store_name bootstrap_url [command_file]");
System.exit(-1);
}
String storeName = args[0];
String bootstrapUrl = args[1];
String commandsFileName = "";
BufferedReader fileReader = null;
BufferedReader inputReader = null;
try {
if (args.length == 3) {
commandsFileName = args[2];
fileReader = new BufferedReader(new FileReader(commandsFileName));
}
inputReader = new BufferedReader(new InputStreamReader(System.in));
} catch (IOException e) {
Utils.croak("Failure to open input stream: " + e.getMessage());
}
ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(bootstrapUrl).setEnableLazy(false).setRequestFormatType(RequestFormatType.VOLDEMORT_V3);
StoreClientFactory factory = null;
DefaultStoreClient<Object, Object> client = null;
try {
try {
factory = new SocketStoreClientFactory(clientConfig);
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);
System.out.print(PROMPT);
Pair<Schema, Schema> keyValueSchemaPair = getLatestKeyValueSchema(bootstrapUrl, storeName);
Schema latestKeySchema = keyValueSchemaPair.getFirst();
if (latestKeySchema == null) {
Utils.croak("Could not parse latest key schema for store name " + storeName);
}
Schema latestValueSchema = keyValueSchemaPair.getSecond();
if (latestValueSchema == null) {
Utils.croak("Could not parse latest value schema for store name " + storeName);
}
if (fileReader != null) {
processCommands(client, fileReader, latestKeySchema, latestValueSchema, true);
} else {
processCommands(client, inputReader, latestKeySchema, latestValueSchema, false);
}
} finally {
if (factory != null)
factory.close();
if (fileReader != null)
fileReader.close();
}
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class ClientExample method avroStoreExample.
public static void avroStoreExample() {
System.out.println("==============Avro 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<GenericRecord, GenericRecord> client = factory.getStoreClient("avro-example");
// creating initial k-v pair
System.out.println("Creating initial Key and Value");
String keySchemaJson = "{ \"name\": \"key\", \"type\": \"record\", \"fields\": [{ \"name\": \"user_id\", \"type\": \"int\" }] }";
Schema keySchema = Schema.parse(keySchemaJson);
GenericRecord key = new GenericData.Record(keySchema);
key.put("user_id", 123);
String valueSchemaJson = "{\n" + " \"name\": \"value\",\n" + " \"type\": \"record\",\n" + " \"fields\": [{ \n" + " \"name\": \"user_id\",\n" + " \"type\": \"int\"\n" + " }, {\n" + " \"name\": \"gender\",\n" + " \"type\": \"string\"\n" + " }, {\n" + " \"name\": \"age\",\n" + " \"type\": \"int\",\n" + " \"optional\": true\n" + " }]\n" + " }";
Schema valueSchema = Schema.parse(valueSchemaJson);
GenericRecord value = new GenericData.Record(valueSchema);
value.put("user_id", 123);
value.put("gender", "male");
value.put("age", 23);
// put initial value
System.out.println("Putting Initial value");
client.put(key, value);
// get the value
System.out.println("Getting the value");
Versioned<GenericRecord> versioned = client.get(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");
GenericRecord modifiedRecord = versioned.getValue();
modifiedRecord.put("gender", "female");
modifiedRecord.put("age", 55);
versioned.setObject(modifiedRecord);
// update the value
System.out.println("Putting the new value");
client.put(key, versioned);
// get again and print
System.out.println("Getting the new value");
versioned = client.get(key);
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 RedirectingStoreTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
currentCluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0, 1 }, { 2, 3 }, {} });
targetCluster = UpdateClusterUtils.createUpdatedCluster(currentCluster, 2, Arrays.asList(0));
this.primaryPartitionsMoved = Lists.newArrayList(0);
this.secondaryPartitionsMoved = Lists.newArrayList(2, 3);
this.storeDef = new StoreDefinitionBuilder().setName("test").setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
File tempStoreXml = new File(TestUtils.createTempDir(), "stores.xml");
FileUtils.writeStringToFile(tempStoreXml, new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(storeDef)));
this.servers = new VoldemortServer[3];
for (int nodeId = 0; nodeId < 3; nodeId++) {
this.servers[nodeId] = startServer(nodeId, tempStoreXml.getAbsolutePath(), currentCluster);
}
// Start another node for only this unit test
HashMap<ByteArray, byte[]> entrySet = ServerTestUtils.createRandomKeyValuePairs(100);
SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(Lists.newArrayList("tcp://" + currentCluster.getNodeById(0).getHost() + ":" + currentCluster.getNodeById(0).getSocketPort())));
StoreClient<Object, Object> storeClient = factory.getStoreClient("test");
this.primaryEntriesMoved = Maps.newHashMap();
this.secondaryEntriesMoved = Maps.newHashMap();
this.proxyPutTestPrimaryEntries = Maps.newHashMap();
this.proxyPutTestSecondaryEntries = Maps.newHashMap();
RoutingStrategy strategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, currentCluster);
for (Entry<ByteArray, byte[]> entry : entrySet.entrySet()) {
storeClient.put(new String(entry.getKey().get()), new String(entry.getValue()));
List<Integer> pList = strategy.getPartitionList(entry.getKey().get());
if (primaryPartitionsMoved.contains(pList.get(0))) {
primaryEntriesMoved.put(entry.getKey(), entry.getValue());
} else if (secondaryPartitionsMoved.contains(pList.get(0))) {
secondaryEntriesMoved.put(entry.getKey(), entry.getValue());
}
}
// Sleep a while for the queries to go through...
// Hope the 'God of perfect timing' is on our side
Thread.sleep(500);
// steal a few primary key-value pairs for testing proxy put logic
int cnt = 0;
for (Entry<ByteArray, byte[]> entry : primaryEntriesMoved.entrySet()) {
if (cnt > 3)
break;
this.proxyPutTestPrimaryEntries.put(entry.getKey(), entry.getValue());
cnt++;
}
for (ByteArray key : this.proxyPutTestPrimaryEntries.keySet()) {
this.primaryEntriesMoved.remove(key);
}
assertTrue("Not enough primary entries", primaryEntriesMoved.size() > 1);
// steal a few secondary key-value pairs for testing proxy put logic
cnt = 0;
for (Entry<ByteArray, byte[]> entry : secondaryEntriesMoved.entrySet()) {
if (cnt > 3)
break;
this.proxyPutTestSecondaryEntries.put(entry.getKey(), entry.getValue());
cnt++;
}
for (ByteArray key : this.proxyPutTestSecondaryEntries.keySet()) {
this.secondaryEntriesMoved.remove(key);
}
assertTrue("Not enough secondary entries", primaryEntriesMoved.size() > 1);
RebalanceBatchPlan RebalanceBatchPlan = new RebalanceBatchPlan(currentCluster, targetCluster, Lists.newArrayList(storeDef));
List<RebalanceTaskInfo> plans = Lists.newArrayList(RebalanceBatchPlan.getBatchPlan());
// Set into rebalancing state
for (RebalanceTaskInfo partitionPlan : plans) {
servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.SERVER_STATE_KEY, MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER);
servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.REBALANCING_STEAL_INFO, new RebalancerState(Lists.newArrayList(partitionPlan)));
servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.REBALANCING_SOURCE_CLUSTER_XML, currentCluster);
// update original storedefs
servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.REBALANCING_SOURCE_STORES_XML, Lists.newArrayList(storeDef));
}
// Update the cluster metadata on all three nodes
for (VoldemortServer server : servers) {
server.getMetadataStore().put(MetadataStore.CLUSTER_KEY, targetCluster);
}
}
Aggregations