Skip to content
Snippets Groups Projects
Commit f23aa0ec authored by Sean Busbey's avatar Sean Busbey
Browse files

Merge pull request #649 from risdenk/pr-491

[tarantool] Checkstyle updates for the Tarantool binding.
parents 215f7230 6d03c8fa
No related branches found
No related tags found
No related merge requests found
...@@ -47,4 +47,29 @@ LICENSE file. ...@@ -47,4 +47,29 @@ LICENSE file.
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </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> </project>
/** /**
* Copyright (c) 2014, Yahoo!, Inc. All rights reserved. * Copyright (c) 2014 - 2016 YCSB Contributors. All rights reserved.
* * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you * Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You * may not use this file except in compliance with the License. You
* may obtain a copy of the License at * may obtain a copy of the License at
* * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
...@@ -16,162 +16,137 @@ ...@@ -16,162 +16,137 @@
*/ */
package com.yahoo.ycsb.db; package com.yahoo.ycsb.db;
import com.yahoo.ycsb.ByteIterator; import com.yahoo.ycsb.*;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.tarantool.TarantoolConnection16; import org.tarantool.TarantoolConnection16;
import org.tarantool.TarantoolConnection16Impl; import org.tarantool.TarantoolConnection16Impl;
import org.tarantool.TarantoolException; import org.tarantool.TarantoolException;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/**
* YCSB binding for <a href="http://tarantool.org/">Tarantool</a>.
*/
public class TarantoolClient extends DB { public class TarantoolClient extends DB {
private static final Logger LOGGER = Logger.getLogger(TarantoolClient.class.getName());
public static final String HOST_PROPERTY = "tarantool.host";
public static final String PORT_PROPERTY = "tarantool.port"; private static final String HOST_PROPERTY = "tarantool.host";
public static final String SPACE_PROPERTY = "tarantool.space"; private static final String PORT_PROPERTY = "tarantool.port";
private static final String SPACE_PROPERTY = "tarantool.space";
public static final String DEFAULT_HOST = "localhost"; private static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 3301; private static final String DEFAULT_PORT = "3301";
public static final int DEFAULT_SPACE = 1024; private static final String DEFAULT_SPACE = "1024";
private static final Logger logger = Logger.getLogger(TarantoolClient.class.getName()); private TarantoolConnection16 connection;
private TarantoolConnection16 connection; private int spaceNo;
private int spaceNo;
public void init() throws DBException {
public void init() throws DBException { Properties props = getProperties();
Properties props = getProperties();
int port = Integer.parseInt(props.getProperty(PORT_PROPERTY, DEFAULT_PORT));
int port = DEFAULT_PORT; String host = props.getProperty(HOST_PROPERTY, DEFAULT_HOST);
String portString = props.getProperty(PORT_PROPERTY); spaceNo = Integer.parseInt(props.getProperty(SPACE_PROPERTY, DEFAULT_SPACE));
if (portString != null) {
port = Integer.parseInt(portString); try {
} this.connection = new TarantoolConnection16Impl(host, port);
} catch (Exception exc) {
String host = props.getProperty(HOST_PROPERTY); throw new DBException("Can't initialize Tarantool connection", exc);
if (host == null) { }
host = DEFAULT_HOST; }
}
public void cleanup() throws DBException {
spaceNo = DEFAULT_SPACE; this.connection.close();
String spaceString = props.getProperty(SPACE_PROPERTY); }
if (spaceString != null) {
spaceNo = Integer.parseInt(spaceString); @Override
} public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
return replace(key, values, "Can't insert element");
try { }
this.connection = new TarantoolConnection16Impl(host, port);
} catch (Exception exc) { private HashMap<String, ByteIterator> tupleConvertFilter(List<String> input, Set<String> fields) {
logger.log(Level.SEVERE,"Can't initialize Tarantool connection", exc); HashMap<String, ByteIterator> result = new HashMap<>();
return; if (input == null) {
} return result;
} }
for (int i = 1; i < input.toArray().length; i += 2) {
public void cleanup() throws DBException{ if (fields == null || fields.contains(input.get(i))) {
this.connection.close(); result.put(input.get(i), new StringByteIterator(input.get(i + 1)));
} }
}
@Override return result;
public Status insert(String table, String key, HashMap<String, ByteIterator> values) { }
return replace(key, values, "Can't insert element");
} @Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
private HashMap<String, ByteIterator> tuple_convert_filter (List<String> input, try {
Set<String> fields) { List<String> response = this.connection.select(this.spaceNo, 0, Arrays.asList(key), 0, 1, 0);
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); result = tupleConvertFilter(response, fields);
if (input == null) return Status.OK;
return result; } catch (TarantoolException exc) {
for (int i = 1; i < input.toArray().length; i += 2) LOGGER.log(Level.SEVERE, "Can't select element", exc);
if (fields == null || fields.contains(input.get(i))) return Status.ERROR;
result.put(input.get(i), new StringByteIterator(input.get(i+1))); } catch (NullPointerException exc) {
return result; return Status.ERROR;
} }
}
@Override
public Status read(String table, String key, Set<String> fields, @Override
HashMap<String, ByteIterator> result) { public Status scan(String table, String startkey,
try { int recordcount, Set<String> fields,
List<String> response; Vector<HashMap<String, ByteIterator>> result) {
response = this.connection.select(this.spaceNo, 0, Arrays.asList(key), 0, 1, 0); List<List<String>> response;
result = tuple_convert_filter(response, fields); try {
return Status.OK; response = this.connection.select(this.spaceNo, 0, Arrays.asList(startkey), 0, recordcount, 6);
} catch (TarantoolException exc) { } catch (TarantoolException exc) {
logger.log(Level.SEVERE,"Can't select element", exc); LOGGER.log(Level.SEVERE, "Can't select range elements", exc);
return Status.ERROR; return Status.ERROR;
} catch (NullPointerException exc) { } catch (NullPointerException exc) {
return Status.ERROR; return Status.ERROR;
} }
} for (List<String> i : response) {
HashMap<String, ByteIterator> temp = tupleConvertFilter(i, fields);
@Override if (!temp.isEmpty()) {
public Status scan(String table, String startkey, result.add((HashMap<String, ByteIterator>) temp.clone());
int recordcount, Set<String> fields, }
Vector<HashMap<String, ByteIterator>> result) { }
List<List<String>> response; return Status.OK;
try { }
response = this.connection.select(this.spaceNo, 0, Arrays.asList(startkey), 0, recordcount, 6);
} catch (TarantoolException exc) { @Override
logger.log(Level.SEVERE,"Can't select range elements", exc); public Status delete(String table, String key) {
return Status.ERROR; try {
} catch (NullPointerException exc) { this.connection.delete(this.spaceNo, Collections.singletonList(key));
return Status.ERROR; } catch (TarantoolException exc) {
} LOGGER.log(Level.SEVERE, "Can't delete element", exc);
for(List<String> i: response) { return Status.ERROR;
HashMap<String, ByteIterator> temp = tuple_convert_filter(i, fields); } catch (NullPointerException e) {
if (!temp.isEmpty()) return Status.ERROR;
result.add((HashMap<String, ByteIterator>) temp.clone()); }
} return Status.OK;
return Status.OK; }
}
@Override
@Override public Status update(String table, String key, HashMap<String, ByteIterator> values) {
public Status delete(String table, String key) { return replace(key, values, "Can't replace element");
try { }
this.connection.delete(this.spaceNo, Arrays.asList(key));
} catch (TarantoolException exc) { private Status replace(String key, HashMap<String, ByteIterator> values, String exceptionDescription) {
logger.log(Level.SEVERE,"Can't delete element", exc); int j = 0;
return Status.ERROR; String[] tuple = new String[1 + 2 * values.size()];
} catch (NullPointerException e) { tuple[0] = key;
return Status.ERROR; for (Map.Entry<String, ByteIterator> i : values.entrySet()) {
} tuple[j + 1] = i.getKey();
return Status.OK; tuple[j + 2] = i.getValue().toString();
} j += 2;
@Override }
public Status update(String table, String key, try {
HashMap<String, ByteIterator> values) { this.connection.replace(this.spaceNo, tuple);
return replace(key, values, "Can't replace element"); } catch (TarantoolException exc) {
LOGGER.log(Level.SEVERE, exceptionDescription, exc);
} return Status.ERROR;
}
private Status replace(String key, return Status.OK;
HashMap<String, ByteIterator> values,
String exceptionDescription) { }
int j = 0;
String[] tuple = new String[1 + 2 * values.size()];
tuple[0] = key;
for (Map.Entry<String, ByteIterator> i: values.entrySet()) {
tuple[j + 1] = i.getKey();
tuple[j + 2] = i.getValue().toString();
j += 2;
}
try {
this.connection.replace(this.spaceNo, tuple);
} catch (TarantoolException exc) {
logger.log(Level.SEVERE,exceptionDescription, exc);
return Status.ERROR;
}
return Status.OK;
}
} }
/*
* Copyright (c) 2014 - 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.
*/
/**
* YCSB binding for <a href="http://tarantool.org/">Tarantool</a>.
*/
package com.yahoo.ycsb.db;
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