Skip to content

Commit

Permalink
add forwards-compatible ConsistencyLevel parameter to get_key_range. …
Browse files Browse the repository at this point in the history
…Currently it is a no-op. patch by Chris Goffinet; reviewed by jbellis for CASSANDRA-322

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@809639 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jbellis committed Aug 31, 2009
1 parent 533dcad commit fa1d99a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 21 deletions.
2 changes: 1 addition & 1 deletion interface/cassandra.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ service Cassandra {
throws (1: InvalidRequestException ire, 2: UnavailableException ue),

# range query: returns matching keys
list<string> get_key_range(1:string keyspace, 2:string column_family, 3:string start="", 4:string finish="", 5:i32 count=100)
list<string> get_key_range(1:string keyspace, 2:string column_family, 3:string start="", 4:string finish="", 5:i32 count=100, 6:ConsistencyLevel consistency_level=1)
throws (1: InvalidRequestException ire),

/////////////////////////////////////////////////////////////////////////////////////
Expand Down
118 changes: 111 additions & 7 deletions interface/gen-java/org/apache/cassandra/service/Cassandra.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface Iface {

public void remove(String keyspace, String key, ColumnPath column_path, long timestamp, int consistency_level) throws InvalidRequestException, UnavailableException, TException;

public List<String> get_key_range(String keyspace, String column_family, String start, String finish, int count) throws InvalidRequestException, TException;
public List<String> get_key_range(String keyspace, String column_family, String start, String finish, int count, int consistency_level) throws InvalidRequestException, TException;

public String get_string_property(String property) throws TException;

Expand Down Expand Up @@ -420,13 +420,13 @@ public void recv_remove() throws InvalidRequestException, UnavailableException,
return;
}

public List<String> get_key_range(String keyspace, String column_family, String start, String finish, int count) throws InvalidRequestException, TException
public List<String> get_key_range(String keyspace, String column_family, String start, String finish, int count, int consistency_level) throws InvalidRequestException, TException
{
send_get_key_range(keyspace, column_family, start, finish, count);
send_get_key_range(keyspace, column_family, start, finish, count, consistency_level);
return recv_get_key_range();
}

public void send_get_key_range(String keyspace, String column_family, String start, String finish, int count) throws TException
public void send_get_key_range(String keyspace, String column_family, String start, String finish, int count, int consistency_level) throws TException
{
oprot_.writeMessageBegin(new TMessage("get_key_range", TMessageType.CALL, seqid_));
get_key_range_args args = new get_key_range_args();
Expand All @@ -435,6 +435,7 @@ public void send_get_key_range(String keyspace, String column_family, String sta
args.start = start;
args.finish = finish;
args.count = count;
args.consistency_level = consistency_level;
args.write(oprot_);
oprot_.writeMessageEnd();
oprot_.getTransport().flush();
Expand Down Expand Up @@ -850,7 +851,7 @@ public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TExcepti
iprot.readMessageEnd();
get_key_range_result result = new get_key_range_result();
try {
result.success = iface_.get_key_range(args.keyspace, args.column_family, args.start, args.finish, args.count);
result.success = iface_.get_key_range(args.keyspace, args.column_family, args.start, args.finish, args.count, args.consistency_level);
} catch (InvalidRequestException ire) {
result.ire = ire;
} catch (Throwable th) {
Expand Down Expand Up @@ -7841,6 +7842,7 @@ public static class get_key_range_args implements TBase, java.io.Serializable, C
private static final TField START_FIELD_DESC = new TField("start", TType.STRING, (short)3);
private static final TField FINISH_FIELD_DESC = new TField("finish", TType.STRING, (short)4);
private static final TField COUNT_FIELD_DESC = new TField("count", TType.I32, (short)5);
private static final TField CONSISTENCY_LEVEL_FIELD_DESC = new TField("consistency_level", TType.I32, (short)6);

public String keyspace;
public static final int KEYSPACE = 1;
Expand All @@ -7852,10 +7854,17 @@ public static class get_key_range_args implements TBase, java.io.Serializable, C
public static final int FINISH = 4;
public int count;
public static final int COUNT = 5;
/**
*
* @see ConsistencyLevel
*/
public int consistency_level;
public static final int CONSISTENCY_LEVEL = 6;

// isset id assignments
private static final int __COUNT_ISSET_ID = 0;
private BitSet __isset_bit_vector = new BitSet(1);
private static final int __CONSISTENCY_LEVEL_ISSET_ID = 1;
private BitSet __isset_bit_vector = new BitSet(2);

public static final Map<Integer, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new HashMap<Integer, FieldMetaData>() {{
put(KEYSPACE, new FieldMetaData("keyspace", TFieldRequirementType.DEFAULT,
Expand All @@ -7868,6 +7877,8 @@ public static class get_key_range_args implements TBase, java.io.Serializable, C
new FieldValueMetaData(TType.STRING)));
put(COUNT, new FieldMetaData("count", TFieldRequirementType.DEFAULT,
new FieldValueMetaData(TType.I32)));
put(CONSISTENCY_LEVEL, new FieldMetaData("consistency_level", TFieldRequirementType.DEFAULT,
new FieldValueMetaData(TType.I32)));
}});

static {
Expand All @@ -7881,14 +7892,17 @@ public get_key_range_args() {

this.count = 100;

this.consistency_level = 1;

}

public get_key_range_args(
String keyspace,
String column_family,
String start,
String finish,
int count)
int count,
int consistency_level)
{
this();
this.keyspace = keyspace;
Expand All @@ -7897,6 +7911,8 @@ public get_key_range_args(
this.finish = finish;
this.count = count;
setCountIsSet(true);
this.consistency_level = consistency_level;
setConsistency_levelIsSet(true);
}

/**
Expand All @@ -7918,6 +7934,7 @@ public get_key_range_args(get_key_range_args other) {
this.finish = other.finish;
}
this.count = other.count;
this.consistency_level = other.consistency_level;
}

@Override
Expand Down Expand Up @@ -8044,6 +8061,37 @@ public void setCountIsSet(boolean value) {
__isset_bit_vector.set(__COUNT_ISSET_ID, value);
}

/**
*
* @see ConsistencyLevel
*/
public int getConsistency_level() {
return this.consistency_level;
}

/**
*
* @see ConsistencyLevel
*/
public get_key_range_args setConsistency_level(int consistency_level) {
this.consistency_level = consistency_level;
setConsistency_levelIsSet(true);
return this;
}

public void unsetConsistency_level() {
__isset_bit_vector.clear(__CONSISTENCY_LEVEL_ISSET_ID);
}

// Returns true if field consistency_level is set (has been asigned a value) and false otherwise
public boolean isSetConsistency_level() {
return __isset_bit_vector.get(__CONSISTENCY_LEVEL_ISSET_ID);
}

public void setConsistency_levelIsSet(boolean value) {
__isset_bit_vector.set(__CONSISTENCY_LEVEL_ISSET_ID, value);
}

public void setFieldValue(int fieldID, Object value) {
switch (fieldID) {
case KEYSPACE:
Expand Down Expand Up @@ -8086,6 +8134,14 @@ public void setFieldValue(int fieldID, Object value) {
}
break;

case CONSISTENCY_LEVEL:
if (value == null) {
unsetConsistency_level();
} else {
setConsistency_level((Integer)value);
}
break;

default:
throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
}
Expand All @@ -8108,6 +8164,9 @@ public Object getFieldValue(int fieldID) {
case COUNT:
return new Integer(getCount());

case CONSISTENCY_LEVEL:
return getConsistency_level();

default:
throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
}
Expand All @@ -8126,6 +8185,8 @@ public boolean isSet(int fieldID) {
return isSetFinish();
case COUNT:
return isSetCount();
case CONSISTENCY_LEVEL:
return isSetConsistency_level();
default:
throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
}
Expand Down Expand Up @@ -8189,6 +8250,15 @@ public boolean equals(get_key_range_args that) {
return false;
}

boolean this_present_consistency_level = true;
boolean that_present_consistency_level = true;
if (this_present_consistency_level || that_present_consistency_level) {
if (!(this_present_consistency_level && that_present_consistency_level))
return false;
if (this.consistency_level != that.consistency_level)
return false;
}

return true;
}

Expand Down Expand Up @@ -8245,6 +8315,14 @@ public int compareTo(get_key_range_args other) {
if (lastComparison != 0) {
return lastComparison;
}
lastComparison = Boolean.valueOf(isSetConsistency_level()).compareTo(isSetConsistency_level());
if (lastComparison != 0) {
return lastComparison;
}
lastComparison = TBaseHelper.compareTo(consistency_level, typedOther.consistency_level);
if (lastComparison != 0) {
return lastComparison;
}
return 0;
}

Expand Down Expand Up @@ -8295,6 +8373,14 @@ public void read(TProtocol iprot) throws TException {
TProtocolUtil.skip(iprot, field.type);
}
break;
case CONSISTENCY_LEVEL:
if (field.type == TType.I32) {
this.consistency_level = iprot.readI32();
setConsistency_levelIsSet(true);
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
default:
TProtocolUtil.skip(iprot, field.type);
break;
Expand Down Expand Up @@ -8335,6 +8421,9 @@ public void write(TProtocol oprot) throws TException {
oprot.writeFieldBegin(COUNT_FIELD_DESC);
oprot.writeI32(this.count);
oprot.writeFieldEnd();
oprot.writeFieldBegin(CONSISTENCY_LEVEL_FIELD_DESC);
oprot.writeI32(this.consistency_level);
oprot.writeFieldEnd();
oprot.writeFieldStop();
oprot.writeStructEnd();
}
Expand Down Expand Up @@ -8379,13 +8468,28 @@ public String toString() {
sb.append("count:");
sb.append(this.count);
first = false;
if (!first) sb.append(", ");
sb.append("consistency_level:");
String consistency_level_name = ConsistencyLevel.VALUES_TO_NAMES.get(this.consistency_level);
if (consistency_level_name != null) {
sb.append(consistency_level_name);
sb.append(" (");
}
sb.append(this.consistency_level);
if (consistency_level_name != null) {
sb.append(")");
}
first = false;
sb.append(")");
return sb.toString();
}

public void validate() throws TException {
// check for required fields
// check that fields of type enum have valid values
if (isSetConsistency_level() && !ConsistencyLevel.VALID_VALUES.contains(consistency_level)){
throw new TProtocolException("The field 'consistency_level' has been assigned the invalid value " + consistency_level);
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/service/CassandraServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public Map<String, Map<String, String>> describe_keyspace(String table) throws N
return columnFamiliesMap;
}

public List<String> get_key_range(String tablename, String columnFamily, String startWith, String stopAt, int maxResults) throws InvalidRequestException, TException
public List<String> get_key_range(String tablename, String columnFamily, String startWith, String stopAt, int maxResults, int consistency_level) throws InvalidRequestException, TException
{
if (logger.isDebugEnabled())
logger.debug("get_key_range");
Expand Down
24 changes: 12 additions & 12 deletions test/system/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_bad_calls(self):
# get doesn't specify supercolumn name
_expect_exception(lambda: client.get('Keyspace1', 'key1', ColumnPath('Super1'), ConsistencyLevel.ONE), InvalidRequestException)
# invalid CF
_expect_exception(lambda: client.get_key_range('Keyspace1', 'S', '', '', 1000), InvalidRequestException)
_expect_exception(lambda: client.get_key_range('Keyspace1', 'S', '', '', 1000, ConsistencyLevel.ONE), InvalidRequestException)
# 'x' is not a valid Long
_expect_exception(lambda: client.insert('Keyspace1', 'key1', ColumnPath('Super1', 'sc1', 'x'), 'value', 0, ConsistencyLevel.ONE), InvalidRequestException)
# start is not a valid Long
Expand Down Expand Up @@ -440,48 +440,48 @@ def test_super_cf_remove_supercolumn(self):


def test_empty_range(self):
assert client.get_key_range('Keyspace1', 'Standard1', '', '', 1000) == []
assert client.get_key_range('Keyspace1', 'Standard1', '', '', 1000, ConsistencyLevel.ONE) == []
_insert_simple()
assert client.get_key_range('Keyspace1', 'Super1', '', '', 1000) == []
assert client.get_key_range('Keyspace1', 'Super1', '', '', 1000, ConsistencyLevel.ONE) == []

def test_range_with_remove(self):
_insert_simple()
assert client.get_key_range('Keyspace1', 'Standard1', 'key1', '', 1000) == ['key1']
assert client.get_key_range('Keyspace1', 'Standard1', 'key1', '', 1000, ConsistencyLevel.ONE) == ['key1']

client.remove('Keyspace1', 'key1', ColumnPath('Standard1', column='c1'), 1, ConsistencyLevel.ONE)
client.remove('Keyspace1', 'key1', ColumnPath('Standard1', column='c2'), 1, ConsistencyLevel.ONE)
actual = client.get_key_range('Keyspace1', 'Standard1', '', '', 1000)
actual = client.get_key_range('Keyspace1', 'Standard1', '', '', 1000, ConsistencyLevel.ONE)
assert actual == [], actual

def test_range_with_remove_cf(self):
_insert_simple()
assert client.get_key_range('Keyspace1', 'Standard1', 'key1', '', 1000) == ['key1']
assert client.get_key_range('Keyspace1', 'Standard1', 'key1', '', 1000, ConsistencyLevel.ONE) == ['key1']

client.remove('Keyspace1', 'key1', ColumnPath('Standard1'), 1, ConsistencyLevel.ONE)
actual = client.get_key_range('Keyspace1', 'Standard1', '', '', 1000)
actual = client.get_key_range('Keyspace1', 'Standard1', '', '', 1000, ConsistencyLevel.ONE)
assert actual == [], actual

def test_range_collation(self):
for key in ['-a', '-b', 'a', 'b'] + [str(i) for i in xrange(100)]:
client.insert('Keyspace1', key, ColumnPath('Standard1', column=key), 'v', 0, ConsistencyLevel.ONE)
L = client.get_key_range('Keyspace1', 'Standard1', '', '', 1000)
L = client.get_key_range('Keyspace1', 'Standard1', '', '', 1000, ConsistencyLevel.ONE)
# note the collated ordering rather than ascii
assert L == ['0', '1', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '2', '20', '21', '22', '23', '24', '25', '26', '27','28', '29', '3', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '4', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '5', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '6', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '7', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '8', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '9', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', 'a', '-a', 'b', '-b'], L

def test_range_partial(self):
for key in ['-a', '-b', 'a', 'b'] + [str(i) for i in xrange(100)]:
client.insert('Keyspace1', key, ColumnPath('Standard1', column=key), 'v', 0, ConsistencyLevel.ONE)

L = client.get_key_range('Keyspace1', 'Standard1', 'a', '', 1000)
L = client.get_key_range('Keyspace1', 'Standard1', 'a', '', 1000, ConsistencyLevel.ONE)
assert L == ['a', '-a', 'b', '-b'], L

L = client.get_key_range('Keyspace1', 'Standard1', '', '15', 1000)
L = client.get_key_range('Keyspace1', 'Standard1', '', '15', 1000, ConsistencyLevel.ONE)
assert L == ['0', '1', '10', '11', '12', '13', '14', '15'], L

L = client.get_key_range('Keyspace1', 'Standard1', '50', '51', 1000)
L = client.get_key_range('Keyspace1', 'Standard1', '50', '51', 1000, ConsistencyLevel.ONE)
assert L == ['50', '51'], L

L = client.get_key_range('Keyspace1', 'Standard1', '1', '', 10)
L = client.get_key_range('Keyspace1', 'Standard1', '1', '', 10, ConsistencyLevel.ONE)
assert L == ['1', '10', '11', '12', '13', '14', '15', '16', '17', '18'], L

def test_get_slice_range(self):
Expand Down

0 comments on commit fa1d99a

Please sign in to comment.