Merge COSC and Counter thrift structure

patch by slebresne; reviewed by jbellis for CASSANDRA-2440


git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1090842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sylvain Lebresne 2011-04-10 17:31:15 +00:00
parent dc89826fd8
commit 9a0bbc542b
13 changed files with 2906 additions and 7528 deletions

View File

@ -76,6 +76,16 @@ struct SuperColumn {
2: required list<Column> columns,
}
struct CounterColumn {
1: required binary name,
2: required i64 value
}
struct CounterSuperColumn {
1: required binary name,
2: required list<CounterColumn> 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
@ -83,12 +93,19 @@ struct SuperColumn {
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.
If the query was on a counter column family, you will either get a counter_column (instead of a column) or a
counter_super_column (instead of a super_column)
@param column. The Column returned by get() or get_slice().
@param super_column. The SuperColumn returned by get() or get_slice().
@param counter_column. The Counterolumn returned by get() or get_slice().
@param counter_super_column. The CounterSuperColumn returned by get() or get_slice().
*/
struct ColumnOrSuperColumn {
1: optional Column column,
2: optional SuperColumn super_column,
3: optional CounterColumn counter_column,
4: optional CounterSuperColumn counter_super_column
}
@ -213,21 +230,6 @@ 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
@ -331,15 +333,13 @@ struct Deletion {
}
/**
A Mutation is either an insert (represented by filling column_or_supercolumn), a deletion (represented by filling the deletion attribute),
a counter addition (represented by filling counter), or a counter deletion (represented by filling counter_deletion).
@param column_or_supercolumn. An insert to a column or supercolumn
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 (possibly counter column or supercolumn)
@param deletion. A deletion of a column or supercolumn
*/
struct Mutation {
1: optional ColumnOrSuperColumn column_or_supercolumn,
2: optional Deletion deletion,
3: optional Counter counter,
}
struct TokenRange {
@ -390,7 +390,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,
24: optional bool replicate_on_write,
25: optional double merge_shards_chance,
26: optional string key_validation_class,
27: optional string row_cache_provider="org.apache.cassandra.cache.ConcurrentLinkedHashCacheProvider",
@ -512,15 +512,19 @@ service Cassandra {
4:required ConsistencyLevel consistency_level=ConsistencyLevel.ONE)
throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te),
/**
* 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),
/**
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.
Note that counters have limited support for deletes: if you remove
a counter, you must wait to issue any following update until the
delete has reached all the nodes and all of them have been fully
compacted.
*/
void remove(1:required binary key,
2:required ColumnPath column_path,
@ -528,6 +532,17 @@ service Cassandra {
4:ConsistencyLevel consistency_level=ConsistencyLevel.ONE)
throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te),
/**
* Remove a counter at the specified location.
* Note that counters have limited support for deletes: if you remove a counter, you must wait to issue any following update
* until the delete has reached all the nodes and all of them have been fully compacted.
*/
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),
/**
Mutate many columns or super columns for many row keys. See also: Mutation.
@ -549,51 +564,6 @@ service Cassandra {
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),
/**
* 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.

View File

@ -306,8 +306,6 @@ public class CfDef implements org.apache.thrift.TBase<CfDef, CfDef._Fields>, jav
this.read_repair_chance = 1;
this.replicate_on_write = false;
this.row_cache_provider = "org.apache.cassandra.cache.ConcurrentLinkedHashCacheProvider";
}
@ -417,8 +415,8 @@ public class CfDef implements org.apache.thrift.TBase<CfDef, CfDef._Fields>, jav
this.memtable_throughput_in_mb = 0;
setMemtable_operations_in_millionsIsSet(false);
this.memtable_operations_in_millions = 0.0;
setReplicate_on_writeIsSet(false);
this.replicate_on_write = false;
setMerge_shards_chanceIsSet(false);
this.merge_shards_chance = 0.0;
this.key_validation_class = null;

View File

@ -49,22 +49,33 @@ import org.slf4j.LoggerFactory;
* 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.
*
* If the query was on a counter column family, you will either get a counter_column (instead of a column) or a
* counter_super_column (instead of a super_column)
*
* @param column. The Column returned by get() or get_slice().
* @param super_column. The SuperColumn returned by get() or get_slice().
* @param counter_column. The Counterolumn returned by get() or get_slice().
* @param counter_super_column. The CounterSuperColumn returned by get() or get_slice().
*/
public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSuperColumn, ColumnOrSuperColumn._Fields>, java.io.Serializable, Cloneable {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ColumnOrSuperColumn");
private static final org.apache.thrift.protocol.TField COLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("column", org.apache.thrift.protocol.TType.STRUCT, (short)1);
private static final org.apache.thrift.protocol.TField SUPER_COLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("super_column", org.apache.thrift.protocol.TType.STRUCT, (short)2);
private static final org.apache.thrift.protocol.TField COUNTER_COLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("counter_column", org.apache.thrift.protocol.TType.STRUCT, (short)3);
private static final org.apache.thrift.protocol.TField COUNTER_SUPER_COLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("counter_super_column", org.apache.thrift.protocol.TType.STRUCT, (short)4);
public Column column;
public SuperColumn super_column;
public CounterColumn counter_column;
public CounterSuperColumn counter_super_column;
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
COLUMN((short)1, "column"),
SUPER_COLUMN((short)2, "super_column");
SUPER_COLUMN((short)2, "super_column"),
COUNTER_COLUMN((short)3, "counter_column"),
COUNTER_SUPER_COLUMN((short)4, "counter_super_column");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@ -83,6 +94,10 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
return COLUMN;
case 2: // SUPER_COLUMN
return SUPER_COLUMN;
case 3: // COUNTER_COLUMN
return COUNTER_COLUMN;
case 4: // COUNTER_SUPER_COLUMN
return COUNTER_SUPER_COLUMN;
default:
return null;
}
@ -131,6 +146,10 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Column.class)));
tmpMap.put(_Fields.SUPER_COLUMN, new org.apache.thrift.meta_data.FieldMetaData("super_column", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, SuperColumn.class)));
tmpMap.put(_Fields.COUNTER_COLUMN, new org.apache.thrift.meta_data.FieldMetaData("counter_column", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CounterColumn.class)));
tmpMap.put(_Fields.COUNTER_SUPER_COLUMN, new org.apache.thrift.meta_data.FieldMetaData("counter_super_column", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CounterSuperColumn.class)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ColumnOrSuperColumn.class, metaDataMap);
}
@ -148,6 +167,12 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
if (other.isSetSuper_column()) {
this.super_column = new SuperColumn(other.super_column);
}
if (other.isSetCounter_column()) {
this.counter_column = new CounterColumn(other.counter_column);
}
if (other.isSetCounter_super_column()) {
this.counter_super_column = new CounterSuperColumn(other.counter_super_column);
}
}
public ColumnOrSuperColumn deepCopy() {
@ -158,6 +183,8 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
public void clear() {
this.column = null;
this.super_column = null;
this.counter_column = null;
this.counter_super_column = null;
}
public Column getColumn() {
@ -208,6 +235,54 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
}
}
public CounterColumn getCounter_column() {
return this.counter_column;
}
public ColumnOrSuperColumn setCounter_column(CounterColumn counter_column) {
this.counter_column = counter_column;
return this;
}
public void unsetCounter_column() {
this.counter_column = null;
}
/** Returns true if field counter_column is set (has been assigned a value) and false otherwise */
public boolean isSetCounter_column() {
return this.counter_column != null;
}
public void setCounter_columnIsSet(boolean value) {
if (!value) {
this.counter_column = null;
}
}
public CounterSuperColumn getCounter_super_column() {
return this.counter_super_column;
}
public ColumnOrSuperColumn setCounter_super_column(CounterSuperColumn counter_super_column) {
this.counter_super_column = counter_super_column;
return this;
}
public void unsetCounter_super_column() {
this.counter_super_column = null;
}
/** Returns true if field counter_super_column is set (has been assigned a value) and false otherwise */
public boolean isSetCounter_super_column() {
return this.counter_super_column != null;
}
public void setCounter_super_columnIsSet(boolean value) {
if (!value) {
this.counter_super_column = null;
}
}
public void setFieldValue(_Fields field, Object value) {
switch (field) {
case COLUMN:
@ -226,6 +301,22 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
}
break;
case COUNTER_COLUMN:
if (value == null) {
unsetCounter_column();
} else {
setCounter_column((CounterColumn)value);
}
break;
case COUNTER_SUPER_COLUMN:
if (value == null) {
unsetCounter_super_column();
} else {
setCounter_super_column((CounterSuperColumn)value);
}
break;
}
}
@ -237,6 +328,12 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
case SUPER_COLUMN:
return getSuper_column();
case COUNTER_COLUMN:
return getCounter_column();
case COUNTER_SUPER_COLUMN:
return getCounter_super_column();
}
throw new IllegalStateException();
}
@ -252,6 +349,10 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
return isSetColumn();
case SUPER_COLUMN:
return isSetSuper_column();
case COUNTER_COLUMN:
return isSetCounter_column();
case COUNTER_SUPER_COLUMN:
return isSetCounter_super_column();
}
throw new IllegalStateException();
}
@ -287,6 +388,24 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
return false;
}
boolean this_present_counter_column = true && this.isSetCounter_column();
boolean that_present_counter_column = true && that.isSetCounter_column();
if (this_present_counter_column || that_present_counter_column) {
if (!(this_present_counter_column && that_present_counter_column))
return false;
if (!this.counter_column.equals(that.counter_column))
return false;
}
boolean this_present_counter_super_column = true && this.isSetCounter_super_column();
boolean that_present_counter_super_column = true && that.isSetCounter_super_column();
if (this_present_counter_super_column || that_present_counter_super_column) {
if (!(this_present_counter_super_column && that_present_counter_super_column))
return false;
if (!this.counter_super_column.equals(that.counter_super_column))
return false;
}
return true;
}
@ -304,6 +423,16 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
if (present_super_column)
builder.append(super_column);
boolean present_counter_column = true && (isSetCounter_column());
builder.append(present_counter_column);
if (present_counter_column)
builder.append(counter_column);
boolean present_counter_super_column = true && (isSetCounter_super_column());
builder.append(present_counter_super_column);
if (present_counter_super_column)
builder.append(counter_super_column);
return builder.toHashCode();
}
@ -335,6 +464,26 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetCounter_column()).compareTo(typedOther.isSetCounter_column());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetCounter_column()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.counter_column, typedOther.counter_column);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetCounter_super_column()).compareTo(typedOther.isSetCounter_super_column());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetCounter_super_column()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.counter_super_column, typedOther.counter_super_column);
if (lastComparison != 0) {
return lastComparison;
}
}
return 0;
}
@ -368,6 +517,22 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 3: // COUNTER_COLUMN
if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
this.counter_column = new CounterColumn();
this.counter_column.read(iprot);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 4: // COUNTER_SUPER_COLUMN
if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
this.counter_super_column = new CounterSuperColumn();
this.counter_super_column.read(iprot);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
@ -397,6 +562,20 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
oprot.writeFieldEnd();
}
}
if (this.counter_column != null) {
if (isSetCounter_column()) {
oprot.writeFieldBegin(COUNTER_COLUMN_FIELD_DESC);
this.counter_column.write(oprot);
oprot.writeFieldEnd();
}
}
if (this.counter_super_column != null) {
if (isSetCounter_super_column()) {
oprot.writeFieldBegin(COUNTER_SUPER_COLUMN_FIELD_DESC);
this.counter_super_column.write(oprot);
oprot.writeFieldEnd();
}
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@ -425,6 +604,26 @@ public class ColumnOrSuperColumn implements org.apache.thrift.TBase<ColumnOrSupe
}
first = false;
}
if (isSetCounter_column()) {
if (!first) sb.append(", ");
sb.append("counter_column:");
if (this.counter_column == null) {
sb.append("null");
} else {
sb.append(this.counter_column);
}
first = false;
}
if (isSetCounter_super_column()) {
if (!first) sb.append(", ");
sb.append("counter_super_column:");
if (this.counter_super_column == null) {
sb.append("null");
} else {
sb.append(this.counter_super_column);
}
first = false;
}
sb.append(")");
return sb.toString();
}

