diff --git a/.gitignore b/.gitignore
index 38483ef..e69de29 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +0,0 @@
-cassandra
-data
diff --git a/CHANGELOG b/CHANGELOG
index 0178827..8b9ddcc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
+v0.5.1. Add bin/cassandra script, to build and start the server for you.
+
v0.5. More API changes. Working temporal comparators.
v0.4. Use new comparator API. Namespace Thrift bindings; rename gem and class to Cassandra. Make tokens and limits actually work. Retry UnavailableExceptions.
diff --git a/Manifest b/Manifest
index 6acf3c9..3f51063 100644
--- a/Manifest
+++ b/Manifest
@@ -1,3 +1,4 @@
+bin/cassandra_helper
CHANGELOG
conf/cassandra.in.sh
conf/log4j.properties
diff --git a/README b/README
index 78d3974..d7b3c4c 100644
--- a/README
+++ b/README
@@ -25,12 +25,14 @@ You need Ruby 1.8 or 1.9. If you have those, just run:
sudo gem install cassandra
-== Usage
-
-Cassandra is a rapidly moving target. In order to get a working server, change to the checkout or gem directory, and run:
+Cassandra is a rapidly moving target. In order to get a working server, use the bin/cassandra_helper script (requires git):
- rake cassandra
+ cassandra_helper cassandra
+
+A server will be installed in $HOME/cassandra/r$REVISION, and started in debug mode.
+== Usage
+
Now, start IRb and require the library:
require 'cassandra'
diff --git a/Rakefile b/Rakefile
index db39530..e8f3319 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,48 +1,71 @@
-require 'echoe'
-Echoe.new("cassandra") do |p|
- p.author = "Evan Weaver"
- p.project = "fauna"
- p.summary = "A Ruby client for the Cassandra distributed database."
- p.rubygems_version = ">= 0.8"
- p.dependencies = ['json', 'thrift']
- p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift)/
- p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
- p.url = "http://blog.evanweaver.com/files/doc/fauna/cassandra/"
- p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
-end
+unless ENV['FROM_BIN_CASSANDRA_HELPER']
+ require 'rubygems'
+ require 'echoe'
-desc "Start Cassandra"
-task :cassandra => [:checkout, :patch, :build] do
- env = "CASSANDRA_INCLUDE=#{Dir.pwd}/conf/cassandra.in.sh" unless ENV["CASSANDRA_INCLUDE"]
- exec("env #{env} cassandra/bin/cassandra -f")
+ Echoe.new("cassandra") do |p|
+ p.author = "Evan Weaver"
+ p.project = "fauna"
+ p.summary = "A Ruby client for the Cassandra distributed database."
+ p.rubygems_version = ">= 0.8"
+ p.dependencies = ['json', 'thrift']
+ p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift)/
+ p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
+ p.url = "http://blog.evanweaver.com/files/doc/fauna/cassandra/"
+ p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
+ end
end
REVISION = "15354b4906fd654d58fe50fd01ebf95b69434ba9"
+
PATCHES = [
"http://issues.apache.org/jira/secure/attachment/12416014/0001-CASSANDRA-356-rename-clean-up-collectColumns-methods.txt",
"http://issues.apache.org/jira/secure/attachment/12416073/0002-v3.patch",
"http://issues.apache.org/jira/secure/attachment/12416074/357-v2.patch",
"http://issues.apache.org/jira/secure/attachment/12416086/357-3.patch"]
-
+
+CASSANDRA_HOME = "#{ENV['HOME']}/cassandra/r#{REVISION[0, 8]}"
+
+CASSANDRA_TEST = "#{ENV['HOME']}/cassandra/test"
+
+desc "Start Cassandra"
+task :cassandra => [:checkout, :patch, :build] do
+ # Construct environment
+ env = ""
+ if !ENV["CASSANDRA_INCLUDE"]
+ env << "CASSANDRA_INCLUDE=#{Dir.pwd}/conf/cassandra.in.sh "
+ env << "CASSANDRA_HOME=#{CASSANDRA_HOME} "
+ env << "CASSANDRA_CONF=#{File.expand_path(File.dirname(__FILE__))}/conf"
+ end
+ # Create data dir
+ Dir.mkdir(CASSANDRA_TEST) if !File.exist?(CASSANDRA_TEST)
+ # Start server
+ Dir.chdir(CASSANDRA_TEST) do
+ exec("env #{env} #{CASSANDRA_HOME}/bin/cassandra -f")
+ end
+end
+
+desc "Checkout Cassandra from git"
task :checkout do
# Like a git submodule, but all in one obvious place
- unless File.exist?("cassandra")
- system("git clone git://git.apache.org/cassandra.git")
+ unless File.exist?(CASSANDRA_HOME)
+ system("git clone git://git.apache.org/cassandra.git #{CASSANDRA_HOME}")
ENV["RESET"] = "true"
end
end
+desc "Apply patches to Cassandra checkout"
task :patch do
if ENV["RESET"]
- Dir.chdir("cassandra") do
+ system("rm -rf #{CASSANDRA_TEST}/data")
+ Dir.chdir(CASSANDRA_HOME) do
system("ant clean && git fetch && git reset #{REVISION} --hard")
# Delete untracked files, so that the patchs can apply again
Array(`git status`[/Untracked files:(.*)$/m, 1].to_s.split("\n")[3..-1]).each do |file|
File.unlink(file.sub(/^.\s+/, "")) rescue nil
end
# Patch, with a handy commit for each one
- PATCHES.each do |url|
+ PATCHES.each do |url|
raise "#{url} failed" unless system("curl #{url} | patch -p1")
system("git commit -a -m 'Applied patch: #{url.inspect}'")
end
@@ -50,12 +73,21 @@ task :patch do
end
end
+desc "Rebuild Cassandra"
task :build do
- Dir.chdir("cassandra") { system("ant") } unless File.exist?("cassandra/build")
+ Dir.chdir(CASSANDRA_HOME) { system("ant") } unless File.exist?("#{CASSANDRA_HOME}/build")
end
+desc "Clean Cassandra build"
task :clean do
- Dir.chdir("cassandra") { system("ant clean") }
+ Dir.chdir(CASSANDRA_HOME) { system("ant clean") } if File.exist?(CASSANDRA_HOME)
+end
+
+namespace :data do
+ desc "Reset test data"
+ task :reset do
+ system("rm -rf #{CASSANDRA_TEST}/data")
+ end
end
desc "Regenerate thrift bindings for Cassandra"
@@ -63,6 +95,6 @@ task :thrift do
system(
"cd vendor &&
rm -rf gen-rb &&
- thrift -gen rb ../cassandra/interface/cassandra.thrift")
+ thrift -gen rb #{CASSANDRA_HOME}/interface/cassandra.thrift")
end
diff --git a/bin/cassandra_helper b/bin/cassandra_helper
new file mode 100755
index 0000000..13133bd
--- /dev/null
+++ b/bin/cassandra_helper
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'rake'
+require 'cassandra'
+
+gem_path = $LOAD_PATH.last.sub(/lib$/, "")
+
+Dir.chdir(gem_path) do
+ if !ENV["CASSANDRA_INCLUDE"]
+ puts "Set the CASSANDRA_INCLUDE environment variable to use a non-default cassandra.in.sh and friends."
+ end
+
+ ARGV << "-T" if ARGV.empty?
+ exec("env FROM_BIN_CASSANDRA_HELPER=1 rake #{ARGV.join(' ')}")
+end
\ No newline at end of file
diff --git a/conf/cassandra.in.sh b/conf/cassandra.in.sh
index d8506bc..4682b41 100644
--- a/conf/cassandra.in.sh
+++ b/conf/cassandra.in.sh
@@ -14,27 +14,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
-cassandra_home=`pwd`/cassandra
-
# The directory where Cassandra's configs live (required)
-CASSANDRA_CONF=`pwd`/conf
+CASSANDRA_CONF=$CASSANDRA_CONF
# This can be the path to a jar file, or a directory containing the
-# compiled classes. NOTE: This isn't needed by the startup script,
-# it's just used here in constructing the classpath.
-cassandra_bin=$cassandra_home/build/classes
-#cassandra_bin=$cassandra_home/build/cassandra.jar
+# compiled classes.
+cassandra_bin=$CASSANDRA_HOME/build/classes
# The java classpath (required)
CLASSPATH=$CASSANDRA_CONF:$cassandra_bin
-for jar in $cassandra_home/lib/*.jar; do
+for jar in $CASSANDRA_HOME/lib/*.jar; do
CLASSPATH=$CLASSPATH:$jar
done
-echo $cassandra_home
-
# Arguments to pass to the JVM
JVM_OPTS=" \
-ea \