Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ output*
# ignore standard Vim and Emacs temp files
*.swp
*~
.vim/

# ignore standard Mac OS X files/dirs
.DS_Store
Expand Down
38 changes: 38 additions & 0 deletions basictcp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>site.ycsb</groupId>
<artifactId>binding-parent</artifactId>
<version>0.18.0-SNAPSHOT</version>
<relativePath>../binding-parent</relativePath>
</parent>

<artifactId>basictcp-binding</artifactId>
<name>BasicTCP Binding</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>site.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
201 changes: 201 additions & 0 deletions basictcp/src/main/java/site/ycsb/db/BasicTcpDB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/**
* Copyright (c) 2015 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.
*
* Basic TCP based DB client binding for YCSB.
*
* Based off of the S3 client.
*/
package site.ycsb.db;

import java.util.HashMap;
import java.util.Set;
import java.util.Vector;
import java.io.*;
import java.util.*;
import java.net.*;

import site.ycsb.ByteIterator;
import site.ycsb.DB;
import site.ycsb.DBException;
import site.ycsb.Status;

/**
* Basic TCP based DB client for YCSB framework.
*
*/
public class BasicTcpDB extends DB {
public static final String HOST = "basictcpdb.host";
public static final String HOST_DEFAULT = "127.0.0.1";

public static final String PORT = "basictcpdb.port";
public static final String PORT_DEFAULT = "54321";

private Socket socket;
private String host;
private Integer port;
private PrintWriter outStream;
private BufferedReader inStream;

protected static final ThreadLocal<StringBuilder> TL_STRING_BUILDER =
new ThreadLocal<StringBuilder>() {
@Override
protected StringBuilder initialValue() {
return new StringBuilder();
}
};

protected StringBuilder getStringBuilder() {
StringBuilder sb = TL_STRING_BUILDER.get();
sb.setLength(0);
return sb;
}

/**
* Initialize.
*/
@Override
public void init() throws DBException {
host = getProperties().getProperty(HOST, HOST_DEFAULT);
port = Integer.parseInt(getProperties().getProperty(PORT, PORT_DEFAULT));

try {
this.socket = new Socket(host, port);
this.outStream = new PrintWriter(socket.getOutputStream(), true);
this.inStream =
new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {
throw new DBException(e);
}
}

/**
* Cleanup.
*/
@Override
public void cleanup() throws DBException {
try {
this.socket.close();
} catch (IOException e) {
throw new DBException(e);
}
}

/**
* Insert.
*/
@Override
public Status insert(String table, String key,
Map<String, ByteIterator> values) {

StringBuilder sb = this.getStringBuilder();
sb.append("INSERT ").append(table).append(" ").append(key).append(" [ ");
if (values != null) {
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
sb.append(entry.getKey()).append("=").append(entry.getValue())
.append(" ");
}
}

sb.append("]");

this.outStream.write(sb.toString());

return Status.OK;
}

/**
* Read.
*/
@Override
public Status read(String table, String key, Set<String> fields,
Map<String, ByteIterator> result) {

StringBuilder sb = this.getStringBuilder();
sb.append("READ ").append(table).append(" ").append(key).append(" [ ");
if (fields != null) {
for (String f : fields) {
sb.append(f).append(" ");
}
} else {
sb.append("<all fields>");
}

sb.append("]");

this.outStream.write(sb.toString());

return Status.OK;
}

/**
* Update.
*/
@Override
public Status update(String table, String key,
Map<String, ByteIterator> values) {

StringBuilder sb = this.getStringBuilder();
sb.append("UPDATE ").append(table).append(" ").append(key).append(" [ ");
if (values != null) {
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
sb.append(entry.getKey()).append("=").append(entry.getValue())
.append(" ");
}
}
sb.append("]");

this.outStream.write(sb.toString());

return Status.OK;
}

/**
* Delete.
*/
@Override
public Status delete(String table, String key) {
StringBuilder sb = this.getStringBuilder();
sb.append("DELETE ").append(table).append(" ").append(key);

this.outStream.write(sb.toString());

return Status.OK;
}

/**
* Scan.
*/
@Override
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {

StringBuilder sb = this.getStringBuilder();
sb.append("SCAN ").append(table).append(" ").append(startkey).append(" ")
.append(recordcount).append(" [ ");
if (fields != null) {
for (String f : fields) {
sb.append(f).append(" ");
}
} else {
sb.append("<all fields>");
}

sb.append("]");

this.outStream.write(sb.toString());

return Status.OK;
}
}
19 changes: 19 additions & 0 deletions basictcp/src/main/java/site/ycsb/db/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2015 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.
*
* Basic TCP based DB client binding for YCSB.
*/

package site.ycsb.db;
3 changes: 2 additions & 1 deletion bin/bindings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ arangodb3:site.ycsb.db.arangodb.ArangoDBClient
azurecosmos:site.ycsb.db.AzureCosmosClient
azuretablestorage:site.ycsb.db.azuretablestorage.AzureClient
basic:site.ycsb.BasicDB
basictcp:site.ycsb.db.BasicTcpDB
basicts:site.ycsb.BasicTSDB
cassandra-cql:site.ycsb.db.CassandraCQLClient
cassandra2-cql:site.ycsb.db.CassandraCQLClient
Expand Down Expand Up @@ -73,4 +74,4 @@ solr7:site.ycsb.db.solr7.SolrClient
tarantool:site.ycsb.db.TarantoolClient
tablestore:site.ycsb.db.tablestore.TableStoreClient
voltdb:site.ycsb.db.voltdb.VoltClient4
zookeeper:site.ycsb.db.zookeeper.ZKClient
zookeeper:site.ycsb.db.zookeeper.ZKClient
1 change: 1 addition & 0 deletions bin/ycsb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ DATABASES = {
"azurecosmos" : "site.ycsb.db.AzureCosmosClient",
"azuretablestorage" : "site.ycsb.db.azuretablestorage.AzureClient",
"basic" : "site.ycsb.BasicDB",
"basictcp" : "site.ycsb.db.BasicTcpDB",
"basicts" : "site.ycsb.BasicTSDB",
"cassandra-cql": "site.ycsb.db.CassandraCQLClient",
"cassandra2-cql": "site.ycsb.db.CassandraCQLClient",
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ LICENSE file.
<module>asynchbase</module>
<module>azurecosmos</module>
<module>azuretablestorage</module>
<module>basictcp</module>
<module>cassandra</module>
<module>cloudspanner</module>
<module>couchbase</module>
Expand Down