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

using ByteIterator instead of String for field values.

parent e1297f5e
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,11 @@ import com.gemstone.gemfire.cache.client.ClientCacheFactory; ...@@ -18,8 +18,11 @@ import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionFactory; import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut; import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.internal.admin.remote.DistributionLocatorId; import com.gemstone.gemfire.internal.admin.remote.DistributionLocatorId;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB; import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException; import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.StringByteIterator;
/** /**
* VMware vFabric GemFire client for the YCSB benchmark.<br /> * VMware vFabric GemFire client for the YCSB benchmark.<br />
...@@ -124,15 +127,17 @@ public class GemFireClient extends DB { ...@@ -124,15 +127,17 @@ public class GemFireClient extends DB {
@Override @Override
public int read(String table, String key, Set<String> fields, public int read(String table, String key, Set<String> fields,
HashMap<String, String> result) { HashMap<String, ByteIterator> result) {
Region<String, Map<String, String>> r = getRegion(table); Region<String, Map<String, byte[]>> r = getRegion(table);
Map<String, String> val = r.get(key); Map<String, byte[]> val = r.get(key);
if (val != null) { if (val != null) {
if (fields == null) { if (fields == null) {
result.putAll(val); for (String k : val.keySet()) {
result.put(key, new ByteArrayByteIterator(val.get(key)));
}
} else { } else {
for (String field : fields) { for (String field : fields) {
result.put(field, val.get(field)); result.put(field, new ByteArrayByteIterator(val.get(field)));
} }
} }
return SUCCESS; return SUCCESS;
...@@ -142,20 +147,20 @@ public class GemFireClient extends DB { ...@@ -142,20 +147,20 @@ public class GemFireClient extends DB {
@Override @Override
public int scan(String table, String startkey, int recordcount, public int scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, String>> result) { Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
// GemFire does not support scan // GemFire does not support scan
return ERROR; return ERROR;
} }
@Override @Override
public int update(String table, String key, HashMap<String, String> values) { public int update(String table, String key, HashMap<String, ByteIterator> values) {
getRegion(table).put(key, values); getRegion(table).put(key, convertToBytearrayMap(values));
return 0; return 0;
} }
@Override @Override
public int insert(String table, String key, HashMap<String, String> values) { public int insert(String table, String key, HashMap<String, ByteIterator> values) {
getRegion(table).put(key, values); getRegion(table).put(key, convertToBytearrayMap(values));
return 0; return 0;
} }
...@@ -165,15 +170,23 @@ public class GemFireClient extends DB { ...@@ -165,15 +170,23 @@ public class GemFireClient extends DB {
return 0; return 0;
} }
private Region<String, Map<String, String>> getRegion(String table) { private Map<String, byte[]> convertToBytearrayMap(Map<String,ByteIterator> values) {
Region<String, Map<String, String>> r = cache.getRegion(table); Map<String, byte[]> retVal = new HashMap<String, byte[]>();
for (String key : values.keySet()) {
retVal.put(key, values.get(key).toArray());
}
return retVal;
}
private Region<String, Map<String, byte[]>> getRegion(String table) {
Region<String, Map<String, byte[]>> r = cache.getRegion(table);
if (r == null) { if (r == null) {
try { try {
if (isClient) { if (isClient) {
ClientRegionFactory<String, Map<String, String>> crf = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY); ClientRegionFactory<String, Map<String, byte[]>> crf = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
r = crf.create(table); r = crf.create(table);
} else { } else {
RegionFactory<String, Map<String, String>> rf = ((Cache)cache).createRegionFactory(RegionShortcut.PARTITION); RegionFactory<String, Map<String, byte[]>> rf = ((Cache)cache).createRegionFactory(RegionShortcut.PARTITION);
r = rf.create(table); r = rf.create(table);
} }
} catch (RegionExistsException e) { } catch (RegionExistsException e) {
......
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