View File

@ -1,443 +0,0 @@
/**
* Autogenerated by Thrift
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.cassandra.thrift;
/*
*
* 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.
*
*/
import org.apache.commons.lang.builder.HashCodeBuilder;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Counter implements org.apache.thrift.TBase<Counter, Counter._Fields>, java.io.Serializable, Cloneable {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Counter");
private static final org.apache.thrift.protocol.TField COLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("column", org.apache.thrift.protocol.TType.STRUCT, (short)1);
private static final org.apache.thrift.protocol.TField SUPER_COLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("super_column", org.apache.thrift.protocol.TType.STRUCT, (short)2);
public CounterColumn column;
public CounterSuperColumn super_column;
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
COLUMN((short)1, "column"),
SUPER_COLUMN((short)2, "super_column");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
static {
for (_Fields field : EnumSet.allOf(_Fields.class)) {
byName.put(field.getFieldName(), field);
}
}
/**
* Find the _Fields constant that matches fieldId, or null if its not found.
*/
public static _Fields findByThriftId(int fieldId) {
switch(fieldId) {
case 1: // COLUMN
return COLUMN;
case 2: // SUPER_COLUMN
return SUPER_COLUMN;
default:
return null;
}
}
/**
* Find the _Fields constant that matches fieldId, throwing an exception
* if it is not found.
*/
public static _Fields findByThriftIdOrThrow(int fieldId) {
_Fields fields = findByThriftId(fieldId);
if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
return fields;
}
/**
* Find the _Fields constant that matches name, or null if its not found.
*/
public static _Fields findByName(String name) {
return byName.get(name);
}
private final short _thriftId;
private final String _fieldName;
_Fields(short thriftId, String fieldName) {
_thriftId = thriftId;
_fieldName = fieldName;
}
public short getThriftFieldId() {
return _thriftId;
}
public String getFieldName() {
return _fieldName;
}
}
// isset id assignments
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.COLUMN, new org.apache.thrift.meta_data.FieldMetaData("column", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CounterColumn.class)));
tmpMap.put(_Fields.SUPER_COLUMN, new org.apache.thrift.meta_data.FieldMetaData("super_column", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CounterSuperColumn.class)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Counter.class, metaDataMap);
}
public Counter() {
}
/**
* Performs a deep copy on <i>other</i>.
*/
public Counter(Counter other) {
if (other.isSetColumn()) {
this.column = new CounterColumn(other.column);
}
if (other.isSetSuper_column()) {
this.super_column = new CounterSuperColumn(other.super_column);
}
}
public Counter deepCopy() {
return new Counter(this);
}
@Override
public void clear() {
this.column = null;
this.super_column = null;
}
public CounterColumn getColumn() {
return this.column;
}
public Counter setColumn(CounterColumn column) {
this.column = column;
return this;
}
public void unsetColumn() {
this.column = null;
}
/** Returns true if field column is set (has been assigned a value) and false otherwise */
public boolean isSetColumn() {
return this.column != null;
}
public void setColumnIsSet(boolean value) {
if (!value) {
this.column = null;
}
}
public CounterSuperColumn getSuper_column() {
return this.super_column;
}
public Counter setSuper_column(CounterSuperColumn super_column) {
this.super_column = super_column;
return this;
}
public void unsetSuper_column() {
this.super_column = null;
}
/** Returns true if field super_column is set (has been assigned a value) and false otherwise */
public boolean isSetSuper_column() {
return this.super_column != null;
}
public void setSuper_columnIsSet(boolean value) {
if (!value) {
this.super_column = null;
}
}
public void setFieldValue(_Fields field, Object value) {
switch (field) {
case COLUMN:
if (value == null) {
unsetColumn();
} else {
setColumn((CounterColumn)value);
}
break;
case SUPER_COLUMN:
if (value == null) {
unsetSuper_column();
} else {
setSuper_column((CounterSuperColumn)value);
}
break;
}
}
public Object getFieldValue(_Fields field) {
switch (field) {
case COLUMN:
return getColumn();
case SUPER_COLUMN:
return getSuper_column();
}
throw new IllegalStateException();
}
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
}
switch (field) {
case COLUMN:
return isSetColumn();
case SUPER_COLUMN:
return isSetSuper_column();
}
throw new IllegalStateException();
}
@Override
public boolean equals(Object that) {
if (that == null)
return false;
if (that instanceof Counter)
return this.equals((Counter)that);
return false;
}
public boolean equals(Counter that) {
if (that == null)
return false;
boolean this_present_column = true && this.isSetColumn();
boolean that_present_column = true && that.isSetColumn();
if (this_present_column || that_present_column) {
if (!(this_present_column && that_present_column))
return false;
if (!this.column.equals(that.column))
return false;
}
boolean this_present_super_column = true && this.isSetSuper_column();
boolean that_present_super_column = true && that.isSetSuper_column();
if (this_present_super_column || that_present_super_column) {
if (!(this_present_super_column && that_present_super_column))
return false;
if (!this.super_column.equals(that.super_column))
return false;
}
return true;
}
@Override
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
boolean present_column = true && (isSetColumn());
builder.append(present_column);
if (present_column)
builder.append(column);
boolean present_super_column = true && (isSetSuper_column());
builder.append(present_super_column);
if (present_super_column)
builder.append(super_column);
return builder.toHashCode();
}
public int compareTo(Counter other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
Counter typedOther = (Counter)other;
lastComparison = Boolean.valueOf(isSetColumn()).compareTo(typedOther.isSetColumn());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetColumn()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.column, typedOther.column);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetSuper_column()).compareTo(typedOther.isSetSuper_column());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetSuper_column()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.super_column, typedOther.super_column);
if (lastComparison != 0) {
return lastComparison;
}
}
return 0;
}
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TField field;
iprot.readStructBegin();
while (true)
{
field = iprot.readFieldBegin();
if (field.type == org.apache.thrift.protocol.TType.STOP) {
break;
}
switch (field.id) {
case 1: // COLUMN
if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
this.column = new CounterColumn();
this.column.read(iprot);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 2: // SUPER_COLUMN
if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
this.super_column = new CounterSuperColumn();
this.super_column.read(iprot);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
iprot.readFieldEnd();
}
iprot.readStructEnd();
// check for required fields of primitive type, which can't be checked in the validate method
validate();
}
public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
validate();
oprot.writeStructBegin(STRUCT_DESC);
if (this.column != null) {
if (isSetColumn()) {
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
this.column.write(oprot);
oprot.writeFieldEnd();
}
}
if (this.super_column != null) {
if (isSetSuper_column()) {
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
this.super_column.write(oprot);
oprot.writeFieldEnd();
}
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("Counter(");
boolean first = true;
if (isSetColumn()) {
sb.append("column:");
if (this.column == null) {
sb.append("null");
} else {
sb.append(this.column);
}
first = false;
}
if (isSetSuper_column()) {
if (!first) sb.append(", ");
sb.append("super_column:");
if (this.super_column == null) {
sb.append("null");
} else {
sb.append(this.super_column);
}
first = false;
}
sb.append(")");
return sb.toString();
}
public void validate() throws org.apache.thrift.TException {
// check for required fields
}
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
try {
write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
}
}
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
try {
read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
}
}
}

