row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
+ row.clear();
+ StringByteIterator.putAllAsStrings(row, values);
+ } else {
+ infinispanManager.getCache(table).put(key, values);
}
- }
-
- public Status delete(String table, String key) {
- try {
- if (clustered)
- AtomicMapLookup.removeAtomicMap(infinispanManager.getCache(table), key);
- else
- infinispanManager.getCache(table).remove(key);
- return Status.OK;
- } catch (Exception e) {
- return Status.ERROR;
+
+ return Status.OK;
+ } catch (Exception e) {
+ LOGGER.error(e);
+ return Status.ERROR;
+ }
+ }
+
+ public Status delete(String table, String key) {
+ try {
+ if (clustered) {
+ AtomicMapLookup.removeAtomicMap(infinispanManager.getCache(table), key);
+ } else {
+ infinispanManager.getCache(table).remove(key);
}
- }
+ return Status.OK;
+ } catch (Exception e) {
+ LOGGER.error(e);
+ return Status.ERROR;
+ }
+ }
}
diff --git a/infinispan/src/main/java/com/yahoo/ycsb/db/InfinispanRemoteClient.java b/infinispan/src/main/java/com/yahoo/ycsb/db/InfinispanRemoteClient.java
index 9b09f553..26ce8359 100644
--- a/infinispan/src/main/java/com/yahoo/ycsb/db/InfinispanRemoteClient.java
+++ b/infinispan/src/main/java/com/yahoo/ycsb/db/InfinispanRemoteClient.java
@@ -1,142 +1,139 @@
/**
- * Copyright (c) 2015 YCSB contributors. All rights reserved.
- *
+ * Copyright (c) 2015-2016 YCSB contributors. All rights reserved.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.yahoo.ycsb.db;
-import com.yahoo.ycsb.ByteIterator;
-import com.yahoo.ycsb.DB;
-import com.yahoo.ycsb.DBException;
-import com.yahoo.ycsb.Status;
-import com.yahoo.ycsb.StringByteIterator;
-
+import com.yahoo.ycsb.*;
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 java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
/**
* 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);
-
- @Override
- public void init() throws DBException {
- remoteIspnManager = RemoteCacheManagerHolder.getInstance(getProperties());
- cacheName = getProperties().getProperty("cache");
- }
-
- @Override
- public void cleanup() {
- remoteIspnManager.stop();
- remoteIspnManager = null;
- }
-
- @Override
- public Status insert(String table, String recordKey, HashMap values) {
- String compositKey = createKey(table, recordKey);
- Map stringValues = new HashMap();
- StringByteIterator.putAllAsStrings(stringValues, values);
- try {
- cache().put(compositKey, stringValues);
- return Status.OK;
- } catch (Exception e) {
- return Status.ERROR;
- }
- }
-
- @Override
- public Status read(String table, String recordKey, Set fields, HashMap result) {
- String compositKey = createKey(table, recordKey);
- try {
- Map 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 Status scan(String table, String startkey, int recordcount, Set fields, Vector> result) {
- logger.warn("Infinispan does not support scan semantics");
- return Status.NOT_IMPLEMENTED;
- }
-
- @Override
- public Status update(String table, String recordKey, HashMap values) {
- String compositKey = createKey(table, recordKey);
- try {
- Map stringValues = new HashMap();
- StringByteIterator.putAllAsStrings(stringValues, values);
- cache().put(compositKey, stringValues);
- return Status.OK;
- } catch (Exception e) {
- return Status.ERROR;
+ private static final Log LOGGER = LogFactory.getLog(InfinispanRemoteClient.class);
+
+ private RemoteCacheManager remoteIspnManager;
+ private String cacheName = null;
+
+ @Override
+ public void init() throws DBException {
+ remoteIspnManager = RemoteCacheManagerHolder.getInstance(getProperties());
+ cacheName = getProperties().getProperty("cache");
+ }
+
+ @Override
+ public void cleanup() {
+ remoteIspnManager.stop();
+ remoteIspnManager = null;
+ }
+
+ @Override
+ public Status insert(String table, String recordKey, HashMap values) {
+ String compositKey = createKey(table, recordKey);
+ Map stringValues = new HashMap<>();
+ StringByteIterator.putAllAsStrings(stringValues, values);
+ try {
+ cache().put(compositKey, stringValues);
+ return Status.OK;
+ } catch (Exception e) {
+ LOGGER.error(e);
+ return Status.ERROR;
+ }
+ }
+
+ @Override
+ public Status read(String table, String recordKey, Set fields, HashMap result) {
+ String compositKey = createKey(table, recordKey);
+ try {
+ Map values = cache().get(compositKey);
+
+ if (values == null || values.isEmpty()) {
+ return Status.NOT_FOUND;
}
- }
- @Override
- public Status delete(String table, String recordKey) {
- String compositKey = createKey(table, recordKey);
- try {
- cache().remove(compositKey);
- return Status.OK;
- } catch (Exception e) {
- return Status.ERROR;
+
+ 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));
+ }
+ }
}
- }
-
- private RemoteCache> cache(){
- if(this.cacheName != null){
- return remoteIspnManager.getCache(cacheName);
- }else{
- return remoteIspnManager.getCache();
- }
- }
-
- private String createKey(String table, String recordKey){
- return table + "-" + recordKey;
- }
+
+ return Status.OK;
+ } catch (Exception e) {
+ LOGGER.error(e);
+ return Status.ERROR;
+ }
+ }
+
+ @Override
+ public Status scan(String table, String startkey, int recordcount, Set fields,
+ Vector> result) {
+ LOGGER.warn("Infinispan does not support scan semantics");
+ return Status.NOT_IMPLEMENTED;
+ }
+
+ @Override
+ public Status update(String table, String recordKey, HashMap values) {
+ String compositKey = createKey(table, recordKey);
+ try {
+ Map stringValues = new HashMap<>();
+ StringByteIterator.putAllAsStrings(stringValues, values);
+ cache().put(compositKey, stringValues);
+ return Status.OK;
+ } catch (Exception e) {
+ LOGGER.error(e);
+ return Status.ERROR;
+ }
+ }
+
+ @Override
+ public Status delete(String table, String recordKey) {
+ String compositKey = createKey(table, recordKey);
+ try {
+ cache().remove(compositKey);
+ return Status.OK;
+ } catch (Exception e) {
+ LOGGER.error(e);
+ return Status.ERROR;
+ }
+ }
+
+ private RemoteCache> cache() {
+ if (this.cacheName != null) {
+ return remoteIspnManager.getCache(cacheName);
+ } else {
+ return remoteIspnManager.getCache();
+ }
+ }
+
+ private String createKey(String table, String recordKey) {
+ return table + "-" + recordKey;
+ }
}
diff --git a/infinispan/src/main/java/com/yahoo/ycsb/db/RemoteCacheManagerHolder.java b/infinispan/src/main/java/com/yahoo/ycsb/db/RemoteCacheManagerHolder.java
index b166f6b8..aea795e0 100644
--- a/infinispan/src/main/java/com/yahoo/ycsb/db/RemoteCacheManagerHolder.java
+++ b/infinispan/src/main/java/com/yahoo/ycsb/db/RemoteCacheManagerHolder.java
@@ -1,42 +1,47 @@
/**
- * Copyright (c) 2015 YCSB contributors. All rights reserved.
+ * Copyright (c) 2015-2016 YCSB contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.yahoo.ycsb.db;
import java.util.Properties;
import org.infinispan.client.hotrod.RemoteCacheManager;
-public class RemoteCacheManagerHolder {
-
- private static volatile RemoteCacheManager cacheManager = null;
-
- private RemoteCacheManagerHolder() {}
-
- public static RemoteCacheManager getInstance(Properties props){
- RemoteCacheManager result = cacheManager;
- if(result == null){
- synchronized (RemoteCacheManagerHolder.class) {
- result = cacheManager;
- if (result == null) {
- cacheManager = result = new RemoteCacheManager(props);
- }
- }
- }
- return result;
- }
+/**
+ * Utility class to ensure only a single RemoteCacheManager is created.
+ */
+final class RemoteCacheManagerHolder {
+
+ private static volatile RemoteCacheManager cacheManager = null;
+
+ private RemoteCacheManagerHolder() {
+ }
+
+ static RemoteCacheManager getInstance(Properties props) {
+ RemoteCacheManager result = cacheManager;
+ if (result == null) {
+ synchronized (RemoteCacheManagerHolder.class) {
+ result = cacheManager;
+ if (result == null) {
+ result = new RemoteCacheManager(props);
+ cacheManager = new RemoteCacheManager(props);
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/infinispan/src/main/java/com/yahoo/ycsb/db/package-info.java b/infinispan/src/main/java/com/yahoo/ycsb/db/package-info.java
new file mode 100644
index 00000000..01231c02
--- /dev/null
+++ b/infinispan/src/main/java/com/yahoo/ycsb/db/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015-2016 YCSB Contributors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License. See accompanying
+ * LICENSE file.
+ */
+
+/**
+ * The YCSB binding for Infinispan.
+ */
+package com.yahoo.ycsb.db;
+