forked from brianfrankcooper/YCSB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[infinispan] impl infinispan db with remote cache manager
- Loading branch information
Showing
7 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ output* | |
.project | ||
.classpath | ||
.settings | ||
.checkstyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
infinispan.client.hotrod.server_list=192.168.101.17:11222 | ||
infinispan.client.hotrod.force_return_values=false | ||
|
||
maxActive=-1 | ||
maxIdle=-1 | ||
minIdle=1 | ||
maxTotal=-1 | ||
|
||
whenExhaustedAction=1 |
128 changes: 128 additions & 0 deletions
128
infinispan/src/main/java/com/yahoo/ycsb/db/InfinispanRemoteClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.yahoo.ycsb.db; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.Vector; | ||
|
||
import org.infinispan.client.hotrod.RemoteCache; | ||
import org.infinispan.client.hotrod.RemoteCacheManager; | ||
import org.infinispan.util.logging.Log; | ||
import org.infinispan.util.logging.LogFactory; | ||
|
||
import com.yahoo.ycsb.ByteIterator; | ||
import com.yahoo.ycsb.DB; | ||
import com.yahoo.ycsb.DBException; | ||
import com.yahoo.ycsb.StringByteIterator; | ||
|
||
/** | ||
* This is a client implementation for Infinispan 5.x in client-server mode. | ||
* | ||
* @author mylesjao | ||
* | ||
*/ | ||
public class InfinispanRemoteClient extends DB { | ||
|
||
private RemoteCacheManager remoteIspnManager; | ||
|
||
private String cacheName = null; | ||
|
||
private static final Log logger = LogFactory.getLog(InfinispanRemoteClient.class); | ||
|
||
public InfinispanRemoteClient() { | ||
|
||
} | ||
|
||
@Override | ||
public void init() throws DBException { | ||
remoteIspnManager = RemoteCacheManagerHolder.getInstance(getProperties()); | ||
cacheName = getProperties().getProperty("cache"); | ||
} | ||
|
||
@Override | ||
public void cleanup() { | ||
remoteIspnManager.stop(); | ||
remoteIspnManager = null; | ||
} | ||
|
||
@Override | ||
public int insert(String table, String recordKey, HashMap<String, ByteIterator> values) { | ||
String compositKey = createKey(table, recordKey); | ||
Map<String, String> stringValues = new HashMap<String,String>(); | ||
StringByteIterator.putAllAsStrings(stringValues, values); | ||
try { | ||
cache().put(compositKey, stringValues); | ||
return Status.OK; | ||
} catch (Exception e) { | ||
return Status.ERROR; | ||
} | ||
} | ||
|
||
@Override | ||
public int read(String table, String recordKey, Set<String> fields, HashMap<String, ByteIterator> result) { | ||
String compositKey = createKey(table, recordKey); | ||
try { | ||
Map<String, String> values = cache().get(compositKey); | ||
|
||
if(values == null || values.isEmpty()){ | ||
return Status.NOT_FOUND; | ||
} | ||
|
||
if(fields == null){ //get all field/value pairs | ||
StringByteIterator.putAllAsByteIterators(result, values); | ||
}else{ | ||
for(String field: fields){ | ||
String value = values.get(field); | ||
if(value != null){ | ||
result.put(field, new StringByteIterator(value) ); | ||
} | ||
} | ||
} | ||
|
||
return Status.OK; | ||
} catch (Exception e) { | ||
return Status.ERROR; | ||
} | ||
} | ||
|
||
@Override | ||
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { | ||
logger.warn("Infinispan does not support scan semantics"); | ||
return Status.NOT_SUPPORT; | ||
} | ||
|
||
@Override | ||
public int update(String table, String recordKey, HashMap<String, ByteIterator> values) { | ||
String compositKey = createKey(table, recordKey); | ||
try { | ||
Map<String, String> stringValues = new HashMap<String, String>(); | ||
StringByteIterator.putAllAsStrings(stringValues, values); | ||
cache().put(compositKey, stringValues); | ||
return Status.OK; | ||
} catch (Exception e) { | ||
return Status.ERROR; | ||
} | ||
} | ||
@Override | ||
public int delete(String table, String recordKey) { | ||
String compositKey = createKey(table, recordKey); | ||
try { | ||
cache().remove(compositKey); | ||
return Status.OK; | ||
} catch (Exception e) { | ||
return Status.ERROR; | ||
} | ||
} | ||
|
||
private RemoteCache<String, Map<String,String>> cache(){ | ||
if(this.cacheName != null){ | ||
return remoteIspnManager.getCache(cacheName); | ||
}else{ | ||
return remoteIspnManager.getCache(); | ||
} | ||
} | ||
|
||
private String createKey(String table, String recordKey){ | ||
return table + "-" + recordKey; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
infinispan/src/main/java/com/yahoo/ycsb/db/RemoteCacheManagerHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.yahoo.ycsb.db; | ||
|
||
import java.util.Properties; | ||
|
||
import org.infinispan.client.hotrod.RemoteCacheManager; | ||
|
||
public class RemoteCacheManagerHolder { | ||
|
||
private static RemoteCacheManager cacheManager = null; | ||
|
||
private RemoteCacheManagerHolder() {} | ||
|
||
public static RemoteCacheManager getInstance(Properties props){ | ||
if(cacheManager == null){ | ||
synchronized (RemoteCacheManager.class) { | ||
cacheManager = new RemoteCacheManager(props); | ||
} | ||
} | ||
return cacheManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.yahoo.ycsb.db; | ||
|
||
public class Status { | ||
public static final int OK = 0; | ||
public static final int ERROR = 1; | ||
public static final int NOT_FOUND = 2; | ||
public static final int CONFLICT = 3; | ||
public static final int NOT_SUPPORT = 4; | ||
} |