Author: johan Date: Tue Dec 21 22:17:09 2010 New Revision: 1051679 URL: http://svn.apache.org/viewvc?rev=1051679&view=rev Log: Adds support for columns that act as incr/decr counters. Patch primarily by Kelvin Kakugawa with select parts from Chris Goffinet, Sylvain Lebresne, Rob Coli, Johan Oskarsson, Adam Samet, Jaakko Laine and more. Review by Jonathan Ellis and Sylvain Lebresne. CASSANDRA-1072.
Added: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Counter.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CounterColumn.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CounterDeletion.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CounterMutation.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CounterSuperColumn.java cassandra/trunk/src/java/org/apache/cassandra/db/CounterColumn.java cassandra/trunk/src/java/org/apache/cassandra/db/ReplicateOnWriteTask.java cassandra/trunk/src/java/org/apache/cassandra/db/ReplicateOnWriteVerbHandler.java cassandra/trunk/src/java/org/apache/cassandra/db/context/ cassandra/trunk/src/java/org/apache/cassandra/db/context/CounterContext.java cassandra/trunk/src/java/org/apache/cassandra/db/context/IContext.java cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractCommutativeType.java cassandra/trunk/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java cassandra/trunk/src/java/org/apache/cassandra/streaming/OperationType.java cassandra/trunk/test/unit/org/apache/cassandra/db/CounterColumnTest.java cassandra/trunk/test/unit/org/apache/cassandra/db/context/ cassandra/trunk/test/unit/org/apache/cassandra/db/context/CounterContextTest.java cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableWriterAESCommutativeTest.java cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceCounterTest.java cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceStandardTest.java cassandra/trunk/test/unit/org/apache/cassandra/service/AntiEntropyServiceTestAbstract.java cassandra/trunk/test/unit/org/apache/cassandra/thrift/ cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java Modified: cassandra/trunk/CHANGES.txt cassandra/trunk/conf/cassandra.yaml cassandra/trunk/interface/cassandra.genavro cassandra/trunk/interface/cassandra.thrift cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/AuthenticationRequest.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CfDef.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/IndexClause.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/KeySlice.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/KsDef.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/SlicePredicate.java cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/TokenRange.java cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java cassandra/trunk/src/java/org/apache/cassandra/concurrent/Stage.java cassandra/trunk/src/java/org/apache/cassandra/concurrent/StageManager.java cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java cassandra/trunk/src/java/org/apache/cassandra/config/Config.java cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java cassandra/trunk/src/java/org/apache/cassandra/config/RawColumnFamily.java cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java cassandra/trunk/src/java/org/apache/cassandra/db/CompactionManager.java cassandra/trunk/src/java/org/apache/cassandra/db/DeletedColumn.java cassandra/trunk/src/java/org/apache/cassandra/db/IColumnContainer.java cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java cassandra/trunk/src/java/org/apache/cassandra/db/RowMutation.java cassandra/trunk/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java cassandra/trunk/src/java/org/apache/cassandra/dht/BootStrapper.java cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java cassandra/trunk/src/java/org/apache/cassandra/service/AntiEntropyService.java cassandra/trunk/src/java/org/apache/cassandra/service/ReadResponseResolver.java cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java cassandra/trunk/src/java/org/apache/cassandra/streaming/PendingFile.java cassandra/trunk/src/java/org/apache/cassandra/streaming/StreamIn.java cassandra/trunk/src/java/org/apache/cassandra/streaming/StreamInSession.java cassandra/trunk/src/java/org/apache/cassandra/streaming/StreamOut.java cassandra/trunk/src/java/org/apache/cassandra/streaming/StreamRequestMessage.java cassandra/trunk/src/java/org/apache/cassandra/streaming/StreamRequestVerbHandler.java cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java cassandra/trunk/src/java/org/apache/cassandra/thrift/ThriftValidation.java cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java cassandra/trunk/test/conf/cassandra.yaml cassandra/trunk/test/system/__init__.py cassandra/trunk/test/system/test_thrift_server.py cassandra/trunk/test/unit/org/apache/cassandra/Util.java cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java cassandra/trunk/test/unit/org/apache/cassandra/db/SuperColumnTest.java cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java cassandra/trunk/test/unit/org/apache/cassandra/streaming/BootstrapTest.java cassandra/trunk/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java Modified: cassandra/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1051679&r1=1051678&r2=1051679&view=diff ============================================================================== --- cassandra/trunk/CHANGES.txt (original) +++ cassandra/trunk/CHANGES.txt Tue Dec 21 22:17:09 2010 @@ -1,5 +1,6 @@ 0.8-dev * avoid double RowMutation serialization on write path (CASSANDRA-1800) + * adds support for columns that act as incr/decr counters (CASSANDRA-1072) 0.7-dev Modified: cassandra/trunk/conf/cassandra.yaml URL: http://svn.apache.org/viewvc/cassandra/trunk/conf/cassandra.yaml?rev=1051679&r1=1051678&r2=1051679&view=diff ============================================================================== --- cassandra/trunk/conf/cassandra.yaml (original) +++ cassandra/trunk/conf/cassandra.yaml Tue Dec 21 22:17:09 2010 @@ -459,3 +459,10 @@ keyspaces: validator_class: LongType index_name: birthdate_idx index_type: KEYS + + - name: Counter1 + default_validation_class: CounterColumnType + + - name: SuperCounter1 + column_type: Super + default_validation_class: CounterColumnType Modified: cassandra/trunk/interface/cassandra.genavro URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.genavro?rev=1051679&r1=1051678&r2=1051679&view=diff ============================================================================== --- cassandra/trunk/interface/cassandra.genavro (original) +++ cassandra/trunk/interface/cassandra.genavro Tue Dec 21 22:17:09 2010 @@ -146,6 +146,7 @@ protocol Cassandra { union { double, null } row_cache_size; union { double, null } key_cache_size; union { double, null } read_repair_chance; + union { boolean, null } replicate_on_write; union { int, null } gc_grace_seconds; union { null, string } default_validation_class = null; union { null, int } min_compaction_threshold = null; Modified: cassandra/trunk/interface/cassandra.thrift URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.thrift?rev=1051679&r1=1051678&r2=1051679&view=diff ============================================================================== --- cassandra/trunk/interface/cassandra.thrift (original) +++ cassandra/trunk/interface/cassandra.thrift Tue Dec 21 22:17:09 2010 @@ -189,6 +189,21 @@ struct ColumnPath { 5: optional binary column, } +struct CounterColumn { + 1: required binary name, + 2: required i64 value +} + +struct CounterSuperColumn { + 1: required binary name, + 2: required list<CounterColumn> columns +} + +struct Counter { + 1: optional CounterColumn column, + 2: optional CounterSuperColumn super_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 @@ -298,6 +313,21 @@ struct Mutation { 2: optional Deletion deletion, } +struct CounterDeletion { + 1: optional binary super_column, + 2: optional SlicePredicate predicate, +} + +/** + A CounterMutation is either an insert, represented by filling counter, or a deletion, represented by filling the deletion attribute. + @param counter. An insert to a counter column or supercolumn + @param deletion. A deletion of a counter column or supercolumn +*/ +struct CounterMutation { + 1: optional Counter counter, + 2: optional CounterDeletion deletion, +} + struct TokenRange { 1: required string start_token, 2: required string end_token, @@ -346,6 +376,7 @@ struct CfDef { 21: optional i32 memtable_flush_after_mins, 22: optional i32 memtable_throughput_in_mb, 23: optional double memtable_operations_in_millions, + 24: optional bool replicate_on_write=0, } /* describes a keyspace. */ @@ -470,6 +501,59 @@ service Cassandra { */ void truncate(1:required string cfname) throws (1: InvalidRequestException ire, 2: UnavailableException ue), + + + # counter methods + + /** + * Increment or decrement a counter. + */ + void add(1:required binary key, + 2:required ColumnParent column_parent, + 3:required CounterColumn column, + 4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + /** + * Batch increment or decrement a counter. + */ + void batch_add(1:required map<binary, map<string, list<CounterMutation>>> update_map, + 2:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + + /** + * Return the counter at the specified column path. + */ + Counter get_counter(1:required binary key, + 2:required ColumnPath path, + 3:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:NotFoundException nfe, 3:UnavailableException ue, 4:TimedOutException te), + + /** + * Get a list of counters from the specified columns. + */ + list<Counter> get_counter_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), + + /** + * Get counter slices from multiple keys. + */ + map<binary,list<Counter>> multiget_counter_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), + + /** + * Remove a counter at the specified location. + */ + void remove_counter(1:required binary key, + 2:required ColumnPath path, + 3:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE) + throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te), + // Meta-APIs -- APIs to get information about the node or cluster, // rather than user data. The nodeprobe program provides usage examples. Modified: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/AuthenticationRequest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/AuthenticationRequest.java?rev=1051679&r1=1051678&r2=1051679&view=diff ============================================================================== --- cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/AuthenticationRequest.java (original) +++ cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/AuthenticationRequest.java Tue Dec 21 22:17:09 2010 @@ -314,15 +314,15 @@ public class AuthenticationRequest imple case 1: // CREDENTIALS if (field.type == TType.MAP) { { - TMap _map20 = iprot.readMapBegin(); - this.credentials = new HashMap<String,String>(2*_map20.size); - for (int _i21 = 0; _i21 < _map20.size; ++_i21) + TMap _map24 = iprot.readMapBegin(); + this.credentials = new HashMap<String,String>(2*_map24.size); + for (int _i25 = 0; _i25 < _map24.size; ++_i25) { - String _key22; - String _val23; - _key22 = iprot.readString(); - _val23 = iprot.readString(); - this.credentials.put(_key22, _val23); + String _key26; + String _val27; + _key26 = iprot.readString(); + _val27 = iprot.readString(); + this.credentials.put(_key26, _val27); } iprot.readMapEnd(); } @@ -349,10 +349,10 @@ public class AuthenticationRequest imple oprot.writeFieldBegin(CREDENTIALS_FIELD_DESC); { oprot.writeMapBegin(new TMap(TType.STRING, TType.STRING, this.credentials.size())); - for (Map.Entry<String, String> _iter24 : this.credentials.entrySet()) + for (Map.Entry<String, String> _iter28 : this.credentials.entrySet()) { - oprot.writeString(_iter24.getKey()); - oprot.writeString(_iter24.getValue()); + oprot.writeString(_iter28.getKey()); + oprot.writeString(_iter28.getValue()); } oprot.writeMapEnd(); }