View File

@ -43,9 +43,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A Mutation is either an insert (represented by filling column_or_supercolumn), a deletion (represented by filling the deletion attribute),
* a counter addition (represented by filling counter), or a counter deletion (represented by filling counter_deletion).
* @param column_or_supercolumn. An insert to a column or supercolumn
* 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 (possibly counter column or supercolumn)
* @param deletion. A deletion of a column or supercolumn
*/
public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fields>, java.io.Serializable, Cloneable {
@ -53,17 +52,14 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
private static final org.apache.thrift.protocol.TField COLUMN_OR_SUPERCOLUMN_FIELD_DESC = new org.apache.thrift.protocol.TField("column_or_supercolumn", org.apache.thrift.protocol.TType.STRUCT, (short)1);
private static final org.apache.thrift.protocol.TField DELETION_FIELD_DESC = new org.apache.thrift.protocol.TField("deletion", org.apache.thrift.protocol.TType.STRUCT, (short)2);
private static final org.apache.thrift.protocol.TField COUNTER_FIELD_DESC = new org.apache.thrift.protocol.TField("counter", org.apache.thrift.protocol.TType.STRUCT, (short)3);
public ColumnOrSuperColumn column_or_supercolumn;
public Deletion deletion;
public Counter counter;
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
COLUMN_OR_SUPERCOLUMN((short)1, "column_or_supercolumn"),
DELETION((short)2, "deletion"),
COUNTER((short)3, "counter");
DELETION((short)2, "deletion");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@ -82,8 +78,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
return COLUMN_OR_SUPERCOLUMN;
case 2: // DELETION
return DELETION;
case 3: // COUNTER
return COUNTER;
default:
return null;
}
@ -132,8 +126,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ColumnOrSuperColumn.class)));
tmpMap.put(_Fields.DELETION, new org.apache.thrift.meta_data.FieldMetaData("deletion", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Deletion.class)));
tmpMap.put(_Fields.COUNTER, new org.apache.thrift.meta_data.FieldMetaData("counter", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Counter.class)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Mutation.class, metaDataMap);
}
@ -151,9 +143,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
if (other.isSetDeletion()) {
this.deletion = new Deletion(other.deletion);
}
if (other.isSetCounter()) {
this.counter = new Counter(other.counter);
}
}
public Mutation deepCopy() {
@ -164,7 +153,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
public void clear() {
this.column_or_supercolumn = null;
this.deletion = null;
this.counter = null;
}
public ColumnOrSuperColumn getColumn_or_supercolumn() {
@ -215,30 +203,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
}
}
public Counter getCounter() {
return this.counter;
}
public Mutation setCounter(Counter counter) {
this.counter = counter;
return this;
}
public void unsetCounter() {
this.counter = null;
}
/** Returns true if field counter is set (has been assigned a value) and false otherwise */
public boolean isSetCounter() {
return this.counter != null;
}
public void setCounterIsSet(boolean value) {
if (!value) {
this.counter = null;
}
}
public void setFieldValue(_Fields field, Object value) {
switch (field) {
case COLUMN_OR_SUPERCOLUMN:
@ -257,14 +221,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
}
break;
case COUNTER:
if (value == null) {
unsetCounter();
} else {
setCounter((Counter)value);
}
break;
}
}
@ -276,9 +232,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
case DELETION:
return getDeletion();
case COUNTER:
return getCounter();
}
throw new IllegalStateException();
}
@ -294,8 +247,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
return isSetColumn_or_supercolumn();
case DELETION:
return isSetDeletion();
case COUNTER:
return isSetCounter();
}
throw new IllegalStateException();
}
@ -331,15 +282,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
return false;
}
boolean this_present_counter = true && this.isSetCounter();
boolean that_present_counter = true && that.isSetCounter();
if (this_present_counter || that_present_counter) {
if (!(this_present_counter && that_present_counter))
return false;
if (!this.counter.equals(that.counter))
return false;
}
return true;
}
@ -357,11 +299,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
if (present_deletion)
builder.append(deletion);
boolean present_counter = true && (isSetCounter());
builder.append(present_counter);
if (present_counter)
builder.append(counter);
return builder.toHashCode();
}
@ -393,16 +330,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetCounter()).compareTo(typedOther.isSetCounter());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetCounter()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.counter, typedOther.counter);
if (lastComparison != 0) {
return lastComparison;
}
}
return 0;
}
@ -436,14 +363,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 3: // COUNTER
if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
this.counter = new Counter();
this.counter.read(iprot);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
@ -473,13 +392,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
oprot.writeFieldEnd();
}
}
if (this.counter != null) {
if (isSetCounter()) {
oprot.writeFieldBegin(COUNTER_FIELD_DESC);
this.counter.write(oprot);
oprot.writeFieldEnd();
}
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@ -508,16 +420,6 @@ public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fie
}
first = false;
}
if (isSetCounter()) {
if (!first) sb.append(", ");
sb.append("counter:");
if (this.counter == null) {
sb.append("null");
} else {
sb.append(this.counter);
}
first = false;
}
sb.append(")");
return sb.toString();
}

