зеркало из https://github.com/Azure/YCSB.git
Merge pull request #650 from risdenk/pr-487
[infinispan] Checkstyle updates for the Infinispan binding.
This commit is contained in:
Коммит
215f7230f0
|
@ -51,4 +51,28 @@ LICENSE file.
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.15</version>
|
||||
<configuration>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<configLocation>../checkstyle.xml</configLocation>
|
||||
<failOnViolation>true</failOnViolation>
|
||||
<failsOnError>true</failsOnError>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>checkstyle</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2012 YCSB contributors. All rights reserved.
|
||||
* Copyright (c) 2012-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
|
||||
|
@ -39,112 +39,118 @@ import java.util.Vector;
|
|||
|
||||
/**
|
||||
* This is a client implementation for Infinispan 5.x.
|
||||
*
|
||||
* Some settings:
|
||||
*
|
||||
* @author Manik Surtani (manik AT jboss DOT org)
|
||||
*/
|
||||
public class InfinispanClient extends DB {
|
||||
private static final Log LOGGER = LogFactory.getLog(InfinispanClient.class);
|
||||
|
||||
// An optimisation for clustered mode
|
||||
private final boolean clustered;
|
||||
// An optimisation for clustered mode
|
||||
private final boolean clustered;
|
||||
|
||||
private EmbeddedCacheManager infinispanManager;
|
||||
private EmbeddedCacheManager infinispanManager;
|
||||
|
||||
private static final Log logger = LogFactory.getLog(InfinispanClient.class);
|
||||
public InfinispanClient() {
|
||||
clustered = Boolean.getBoolean("infinispan.clustered");
|
||||
}
|
||||
|
||||
public InfinispanClient() {
|
||||
clustered = Boolean.getBoolean("infinispan.clustered");
|
||||
}
|
||||
public void init() throws DBException {
|
||||
try {
|
||||
infinispanManager = new DefaultCacheManager("infinispan-config.xml");
|
||||
} catch (IOException e) {
|
||||
throw new DBException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() throws DBException {
|
||||
try {
|
||||
infinispanManager = new DefaultCacheManager("infinispan-config.xml");
|
||||
} catch (IOException e) {
|
||||
throw new DBException(e);
|
||||
public void cleanup() {
|
||||
infinispanManager.stop();
|
||||
infinispanManager = null;
|
||||
}
|
||||
|
||||
public Status read(String table, String key, Set<String> fields,
|
||||
HashMap<String, ByteIterator> result) {
|
||||
try {
|
||||
Map<String, String> row;
|
||||
if (clustered) {
|
||||
row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false);
|
||||
} else {
|
||||
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
|
||||
row = cache.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
infinispanManager.stop();
|
||||
infinispanManager = null;
|
||||
}
|
||||
|
||||
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
|
||||
try {
|
||||
Map<String, String> row;
|
||||
if (clustered) {
|
||||
row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false);
|
||||
} else {
|
||||
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
|
||||
row = cache.get(key);
|
||||
}
|
||||
if (row != null) {
|
||||
result.clear();
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
StringByteIterator.putAllAsByteIterators(result, row);
|
||||
} else {
|
||||
for (String field : fields) result.put(field, new StringByteIterator(row.get(field)));
|
||||
}
|
||||
}
|
||||
return Status.OK;
|
||||
} catch (Exception e) {
|
||||
return Status.ERROR;
|
||||
if (row != null) {
|
||||
result.clear();
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
StringByteIterator.putAllAsByteIterators(result, row);
|
||||
} else {
|
||||
for (String field : fields) {
|
||||
result.put(field, new StringByteIterator(row.get(field)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Status 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.OK;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return Status.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
|
||||
try {
|
||||
if (clustered) {
|
||||
AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
|
||||
StringByteIterator.putAllAsStrings(row, values);
|
||||
} else {
|
||||
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
|
||||
Map<String, String> row = cache.get(key);
|
||||
if (row == null) {
|
||||
row = StringByteIterator.getStringMap(values);
|
||||
cache.put(key, row);
|
||||
} else {
|
||||
StringByteIterator.putAllAsStrings(row, values);
|
||||
}
|
||||
}
|
||||
public Status 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.OK;
|
||||
}
|
||||
|
||||
return Status.OK;
|
||||
} catch (Exception e) {
|
||||
return Status.ERROR;
|
||||
public Status update(String table, String key,
|
||||
HashMap<String, ByteIterator> values) {
|
||||
try {
|
||||
if (clustered) {
|
||||
AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
|
||||
StringByteIterator.putAllAsStrings(row, values);
|
||||
} else {
|
||||
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
|
||||
Map<String, String> row = cache.get(key);
|
||||
if (row == null) {
|
||||
row = StringByteIterator.getStringMap(values);
|
||||
cache.put(key, row);
|
||||
} else {
|
||||
StringByteIterator.putAllAsStrings(row, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
|
||||
try {
|
||||
if (clustered) {
|
||||
AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
|
||||
row.clear();
|
||||
StringByteIterator.putAllAsStrings(row, values);
|
||||
} else {
|
||||
infinispanManager.getCache(table).put(key, values);
|
||||
}
|
||||
return Status.OK;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return Status.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return Status.OK;
|
||||
} catch (Exception e) {
|
||||
return Status.ERROR;
|
||||
public Status insert(String table, String key,
|
||||
HashMap<String, ByteIterator> values) {
|
||||
try {
|
||||
if (clustered) {
|
||||
AtomicMap<String, String> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Copyright (c) 2015 YCSB contributors. All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2015-2016 YCSB contributors. All rights reserved.
|
||||
* <p>
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* 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
|
||||
|
@ -17,12 +17,7 @@
|
|||
|
||||
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;
|
||||
|
@ -35,108 +30,110 @@ 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);
|
||||
|
||||
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<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 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<String, ByteIterator> values) {
|
||||
String compositKey = createKey(table, recordKey);
|
||||
Map<String, String> 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<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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status 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;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status 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_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status 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 Status 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;
|
||||
}
|
||||
|
||||
return Status.OK;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return Status.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status 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_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status update(String table, String recordKey, HashMap<String, ByteIterator> values) {
|
||||
String compositKey = createKey(table, recordKey);
|
||||
try {
|
||||
Map<String, String> 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<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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* 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
|
||||
|
@ -21,22 +21,27 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="http://infinispan.org/">Infinispan</a>.
|
||||
*/
|
||||
package com.yahoo.ycsb.db;
|
||||
|
Загрузка…
Ссылка в новой задаче