Skip to content
Snippets Groups Projects
Commit 7aef3fab authored by Swapnil Bawaskar's avatar Swapnil Bawaskar
Browse files

-adding initial implementation of GemFireClient for ycsb.

-adding compile target for gemfire-client.
-adding ConfigHelper which calculates the number of entries to use to fill up a certain percentage of memory
parent 7cb82c4f
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,11 @@
</fileset>
</path>
<target name="dbcompile-gemfire" depends="compile">
<property name="db.dir" value="db/gemfire" />
<antcall target="dbcompile" />
</target>
<target name="dbcompile-infinispan-5.0" depends="compile">
<property name="db.dir" value="db/infinispan-5.0" />
<antcall target="dbcompile" />
......
package com.yahoo.ycsb.db;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import com.yahoo.ycsb.workloads.CoreWorkload;
public class ConfigHelper {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the heap size for GemFire in GB:");
String input = null;
input = br.readLine();
long bytes = convertToBytes(input);
System.out.print("Enter % of heap to be filled: (default:90):");
input = br.readLine();
int percent = 90;
if (!input.equals("")) {
percent = Integer.parseInt(input.trim());
}
long bytesToFill = (bytes*percent)/100;
System.out.println("Bytes available:"+bytes);
System.out.println("Bytes to fill :"+bytesToFill);
System.out.print("Enter field count for value: (default:"+CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT+"):");
input = br.readLine();
int fieldCount = 0;
if (input.equals("")) {
fieldCount = Integer.parseInt(CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT);
} else {
fieldCount = Integer.parseInt(input.trim());
}
System.out.print("Enter field length in bytes: (default:"+CoreWorkload.FIELD_LENGTH_PROPERTY_DEFAULT+"):");
input = br.readLine();
int fieldLength = 0;
if (input.equals("")) {
fieldLength = Integer.parseInt(CoreWorkload.FIELD_LENGTH_PROPERTY_DEFAULT);
} else {
fieldLength = Integer.parseInt(input.trim());
}
ObjectSizer s = ObjectSizer.DEFAULT;
String keyPrefix = "user";
String valPrefix = "field";
int sizeOfInt = 4;
int keySize = s.sizeof(keyPrefix) + sizeOfInt;
int valSize = (s.sizeof(valPrefix) + sizeOfInt + fieldLength) * fieldCount;
long entrySize = keySize + valSize;
System.out.println("Entry size in bytes:"+entrySize+"\n");
System.out.println("recordcount="+(bytesToFill/entrySize));
}
private static long convertToBytes(String input) {
input = input.trim();
String b = null;
long bytes = 0;
if (input.contains("g") || input.contains("G")) {
b = input.substring(0, input.length()-1);
} else {
b = input;
}
long g = Long.parseLong(b);
bytes = g * 1024 * 1024 * 1024;
return bytes;
}
}
package com.yahoo.ycsb.db;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionExistsException;
import com.gemstone.gemfire.cache.RegionFactory;
import com.gemstone.gemfire.cache.RegionShortcut;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
public class GemFireClient extends DB {
private static final int SUCCESS = 0;
private static final int ERROR = -1;
private GemFireCache cache;
private int serverPort;
@Override
public void init() throws DBException {
Properties props = getProperties();
if (props != null && !props.isEmpty()) {
String serverPortStr = props.getProperty("gemfire.serverport");
if (serverPortStr != null) {
serverPort = Integer.parseInt(serverPortStr);
}
String topology = props.getProperty("gemfire.topology");
if (topology != null) {
if (topology.equals("embedded")) {
cache = new CacheFactory().create();
}
return;
}
}
cache = new ClientCacheFactory().create();
}
@Override
public int read(String table, String key, Set<String> fields,
HashMap<String, String> result) {
Region<String, Map<String, String>> r = getRegion(table);
Map<String, String> val = r.get(key);
if (val != null) {
if (fields == null) {
result.putAll(val);
} else {
for (String field : fields) {
result.put(field, val.get(field));
}
}
return SUCCESS;
}
return ERROR;
}
@Override
public int scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, String>> result) {
// TODO
return SUCCESS;
}
@Override
public int update(String table, String key, HashMap<String, String> values) {
getRegion(table).put(key, values);
return 0;
}
@Override
public int insert(String table, String key, HashMap<String, String> values) {
getRegion(table).put(key, values);
return 0;
}
@Override
public int delete(String table, String key) {
getRegion(table).destroy(key);
return 0;
}
private Region<String, Map<String, String>> getRegion(String table) {
Region<String, Map<String, String>> r = cache.getRegion(table);
if (r == null) {
try {
if (cache instanceof ClientCache) {
ClientRegionFactory<String, Map<String, String>> crf = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
r = crf.create(table);
} else {
RegionFactory<String, Map<String, String>> rf = ((Cache)cache).createRegionFactory(RegionShortcut.PARTITION);
r = rf.create(table);
}
} catch (RegionExistsException e) {
// another thread created the region
r = cache.getRegion(table);
}
}
return r;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment