Skip to content

Commit

Permalink
Merge remote branch 'sudiptodas/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Cooper committed Mar 27, 2011
2 parents bdb3020 + 2f1100a commit 8f70da1
Show file tree
Hide file tree
Showing 13 changed files with 1,170 additions and 1 deletion.
125 changes: 125 additions & 0 deletions bin/ycsb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#! /usr/bin/env bash

# Set the YCSB specific environment. Adds all the required libraries to the class path.

# Copyright (c) 2010 Yahoo! Inc. 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 Java implementation to use. This is required.
#export JAVA_HOME=

# Any JVM options to pass.
#export YCSB_OPTS="-Djava.compiler=NONE"

# YCSB client heap size.
#export YCSB_HEAP_SIZE=500

this=`dirname "$0"`
this=`cd "$this"; pwd`

while [ -h "$this" ]; do
ls=`ls -ld "$this"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
this="$link"
else
this=`dirname "$this"`/"$link"
fi
done

bin=`dirname "$this"`
script=`basename "$this"`
bin=`cd "$bin"; pwd`
this="$bin/$script"

# the root of the Hadoop installation
export YCSB_HOME=`dirname "$this"`

echo "YCSB_HOME $YCSB_HOME"

cygwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac

# if no args specified, show usage
if [ $# = 0 ]; then
echo "Usage: ycsb CLASSNAME"
echo "where CLASSNAME is the name of the class to run"
echo "The jar file for the class must be in bin, build, lib, or db/*/lib."
exit 1
fi

# get arguments
COMMAND=$1
shift

JAVA=""
if [ "$JAVA_HOME" != "" ]; then
JAVA=$JAVA_HOME/bin/java
else
echo "JAVA_HOME must be set."
exit 1
fi

JAVA_HEAP_MAX=-Xmx500m
# check envvars which might override default args
if [ "$YCSB_HEAP_SIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$YCSB_HEAP_SIZE""m"
fi

# Set the classpath.

if [ "$CLASSPATH" != "" ]; then
CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
else
CLASSPATH=$JAVA_HOME/lib/tools.jar
fi

# so that filenames w/ spaces are handled correctly in loops below
IFS=

for f in $YCSB_HOME/build/*.jar; do
CLASSPATH=${CLASSPATH}:$f
done

for f in $YCSB_HOME/lib/*.jar; do
CLASSPATH=${CLASSPATH}:$f
done

for f in $YCSB_HOME/db/*; do
if [ -d $f ]; then
for j in $f/lib/*.jar; do
CLASSPATH=${CLASSPATH}:$j
done
fi
done

#echo "CLASSPATH=$CLASSPATH"

# restore ordinary behavior
unset IFS

CLASS=$COMMAND

# cygwin path translation
if $cygwin; then
CLASSPATH=`cygpath -p -w "$CLASSPATH"`
YCSB_HOME=`cygpath -w "$YCSB_HOME"`
fi

#echo "Executing command $CLASS with options $JAVA_HEAP_MAX $YCSB_OPTS $CLASS $@"
exec "$JAVA" $JAVA_HEAP_MAX $YCSB_OPTS -classpath "$CLASSPATH" $CLASS "$@"
5 changes: 5 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<property name="db.dir" value="db/voldemort"/>
<antcall target="dbcompile"/>
</target>

<target name="dbcompile-jdbc" depends="compile">
<property name="db.dir" value="db/jdbc"/>
<antcall target="dbcompile"/>
</target>

<target name="compile">
<mkdir dir="${classes.dir}"/>
Expand Down
6 changes: 6 additions & 0 deletions db/jdbc/conf/db.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Properties file that contains database connection information.

jdbc.driver=org.h2.Driver
db.url=jdbc:h2:tcp://foo.com:9092/~/h2/ycsb
db.user=sa
db.passwd=
6 changes: 6 additions & 0 deletions db/jdbc/conf/h2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Properties file that contains database connection information.

jdbc.driver=org.h2.Driver
db.url=jdbc:h2:tcp://foo.com:9092/~/h2/ycsb
db.user=sa
db.passwd=
1 change: 1 addition & 0 deletions db/jdbc/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory should contain jars for building and running the JDBC database.
1 change: 1 addition & 0 deletions db/jdbc/sql/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contains all the SQL statements used by the JDBC client.
12 changes: 12 additions & 0 deletions db/jdbc/sql/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Creates a Table.

-- Drop the table if it exists;
DROP TABLE IF EXISTS USERTABLE;

-- Create the user table with 5 fields.
CREATE TABLE usertable(KEY VARCHAR PRIMARY KEY,
FIELD1 VARCHAR, FIELD2 VARCHAR,
FIELD3 VARCHAR, FIELD4 VARCHAR,
FIELD5 VARCHAR, FIELD6 VARCHAR,
FIELD7 VARCHAR, FIELD8 VARCHAR,
FIELD9 VARCHAR, FIELD10 VARCHAR);
178 changes: 178 additions & 0 deletions db/jdbc/src/com/yahoo/ycsb/db/JdbcDBCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
* Copyright (c) 2010 Yahoo! Inc. 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.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Properties;

/**
* Execute a JDBC command line.
*
* @author sudipto
*
*/
public class JdbcDBCli implements JdbcDBClientConstants {

private static void usageMessage() {
System.out.println("JdbcCli. Options:");
System.out.println(" -p key=value properties defined.");
System.out.println(" -P location of the properties file to load.");
System.out.println(" -c SQL command to execute.");
}

private static void executeCommand(Properties props, String sql)
throws SQLException {
String driver = props.getProperty(DRIVER_CLASS);
String username = props.getProperty(CONNECTION_USER);
String password = props.getProperty(CONNECTION_PASSWD, "");
String url = props.getProperty(CONNECTION_URL);
if (driver == null || username == null || url == null) {
throw new SQLException("Missing connection information.");
}

Connection conn = null;

try {
Class.forName(driver);

conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
stmt.execute(sql);
System.out.println("Command \"" + sql + "\" successfully executed.");
} catch (ClassNotFoundException e) {
throw new SQLException("JDBC Driver class not found.");
} finally {
if (conn != null) {
System.out.println("Closing database connection.");
conn.close();
}
}
}

/**
* @param args
*/
public static void main(String[] args) {

if (args.length == 0) {
usageMessage();
System.exit(0);
}

Properties props = new Properties();
Properties fileprops = new Properties();
String sql = null;

// parse arguments
int argindex = 0;
while (args[argindex].startsWith("-")) {
if (args[argindex].compareTo("-P") == 0) {
argindex++;
if (argindex >= args.length) {
usageMessage();
System.exit(0);
}
String propfile = args[argindex];
argindex++;

Properties myfileprops = new Properties();
try {
myfileprops.load(new FileInputStream(propfile));
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(0);
}

// Issue #5 - remove call to stringPropertyNames to make compilable
// under Java 1.5
for (Enumeration<?> e = myfileprops.propertyNames(); e
.hasMoreElements();) {
String prop = (String) e.nextElement();

fileprops.setProperty(prop, myfileprops.getProperty(prop));
}

} else if (args[argindex].compareTo("-p") == 0) {
argindex++;
if (argindex >= args.length) {
usageMessage();
System.exit(0);
}
int eq = args[argindex].indexOf('=');
if (eq < 0) {
usageMessage();
System.exit(0);
}

String name = args[argindex].substring(0, eq);
String value = args[argindex].substring(eq + 1);
props.put(name, value);
argindex++;
} else if (args[argindex].compareTo("-c") == 0) {
argindex++;
if (argindex >= args.length) {
usageMessage();
System.exit(0);
}
sql = args[argindex++];
} else {
System.out.println("Unknown option " + args[argindex]);
usageMessage();
System.exit(0);
}

if (argindex >= args.length) {
break;
}
}

if (argindex != args.length) {
usageMessage();
System.exit(0);
}

// overwrite file properties with properties from the command line

// Issue #5 - remove call to stringPropertyNames to make compilable under
// Java 1.5
for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
String prop = (String) e.nextElement();

fileprops.setProperty(prop, props.getProperty(prop));
}

if (sql == null) {
System.err.println("Missing command.");
usageMessage();
System.exit(1);
}

try {
executeCommand(fileprops, sql);
} catch (SQLException e) {
System.err.println("Error in executing command. " + e);
System.exit(1);
}
}

}
Loading

0 comments on commit 8f70da1

Please sign in to comment.