Author: ivol37 at gmail.com Date: Fri Jan 14 12:35:31 2011 New Revision: 629
Log: stand alone cassandra for cluster testing Added: sandbox/ivol/standalone-cassandra/ sandbox/ivol/standalone-cassandra/cassandra-cli sandbox/ivol/standalone-cassandra/cassandra-cli.bat sandbox/ivol/standalone-cassandra/cassandra.bat sandbox/ivol/standalone-cassandra/compile.bat sandbox/ivol/standalone-cassandra/conf/ sandbox/ivol/standalone-cassandra/conf/README.txt sandbox/ivol/standalone-cassandra/conf/access.properties sandbox/ivol/standalone-cassandra/conf/cassandra-env.sh sandbox/ivol/standalone-cassandra/conf/cassandra-topology.properties sandbox/ivol/standalone-cassandra/conf/cassandra.yaml sandbox/ivol/standalone-cassandra/conf/log4j-server.properties sandbox/ivol/standalone-cassandra/conf/log4j-tools.properties sandbox/ivol/standalone-cassandra/conf/passwd.properties sandbox/ivol/standalone-cassandra/interface/ sandbox/ivol/standalone-cassandra/interface/avro/ sandbox/ivol/standalone-cassandra/interface/avro/cassandra.avpr sandbox/ivol/standalone-cassandra/interface/cassandra.genavro sandbox/ivol/standalone-cassandra/interface/cassandra.thrift sandbox/ivol/standalone-cassandra/lib/ sandbox/ivol/standalone-cassandra/lib/antlr-3.1.3.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/apache-cassandra-0.7.0.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/avro-1.4.0-fixes.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/avro-1.4.0-sources-fixes.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/commons-cli-1.1.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/commons-codec-1.2.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/commons-collections-3.2.1.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/commons-lang-2.4.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/concurrentlinkedhashmap-lru-1.1.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/guava-r05.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/high-scale-lib.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/ivy-2.1.0.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/jackson-core-asl-1.4.0.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/jackson-mapper-asl-1.4.0.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/jetty-6.1.21.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/jetty-util-6.1.21.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/jline-0.9.94.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/json-simple-1.1.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/jug-2.0.0.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/libthrift-0.5.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/log4j-1.2.16.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/servlet-api-2.5-20081211.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/slf4j-api-1.6.1.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/slf4j-log4j12-1.6.1.jar (contents, props changed) sandbox/ivol/standalone-cassandra/lib/snakeyaml-1.6.jar (contents, props changed) sandbox/ivol/standalone-cassandra/readme.txt sandbox/ivol/standalone-cassandra/src/ sandbox/ivol/standalone-cassandra/src/org/ sandbox/ivol/standalone-cassandra/src/org/amdatu/ sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/ sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/DummyMain.java sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/Main.class (contents, props changed) sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/Main.java Added: sandbox/ivol/standalone-cassandra/cassandra-cli ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/cassandra-cli Fri Jan 14 12:35:31 2011 @@ -0,0 +1,50 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +if [ "x$CASSANDRA_INCLUDE" = "x" ]; then + for include in /usr/share/cassandra/cassandra.in.sh \ + /usr/local/share/cassandra/cassandra.in.sh \ + /opt/cassandra/cassandra.in.sh \ + ~/.cassandra.in.sh \ + `dirname $0`/cassandra.in.sh; do + if [ -r $include ]; then + . $include + break + fi + done +elif [ -r $CASSANDRA_INCLUDE ]; then + . $CASSANDRA_INCLUDE +fi + +# Use JAVA_HOME if set, otherwise look for java in PATH +if [ -x $JAVA_HOME/bin/java ]; then + JAVA=$JAVA_HOME/bin/java +else + JAVA=`which java` +fi + +if [ -z $CLASSPATH ]; then + echo "You must set the CLASSPATH var" >&2 + exit 1 +fi + +$JAVA -ea -cp $CLASSPATH -Xmx256M \ + -Dlog4j.configuration=log4j-tools.properties \ + org.apache.cassandra.cli.CliMain "$@" + +# vi:ai sw=4 ts=4 tw=0 et Added: sandbox/ivol/standalone-cassandra/cassandra-cli.bat ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/cassandra-cli.bat Fri Jan 14 12:35:31 2011 @@ -0,0 +1,52 @@ + at REM + at REM Licensed to the Apache Software Foundation (ASF) under one or more + at REM contributor license agreements. See the NOTICE file distributed with + at REM this work for additional information regarding copyright ownership. + at REM The ASF licenses this file to You under the Apache License, Version 2.0 + at REM (the "License"); you may not use this file except in compliance with + at REM the License. You may obtain a copy of the License at + at REM + at REM http://www.apache.org/licenses/LICENSE-2.0 + at REM + at REM Unless required by applicable law or agreed to in writing, software + at REM distributed under the License is distributed on an "AS IS" BASIS, + at REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + at REM See the License for the specific language governing permissions and + at REM limitations under the License. + + + at echo off +if "%OS%" == "Windows_NT" setlocal + +set CASSANDRA_HOME=. +if NOT DEFINED JAVA_HOME goto err + +REM Ensure that any user defined CLASSPATH variables are not used on startup +set CLASSPATH= + +REM For each jar in the CASSANDRA_HOME lib directory call append to build the CLASSPATH variable. +for %%i in ("%CASSANDRA_HOME%\lib\*.jar") do call :append "%%i" +goto okClasspath + +:append +set CLASSPATH=%CLASSPATH%;%1 +goto :eof + +:okClasspath +REM Include the build\classes directory so it works in development +set CASSANDRA_CLASSPATH=%CLASSPATH%;"%CASSANDRA_HOME%\build\classes" +goto runCli + +:runCli +echo Starting Cassandra Client +echo CASSANDRA_HOME=%CASSANDRA_HOME% +"%JAVA_HOME%\bin\java" -Xmx1524m -cp %CASSANDRA_CLASSPATH% org.apache.cassandra.cli.CliMain %* -host localhost -port 9160 +goto finally + +:err +echo The JAVA_HOME environment variable must be set to run this program! +pause + +:finally + +ENDLOCAL Added: sandbox/ivol/standalone-cassandra/cassandra.bat ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/cassandra.bat Fri Jan 14 12:35:31 2011 @@ -0,0 +1,32 @@ + at echo off +if "%OS%" == "Windows_NT" setlocal + +REM Ensure that any user defined CLASSPATH variables are not used on startup +set CLASSPATH=conf;target + +set JAVA_OPTS=^ + -Dcom.sun.management.jmxremote.port=8080^ + -Dcom.sun.management.jmxremote.ssl=false^ + -Dcom.sun.management.jmxremote.authenticate=false + +REM For each jar in the CASSANDRA_HOME lib directory call append to build the CLASSPATH variable. +for %%i in ("lib\*.jar") do call :append "%%i" +goto okClasspath + +:append +set CLASSPATH=%CLASSPATH%;%1 +goto :eof + +:okClasspath +REM Include the build\classes directory so it works in development +set CASSANDRA_CLASSPATH=%CLASSPATH%; +goto runDaemon + +:runDaemon +echo Starting Cassandra Server +java %CASSANDRA_PARAMS% %JAVA_OPTS% -cp %CASSANDRA_CLASSPATH% "org.amdatu.cassandra.Main" +goto finally + +:finally + +ENDLOCAL Added: sandbox/ivol/standalone-cassandra/compile.bat ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/compile.bat Fri Jan 14 12:35:31 2011 @@ -0,0 +1,18 @@ + at echo off +if "%OS%" == "Windows_NT" setlocal + +for %%i in ("lib\*.jar") do call :append "%%i" +del /S /Q target +mkdir target +del /S /Q work +mkdir work + +javac -cp %CLASSPATH% src\org\amdatu\cassandra\Main.java -d target +goto finally + +:append +set CLASSPATH=%CLASSPATH%;%1 + +:finally + +ENDLOCAL \ No newline at end of file Added: sandbox/ivol/standalone-cassandra/conf/README.txt ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/README.txt Fri Jan 14 12:35:31 2011 @@ -0,0 +1,13 @@ +Required configuration files +============================ + +cassandra.yaml: main Cassandra configuration file +log4j-server.proprties: log4j configuration file for Cassandra server + + +Optional configuration files +============================ + +access.properties: used for authorization +passwd.properties: used for authentication +cassandra-topology.properties: used by PropertyFileSnitch Added: sandbox/ivol/standalone-cassandra/conf/access.properties ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/access.properties Fri Jan 14 12:35:31 2011 @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# This is a sample access file for SimpleAuthority. The format of this file +# is KEYSPACE[.COLUMNFAMILY].PERMISSION=USERS, where: +# +# * KEYSPACE is the keyspace name. +# * COLUMNFAMILY is the column family name. +# * PERMISSION is one of <ro> or <rw> for read-only or read-write respectively. +# * USERS is a comma delimited list of users from passwd.properties. +# +# See below for example entries. + +# NOTE: This file contains potentially sensitive information, please keep +# this in mind when setting its mode and ownership. + +# The magical '<modify-keyspaces>' property lists users who can modify the +# list of keyspaces: all users will be able to view the list of keyspaces. +<modify-keyspaces>=jsmith + +# Access to Keyspace1 (add/remove column families, etc). +Keyspace1.<ro>=jsmith,Elvis Presley +Keyspace1.<rw>=dilbert + +# Access to Standard1 (keyspace Keyspace1) +Keyspace1.Standard1.<rw>=jsmith,Elvis Presley,dilbert Added: sandbox/ivol/standalone-cassandra/conf/cassandra-env.sh ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/cassandra-env.sh Fri Jan 14 12:35:31 2011 @@ -0,0 +1,122 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +calculate_heap_size() +{ + case "`uname`" in + Linux) + system_memory_in_mb=`free -m | awk '/Mem:/ {print $2}'` + MAX_HEAP_SIZE=$((system_memory_in_mb / 2))M + return 0 + ;; + FreeBSD) + system_memory_in_bytes=`sysctl hw.physmem | awk '{print $2}'` + MAX_HEAP_SIZE=$((system_memory_in_bytes / 1024 / 1024 / 2))M + return 0 + ;; + *) + MAX_HEAP_SIZE=1024M + return 1 + ;; + esac +} + +# The amount of memory to allocate to the JVM at startup, you almost +# certainly want to adjust this for your environment. If left commented +# out, the heap size will be automatically determined by calculate_heap_size +# MAX_HEAP_SIZE="4G" + +if [ "x$MAX_HEAP_SIZE" = "x" ]; then + calculate_heap_size +fi + +# Specifies the default port over which Cassandra will be available for +# JMX connections. +JMX_PORT="8080" + +# To use mx4j, an HTML interface for JMX, add mx4j-tools.jar to the lib/ directory. +# By default mx4j listens on 0.0.0.0:8081. Uncomment the following lines to control +# its listen address and port. +#MX4J_ADDRESS="-Dmx4jaddress=0.0.0.0" +#MX4J_PORT="-Dmx4jport=8081" + + +# Here we create the arguments that will get passed to the jvm when +# starting cassandra. + +# enable assertions. disabling this in production will give a modest +# performance benefit (around 5%). +JVM_OPTS="$JVM_OPTS -ea" + +# enable thread priorities, primarily so we can give periodic tasks +# a lower priority to avoid interfering with client workload +JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities" +# allows lowering thread priority without being root. see +# http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html +JVM_OPTS="$JVM_OPTS -XX:ThreadPriorityPolicy=42" + +# min and max heap sizes should be set to the same value to avoid +# stop-the-world GC pauses during resize, and so that we can lock the +# heap in memory on startup to prevent any of it from being swapped +# out. +JVM_OPTS="$JVM_OPTS -Xms$MAX_HEAP_SIZE" +JVM_OPTS="$JVM_OPTS -Xmx$MAX_HEAP_SIZE" +JVM_OPTS="$JVM_OPTS -XX:+HeapDumpOnOutOfMemoryError" + +if [ "`uname`" = "Linux" ] ; then + # reduce the per-thread stack size to minimize the impact of Thrift + # thread-per-client. (Best practice is for client connections to + # be pooled anyway.) Only do so on Linux where it is known to be + # supported. + JVM_OPTS="$JVM_OPTS -Xss128k" +fi + +# GC tuning options +JVM_OPTS="$JVM_OPTS -XX:+UseParNewGC" +JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC" +JVM_OPTS="$JVM_OPTS -XX:+CMSParallelRemarkEnabled" +JVM_OPTS="$JVM_OPTS -XX:SurvivorRatio=8" +JVM_OPTS="$JVM_OPTS -XX:MaxTenuringThreshold=1" +JVM_OPTS="$JVM_OPTS -XX:CMSInitiatingOccupancyFraction=75" +JVM_OPTS="$JVM_OPTS -XX:+UseCMSInitiatingOccupancyOnly" + +# GC logging options -- uncomment to enable +# JVM_OPTS="$JVM_OPTS -XX:+PrintGCDetails" +# JVM_OPTS="$JVM_OPTS -XX:+PrintGCTimeStamps" +# JVM_OPTS="$JVM_OPTS -XX:+PrintClassHistogram" +# JVM_OPTS="$JVM_OPTS -XX:+PrintTenuringDistribution" +# JVM_OPTS="$JVM_OPTS -XX:+PrintGCApplicationStoppedTime" +# JVM_OPTS="$JVM_OPTS -Xloggc:/var/log/cassandra/gc.log" + +# Prefer binding to IPv4 network intefaces (when net.ipv6.bindv6only=1). See +# http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342561 (short version: +# comment out this entry to enable IPv6 support). +JVM_OPTS="$JVM_OPTS -Djava.net.preferIPv4Stack=true" + +# jmx: metrics and administration interface +# +# add this if you're having trouble connecting: +# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>" +# +# see +# http://blogs.sun.com/jmxetc/entry/troubleshooting_connection_problems_in_jconsole +# for more on configuring JMX through firewalls, etc. (Short version: +# get it working with no firewall first.) +JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT" +JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false" +JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" +JVM_OPTS="$JVM_OPTS $MX4J_ADDRESS" +JVM_OPTS="$JVM_OPTS $MX4J_PORT" Added: sandbox/ivol/standalone-cassandra/conf/cassandra-topology.properties ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/cassandra-topology.properties Fri Jan 14 12:35:31 2011 @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Cassandra Node IP=Data Center:Rack +192.168.1.100=DC1:RAC1 +192.168.2.200=DC2:RAC2 + +10.0.0.10=DC1:RAC1 +10.0.0.11=DC1:RAC1 +10.0.0.12=DC1:RAC2 + +10.20.114.10=DC2:RAC1 +10.20.114.11=DC2:RAC1 + +10.21.119.13=DC3:RAC1 +10.21.119.10=DC3:RAC1 + +10.0.0.13=DC1:RAC2 +10.21.119.14=DC3:RAC2 +10.20.114.15=DC2:RAC2 + +# default for unknown nodes +default=DC1:r1 + Added: sandbox/ivol/standalone-cassandra/conf/cassandra.yaml ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/cassandra.yaml Fri Jan 14 12:35:31 2011 @@ -0,0 +1,281 @@ +# Cassandra storage config YAML + +# NOTE: +# See http://wiki.apache.org/cassandra/StorageConfiguration for +# full explanations of configuration directives +# /NOTE + +# The name of the cluster. This is mainly used to prevent machines in +# one logical cluster from joining another. +cluster_name: 'Test Cluster' + +# You should always specify InitialToken when setting up a production +# cluster for the first time, and often when adding capacity later. +# The principle is that each node should be given an equal slice of +# the token ring; see http://wiki.apache.org/cassandra/Operations +# for more details. +# +# If blank, Cassandra will request a token bisecting the range of +# the heaviest-loaded existing node. If there is no load information +# available, such as is the case with a new cluster, it will pick +# a random token, which will lead to hot spots. +initial_token: + +# Set to true to make new [non-seed] nodes automatically migrate data +# to themselves from the pre-existing nodes in the cluster. Defaults +# to false because you can only bootstrap N machines at a time from +# an existing cluster of N, so if you are bringing up a cluster of +# 10 machines with 3 seeds you would have to do it in stages. Leaving +# this off for the initial start simplifies that. +auto_bootstrap: false + +# See http://wiki.apache.org/cassandra/HintedHandoff +hinted_handoff_enabled: true + +# authentication backend, implementing IAuthenticator; used to identify users +authenticator: org.apache.cassandra.auth.AllowAllAuthenticator + +# authorization backend, implementing IAuthority; used to limit access/provide permissions +authority: org.apache.cassandra.auth.AllowAllAuthority + +# The partitioner is responsible for distributing rows (by key) across +# nodes in the cluster. Any IPartitioner may be used, including your +# own as long as it is on the classpath. Out of the box, Cassandra +# provides org.apache.cassandra.dht.RandomPartitioner +# org.apache.cassandra.dht.ByteOrderedPartitioner, +# org.apache.cassandra.dht.OrderPreservingPartitioner (deprecated), +# and org.apache.cassandra.dht.CollatingOrderPreservingPartitioner +# (deprecated). +# +# - RandomPartitioner distributes rows across the cluster evenly by md5. +# When in doubt, this is the best option. +# - ByteOrderedPartitioner orders rows lexically by key bytes. BOP allows +# scanning rows in key order, but the ordering can generate hot spots +# for sequential insertion workloads. +# - OrderPreservingPartitioner is an obsolete form of BOP, that stores +# - keys in a less-efficient format and only works with keys that are +# UTF8-encoded Strings. +# - CollatingOPP colates according to EN,US rules rather than lexical byte +# ordering. Use this as an example if you need custom collation. +# +# See http://wiki.apache.org/cassandra/Operations for more on +# partitioners and token selection. +partitioner: org.apache.cassandra.dht.RandomPartitioner + +# directories where Cassandra should store data on disk. +data_file_directories: + - work/data + +# commit log +commitlog_directory: work/commitlog + +# saved caches +saved_caches_directory: work/saved_caches + +# Size to allow commitlog to grow to before creating a new segment +commitlog_rotation_threshold_in_mb: 128 + +# commitlog_sync may be either "periodic" or "batch." +# When in batch mode, Cassandra won't ack writes until the commit log +# has been fsynced to disk. It will wait up to +# CommitLogSyncBatchWindowInMS milliseconds for other writes, before +# performing the sync. +commitlog_sync: periodic + +# the other option is "timed," where writes may be acked immediately +# and the CommitLog is simply synced every commitlog_sync_period_in_ms +# milliseconds. +commitlog_sync_period_in_ms: 10000 + +# Addresses of hosts that are deemed contact points. +# Cassandra nodes use this list of hosts to find each other and learn +# the topology of the ring. You must change this if you are running +# multiple nodes! +seeds: + - 127.0.0.1 + +# Access mode. mmapped i/o is substantially faster, but only practical on +# a 64bit machine (which notably does not include EC2 "small" instances) +# or relatively small datasets. "auto", the safe choice, will enable +# mmapping on a 64bit JVM. Other values are "mmap", "mmap_index_only" +# (which may allow you to get part of the benefits of mmap on a 32bit +# machine by mmapping only index files) and "standard". +# (The buffer size settings that follow only apply to standard, +# non-mmapped i/o.) +disk_access_mode: auto + +# Unlike most systems, in Cassandra writes are faster than reads, so +# you can afford more of those in parallel. A good rule of thumb is 2 +# concurrent reads per processor core. Increase ConcurrentWrites to +# the number of clients writing at once if you enable CommitLogSync + +# CommitLogSyncDelay. --> +concurrent_reads: 8 +concurrent_writes: 32 + +# This sets the amount of memtable flush writer threads. These will +# be blocked by disk io, and each one will hold a memtable in memory +# while blocked. If you have a large heap and many data directories, +# you can increase this value for better flush performance. +# By default this will be set to the amount of data directories defined. +#memtable_flush_writers: 1 + +# Buffer size to use when performing contiguous column slices. +# Increase this to the size of the column slices you typically perform +sliced_buffer_size_in_kb: 64 + +# TCP port, for commands and data +storage_port: 7000 + +# Address to bind to and tell other Cassandra nodes to connect to. You +# _must_ change this if you want multiple nodes to be able to +# communicate! +# +# Leaving it blank leaves it up to InetAddress.getLocalHost(). This +# will always do the Right Thing *if* the node is properly configured +# (hostname, name resolution, etc), and the Right Thing is to use the +# address associated with the hostname (it might not be). +# +# Setting this to 0.0.0.0 is always wrong. +listen_address: localhost + +# The address to bind the Thrift RPC service to -- clients connect +# here. Unlike ListenAddress above, you *can* specify 0.0.0.0 here if +# you want Thrift to listen on all interfaces. +# +# Leaving this blank has the same effect it does for ListenAddress, +# (i.e. it will be based on the configured hostname of the node). +rpc_address: localhost +# port for Thrift to listen for clients on +rpc_port: 9160 + +# enable or disable keepalive on rpc connections +rpc_keepalive: true + +# uncomment to set socket buffer sizes on rpc connections +# rpc_send_buff_size_in_bytes: +# rpc_recv_buff_size_in_bytes: + +# Frame size for thrift (maximum field length). +# 0 disables TFramedTransport in favor of TSocket. This option +# is deprecated; we strongly recommend using Framed mode. +thrift_framed_transport_size_in_mb: 15 + +# The max length of a thrift message, including all fields and +# internal thrift overhead. +thrift_max_message_length_in_mb: 16 + +# Whether or not to take a snapshot before each compaction. Be +# careful using this option, since Cassandra won't clean up the +# snapshots for you. Mostly useful if you're paranoid when there +# is a data format change. +snapshot_before_compaction: false + +# change this to increase the compaction thread's priority. In java, 1 is the +# lowest priority and that is our default. +# compaction_thread_priority: 1 + +# The threshold size in megabytes the binary memtable must grow to, +# before it's submitted for flushing to disk. +binary_memtable_throughput_in_mb: 256 + +# Add column indexes to a row after its contents reach this size. +# Increase if your column values are large, or if you have a very large +# number of columns. The competing causes are, Cassandra has to +# deserialize this much of the row to read a single column, so you want +# it to be small - at least if you do many partial-row reads - but all +# the index data is read for each access, so you don't want to generate +# that wastefully either. +column_index_size_in_kb: 64 + +# Size limit for rows being compacted in memory. Larger rows will spill +# over to disk and use a slower two-pass compaction process. A message +# will be logged specifying the row key. +in_memory_compaction_limit_in_mb: 64 + +# Time to wait for a reply from other nodes before failing the command +rpc_timeout_in_ms: 10000 + +# phi value that must be reached for a host to be marked down. +# most users should never need to adjust this. +# phi_convict_threshold: 8 + +# endpoint_snitch -- Set this to a class that implements +# IEndpointSnitch, which will let Cassandra know enough +# about your network topology to route requests efficiently. +# Out of the box, Cassandra provides +# - org.apache.cassandra.locator.SimpleSnitch: +# Treats Strategy order as proximity. This improves cache locality +# when disabling read repair, which can further improve throughput. +# - org.apache.cassandra.locator.RackInferringSnitch: +# Proximity is determined by rack and data center, which are +# assumed to correspond to the 3rd and 2nd octet of each node's +# IP address, respectively +# org.apache.cassandra.locator.PropertyFileSnitch: +# - Proximity is determined by rack and data center, which are +# explicitly configured in cassandra-topology.properties. +endpoint_snitch: org.apache.cassandra.locator.SimpleSnitch + +# dynamic_snitch -- This boolean controls whether the above snitch is +# wrapped with a dynamic snitch, which will monitor read latencies +# and avoid reading from hosts that have slowed (due to compaction, +# for instance) +dynamic_snitch: true +# controls how often to perform the more expensive part of host score +# calculation +dynamic_snitch_update_interval_in_ms: 100 +# controls how often to reset all host scores, allowing a bad host to +# possibly recover +dynamic_snitch_reset_interval_in_ms: 600000 +# if set greater than zero and read_repair_chance is < 1.0, this will allow +# 'pinning' of replicas to hosts in order to increase cache capacity. +# The badness threshold will control how much worse the pinned host has to be +# before the dynamic snitch will prefer other replicas over it. This is +# expressed as a double which represents a percentage. Thus, a value of +# 0.2 means Cassandra would continue to prefer the static snitch values +# until the pinned host was 20% worse than the fastest. +dynamic_snitch_badness_threshold: 0.0 + +# request_scheduler -- Set this to a class that implements +# RequestScheduler, which will schedule incoming client requests +# according to the specific policy. This is useful for multi-tenancy +# with a single Cassandra cluster. +# NOTE: This is specifically for requests from the client and does +# not affect inter node communication. +# org.apache.cassandra.scheduler.NoScheduler - No scheduling takes place +# org.apache.cassandra.scheduler.RoundRobinScheduler - Round robin of +# client requests to a node with a separate queue for each +# request_scheduler_id. The scheduler is further customized by +# request_scheduler_options as described below. +request_scheduler: org.apache.cassandra.scheduler.NoScheduler + +# Scheduler Options vary based on the type of scheduler +# NoScheduler - Has no options +# RoundRobin +# - throttle_limit -- The throttle_limit is the number of in-flight +# requests per client. Requests beyond +# that limit are queued up until +# running requests can complete. +# The value of 80 here is twice the number of +# concurrent_reads + concurrent_writes. +# - default_weight -- default_weight is optional and allows for +# overriding the default which is 1. +# - weights -- Weights are optional and will default to 1 or the +# overridden default_weight. The weight translates into how +# many requests are handled during each turn of the +# RoundRobin, based on the scheduler id. +# +# request_scheduler_options: +# throttle_limit: 80 +# default_weight: 5 +# weights: +# Keyspace1: 1 +# Keyspace2: 5 + +# request_scheduler_id -- An identifer based on which to perform +# the request scheduling. Currently the only valid option is keyspace. +# request_scheduler_id: keyspace + +# The Index Interval determines how large the sampling of row keys +# is for a given SSTable. The larger the sampling, the more effective +# the index is at the cost of space. +index_interval: 128 \ No newline at end of file Added: sandbox/ivol/standalone-cassandra/conf/log4j-server.properties ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/log4j-server.properties Fri Jan 14 12:35:31 2011 @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# for production, you should probably set pattern to %c instead of %l. +# (%l is slower.) + +# output messages into a rolling log file as well as stdout +log4j.rootLogger=INFO,stdout,R + +# stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n + +# rolling log file +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.maxFileSize=20MB +log4j.appender.R.maxBackupIndex=50 +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n +# Edit the next line to point to your logs directory +log4j.appender.R.File=D:/Amdatu-svn/sandbox/ivol/standalone-cassandra/work/system.log + +# Application logging options +#log4j.logger.com.facebook=DEBUG +#log4j.logger.com.facebook.infrastructure.gms=DEBUG +#log4j.logger.com.facebook.infrastructure.db=DEBUG Added: sandbox/ivol/standalone-cassandra/conf/log4j-tools.properties ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/log4j-tools.properties Fri Jan 14 12:35:31 2011 @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# for production, you should probably set the root to INFO +# and the pattern to %c instead of %l. (%l is slower.) + +# output messages into a rolling log file as well as stdout +log4j.rootLogger=WARN,stderr + +# stderr +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.target=System.err +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n Added: sandbox/ivol/standalone-cassandra/conf/passwd.properties ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/conf/passwd.properties Fri Jan 14 12:35:31 2011 @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# +# This is a sample password file for SimpleAuthenticator. The format of +# this file is username=password. If -Dpasswd.mode=MD5 then the password +# is represented as an md5 digest, otherwise it is cleartext (keep this +# in mind when setting file mode and ownership). +jsmith=havebadpass +Elvis\ Presley=graceland4evar +dilbert=nomoovertime Added: sandbox/ivol/standalone-cassandra/interface/avro/cassandra.avpr ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/interface/avro/cassandra.avpr Fri Jan 14 12:35:31 2011 @@ -0,0 +1,762 @@ +{ + "protocol" : "Cassandra", + "namespace" : "org.apache.cassandra.avro", + "types" : [ { + "type" : "record", + "name" : "ColumnPath", + "fields" : [ { + "name" : "column_family", + "type" : "string" + }, { + "name" : "super_column", + "type" : [ "bytes", "null" ] + }, { + "name" : "column", + "type" : [ "bytes", "null" ] + } ] + }, { + "type" : "record", + "name" : "ColumnParent", + "fields" : [ { + "name" : "column_family", + "type" : "string" + }, { + "name" : "super_column", + "type" : [ "bytes", "null" ] + } ] + }, { + "type" : "record", + "name" : "Column", + "fields" : [ { + "name" : "name", + "type" : "bytes" + }, { + "name" : "value", + "type" : "bytes" + }, { + "name" : "timestamp", + "type" : "long" + }, { + "name" : "ttl", + "type" : [ "int", "null" ] + } ] + }, { + "type" : "record", + "name" : "SuperColumn", + "fields" : [ { + "name" : "name", + "type" : "bytes" + }, { + "name" : "columns", + "type" : { + "type" : "array", + "items" : "Column" + } + } ] + }, { + "type" : "record", + "name" : "ColumnOrSuperColumn", + "fields" : [ { + "name" : "column", + "type" : [ "Column", "null" ] + }, { + "name" : "super_column", + "type" : [ "SuperColumn", "null" ] + } ] + }, { + "type" : "record", + "name" : "SliceRange", + "fields" : [ { + "name" : "start", + "type" : "bytes" + }, { + "name" : "finish", + "type" : "bytes" + }, { + "name" : "reversed", + "type" : "boolean" + }, { + "name" : "count", + "type" : "int" + }, { + "name" : "bitmasks", + "type" : [ { + "type" : "array", + "items" : "bytes" + }, "null" ] + } ] + }, { + "type" : "record", + "name" : "SlicePredicate", + "fields" : [ { + "name" : "column_names", + "type" : [ { + "type" : "array", + "items" : "bytes" + }, "null" ] + }, { + "name" : "slice_range", + "type" : [ "SliceRange", "null" ] + } ] + }, { + "type" : "record", + "name" : "TokenRange", + "fields" : [ { + "name" : "start_token", + "type" : "string" + }, { + "name" : "end_token", + "type" : "string" + }, { + "name" : "endpoints", + "type" : { + "type" : "array", + "items" : "string" + } + } ] + }, { + "type" : "enum", + "name" : "IndexOperator", + "symbols" : [ "EQ", "GTE", "GT", "LTE", "LT" ] + }, { + "type" : "record", + "name" : "IndexExpression", + "fields" : [ { + "name" : "column_name", + "type" : "bytes" + }, { + "name" : "op", + "type" : "IndexOperator" + }, { + "name" : "value", + "type" : "bytes" + } ] + }, { + "type" : "record", + "name" : "IndexClause", + "fields" : [ { + "name" : "expressions", + "type" : { + "type" : "array", + "items" : "IndexExpression" + } + }, { + "name" : "start_key", + "type" : "bytes" + }, { + "name" : "count", + "type" : "int" + } ] + }, { + "type" : "record", + "name" : "KeyRange", + "fields" : [ { + "name" : "start_key", + "type" : [ "bytes", "null" ] + }, { + "name" : "end_key", + "type" : [ "bytes", "null" ] + }, { + "name" : "start_token", + "type" : [ "string", "null" ] + }, { + "name" : "end_token", + "type" : [ "string", "null" ] + }, { + "name" : "count", + "type" : "int" + } ] + }, { + "type" : "record", + "name" : "KeySlice", + "fields" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "columns", + "type" : { + "type" : "array", + "items" : "ColumnOrSuperColumn" + } + } ] + }, { + "type" : "record", + "name" : "Deletion", + "fields" : [ { + "name" : "timestamp", + "type" : "long" + }, { + "name" : "super_column", + "type" : [ "bytes", "null" ] + }, { + "name" : "predicate", + "type" : [ "SlicePredicate", "null" ] + } ] + }, { + "type" : "record", + "name" : "Mutation", + "fields" : [ { + "name" : "column_or_supercolumn", + "type" : [ "ColumnOrSuperColumn", "null" ] + }, { + "name" : "deletion", + "type" : [ "Deletion", "null" ] + } ] + }, { + "type" : "enum", + "name" : "IndexType", + "symbols" : [ "KEYS" ], + "aliases" : [ "org.apache.cassandra.config.avro.IndexType" ] + }, { + "type" : "record", + "name" : "ColumnDef", + "fields" : [ { + "name" : "name", + "type" : "bytes" + }, { + "name" : "validation_class", + "type" : "string" + }, { + "name" : "index_type", + "type" : [ "IndexType", "null" ] + }, { + "name" : "index_name", + "type" : [ "string", "null" ] + } ], + "aliases" : [ "org.apache.cassandra.config.avro.ColumnDef" ] + }, { + "type" : "record", + "name" : "CfDef", + "fields" : [ { + "name" : "keyspace", + "type" : "string" + }, { + "name" : "name", + "type" : "string" + }, { + "name" : "column_type", + "type" : [ "string", "null" ] + }, { + "name" : "comparator_type", + "type" : [ "string", "null" ] + }, { + "name" : "subcomparator_type", + "type" : [ "string", "null" ] + }, { + "name" : "comment", + "type" : [ "string", "null" ] + }, { + "name" : "row_cache_size", + "type" : [ "double", "null" ] + }, { + "name" : "key_cache_size", + "type" : [ "double", "null" ] + }, { + "name" : "read_repair_chance", + "type" : [ "double", "null" ] + }, { + "name" : "gc_grace_seconds", + "type" : [ "int", "null" ] + }, { + "name" : "default_validation_class", + "type" : [ "null", "string" ], + "default" : null + }, { + "name" : "min_compaction_threshold", + "type" : [ "null", "int" ], + "default" : null + }, { + "name" : "max_compaction_threshold", + "type" : [ "null", "int" ], + "default" : null + }, { + "name" : "row_cache_save_period_in_seconds", + "type" : [ "int", "null" ], + "default" : 0 + }, { + "name" : "key_cache_save_period_in_seconds", + "type" : [ "int", "null" ], + "default" : 3600 + }, { + "name" : "memtable_flush_after_mins", + "type" : [ "int", "null" ], + "default" : 60 + }, { + "name" : "memtable_throughput_in_mb", + "type" : [ "null", "int" ], + "default" : null + }, { + "name" : "memtable_operations_in_millions", + "type" : [ "null", "double" ], + "default" : null + }, { + "name" : "id", + "type" : [ "int", "null" ] + }, { + "name" : "column_metadata", + "type" : [ { + "type" : "array", + "items" : "ColumnDef" + }, "null" ] + } ], + "aliases" : [ "org.apache.cassandra.config.avro.CfDef" ] + }, { + "type" : "record", + "name" : "KsDef", + "fields" : [ { + "name" : "name", + "type" : "string" + }, { + "name" : "strategy_class", + "type" : "string" + }, { + "name" : "strategy_options", + "type" : [ { + "type" : "map", + "values" : "string" + }, "null" ] + }, { + "name" : "replication_factor", + "type" : "int" + }, { + "name" : "cf_defs", + "type" : { + "type" : "array", + "items" : "CfDef" + } + } ], + "aliases" : [ "org.apache.cassandra.config.avro.KsDef" ] + }, { + "type" : "record", + "name" : "StreamingMutation", + "fields" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "mutation", + "type" : "Mutation" + } ] + }, { + "type" : "record", + "name" : "MutationsMapEntry", + "fields" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "mutations", + "type" : { + "type" : "map", + "values" : { + "type" : "array", + "items" : "Mutation" + } + } + } ] + }, { + "type" : "record", + "name" : "CoscsMapEntry", + "fields" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "columns", + "type" : { + "type" : "array", + "items" : "ColumnOrSuperColumn" + } + } ] + }, { + "type" : "record", + "name" : "KeyCountMapEntry", + "fields" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "count", + "type" : "int" + } ] + }, { + "type" : "record", + "name" : "AuthenticationRequest", + "fields" : [ { + "name" : "credentials", + "type" : { + "type" : "map", + "values" : "string" + } + } ] + }, { + "type" : "enum", + "name" : "ConsistencyLevel", + "symbols" : [ "ONE", "QUORUM", "LOCAL_QUORUM", "EACH_QUORUM", "ALL" ] + }, { + "type" : "error", + "name" : "InvalidRequestException", + "fields" : [ { + "name" : "why", + "type" : [ "string", "null" ] + } ] + }, { + "type" : "error", + "name" : "NotFoundException", + "fields" : [ { + "name" : "why", + "type" : [ "string", "null" ] + } ] + }, { + "type" : "error", + "name" : "UnavailableException", + "fields" : [ { + "name" : "why", + "type" : [ "string", "null" ] + } ] + }, { + "type" : "error", + "name" : "TimedOutException", + "fields" : [ { + "name" : "why", + "type" : [ "string", "null" ] + } ] + }, { + "type" : "error", + "name" : "AuthenticationException", + "fields" : [ { + "name" : "why", + "type" : [ "string", "null" ] + } ] + }, { + "type" : "error", + "name" : "AuthorizationException", + "fields" : [ { + "name" : "why", + "type" : [ "string", "null" ] + } ] + } ], + "messages" : { + "login" : { + "request" : [ { + "name" : "auth_request", + "type" : "AuthenticationRequest" + } ], + "response" : "null", + "errors" : [ "AuthenticationException", "AuthorizationException" ] + }, + "set_keyspace" : { + "request" : [ { + "name" : "keyspace", + "type" : "string" + } ], + "response" : "null", + "errors" : [ "InvalidRequestException" ] + }, + "get" : { + "request" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "column_path", + "type" : "ColumnPath" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : "ColumnOrSuperColumn", + "errors" : [ "InvalidRequestException", "NotFoundException", "UnavailableException", "TimedOutException" ] + }, + "get_slice" : { + "request" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "predicate", + "type" : "SlicePredicate" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : { + "type" : "array", + "items" : "ColumnOrSuperColumn" + }, + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "multiget_slice" : { + "request" : [ { + "name" : "keys", + "type" : { + "type" : "array", + "items" : "bytes" + } + }, { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "predicate", + "type" : "SlicePredicate" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : { + "type" : "array", + "items" : "CoscsMapEntry" + }, + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "multiget_count" : { + "request" : [ { + "name" : "keys", + "type" : { + "type" : "array", + "items" : "bytes" + } + }, { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "predicate", + "type" : "SlicePredicate" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : { + "type" : "array", + "items" : "KeyCountMapEntry" + }, + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "get_indexed_slices" : { + "request" : [ { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "index_clause", + "type" : "IndexClause" + }, { + "name" : "column_predicate", + "type" : "SlicePredicate" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : { + "type" : "array", + "items" : "KeySlice" + }, + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "get_count" : { + "request" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "predicate", + "type" : "SlicePredicate" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : "int", + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "insert" : { + "request" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "column", + "type" : "Column" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : "null", + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "remove" : { + "request" : [ { + "name" : "key", + "type" : "bytes" + }, { + "name" : "column_path", + "type" : "ColumnPath" + }, { + "name" : "timestamp", + "type" : "long" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : "null", + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "batch_mutate" : { + "request" : [ { + "name" : "mutation_map", + "type" : { + "type" : "array", + "items" : "MutationsMapEntry" + } + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : "null", + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + }, + "truncate" : { + "request" : [ { + "name" : "column_family", + "type" : "string" + } ], + "response" : "null", + "errors" : [ "InvalidRequestException", "UnavailableException" ] + }, + "check_schema_agreement" : { + "request" : [ ], + "response" : { + "type" : "map", + "values" : { + "type" : "array", + "items" : "string" + } + }, + "errors" : [ "InvalidRequestException" ] + }, + "system_add_column_family" : { + "request" : [ { + "name" : "cf_def", + "type" : "CfDef" + } ], + "response" : "string", + "errors" : [ "InvalidRequestException" ] + }, + "system_add_keyspace" : { + "request" : [ { + "name" : "ks_def", + "type" : "KsDef" + } ], + "response" : "string", + "errors" : [ "InvalidRequestException" ] + }, + "system_drop_column_family" : { + "request" : [ { + "name" : "column_family", + "type" : "string" + } ], + "response" : "string", + "errors" : [ "InvalidRequestException" ] + }, + "system_drop_keyspace" : { + "request" : [ { + "name" : "keyspace", + "type" : "string" + } ], + "response" : "string", + "errors" : [ "InvalidRequestException" ] + }, + "system_update_column_family" : { + "request" : [ { + "name" : "cf_def", + "type" : "CfDef" + } ], + "response" : "string", + "errors" : [ "InvalidRequestException" ] + }, + "system_update_keyspace" : { + "request" : [ { + "name" : "ks_def", + "type" : "KsDef" + } ], + "response" : "string", + "errors" : [ "InvalidRequestException" ] + }, + "describe_keyspaces" : { + "request" : [ ], + "response" : { + "type" : "array", + "items" : "string" + } + }, + "describe_keyspace" : { + "request" : [ { + "name" : "keyspace", + "type" : "string" + } ], + "response" : "KsDef", + "errors" : [ "NotFoundException" ] + }, + "describe_cluster_name" : { + "request" : [ ], + "response" : "string" + }, + "describe_version" : { + "request" : [ ], + "response" : "string" + }, + "describe_partitioner" : { + "request" : [ ], + "response" : "string" + }, + "describe_splits" : { + "request" : [ { + "name" : "cfName", + "type" : "string" + }, { + "name" : "start_token", + "type" : "string" + }, { + "name" : "end_token", + "type" : "string" + }, { + "name" : "keys_per_split", + "type" : "int" + } ], + "response" : { + "type" : "array", + "items" : "string" + } + }, + "describe_ring" : { + "request" : [ { + "name" : "keyspace", + "type" : "string" + } ], + "response" : { + "type" : "array", + "items" : "TokenRange" + }, + "errors" : [ "InvalidRequestException" ] + }, + "get_range_slices" : { + "request" : [ { + "name" : "column_parent", + "type" : "ColumnParent" + }, { + "name" : "predicate", + "type" : "SlicePredicate" + }, { + "name" : "range", + "type" : "KeyRange" + }, { + "name" : "consistency_level", + "type" : "ConsistencyLevel" + } ], + "response" : { + "type" : "array", + "items" : "KeySlice" + }, + "errors" : [ "InvalidRequestException", "UnavailableException", "TimedOutException" ] + } + } +} \ No newline at end of file Added: sandbox/ivol/standalone-cassandra/interface/cassandra.genavro ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/interface/cassandra.genavro Fri Jan 14 12:35:31 2011 @@ -0,0 +1,378 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * Cassandra client interface + */ + at namespace("org.apache.cassandra.avro") + +protocol Cassandra { + record ColumnPath { + string column_family; + union { bytes, null } super_column; + union { bytes, null } column; + } + + record ColumnParent { + string column_family; + union { bytes, null } super_column; + } + + record Column { + bytes name; + bytes value; + long timestamp; + union { int, null } ttl; + } + + record SuperColumn { + bytes name; + array<Column> columns; + } + + record ColumnOrSuperColumn { + union { Column, null } column; + union { SuperColumn, null } super_column; + } + + record SliceRange { + bytes start; + bytes finish; + boolean reversed; + int count; + union { array<bytes>, null } bitmasks; + } + + record SlicePredicate { + union { array<bytes>, null } column_names; + union { SliceRange, null } slice_range; + } + + record TokenRange { + string start_token; + string end_token; + array<string> endpoints; + } + + enum IndexOperator { + EQ, GTE, GT, LTE, LT + } + + record IndexExpression { + bytes column_name; + IndexOperator op; + bytes value; + } + + record IndexClause { + array<IndexExpression> expressions; + bytes start_key; + int count; + } + + /** + * The semantics of start keys and tokens are slightly different. + * Keys are start-inclusive; tokens are start-exclusive. Token + * ranges may also wrap -- that is, the end token may be less + * than the start one. Thus, a range from keyX to keyX is a + * one-element range, but a range from tokenY to tokenY is the + * full ring. + */ + record KeyRange { + union { bytes, null } start_key; + union { bytes, null } end_key; + union { string, null } start_token; + union { string, null } end_token; + int count; + } + + record KeySlice { + bytes key; + array<ColumnOrSuperColumn> columns; + } + + record Deletion { + long timestamp; + union { bytes, null } super_column; + union { SlicePredicate, null } predicate; + } + + record Mutation { + union { ColumnOrSuperColumn, null } column_or_supercolumn; + union { Deletion, null } deletion; + } + + @aliases(["org.apache.cassandra.config.avro.IndexType"]) + enum IndexType { + KEYS + } + + /* describes a column in a column family. */ + @aliases(["org.apache.cassandra.config.avro.ColumnDef"]) + record ColumnDef { + bytes name; + string validation_class; + union { IndexType, null } index_type; + union { string, null } index_name; + } + + /** + * describes a keyspace: + * NB: the id field is ignored during column family creation: the server will choose an appropriate value. + */ + @aliases(["org.apache.cassandra.config.avro.CfDef"]) + record CfDef { + string keyspace; + string name; + union { string, null } column_type; + union { string, null } comparator_type; + union { string, null } subcomparator_type; + union { string, null } comment; + union { double, null } row_cache_size; + union { double, null } key_cache_size; + union { double, null } read_repair_chance; + union { int, null } gc_grace_seconds; + union { null, string } default_validation_class = null; + union { null, int } min_compaction_threshold = null; + union { null, int } max_compaction_threshold = null; + union { int, null } row_cache_save_period_in_seconds = 0; + union { int, null } key_cache_save_period_in_seconds = 3600; + union { int, null } memtable_flush_after_mins = 60; + union { null, int } memtable_throughput_in_mb = null; + union { null, double} memtable_operations_in_millions = null; + union { int, null } id; + union { array<ColumnDef>, null } column_metadata; + } + + /* describes a keyspace. */ + @aliases(["org.apache.cassandra.config.avro.KsDef"]) + record KsDef { + string name; + string strategy_class; + union{ map<string>, null } strategy_options; + int replication_factor; + array<CfDef> cf_defs; + } + + record StreamingMutation { + bytes key; + Mutation mutation; + } + + record MutationsMapEntry { + bytes key; + map<array<Mutation>> mutations; + } + + record CoscsMapEntry { + bytes key; + array<ColumnOrSuperColumn> columns; + } + + record KeyCountMapEntry { + bytes key; + int count; + } + + record AuthenticationRequest { + map<string> credentials; + } + + enum ConsistencyLevel { + ONE, QUORUM, LOCAL_QUORUM, EACH_QUORUM, ALL + } + + error InvalidRequestException { + union { string, null } why; + } + + error NotFoundException { + union { string, null } why; + } + + error UnavailableException { + union { string, null } why; + } + + error TimedOutException { + union { string, null } why; + } + + error AuthenticationException { + union { string, null } why; + } + + error AuthorizationException { + union { string, null } why; + } + + void login (AuthenticationRequest auth_request) + throws AuthenticationException, AuthorizationException; + + void set_keyspace(string keyspace) throws InvalidRequestException; + + ColumnOrSuperColumn get(bytes key, + ColumnPath column_path, + ConsistencyLevel consistency_level) + throws InvalidRequestException, NotFoundException, UnavailableException, + TimedOutException; + + /** + * Get the group of columns contained by a column_parent (either a + * ColumnFamily name or a ColumnFamily/SuperColumn name pair) specified + * by the given SlicePredicate. If no matching values are found, an empty + * list is returned. + */ + array<ColumnOrSuperColumn> get_slice(bytes key, + ColumnParent column_parent, + SlicePredicate predicate, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + /** + * Performs a get_slice for column_parent and predicate against the given + * set of keys in parallel. + */ + array<CoscsMapEntry> multiget_slice(array<bytes> keys, + ColumnParent column_parent, + SlicePredicate predicate, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + /** + * Performs a get_count in parallel on the given list of keys. The + * return value maps keys to the count found. + */ + array<KeyCountMapEntry> multiget_count(array<bytes> keys, + ColumnParent column_parent, + SlicePredicate predicate, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + /** + * Returns the subset of columns specified in SlicePredicate for + * the rows matching the IndexClause. + */ + array<KeySlice> get_indexed_slices(ColumnParent column_parent, + IndexClause index_clause, + SlicePredicate column_predicate, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + /** + * Returns the number of columns matching a predicate for a particular + * key, ColumnFamily, and optionally SuperColumn. + */ + int get_count(bytes key, + ColumnParent column_parent, + SlicePredicate predicate, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + void insert(bytes key, + ColumnParent column_parent, + Column column, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + void remove(bytes key, + ColumnPath column_path, + long timestamp, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + void batch_mutate(array<MutationsMapEntry> mutation_map, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; + + /** + * Truncate will mark and entire column family as deleted. From the user's + * perspective a successful call to truncate will result in complete data + * deletion from column family. Internally, however, disk space will not be + * immediately released, as with all deletes in Cassandra, this one only + * marks the data as deleted. The operation succeeds only if all hosts in + * the cluster at available and will throw an UnavailableException if some + * hosts are down. + */ + void truncate(string column_family) + throws InvalidRequestException, UnavailableException; + + /** + * Ask the cluster if they all are using the same migration id. Returns a + * map of version->hosts-on-that-version. Hosts that did not respond will + * be under the key DatabaseDescriptor.INITIAL_VERSION. Agreement can be + * determined by checking if the size of the map is 1. + */ + map<array<string>> check_schema_agreement() + throws InvalidRequestException; + + string system_add_column_family(CfDef cf_def) + throws InvalidRequestException; + + string system_add_keyspace(KsDef ks_def) throws InvalidRequestException; + + string system_drop_column_family(string column_family) + throws InvalidRequestException; + + string system_drop_keyspace(string keyspace) + throws InvalidRequestException; + + string system_update_column_family(CfDef cf_def) + throws InvalidRequestException; + + string system_update_keyspace(KsDef ks_def) + throws InvalidRequestException; + + array<string> describe_keyspaces(); + + KsDef describe_keyspace(string keyspace) throws NotFoundException; + + string describe_cluster_name(); + + string describe_version(); + + string describe_partitioner(); + + /** + * experimental API for hadoop/parallel query support. + * may change violently and without warning. + * + * returns list of token strings such that first subrange is (list[0], list[1]], + * next is (list[1], list[2]], etc. + */ + array<string> describe_splits(string cfName, + string start_token, + string end_token, + int keys_per_split); + + /** + * Get the token ring: a map of ranges to host addresses, represented as + * an array of TokenRange->start-end range and list of host addresses. + */ + array<TokenRange> describe_ring(string keyspace) + throws InvalidRequestException; + + /** + *returns a subset of columns for a contiguous range of keys. + */ + array<KeySlice> get_range_slices(ColumnParent column_parent, + SlicePredicate predicate, + KeyRange range, + ConsistencyLevel consistency_level) + throws InvalidRequestException, UnavailableException, TimedOutException; +} Added: sandbox/ivol/standalone-cassandra/interface/cassandra.thrift ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/interface/cassandra.thrift Fri Jan 14 12:35:31 2011 @@ -0,0 +1,549 @@ +#!/usr/local/bin/thrift --java --php --py +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# *** PLEASE REMEMBER TO EDIT THE VERSION CONSTANT WHEN MAKING CHANGES *** +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# +# Interface definition for Cassandra Service +# + +namespace java org.apache.cassandra.thrift +namespace cpp org.apache.cassandra +namespace csharp Apache.Cassandra +namespace py cassandra +namespace php cassandra +namespace perl Cassandra + +# Thrift.rb has a bug where top-level modules that include modules +# with the same name are not properly referenced, so we can't do +# Cassandra::Cassandra::Client. +namespace rb CassandraThrift + +# The API version (NOT the product version), composed as a dot delimited +# string with major, minor, and patch level components. +# +# - Major: Incremented for backward incompatible changes. An example would +# be changes to the number or disposition of method arguments. +# - Minor: Incremented for backward compatible changes. An example would +# be the addition of a new (optional) method. +# - Patch: Incremented for bug fixes. The patch level should be increased +# for every edit that doesn't result in a change to major/minor. +# +# See the Semantic Versioning Specification (SemVer) http://semver.org. +const string VERSION = "19.4.0" + + +# +# data structures +# + +/** Basic unit of data within a ColumnFamily. + * @param name, the name by which this column is set and retrieved. Maximum 64KB long. + * @param value. The data associated with the name. Maximum 2GB long, but in practice you should limit it to small numbers of MB (since Thrift must read the full value into memory to operate on it). + * @param timestamp. The timestamp is used for conflict detection/resolution when two columns with same name need to be compared. + * @param ttl. An optional, positive delay (in seconds) after which the column will be automatically deleted. + */ +struct Column { + 1: required binary name, + 2: required binary value, + 3: required i64 timestamp, + 4: optional i32 ttl, +} + +/** A named list of columns. + * @param name. see Column.name. + * @param columns. A collection of standard Columns. The columns within a super column are defined in an adhoc manner. + * Columns within a super column do not have to have matching structures (similarly named child columns). + */ +struct SuperColumn { + 1: required binary name, + 2: required list<Column> columns, +} + +/** + Methods for fetching rows/records from Cassandra will return either a single instance of ColumnOrSuperColumn or a list + of ColumnOrSuperColumns (get_slice()). If you're looking up a SuperColumn (or list of SuperColumns) then the resulting + instances of ColumnOrSuperColumn will have the requested SuperColumn in the attribute super_column. For queries resulting + in Columns, those values will be in the attribute column. This change was made between 0.3 and 0.4 to standardize on + single query methods that may return either a SuperColumn or Column. + + @param column. The Column returned by get() or get_slice(). + @param super_column. The SuperColumn returned by get() or get_slice(). + */ +struct ColumnOrSuperColumn { + 1: optional Column column, + 2: optional SuperColumn super_column, +} + + +# +# Exceptions +# (note that internal server errors will raise a TApplicationException, courtesy of Thrift) +# + +/** A specific column was requested that does not exist. */ +exception NotFoundException { +} + +/** Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed. + why contains an associated error message. +*/ +exception InvalidRequestException { + 1: required string why +} + +/** Not all the replicas required could be created and/or read. */ +exception UnavailableException { +} + +/** RPC timeout was exceeded. either a node failed mid-operation, or load was too high, or the requested op was too large. */ +exception TimedOutException { +} + +/** invalid authentication request (invalid keyspace, user does not exist, or credentials invalid) */ +exception AuthenticationException { + 1: required string why +} + +/** invalid authorization request (user does not have access to keyspace) */ +exception AuthorizationException { + 1: required string why +} + + +# +# service api +# +/** The ConsistencyLevel is an enum that controls both read and write behavior based on <ReplicationFactor> in your + * storage-conf.xml. The different consistency levels have different meanings, depending on if you're doing a write or read + * operation. Note that if W + R > ReplicationFactor, where W is the number of nodes to block for on write, and R + * the number to block for on reads, you will have strongly consistent behavior; that is, readers will always see the most + * recent write. Of these, the most interesting is to do QUORUM reads and writes, which gives you consistency while still + * allowing availability in the face of node failures up to half of <ReplicationFactor>. Of course if latency is more + * important than consistency then you can use lower values for either or both. + * + * Write consistency levels make the following guarantees before reporting success to the client: + * ANY Ensure that the write has been written once somewhere, including possibly being hinted in a non-target node. + * ONE Ensure that the write has been written to at least 1 node's commit log and memory table + * QUORUM Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes + * LOCAL_QUORUM Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy) + * EACH_QUORUM Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy) + * ALL Ensure that the write is written to <code><ReplicationFactor></code> nodes before responding to the client. + * + * Read: + * ANY Not supported. You probably want ONE instead. + * ONE Will return the record returned by the first node to respond. A consistency check is always done in a background thread to fix any consistency issues when ConsistencyLevel.ONE is used. This means subsequent calls will have correct data even if the initial read gets an older value. (This is called 'read repair'.) + * QUORUM Will query all storage nodes and return the record with the most recent timestamp once it has at least a majority of replicas reported. Again, the remaining replicas will be checked in the background. + * LOCAL_QUORUM Returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied. + * EACH_QUORUM Returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied. + * ALL Queries all storage nodes and returns the record with the most recent timestamp. +*/ +enum ConsistencyLevel { + ONE = 1, + QUORUM = 2, + LOCAL_QUORUM = 3, + EACH_QUORUM = 4, + ALL = 5, + ANY = 6, +} + +/** + ColumnParent is used when selecting groups of columns from the same ColumnFamily. In directory structure terms, imagine + ColumnParent as ColumnPath + '/../'. + + See also <a href="cassandra.html#Struct_ColumnPath">ColumnPath</a> + */ +struct ColumnParent { + 3: required string column_family, + 4: optional binary super_column, +} + +/** The ColumnPath is the path to a single column in Cassandra. It might make sense to think of ColumnPath and + * ColumnParent in terms of a directory structure. + * + * ColumnPath is used to looking up a single column. + * + * @param column_family. The name of the CF of the column being looked up. + * @param super_column. The super column name. + * @param column. The column name. + */ +struct ColumnPath { + 3: required string column_family, + 4: optional binary super_column, + 5: optional binary column, +} + +/** + A slice range is a structure that stores basic range, ordering and limit information for a query that will return + multiple columns. It could be thought of as Cassandra's version of LIMIT and ORDER BY + + @param start. The column name to start the slice with. This attribute is not required, though there is no default value, + and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it + must a valid value under the rules of the Comparator defined for the given ColumnFamily. + @param finish. The column name to stop the slice at. This attribute is not required, though there is no default value, + and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it + must also be a valid value to the ColumnFamily Comparator. + @param reversed. Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL. + @param count. How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will + materialize the whole result into memory before returning it to the client, so be aware that you may + be better served by iterating through slices by passing the last value of one call in as the 'start' + of the next instead of increasing 'count' arbitrarily large. + */ +struct SliceRange { + 1: required binary start, + 2: required binary finish, + 3: required bool reversed=0, + 4: required i32 count=100, +} + +/** + A SlicePredicate is similar to a mathematic predicate (see http://en.wikipedia.org/wiki/Predicate_(mathematical_logic)), + which is described as "a property that the elements of a set have in common." + + SlicePredicate's in Cassandra are described with either a list of column_names or a SliceRange. If column_names is + specified, slice_range is ignored. + + @param column_name. A list of column names to retrieve. This can be used similar to Memcached's "multi-get" feature + to fetch N known column names. For instance, if you know you wish to fetch columns 'Joe', 'Jack', + and 'Jim' you can pass those column names as a list to fetch all three at once. + @param slice_range. A SliceRange describing how to range, order, and/or limit the slice. + */ +struct SlicePredicate { + 1: optional list<binary> column_names, + 2: optional SliceRange slice_range, +} + +enum IndexOperator { + EQ, + GTE, + GT, + LTE, + LT +} + +struct IndexExpression { + 1: required binary column_name, + 2: required IndexOperator op, + 3: required binary value, +} + +struct IndexClause { + 1: required list<IndexExpression> expressions + 2: required binary start_key, + 3: required i32 count=100, +} + +/** +The semantics of start keys and tokens are slightly different. +Keys are start-inclusive; tokens are start-exclusive. Token +ranges may also wrap -- that is, the end token may be less +than the start one. Thus, a range from keyX to keyX is a +one-element range, but a range from tokenY to tokenY is the +full ring. +*/ +struct KeyRange { + 1: optional binary start_key, + 2: optional binary end_key, + 3: optional string start_token, + 4: optional string end_token, + 5: required i32 count=100 +} + +/** + A KeySlice is key followed by the data it maps to. A collection of KeySlice is returned by the get_range_slice operation. + + @param key. a row key + @param columns. List of data represented by the key. Typically, the list is pared down to only the columns specified by + a SlicePredicate. + */ +struct KeySlice { + 1: required binary key, + 2: required list<ColumnOrSuperColumn> columns, +} + +struct KeyCount { + 1: required binary key, + 2: required i32 count +} + +struct Deletion { + 1: required i64 timestamp, + 2: optional binary super_column, + 3: optional SlicePredicate predicate, +} + +/** + A Mutation is either an insert, represented by filling column_or_supercolumn, or a deletion, represented by filling the deletion attribute. + @param column_or_supercolumn. An insert to a column or supercolumn + @param deletion. A deletion of a column or supercolumn +*/ +struct Mutation { + 1: optional ColumnOrSuperColumn column_or_supercolumn, + 2: optional Deletion deletion, +} + +struct TokenRange { + 1: required string start_token, + 2: required string end_token, + 3: required list<string> endpoints, +} + +/** + Authentication requests can contain any data, dependent on the IAuthenticator used +*/ +struct AuthenticationRequest { + 1: required map<string, string> credentials +} + +enum IndexType { + KEYS, +} + +/* describes a column in a column family. */ +struct ColumnDef { + 1: required binary name, + 2: required string validation_class, + 3: optional IndexType index_type, + 4: optional string index_name +} + + +/* describes a column family. */ +struct CfDef { + 1: required string keyspace, + 2: required string name, + 3: optional string column_type="Standard", + 5: optional string comparator_type="BytesType", + 6: optional string subcomparator_type, + 8: optional string comment, + 9: optional double row_cache_size=0, + 11: optional double key_cache_size=200000, + 12: optional double read_repair_chance=1.0, + 13: optional list<ColumnDef> column_metadata, + 14: optional i32 gc_grace_seconds, + 15: optional string default_validation_class, + 16: optional i32 id, + 17: optional i32 min_compaction_threshold, + 18: optional i32 max_compaction_threshold, + 19: optional i32 row_cache_save_period_in_seconds, + 20: optional i32 key_cache_save_period_in_seconds, + 21: optional i32 memtable_flush_after_mins, + 22: optional i32 memtable_throughput_in_mb, + 23: optional double memtable_operations_in_millions, +} + +/* describes a keyspace. */ +struct KsDef { + 1: required string name, + 2: required string strategy_class, + 3: optional map<string,string> strategy_options, + 4: required i32 replication_factor, + 5: required list<CfDef> cf_defs, +} + +service Cassandra { + # auth methods + void login(1: required AuthenticationRequest auth_request) throws (1:AuthenticationException authnx, 2:AuthorizationException authzx), + + # set keyspace + void set_keyspace(1: required string keyspace) throws (1:InvalidRequestException ire), + + # retrieval methods + + /** + Get the Column or SuperColumn at the given column_path. If no value is present, NotFoundException is thrown. (This is + the only method that can throw an exception under non-failure conditions.) + */ + ColumnOrSuperColumn get(1:required binary key, + 2:required ColumnPath column_path, + 3:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:NotFoundException nfe, 3:UnavailableException ue, 4:TimedOutException te), + + /** + Get the group of columns contained by column_parent (either a ColumnFamily name or a ColumnFamily/SuperColumn name + pair) specified by the given SlicePredicate. If no matching values are found, an empty list is returned. + */ + list<ColumnOrSuperColumn> get_slice(1:required binary key, + 2:required ColumnParent column_parent, + 3:required SlicePredicate predicate, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + returns the number of columns matching <code>predicate</code> for a particular <code>key</code>, + <code>ColumnFamily</code> and optionally <code>SuperColumn</code>. + */ + i32 get_count(1:required binary key, + 2:required ColumnParent column_parent, + 3:required SlicePredicate predicate, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + Performs a get_slice for column_parent and predicate for the given keys in parallel. + */ + map<binary,list<ColumnOrSuperColumn>> multiget_slice(1:required list<binary> keys, + 2:required ColumnParent column_parent, + 3:required SlicePredicate predicate, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + Perform a get_count in parallel on the given list<binary> keys. The return value maps keys to the count found. + */ + map<binary, i32> multiget_count(1:required list<binary> keys, + 2:required ColumnParent column_parent, + 3:required SlicePredicate predicate, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + returns a subset of columns for a contiguous range of keys. + */ + list<KeySlice> get_range_slices(1:required ColumnParent column_parent, + 2:required SlicePredicate predicate, + 3:required KeyRange range, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** Returns the subset of columns specified in SlicePredicate for the rows matching the IndexClause */ + list<KeySlice> get_indexed_slices(1:required ColumnParent column_parent, + 2:required IndexClause index_clause, + 3:required SlicePredicate column_predicate, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + # modification methods + + /** + * Insert a Column at the given column_parent.column_family and optional column_parent.super_column. + */ + void insert(1:required binary key, + 2:required ColumnParent column_parent, + 3:required Column column, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + Remove data from the row specified by key at the granularity specified by column_path, and the given timestamp. Note + that all the values in column_path besides column_path.column_family are truly optional: you can remove the entire + row by just specifying the ColumnFamily, or you can remove a SuperColumn or a single Column by specifying those levels too. + */ + void remove(1:required binary key, + 2:required ColumnPath column_path, + 3:required i64 timestamp, + 4:ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + Mutate many columns or super columns for many row keys. See also: Mutation. + + mutation_map maps key to column family to a list of Mutation objects to take place at that scope. + **/ + void batch_mutate(1:required map<binary, map<string, list<Mutation>>> mutation_map, + 2:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + Truncate will mark and entire column family as deleted. + From the user's perspective a successful call to truncate will result complete data deletion from cfname. + Internally, however, disk space will not be immediatily released, as with all deletes in cassandra, this one + only marks the data as deleted. + The operation succeeds only if all hosts in the cluster at available and will throw an UnavailableException if + some hosts are down. + */ + void truncate(1:required string cfname) + throws (1: InvalidRequestException ire, 2: UnavailableException ue), + + // Meta-APIs -- APIs to get information about the node or cluster, + // rather than user data. The nodeprobe program provides usage examples. + + /** + * for each schema version present in the cluster, returns a list of nodes at that version. + * hosts that do not respond will be under the key DatabaseDescriptor.INITIAL_VERSION. + * the cluster is all on the same version if the size of the map is 1. + */ + map<string, list<string>> describe_schema_versions() + throws (1: InvalidRequestException ire), + + /** list the defined keyspaces in this cluster */ + list<KsDef> describe_keyspaces() + throws (1:InvalidRequestException ire), + + /** get the cluster name */ + string describe_cluster_name(), + + /** get the thrift api version */ + string describe_version(), + + /** get the token ring: a map of ranges to host addresses, + represented as a set of TokenRange instead of a map from range + to list of endpoints, because you can't use Thrift structs as + map keys: + https://issues.apache.org/jira/browse/THRIFT-162 + + for the same reason, we can't return a set here, even though + order is neither important nor predictable. */ + list<TokenRange> describe_ring(1:required string keyspace) + throws (1:InvalidRequestException ire), + + /** returns the partitioner used by this cluster */ + string describe_partitioner(), + + /** returns the snitch used by this cluster */ + string describe_snitch(), + + /** describe specified keyspace */ + KsDef describe_keyspace(1:required string keyspace) + throws (1:NotFoundException nfe, 2:InvalidRequestException ire), + + /** experimental API for hadoop/parallel query support. + may change violently and without warning. + + returns list of token strings such that first subrange is (list[0], list[1]], + next is (list[1], list[2]], etc. */ + list<string> describe_splits(1:required string cfName, + 2:required string start_token, + 3:required string end_token, + 4:required i32 keys_per_split), + + /** adds a column family. returns the new schema id. */ + string system_add_column_family(1:required CfDef cf_def) + throws (1:InvalidRequestException ire), + + /** drops a column family. returns the new schema id. */ + string system_drop_column_family(1:required string column_family) + throws (1:InvalidRequestException ire), + + /** adds a keyspace and any column families that are part of it. returns the new schema id. */ + string system_add_keyspace(1:required KsDef ks_def) + throws (1:InvalidRequestException ire), + + /** drops a keyspace and any column families that are part of it. returns the new schema id. */ + string system_drop_keyspace(1:required string keyspace) + throws (1:InvalidRequestException ire), + + /** updates properties of a keyspace. returns the new schema id. */ + string system_update_keyspace(1:required KsDef ks_def) + throws (1:InvalidRequestException ire), + + /** updates properties of a column family. returns the new schema id. */ + string system_update_column_family(1:required CfDef cf_def) + throws (1:InvalidRequestException ire), +} Added: sandbox/ivol/standalone-cassandra/lib/antlr-3.1.3.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/apache-cassandra-0.7.0.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/avro-1.4.0-fixes.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/avro-1.4.0-sources-fixes.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/commons-cli-1.1.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/commons-codec-1.2.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/commons-collections-3.2.1.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/commons-lang-2.4.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/concurrentlinkedhashmap-lru-1.1.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/guava-r05.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/high-scale-lib.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/ivy-2.1.0.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/jackson-core-asl-1.4.0.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/jackson-mapper-asl-1.4.0.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/jetty-6.1.21.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/jetty-util-6.1.21.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/jline-0.9.94.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/json-simple-1.1.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/jug-2.0.0.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/libthrift-0.5.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/log4j-1.2.16.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/servlet-api-2.5-20081211.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/slf4j-api-1.6.1.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/slf4j-log4j12-1.6.1.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/lib/snakeyaml-1.6.jar ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/readme.txt ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/readme.txt Fri Jan 14 12:35:31 2011 @@ -0,0 +1 @@ +This runs a standalone cassandra instace from Java but outside an OSGi container \ No newline at end of file Added: sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/DummyMain.java ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/DummyMain.java Fri Jan 14 12:35:31 2011 @@ -0,0 +1,187 @@ +package org.amdatu.cassandra; + + +public class DummyMain { + /* + // The default placement strategy + private final String DEFAULT_PLACEMENT_STRATEGY = "org.apache.cassandra.locator.SimpleStrategy"; + + private String DEFAULT_KEYSPACE = "Default"; + private String ROLE_CF = "Role"; + private String GADGET_CF = "Gadget"; + private String CATEGORY_CF = "Category"; + + private final static String DEFAULT_CHARSET = "UTF-8"; + + //private CassandraServer m_cassandraServer; + + public static void main(String[] args) { + try { + new Main().run(); + } + catch (InvalidRequestException e) { + e.printStackTrace(); + } + catch (TException e) { + e.printStackTrace(); + } + catch (NotFoundException e) { + e.printStackTrace(); + } + catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + catch (UnavailableException e) { + e.printStackTrace(); + } + catch (TimedOutException e) { + e.printStackTrace(); + } + } + + public Main() { + System.setProperty("cassandra.config", new File("conf/cassandra.yaml").toURI().toString()); + PropertyConfigurator.configure(new File("conf/log4j-server.properties").getAbsolutePath()); + System.setProperty("cassandra-foreground", "true"); + new CassandraDaemon().activate(); + //m_cassandraServer = new CassandraServer(); + } + + private void run() throws InvalidRequestException, TException, NotFoundException, UnsupportedEncodingException, UnavailableException, TimedOutException { + if (!keyspaceExists(DEFAULT_KEYSPACE)) { + addKeyspace(DEFAULT_KEYSPACE, 1); + } + + if (!columnFamilyExists(DEFAULT_KEYSPACE, ROLE_CF)) { + addColumnFamily(DEFAULT_KEYSPACE, ROLE_CF, "Super", "BytesType", "BytesType"); + } + + // Add 13 test roles to this CF users + for (int i=1; i<=13; i++) { + setValue(DEFAULT_KEYSPACE, ROLE_CF, "user_"+i, "super", "name", toBytes("User " + i)); + } + + if (!columnFamilyExists(DEFAULT_KEYSPACE, GADGET_CF)) { + addColumnFamily(DEFAULT_KEYSPACE, GADGET_CF, "Super", "BytesType", "BytesType"); + } + + // Add 20 test gadgets to this CF gadgets + for (int i=1; i<=20; i++) { + setValue(DEFAULT_KEYSPACE, GADGET_CF, "gadget_"+i, "super", "name", toBytes("Gadget " + i)); + } + + if (!columnFamilyExists(DEFAULT_KEYSPACE, CATEGORY_CF)) { + addColumnFamily(DEFAULT_KEYSPACE, CATEGORY_CF, "Super", "BytesType", "BytesType"); + } + + // Add 3 test categories to this CF category + for (int i=1; i<=3; i++) { + setValue(DEFAULT_KEYSPACE, CATEGORY_CF, "category_"+i, "super", "name", toBytes("Category " + i)); + }*/ +} + +/* + public synchronized boolean keyspaceExists(String keyspaceName) throws TException, InvalidRequestException { + try { + m_cassandraServer.describe_keyspace(keyspaceName); + return true; + } + catch (NotFoundException e) { + return false; + } + } + + public synchronized boolean addKeyspace(String name, int replicationFactor) throws InvalidRequestException, TException { + if (!keyspaceExists(name)) { + List<CfDef> empty = new ArrayList<CfDef>(); + KsDef ksDef = new KsDef(name, DEFAULT_PLACEMENT_STRATEGY, replicationFactor, empty); + try { + m_cassandraServer.system_add_keyspace(ksDef); + } catch (InvalidRequestException e) { + // Now this error may appear if some other node in the cluster added this keyspace + // in the meantime and this keyspace was synchornized to this node. So verify if the + // keyspace exists after all, and if so, return without throwing an exception + if (keyspaceExists(name)) { + System.out.println("Keyspace '" + name + "' was not added since it already existed"); + return false; + } else { + throw e; + } + } + + return true; + } else { + System.out.println("Keyspace '" + name + "' was not added since it already existed"); + return false; + } + } + + public boolean columnFamilyExists(String keyspaceName, String columnFamilyName) throws NotFoundException, InvalidRequestException { + KsDef ksDef = m_cassandraServer.describe_keyspace(keyspaceName); + List<CfDef> cfDefs = ksDef.getCf_defs(); + for (CfDef cfDef : cfDefs) { + if (cfDef.getName().equals(columnFamilyName)) { + return true; + } + } + return false; + } + + public List<String> getColumnFamilies(String keyspaceName) throws NotFoundException, InvalidRequestException { + List<String> cfNames = new ArrayList<String>(); + KsDef ksDef = m_cassandraServer.describe_keyspace(keyspaceName); + List<CfDef> cfDefs = ksDef.getCf_defs(); + for (CfDef cfDef : cfDefs) { + cfNames.add( cfDef.getName()); + } + return cfNames; + } + + public synchronized boolean addColumnFamily(String keyspace, String cfName, String columnType, String comparatorType, + String subComparatorType) throws InvalidRequestException, TException, NotFoundException { + if (keyspace.equals(Table.SYSTEM_TABLE)) { + throw new InvalidRequestException("ColumnFamily's cannot be added to Cassandra's system keyspace"); + } + if (!columnFamilyExists(keyspace, cfName)) { + CfDef cfDef = new CfDef(keyspace, cfName); + cfDef.column_type = columnType; + cfDef.comparator_type = comparatorType; + cfDef.subcomparator_type = subComparatorType; + + m_cassandraServer.set_keyspace(keyspace); + m_cassandraServer.system_add_column_family(cfDef); + System.out.println("ColumnFamily '" + cfName + "' has been added to keyspace '" + keyspace + "'"); + return true; + } else { + System.out.println("ColumnFamily '" + cfName + "' was not added to keyspace '" + keyspace + "' since it already existed"); + return false; + } + } + + + public void setValue(String keyspace, String columnFamilyName, String rowKey, String superColumnName, String columnName, ByteBuffer value) throws UnsupportedEncodingException, InvalidRequestException, UnavailableException, TimedOutException, TException { + long timestamp = System.currentTimeMillis(); + ColumnParent column_parent = new ColumnParent(columnFamilyName); + column_parent.setSuper_column(toBytes(superColumnName)); + Column column = new Column(toBytes(columnName), value, timestamp); + Iface cs = m_cassandraServer; + cs.set_keyspace(keyspace); + cs.insert(toBytes(rowKey), column_parent, column, ConsistencyLevel.ONE); + } + + private ByteBuffer toBytes(String value) throws UnsupportedEncodingException { + return ByteBuffer.wrap(value.getBytes(DEFAULT_CHARSET)); + } + + private String toString(byte[] bytes) throws UnsupportedEncodingException { + return new String(bytes, DEFAULT_CHARSET); + } + + private List<ByteBuffer> toBytesList(List<byte[]> values) { + List<ByteBuffer> result = new ArrayList<ByteBuffer>(); + for (byte[] value : values) { + result.add(ByteBuffer.wrap(value)); + } + return result; + }*/ + Added: sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/Main.class ============================================================================== Binary file. No diff available. Added: sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/Main.java ============================================================================== --- (empty file) +++ sandbox/ivol/standalone-cassandra/src/org/amdatu/cassandra/Main.java Fri Jan 14 12:35:31 2011 @@ -0,0 +1,240 @@ +package org.amdatu.cassandra; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.db.Table; +import org.apache.cassandra.thrift.Cassandra; +import org.apache.cassandra.thrift.CassandraDaemon; +import org.apache.cassandra.thrift.CassandraServer; +import org.apache.cassandra.thrift.CfDef; +import org.apache.cassandra.thrift.Column; +import org.apache.cassandra.thrift.ColumnParent; +import org.apache.cassandra.thrift.ConsistencyLevel; +import org.apache.cassandra.thrift.InvalidRequestException; +import org.apache.cassandra.thrift.KsDef; +import org.apache.cassandra.thrift.NotFoundException; +import org.apache.cassandra.thrift.TimedOutException; +import org.apache.cassandra.thrift.UnavailableException; +import org.apache.cassandra.thrift.Cassandra.Iface; +import org.apache.log4j.PropertyConfigurator; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Main { + private static Logger logger = LoggerFactory.getLogger(CassandraDaemon.class); + + // The default placement strategy + private final String DEFAULT_PLACEMENT_STRATEGY = "org.apache.cassandra.locator.SimpleStrategy"; + + private String DEFAULT_KEYSPACE = "Default"; + private String ROLE_CF = "Role"; + private String GADGET_CF = "Gadget"; + private String CATEGORY_CF = "Category"; + + private final static String DEFAULT_CHARSET = "UTF-8"; + + private CassandraServer m_cassandraServer; + + public static void main(String[] args) { + + try { + Main main = new Main(); + main.run(); + } + catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + catch (InvalidRequestException e) { + e.printStackTrace(); + } + catch (TException e) { + e.printStackTrace(); + } + catch (NotFoundException e) { + e.printStackTrace(); + } + catch (UnavailableException e) { + e.printStackTrace(); + } + catch (TimedOutException e) { + e.printStackTrace(); + } + + } + + public Main() throws TTransportException { + System.out.println("Starting Amdatu cassandra daemon..."); + System.setProperty("cassandra.config", new File("conf/cassandra.yaml").toURI().toString()); + PropertyConfigurator.configure(new File("conf/log4j-server.properties").getAbsolutePath()); + System.setProperty("cassandra-foreground", "true"); + new CassandraDaemonThread().start(); + System.out.println(System.currentTimeMillis() + " Creating cassandra client..."); + getClient(); + System.out.println(System.currentTimeMillis() + " Cassandra client connected..."); + } + + class CassandraDaemonThread extends Thread { + public void run() { + new CassandraDaemon().activate(); + } + } + + private Cassandra.Client getClient() throws TTransportException { + TTransport tr = new TSocket("localhost", 9160); + TProtocol proto = new TBinaryProtocol(tr); + Cassandra.Client client = new Cassandra.Client(proto); + tr.open(); + return client; + } + + + private void run() throws InvalidRequestException, TException, NotFoundException, UnsupportedEncodingException, UnavailableException, TimedOutException { + m_cassandraServer = new CassandraServer(); + System.out.println("Initializing data..."); + if (!keyspaceExists(DEFAULT_KEYSPACE)) { + addKeyspace(DEFAULT_KEYSPACE, 1); + } + + if (!columnFamilyExists(DEFAULT_KEYSPACE, ROLE_CF)) { + addColumnFamily(DEFAULT_KEYSPACE, ROLE_CF, "Super", "BytesType", "BytesType"); + } + + // Add 13 test roles to this CF users + for (int i=1; i<=13; i++) { + setValue(DEFAULT_KEYSPACE, ROLE_CF, "user_"+i, "super", "name", toBytes("User " + i)); + } + + if (!columnFamilyExists(DEFAULT_KEYSPACE, GADGET_CF)) { + addColumnFamily(DEFAULT_KEYSPACE, GADGET_CF, "Super", "BytesType", "BytesType"); + } + + // Add 20 test gadgets to this CF gadgets + for (int i=1; i<=20; i++) { + setValue(DEFAULT_KEYSPACE, GADGET_CF, "gadget_"+i, "super", "name", toBytes("Gadget " + i)); + } + + if (!columnFamilyExists(DEFAULT_KEYSPACE, CATEGORY_CF)) { + addColumnFamily(DEFAULT_KEYSPACE, CATEGORY_CF, "Super", "BytesType", "BytesType"); + } + + // Add 3 test categories to this CF category + for (int i=1; i<=3; i++) { + setValue(DEFAULT_KEYSPACE, CATEGORY_CF, "category_"+i, "super", "name", toBytes("Category " + i)); + } + } + + + public synchronized boolean keyspaceExists(String keyspaceName) throws TException, InvalidRequestException { + try { + m_cassandraServer.describe_keyspace(keyspaceName); + return true; + } + catch (NotFoundException e) { + return false; + } + } + + public synchronized boolean addKeyspace(String name, int replicationFactor) throws InvalidRequestException, TException { + if (!keyspaceExists(name)) { + List<CfDef> empty = new ArrayList<CfDef>(); + KsDef ksDef = new KsDef(name, DEFAULT_PLACEMENT_STRATEGY, replicationFactor, empty); + try { + m_cassandraServer.system_add_keyspace(ksDef); + } catch (InvalidRequestException e) { + // Now this error may appear if some other node in the cluster added this keyspace + // in the meantime and this keyspace was synchornized to this node. So verify if the + // keyspace exists after all, and if so, return without throwing an exception + if (keyspaceExists(name)) { + System.out.println("Keyspace '" + name + "' was not added since it already existed"); + return false; + } else { + throw e; + } + } + + return true; + } else { + System.out.println("Keyspace '" + name + "' was not added since it already existed"); + return false; + } + } + + public boolean columnFamilyExists(String keyspaceName, String columnFamilyName) throws NotFoundException, InvalidRequestException { + KsDef ksDef = m_cassandraServer.describe_keyspace(keyspaceName); + List<CfDef> cfDefs = ksDef.getCf_defs(); + for (CfDef cfDef : cfDefs) { + if (cfDef.getName().equals(columnFamilyName)) { + return true; + } + } + return false; + } + + public List<String> getColumnFamilies(String keyspaceName) throws NotFoundException, InvalidRequestException { + List<String> cfNames = new ArrayList<String>(); + KsDef ksDef = m_cassandraServer.describe_keyspace(keyspaceName); + List<CfDef> cfDefs = ksDef.getCf_defs(); + for (CfDef cfDef : cfDefs) { + cfNames.add( cfDef.getName()); + } + return cfNames; + } + + public synchronized boolean addColumnFamily(String keyspace, String cfName, String columnType, String comparatorType, + String subComparatorType) throws InvalidRequestException, TException, NotFoundException { + if (keyspace.equals(Table.SYSTEM_TABLE)) { + throw new InvalidRequestException("ColumnFamily's cannot be added to Cassandra's system keyspace"); + } + if (!columnFamilyExists(keyspace, cfName)) { + CfDef cfDef = new CfDef(keyspace, cfName); + cfDef.column_type = columnType; + cfDef.comparator_type = comparatorType; + cfDef.subcomparator_type = subComparatorType; + + m_cassandraServer.set_keyspace(keyspace); + m_cassandraServer.system_add_column_family(cfDef); + System.out.println("ColumnFamily '" + cfName + "' has been added to keyspace '" + keyspace + "'"); + return true; + } else { + System.out.println("ColumnFamily '" + cfName + "' was not added to keyspace '" + keyspace + "' since it already existed"); + return false; + } + } + + + public void setValue(String keyspace, String columnFamilyName, String rowKey, String superColumnName, String columnName, ByteBuffer value) throws UnsupportedEncodingException, InvalidRequestException, UnavailableException, TimedOutException, TException { + long timestamp = System.currentTimeMillis(); + ColumnParent column_parent = new ColumnParent(columnFamilyName); + column_parent.setSuper_column(toBytes(superColumnName)); + Column column = new Column(toBytes(columnName), value, timestamp); + Iface cs = m_cassandraServer; + cs.set_keyspace(keyspace); + cs.insert(toBytes(rowKey), column_parent, column, ConsistencyLevel.ONE); + } + + private ByteBuffer toBytes(String value) throws UnsupportedEncodingException { + return ByteBuffer.wrap(value.getBytes(DEFAULT_CHARSET)); + } + + private String toString(byte[] bytes) throws UnsupportedEncodingException { + return new String(bytes, DEFAULT_CHARSET); + } + + private List<ByteBuffer> toBytesList(List<byte[]> values) { + List<ByteBuffer> result = new ArrayList<ByteBuffer>(); + for (byte[] value : values) { + result.add(ByteBuffer.wrap(value)); + } + return result; + } +}
