Skip to content

Commit

Permalink
General refactoring of Bigrecord Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
greglu committed Jan 4, 2010
1 parent e44033c commit 25edf56
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 677 deletions.
81 changes: 41 additions & 40 deletions bigrecord-driver/bin/bigrecord-driver
Expand Up @@ -62,7 +62,7 @@ unset RUBYLIB
if [ "$DRIVERNAME" == "" ]; then
echo "Driver type was not specified"
exit 1
elif [ "$DRIVERNAME" != "hbase" -a "$DRIVERNAME" != "cassandra" ]; then
elif [ "$DRIVERNAME" != "hbase" ]; then
echo "Driver type \"$DRIVERNAME\" is invalid"
exit 1
fi
Expand Down Expand Up @@ -126,30 +126,30 @@ start() {
refresh_pids

if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
echo -e "\nAlready running (pid="$PID")."
exit 1
echo -e "\nAlready running (pid="$PID")."
exit 1
else
rm -f $LOGS_DIR/$PORT.log
nohup jruby $DRIVER $PORT >> $LOGS_DIR/$PORT.log 2>&1 < /dev/null &
PID=$!
if [ "$PID" != "" ] ; then
# monitor the log file for the message saying that the server is started
for ((i=0; i<$STARTUP_TIMEOUT; i+=1)); do
sleep 1
echo -n "."
if [ "$(cat $LOGS_DIR/$PORT.log | grep 'Started drb server')" != "" ] ; then
break
fi
done

if [ "$i" == $STARTUP_TIMEOUT ] ; then
echo -e "\nStartup timeout: couldn't start the DRb server."
else
echo $PID > $PIDS_DIR/$PORT.pid
fi
echo ""
# monitor the log file for the message saying that the server is started
for ((i=0; i<$STARTUP_TIMEOUT; i+=1)); do
sleep 1
echo -n "."
if [ "$(cat $LOGS_DIR/$PORT.log | grep 'Started drb server')" != "" ] ; then
break
fi
done

if [ "$i" == $STARTUP_TIMEOUT ] ; then
echo -e "\nStartup timeout: couldn't start the DRb server."
else
echo $PID > $PIDS_DIR/$PORT.pid
fi
echo ""
else
echo -e "\nAn error occured while starting the DRb server."
echo -e "\nAn error occured while starting the DRb server."
fi
fi
}
Expand All @@ -161,8 +161,8 @@ stop() {

if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
echo "Stopping driver (pid = $PID)." >> $LOGS_DIR/$PORT.log
kill $PID
rm $PIDS_DIR/$PORT.pid
kill $PID
rm $PIDS_DIR/$PORT.pid
else
echo "No $DRIVERNAME driver to kill."
fi
Expand All @@ -183,24 +183,25 @@ start_debug() {
}

case "$ACTION" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
start_debug)
start_debug
;;
*)
print_usage
exit 1
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
start_debug)
start_debug
;;
*)
print_usage
exit 1
esac

exit 0
24 changes: 12 additions & 12 deletions bigrecord-driver/bin/hbase-driver
Expand Up @@ -11,22 +11,22 @@ if ARGV.include?("-l")

# Make sure that the folder exists
if File.exists?(hbase_path)
# We're only going to include the jar files we need.
required_jars = Dir[hbase_path+"/*.jar",
hbase_path+"/lib/commons-logging*.jar",
hbase_path+"/lib/zookeeper*.jar",
hbase_path+"/lib/log4j*.jar",
hbase_path+"/lib/hadoop*.jar"]
classpath = required_jars.join(":")
# We're only going to include the jar files we need.
required_jars = Dir[hbase_path+"/*.jar",
hbase_path+"/lib/commons-logging*.jar",
hbase_path+"/lib/zookeeper*.jar",
hbase_path+"/lib/log4j*.jar",
hbase_path+"/lib/hadoop*.jar"]
classpath = required_jars.join(":")

args.delete_at(switch_index)
args.delete_at(switch_index)
args = args + ["-c", '"'+classpath+'"']
args.delete_at(switch_index)
args.delete_at(switch_index)
args = args + ["-c", '"'+classpath+'"']

# Otherwise we'll warn the user and quit
else
puts "Folder #{hbase_path} does not exist"
exit
puts "Folder #{hbase_path} does not exist"
exit
end
end

Expand Down
11 changes: 5 additions & 6 deletions bigrecord-driver/lib/big_record_driver.rb
@@ -1,7 +1,6 @@
LIB_ROOT = File.dirname(__FILE__)
BRD_ROOT = File.dirname(__FILE__)

require LIB_ROOT + '/big_record_driver/client'
require LIB_ROOT + '/big_record_driver/exceptions'
require LIB_ROOT + '/big_record_driver/column_descriptor'
require LIB_ROOT + '/big_record_driver/driver_manager'
require LIB_ROOT + '/big_record_driver/version'
require BRD_ROOT + '/big_record_driver/client'
require BRD_ROOT + '/big_record_driver/exceptions'
require BRD_ROOT + '/big_record_driver/column_descriptor'
require BRD_ROOT + '/big_record_driver/version'
119 changes: 0 additions & 119 deletions bigrecord-driver/lib/big_record_driver/bigrecord_server.rb

This file was deleted.

61 changes: 32 additions & 29 deletions bigrecord-driver/lib/big_record_driver/client.rb
@@ -1,36 +1,39 @@
require 'rubygems'
require 'activesupport'
require 'active_support'
require 'set'
require 'drb'

module BigRecordDriver
class Client

def initialize(config={}) # :nodoc:
config = config.symbolize_keys
config[:drb_host] ||= '127.0.0.1'
config[:drb_port] ||= 40000

@config = config

DRb.start_service('druby://127.0.0.1:0')
begin
@server = DRbObject.new(nil, "druby://#{@config[:drb_host]}:#{@config[:drb_port]}")
rescue DRb::DRbConnError
raise ConnectionError, "Failed to connect to the DRb server (jruby) " +
"at #{@config[:drb_host]}:#{@config[:drb_port]}."
module BigRecord
module Driver

class Client
attr_accessor :config, :server

def initialize(config={}) # :nodoc:
config = config.symbolize_keys
config[:drb_host] ||= '127.0.0.1'
config[:drb_port] ||= 40000

@config = config

DRb.start_service nil
begin
@server = DRbObject.new(nil, "druby://#{@config[:drb_host]}:#{@config[:drb_port]}")
rescue DRb::DRbConnError
raise ConnectionError, "Failed to connect to the DRb server (jruby) " +
"at #{@config[:drb_host]}:#{@config[:drb_port]}."
end
@server.configure(@config)
end

# Delegate the methods to the server
def method_missing(method, *args)
@server.send(method, *args)
end

def respond_to?(method)
super
end
@server.configure(@config)
end

# Delegate the methods to the server
def method_missing(method, *args)
@server.send(method, *args)
end

def respond_to?(method)
super
end

end
end
29 changes: 13 additions & 16 deletions bigrecord-driver/lib/big_record_driver/column_descriptor.rb
@@ -1,23 +1,20 @@
module BigRecordDriver
module BigRecord
module Driver

class ColumnDescriptor
class ColumnDescriptor
attr_accessor :name, :versions, :in_memory, :bloom_filter, :compression

attr_accessor :name
attr_accessor :versions
attr_accessor :in_memory
attr_accessor :bloom_filter
attr_accessor :compression
def initialize(name, options={})
raise ArgumentError, "name is mandatory" unless name

def initialize(name, options={})
raise ArgumentError, "name is mandatory" unless name

@name = name.to_s
@versions = options[:versions]
@in_memory = options[:in_memory]
@bloom_filter = options[:bloom_filter]
@compression = options[:compression]
@name = name.to_s
@versions = options[:versions]
@in_memory = options[:in_memory]
@bloom_filter = options[:bloom_filter]
@compression = options[:compression]
end
end

end

end

0 comments on commit 25edf56

Please sign in to comment.