View File

@ -339,12 +339,6 @@ public class CliClient extends CliUserHelp
CfDef cfDef = getCfDef(columnFamily);
boolean isSuperCF = cfDef.column_type.equals("Super");
if (isCounterCF(cfDef))
{
doCounterSlice(keyspace, key, parent, predicate, isSuperCF);
return;
}
List<ColumnOrSuperColumn> columns = thriftClient.get_slice(key, parent, predicate, consistencyLevel);
AbstractType validator;
@ -366,7 +360,7 @@ public class CliClient extends CliUserHelp
sessionState.out.println(")");
}
else
else if (cosc.isSetColumn())
{
Column column = cosc.column;
validator = getValidatorForValue(cfDef, column.getName());
@ -381,23 +375,9 @@ public class CliClient extends CliUserHelp
column.timestamp,
column.isSetTtl() ? String.format(", ttl=%d", column.getTtl()) : "");
}
}
sessionState.out.println("Returned " + columns.size() + " results.");
}
private void doCounterSlice(String keyspace, ByteBuffer key, ColumnParent parent, SlicePredicate predicate, boolean isSuperCF)
throws InvalidRequestException, UnavailableException, TimedOutException, TException, IllegalAccessException, NotFoundException, InstantiationException, NoSuchFieldException
{
String columnFamily = parent.column_family;
List<Counter> columns = thriftClient.get_counter_slice(key, parent, predicate, consistencyLevel);
// Print out super columns or columns.
for (Counter cosc : columns)
{
if (cosc.isSetSuper_column())
else if (cosc.isSetCounter_super_column())
{
CounterSuperColumn superColumn = cosc.super_column;
CounterSuperColumn superColumn = cosc.counter_super_column;
sessionState.out.printf("=> (super_column=%s,", formatColumnName(keyspace, columnFamily, superColumn.name));
for (CounterColumn col : superColumn.getColumns())
@ -406,9 +386,9 @@ public class CliClient extends CliUserHelp
}
sessionState.out.println(")");
}
else
else // cosc.isSetCounter_column()
{
CounterColumn column = cosc.column;
CounterColumn column = cosc.counter_column;
String formattedName = isSuperCF
? formatSubcolumnName(keyspace, columnFamily, column.name)
: formatColumnName(keyspace, columnFamily, column.name);
@ -562,7 +542,7 @@ public class CliClient extends CliUserHelp
CounterColumn column;
try
{
column = thriftClient.get_counter(key, path, consistencyLevel).column;
column = thriftClient.get(key, path, consistencyLevel).counter_column;
}
catch (NotFoundException e)
{

View File

@ -33,7 +33,6 @@ import org.apache.cassandra.io.ICompactSerializer;
import org.apache.cassandra.net.Message;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.ColumnOrSuperColumn;
import org.apache.cassandra.thrift.Counter;
import org.apache.cassandra.thrift.Deletion;
import org.apache.cassandra.thrift.Mutation;
import org.apache.cassandra.thrift.SlicePredicate;
@ -243,10 +242,6 @@ public class RowMutation implements IMutation, MessageProducer
{
addColumnOrSuperColumnToRowMutation(rm, cfName, mutation.column_or_supercolumn);
}
if (mutation.counter != null)
{
addCounterToRowMutation(rm, cfName, mutation.counter);
}
}
}
return rm;
@ -295,31 +290,27 @@ public class RowMutation implements IMutation, MessageProducer
private static void addColumnOrSuperColumnToRowMutation(RowMutation rm, String cfName, ColumnOrSuperColumn cosc)
{
if (cosc.column == null)
if (cosc.super_column != null)
{
for (org.apache.cassandra.thrift.Column column : cosc.super_column.columns)
{
rm.add(new QueryPath(cfName, cosc.super_column.name, column.name), column.value, column.timestamp, column.ttl);
}
}
else
else if (cosc.column != null)
{
rm.add(new QueryPath(cfName, null, cosc.column.name), cosc.column.value, cosc.column.timestamp, cosc.column.ttl);
}
}
private static void addCounterToRowMutation(RowMutation rm, String cfName, Counter counter)
{
if (counter.column == null)
else if (cosc.counter_super_column != null)
{
for (org.apache.cassandra.thrift.CounterColumn column : counter.super_column.columns)
for (org.apache.cassandra.thrift.CounterColumn column : cosc.counter_super_column.columns)
{
rm.addCounter(new QueryPath(cfName, counter.super_column.name, column.name), column.value);
rm.addCounter(new QueryPath(cfName, cosc.counter_super_column.name, column.name), column.value);
}
}
else
else // cosc.counter_column != null
{
rm.addCounter(new QueryPath(cfName, null, counter.column.name), counter.column.value);
rm.addCounter(new QueryPath(cfName, null, cosc.counter_column.name), cosc.counter_column.value);
}
}

View File

@ -65,6 +65,7 @@ public class CassandraServer implements Cassandra.Iface
private final static List<ColumnOrSuperColumn> EMPTY_COLUMNS = Collections.emptyList();
private final static List<Column> EMPTY_SUBCOLUMNS = Collections.emptyList();
private final static List<CounterColumn> EMPTY_COUNTER_SUBCOLUMNS = Collections.emptyList();
// thread local state containing session information
public final ThreadLocal<ClientState> clientState = new ThreadLocal<ClientState>()
@ -157,6 +158,28 @@ public class CassandraServer implements Cassandra.Iface
return thriftColumns;
}
public List<CounterColumn> thriftifyCounterSubColumns(Collection<IColumn> columns)
{
if (columns == null || columns.isEmpty())
{
return EMPTY_COUNTER_SUBCOLUMNS;
}
ArrayList<CounterColumn> thriftColumns = new ArrayList<CounterColumn>(columns.size());
for (IColumn column : columns)
{
if (column.isMarkedForDelete())
{
continue;
}
assert column instanceof org.apache.cassandra.db.CounterColumn;
CounterColumn thrift_column = new CounterColumn(column.name(), CounterContext.instance().total(column.value()));
thriftColumns.add(thrift_column);
}
return thriftColumns;
}
public List<ColumnOrSuperColumn> thriftifyColumns(Collection<IColumn> columns, boolean reverseOrder)
{
ArrayList<ColumnOrSuperColumn> thriftColumns = new ArrayList<ColumnOrSuperColumn>(columns.size());
@ -166,12 +189,20 @@ public class CassandraServer implements Cassandra.Iface
{
continue;
}
Column thrift_column = new Column(column.name(), column.value(), column.timestamp());
if (column instanceof ExpiringColumn)
if (column instanceof org.apache.cassandra.db.CounterColumn)
{
thrift_column.setTtl(((ExpiringColumn) column).getTimeToLive());
CounterColumn thrift_column = new CounterColumn(column.name(), CounterContext.instance().total(column.value()));
thriftColumns.add(new ColumnOrSuperColumn().setCounter_column(thrift_column));
}
else
{
Column thrift_column = new Column(column.name(), column.value(), column.timestamp());
if (column instanceof ExpiringColumn)
{
thrift_column.setTtl(((ExpiringColumn) column).getTimeToLive());
}
thriftColumns.add(new ColumnOrSuperColumn().setColumn(thrift_column));
}
thriftColumns.add(new ColumnOrSuperColumn().setColumn(thrift_column));
}
// we have to do the reversing here, since internally we pass results around in ColumnFamily
@ -182,6 +213,14 @@ public class CassandraServer implements Cassandra.Iface
return thriftColumns;
}
private List<ColumnOrSuperColumn> thriftifySuperColumns(Collection<IColumn> columns, boolean reverseOrder, boolean isCounterCF)
{
if (isCounterCF)
return thriftifyCounterSuperColumns(columns, reverseOrder);
else
return thriftifySuperColumns(columns, reverseOrder);
}
private List<ColumnOrSuperColumn> thriftifySuperColumns(Collection<IColumn> columns, boolean reverseOrder)
{
ArrayList<ColumnOrSuperColumn> thriftSuperColumns = new ArrayList<ColumnOrSuperColumn>(columns.size());
@ -202,6 +241,26 @@ public class CassandraServer implements Cassandra.Iface
return thriftSuperColumns;
}
private List<ColumnOrSuperColumn> thriftifyCounterSuperColumns(Collection<IColumn> columns, boolean reverseOrder)
{
ArrayList<ColumnOrSuperColumn> thriftSuperColumns = new ArrayList<ColumnOrSuperColumn>(columns.size());
for (IColumn column : columns)
{
List<CounterColumn> subcolumns = thriftifyCounterSubColumns(column.getSubColumns());
if (subcolumns.isEmpty())
{
continue;
}
CounterSuperColumn superColumn = new CounterSuperColumn(column.name(), subcolumns);
thriftSuperColumns.add(new ColumnOrSuperColumn().setCounter_super_column(superColumn));
}
if (reverseOrder)
Collections.reverse(thriftSuperColumns);
return thriftSuperColumns;
}
private Map<ByteBuffer, List<ColumnOrSuperColumn>> getSlice(List<ReadCommand> commands, ConsistencyLevel consistency_level)
throws InvalidRequestException, UnavailableException, TimedOutException
{
@ -232,9 +291,14 @@ public class CassandraServer implements Cassandra.Iface
return thriftifyColumns(subcolumns, reverseOrder);
}
if (cf.isSuper())
return thriftifySuperColumns(cf.getSortedColumns(), reverseOrder);
{
boolean isCounterCF = cf.metadata().getDefaultValidator().isCommutative();
return thriftifySuperColumns(cf.getSortedColumns(), reverseOrder, isCounterCF);
}
else
{
return thriftifyColumns(cf.getSortedColumns(), reverseOrder);
}
}
public List<ColumnOrSuperColumn> get_slice(ByteBuffer key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
@ -243,7 +307,7 @@ public class CassandraServer implements Cassandra.Iface
logger.debug("get_slice");
state().hasColumnFamilyAccess(column_parent.column_family, Permission.READ);
return multigetSliceInternal(state().getKeyspace(), Collections.singletonList(key), column_parent, predicate, consistency_level, false).get(key);
return multigetSliceInternal(state().getKeyspace(), Collections.singletonList(key), column_parent, predicate, consistency_level).get(key);
}
public Map<ByteBuffer, List<ColumnOrSuperColumn>> multiget_slice(List<ByteBuffer> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
@ -252,13 +316,13 @@ public class CassandraServer implements Cassandra.Iface
logger.debug("multiget_slice");
state().hasColumnFamilyAccess(column_parent.column_family, Permission.READ);
return multigetSliceInternal(state().getKeyspace(), keys, column_parent, predicate, consistency_level, false);
return multigetSliceInternal(state().getKeyspace(), keys, column_parent, predicate, consistency_level);
}
private Map<ByteBuffer, List<ColumnOrSuperColumn>> multigetSliceInternal(String keyspace, List<ByteBuffer> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level, boolean isCommutativeOp)
private Map<ByteBuffer, List<ColumnOrSuperColumn>> multigetSliceInternal(String keyspace, List<ByteBuffer> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
throws InvalidRequestException, UnavailableException, TimedOutException
{
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, column_parent.column_family, isCommutativeOp);
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, column_parent.column_family);
ThriftValidation.validateColumnParent(metadata, column_parent);
ThriftValidation.validatePredicate(metadata, column_parent, predicate);
@ -284,13 +348,13 @@ public class CassandraServer implements Cassandra.Iface
return getSlice(commands, consistency_level);
}
private ColumnOrSuperColumn internal_get(ByteBuffer key, ColumnPath column_path, ConsistencyLevel consistency_level, boolean isCommutativeOp)
private ColumnOrSuperColumn internal_get(ByteBuffer key, ColumnPath column_path, ConsistencyLevel consistency_level)
throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException
{
state().hasColumnFamilyAccess(column_path.column_family, Permission.READ);
String keyspace = state().getKeyspace();
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, column_path.column_family, isCommutativeOp);
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, column_path.column_family);
ThriftValidation.validateColumnPath(metadata, column_path);
QueryPath path = new QueryPath(column_path.column_family, column_path.column == null ? null : column_path.super_column);
@ -316,7 +380,7 @@ public class CassandraServer implements Cassandra.Iface
{
logger.debug("get");
return internal_get(key, column_path, consistency_level, false);
return internal_get(key, column_path, consistency_level);
}
public int get_count(ByteBuffer key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
@ -338,7 +402,7 @@ public class CassandraServer implements Cassandra.Iface
String keyspace = state().getKeyspace();
Map<ByteBuffer, Integer> counts = new HashMap<ByteBuffer, Integer>();
Map<ByteBuffer, List<ColumnOrSuperColumn>> columnFamiliesMap = multigetSliceInternal(keyspace, keys, column_parent, predicate, consistency_level, false);
Map<ByteBuffer, List<ColumnOrSuperColumn>> columnFamiliesMap = multigetSliceInternal(keyspace, keys, column_parent, predicate, consistency_level);
for (Map.Entry<ByteBuffer, List<ColumnOrSuperColumn>> cf : columnFamiliesMap.entrySet()) {
counts.put(cf.getKey(), cf.getValue().size());
@ -398,8 +462,6 @@ public class CassandraServer implements Cassandra.Iface
cfamsSeen.add(cfName);
}
boolean isCommutativeOp = false;
boolean isOnlyDeletion = true;
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, cfName);
ThriftValidation.validateKey(metadata, key);
@ -1028,73 +1090,6 @@ public class CassandraServer implements Cassandra.Iface
doInsert(consistency_level, Arrays.asList(rm));
}
private Counter getCounter(ColumnOrSuperColumn cosc)
{
if (cosc.isSetColumn()) {
return new Counter().setColumn(new CounterColumn(cosc.column.name, CounterContext.instance().total(cosc.column.value)));
} else if(cosc.isSetSuper_column()) {
List<CounterColumn> cc = new ArrayList<CounterColumn>(cosc.super_column.columns.size());
for (Column col : cosc.super_column.columns)
{
cc.add(new CounterColumn(col.name, CounterContext.instance().total(col.value)));
}
return new Counter().setSuper_column(new CounterSuperColumn(cosc.super_column.name, cc));
}
return null;
}
public Counter get_counter(ByteBuffer key, ColumnPath path, ConsistencyLevel consistency_level)
throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException
{
logger.debug("get_counter");
String keyspace = state().getKeyspace();
return getCounter(internal_get(key, path, consistency_level, true));
}
private List<Counter> getCounters(List<ColumnOrSuperColumn> cosc)
{
List<Counter> rv = new ArrayList<Counter>(cosc.size());
for (ColumnOrSuperColumn columnOrSuperColumn : cosc)
{
Counter c = getCounter(columnOrSuperColumn);
if (c != null) {
rv.add(c);
}
}
return rv;
}
public List<Counter> get_counter_slice(ByteBuffer key, ColumnParent column_parent, SlicePredicate predicate,
ConsistencyLevel consistency_level) throws InvalidRequestException, UnavailableException, TimedOutException,
TException
{
if (logger.isDebugEnabled())
logger.debug("get_counter_slice");
state().hasColumnFamilyAccess(column_parent.column_family, Permission.READ);
List<ColumnOrSuperColumn> cosc = multigetSliceInternal(state().getKeyspace(), Collections.singletonList(key), column_parent, predicate, consistency_level, true).get(key);
return getCounters(cosc);
}
public Map<ByteBuffer, List<Counter>> multiget_counter_slice(List<ByteBuffer> keys, ColumnParent column_parent,
SlicePredicate predicate, ConsistencyLevel consistency_level) throws InvalidRequestException,
UnavailableException, TimedOutException, TException
{
if (logger.isDebugEnabled())
logger.debug("multiget_counter_slice");
state().hasColumnFamilyAccess(column_parent.column_family, Permission.READ);
Map<ByteBuffer, List<ColumnOrSuperColumn>> slices = multigetSliceInternal(state().getKeyspace(), keys, column_parent, predicate, consistency_level, true);
Map<ByteBuffer, List<Counter>> rv = new HashMap<ByteBuffer, List<Counter>>(slices.size());
for (Entry<ByteBuffer, List<ColumnOrSuperColumn>> entry : slices.entrySet())
{
rv.put(entry.getKey(), getCounters(entry.getValue()));
}
return rv;
}
public void remove_counter(ByteBuffer key, ColumnPath path, ConsistencyLevel consistency_level)
throws InvalidRequestException, UnavailableException, TimedOutException, TException
{

View File

@ -96,7 +96,7 @@ public class ThriftValidation
return metadata;
}
// This should only be used when the operation should be authorized whether this is a counter CF or not
// To be used when the operation should be authorized whether this is a counter CF or not
public static CFMetaData validateColumnFamily(String tablename, String cfName) throws InvalidRequestException
{
validateTable(tablename);
@ -249,8 +249,22 @@ public class ThriftValidation
public static void validateColumnOrSuperColumn(CFMetaData metadata, ColumnOrSuperColumn cosc)
throws InvalidRequestException
{
boolean isCommutative = metadata.getDefaultValidator().isCommutative();
int nulls = 0;
if (cosc.column == null) nulls++;
if (cosc.super_column == null) nulls++;
if (cosc.counter_column == null) nulls++;
if (cosc.counter_super_column == null) nulls++;
if (nulls != 3)
throw new InvalidRequestException("ColumnOrSuperColumn must have one (and only one) of column, super_column, counter and counter_super_column");
if (cosc.column != null)
{
if (isCommutative)
throw new InvalidRequestException("invalid operation for commutative columnfamily " + metadata.cfName);
validateTtl(cosc.column);
validateColumnPath(metadata, new ColumnPath(metadata.cfName).setSuper_column((ByteBuffer)null).setColumn(cosc.column.name));
validateColumnData(metadata, cosc.column);
@ -258,6 +272,9 @@ public class ThriftValidation
if (cosc.super_column != null)
{
if (isCommutative)
throw new InvalidRequestException("invalid operation for commutative columnfamily " + metadata.cfName);
for (Column c : cosc.super_column.columns)
{
validateColumnPath(metadata, new ColumnPath(metadata.cfName).setSuper_column(cosc.super_column.name).setColumn(c.name));
@ -265,24 +282,22 @@ public class ThriftValidation
}
}
if (cosc.column == null && cosc.super_column == null)
throw new InvalidRequestException("ColumnOrSuperColumn must have one or both of Column or SuperColumn");
}
public static void validateCounter(CFMetaData metadata, Counter counter)
throws InvalidRequestException
{
if (counter.column != null)
validateColumnPath(metadata, new ColumnPath(metadata.cfName).setSuper_column((ByteBuffer)null).setColumn(counter.column.name));
if (counter.super_column != null)
if (cosc.counter_column != null)
{
for (CounterColumn c : counter.super_column.columns)
validateColumnPath(metadata, new ColumnPath(metadata.cfName).setSuper_column(counter.super_column.name).setColumn(c.name));
if (!isCommutative)
throw new InvalidRequestException("invalid operation for non commutative columnfamily " + metadata.cfName);
validateColumnPath(metadata, new ColumnPath(metadata.cfName).setSuper_column((ByteBuffer)null).setColumn(cosc.counter_column.name));
}
if (counter.column == null && counter.super_column == null)
throw new InvalidRequestException("Counter must have one or both of column or super_column");
if (cosc.counter_super_column != null)
{
if (!isCommutative)
throw new InvalidRequestException("invalid operation for non commutative columnfamily " + metadata.cfName);
for (CounterColumn c : cosc.counter_super_column.columns)
validateColumnPath(metadata, new ColumnPath(metadata.cfName).setSuper_column(cosc.counter_super_column.name).setColumn(c.name));
}
}
private static void validateTtl(Column column) throws InvalidRequestException
@ -300,34 +315,21 @@ public class ThriftValidation
{
ColumnOrSuperColumn cosc = mut.column_or_supercolumn;
Deletion del = mut.deletion;
Counter counter = mut.counter;
boolean isCommutative = metadata.getDefaultValidator().isCommutative();
int nulls = 0;
if (cosc == null) nulls++;
if (del == null) nulls++;
if (counter == null) nulls++;
if (nulls != 2)
if (nulls != 1)
{
throw new InvalidRequestException("mutation must have one and only one of column_or_supercolumn, deletion, counter or counter_deletion");
throw new InvalidRequestException("mutation must have one and only one of column_or_supercolumn or deletion");
}
if (cosc != null)
{
if (isCommutative)
throw new InvalidRequestException("invalid operation for commutative columnfamily " + metadata.cfName);
validateColumnOrSuperColumn(metadata, cosc);
}
if (counter != null)
{
if (!isCommutative)
throw new InvalidRequestException("invalid operation for non commutative columnfamily " + metadata.cfName);
validateCounter(metadata, counter);
}
if (del != null)
else
{
validateDeletion(metadata, del);
}

View File

@ -55,13 +55,6 @@ def _assert_no_columnpath(key, column_path):
except NotFoundException:
assert True, 'column did not exist'
def _assert_no_columnpath_counter(key, column_path):
try:
client.get_counter(key, column_path, ConsistencyLevel.ONE)
assert False, ('columnpath %s existed in %s when it should not' % (column_path, key))
except NotFoundException:
assert True, 'column did not exist'
def _insert_simple(block=True):
return _insert_multi(['key1'])
@ -1504,18 +1497,18 @@ class TestMutations(ThriftTester):
# insert positive and negative values and check the counts
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(0.1)
rv1 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1
rv1 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d2), ConsistencyLevel.ONE)
time.sleep(0.1)
rv2 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.column.value == (d1+d2)
rv2 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == (d1+d2)
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d3), ConsistencyLevel.ONE)
time.sleep(0.1)
rv3 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv3.column.value == (d1+d2+d3)
rv3 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv3.counter_column.value == (d1+d2+d3)
def test_incr_decr_super_add(self):
_set_keyspace('Keyspace1')
@ -1527,19 +1520,19 @@ class TestMutations(ThriftTester):
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c2', d2), ConsistencyLevel.ONE)
time.sleep(0.1)
rv1 = client.get_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1'), ConsistencyLevel.ONE)
assert rv1.super_column.columns[0].value == d1
assert rv1.super_column.columns[1].value == d2
rv1 = client.get('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1'), ConsistencyLevel.ONE)
assert rv1.counter_super_column.columns[0].value == d1
assert rv1.counter_super_column.columns[1].value == d2
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d2), ConsistencyLevel.ONE)
time.sleep(0.1)
rv2 = client.get_counter('key1', ColumnPath('SuperCounter1', 'sc1', 'c1'), ConsistencyLevel.ONE)
assert rv2.column.value == (d1+d2)
rv2 = client.get('key1', ColumnPath('SuperCounter1', 'sc1', 'c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == (d1+d2)
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d3), ConsistencyLevel.ONE)
time.sleep(0.1)
rv3 = client.get_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv3.column.value == (d1+d2+d3)
rv3 = client.get('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv3.counter_column.value == (d1+d2+d3)
def test_incr_standard_remove(self):
_set_keyspace('Keyspace1')
@ -1549,22 +1542,22 @@ class TestMutations(ThriftTester):
# insert value and check it exists
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv1 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1
rv1 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1
# remove the previous column and check that it is gone
client.remove_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='Counter1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='Counter1', column='c1'))
# insert again and this time delete the whole row, check that it is gone
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv2 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.column.value == d1
rv2 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == d1
client.remove_counter('key1', ColumnPath(column_family='Counter1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='Counter1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='Counter1', column='c1'))
def test_incr_super_remove(self):
_set_keyspace('Keyspace1')
@ -1574,22 +1567,22 @@ class TestMutations(ThriftTester):
# insert value and check it exists
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv1 = client.get_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1
rv1 = client.get('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1
# remove the previous column and check that it is gone
client.remove_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
# insert again and this time delete the whole row, check that it is gone
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv2 = client.get_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv2.column.value == d1
rv2 = client.get('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == d1
client.remove_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
def test_incr_decr_standard_remove(self):
_set_keyspace('Keyspace1')
@ -1599,22 +1592,22 @@ class TestMutations(ThriftTester):
# insert value and check it exists
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv1 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1
rv1 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1
# remove the previous column and check that it is gone
client.remove_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='Counter1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='Counter1', column='c1'))
# insert again and this time delete the whole row, check that it is gone
client.add('key1', ColumnParent(column_family='Counter1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv2 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.column.value == d1
rv2 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == d1
client.remove_counter('key1', ColumnPath(column_family='Counter1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='Counter1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='Counter1', column='c1'))
def test_incr_decr_super_remove(self):
_set_keyspace('Keyspace1')
@ -1624,22 +1617,22 @@ class TestMutations(ThriftTester):
# insert value and check it exists
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv1 = client.get_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1
rv1 = client.get('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1
# remove the previous column and check that it is gone
client.remove_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
# insert again and this time delete the whole row, check that it is gone
client.add('key1', ColumnParent(column_family='SuperCounter1', super_column='sc1'), CounterColumn('c1', d1), ConsistencyLevel.ONE)
time.sleep(5)
rv2 = client.get_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv2.column.value == d1
rv2 = client.get('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == d1
client.remove_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1'), ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='SuperCounter1', super_column='sc1', column='c1'))
def test_incr_decr_standard_batch_add(self):
_set_keyspace('Keyspace1')
@ -1647,15 +1640,15 @@ class TestMutations(ThriftTester):
d1 = 12
d2 = -21
update_map = {'key1': {'Counter1': [
Mutation(counter=Counter(column=CounterColumn('c1', d1))),
Mutation(counter=Counter(column=CounterColumn('c1', d2))),
Mutation(column_or_supercolumn=ColumnOrSuperColumn(counter_column=CounterColumn('c1', d1))),
Mutation(column_or_supercolumn=ColumnOrSuperColumn(counter_column=CounterColumn('c1', d2))),
]}}
# insert positive and negative values and check the counts
client.batch_mutate(update_map, ConsistencyLevel.ONE)
time.sleep(0.1)
rv1 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1+d2
rv1 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1+d2
def test_incr_decr_standard_batch_remove(self):
_set_keyspace('Keyspace1')
@ -1665,13 +1658,13 @@ class TestMutations(ThriftTester):
# insert positive and negative values and check the counts
update_map = {'key1': {'Counter1': [
Mutation(counter=Counter(column=CounterColumn('c1', d1))),
Mutation(counter=Counter(column=CounterColumn('c1', d2))),
Mutation(column_or_supercolumn=ColumnOrSuperColumn(counter_column=CounterColumn('c1', d1))),
Mutation(column_or_supercolumn=ColumnOrSuperColumn(counter_column=CounterColumn('c1', d2))),
]}}
client.batch_mutate(update_map, ConsistencyLevel.ONE)
time.sleep(5)
rv1 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.column.value == d1+d2
rv1 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv1.counter_column.value == d1+d2
# remove the previous column and check that it is gone
update_map = {'key1': {'Counter1': [
@ -1679,24 +1672,24 @@ class TestMutations(ThriftTester):
]}}
client.batch_mutate(update_map, ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='Counter1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='Counter1', column='c1'))
# insert again and this time delete the whole row, check that it is gone
update_map = {'key1': {'Counter1': [
Mutation(counter=Counter(column=CounterColumn('c1', d1))),
Mutation(counter=Counter(column=CounterColumn('c1', d2))),
Mutation(column_or_supercolumn=ColumnOrSuperColumn(counter_column=CounterColumn('c1', d1))),
Mutation(column_or_supercolumn=ColumnOrSuperColumn(counter_column=CounterColumn('c1', d2))),
]}}
client.batch_mutate(update_map, ConsistencyLevel.ONE)
time.sleep(5)
rv2 = client.get_counter('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.column.value == d1+d2
rv2 = client.get('key1', ColumnPath(column_family='Counter1', column='c1'), ConsistencyLevel.ONE)
assert rv2.counter_column.value == d1+d2
update_map = {'key1': {'Counter1': [
Mutation(deletion=Deletion()),
]}}
client.batch_mutate(update_map, ConsistencyLevel.ONE)
time.sleep(5)
_assert_no_columnpath_counter('key1', ColumnPath(column_family='Counter1', column='c1'))
_assert_no_columnpath('key1', ColumnPath(column_family='Counter1', column='c1'))
def test_incr_decr_standard_slice(self):
_set_keyspace('Keyspace1')
@ -1712,10 +1705,10 @@ class TestMutations(ThriftTester):
time.sleep(0.1)
# insert positive and negative values and check the counts
counters = client.get_counter_slice('key1', ColumnParent('Counter1'), SlicePredicate(['c3', 'c4']), ConsistencyLevel.ONE)
counters = client.get_slice('key1', ColumnParent('Counter1'), SlicePredicate(['c3', 'c4']), ConsistencyLevel.ONE)
assert counters[0].column.value == d1+d2
assert counters[1].column.value == d1
assert counters[0].counter_column.value == d1+d2
assert counters[1].counter_column.value == d1
def test_incr_decr_standard_muliget_slice(self):
_set_keyspace('Keyspace1')
@ -1737,12 +1730,12 @@ class TestMutations(ThriftTester):
time.sleep(0.1)
# insert positive and negative values and check the counts
counters = client.multiget_counter_slice(['key1', 'key2'], ColumnParent('Counter1'), SlicePredicate(['c3', 'c4']), ConsistencyLevel.ONE)
counters = client.multiget_slice(['key1', 'key2'], ColumnParent('Counter1'), SlicePredicate(['c3', 'c4']), ConsistencyLevel.ONE)
assert counters['key1'][0].column.value == d1+d2
assert counters['key1'][1].column.value == d1
assert counters['key2'][0].column.value == d1+d2
assert counters['key2'][1].column.value == d1
assert counters['key1'][0].counter_column.value == d1+d2
assert counters['key1'][1].counter_column.value == d1
assert counters['key2'][0].counter_column.value == d1+d2
assert counters['key2'][1].counter_column.value == d1
def test_index_scan(self):
_set_keyspace('Keyspace1')

View File

@ -111,8 +111,8 @@ public class CounterAdder extends Operation
for (CounterSuperColumn s : superColumns)
{
Counter counter = new Counter().setSuper_column(s);
mutations.add(new Mutation().setCounter(counter));
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn().setCounter_super_column(s);
mutations.add(new Mutation().setColumn_or_supercolumn(cosc));
}
mutationMap.put("SuperCounter1", mutations);
@ -127,8 +127,8 @@ public class CounterAdder extends Operation
for (CounterColumn c : columns)
{
Counter counter = new Counter().setColumn(c);
mutations.add(new Mutation().setCounter(counter));
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn().setCounter_column(c);
mutations.add(new Mutation().setColumn_or_supercolumn(cosc));
}
mutationMap.put("Counter1", mutations);

View File

@ -77,8 +77,8 @@ public class CounterGetter extends Operation
try
{
List<Counter> counters;
counters = client.get_counter_slice(key, parent, predicate, session.getConsistencyLevel());
List<ColumnOrSuperColumn> counters;
counters = client.get_slice(key, parent, predicate, session.getConsistencyLevel());
success = (counters.size() != 0);
}
catch (Exception e)
@ -122,8 +122,8 @@ public class CounterGetter extends Operation
try
{
List<Counter> counters;
counters = client.get_counter_slice(keyBuffer, parent, predicate, session.getConsistencyLevel());
List<ColumnOrSuperColumn> counters;
counters = client.get_slice(keyBuffer, parent, predicate, session.getConsistencyLevel());
success = (counters.size() != 0);
}
catch (Exception e)