mirror of https://github.com/apache/cassandra
change String column names to byte[] to allow user-defined ordering.
patch by jbellis; reviewed by Sandeep Tata for CASSANDRA-185 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@796108 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8ff63a92ba
commit
986cee6806
|
|
@ -49,13 +49,21 @@
|
|||
disable entirely.
|
||||
-->
|
||||
<KeysCachedFraction>0.01</KeysCachedFraction>
|
||||
<!-- if FlushPeriodInMinutes is configured and positive, it will be
|
||||
<!--
|
||||
The CompareWith attribute tells Cassandra how to sort the columns
|
||||
for slicing operations. For backwards compatibility, the default
|
||||
is to use AsciiType, which is probably NOT what you want.
|
||||
Other options are UTF8Type, UUIDType, and LongType.
|
||||
You can also specify the fully-qualified class name to a class
|
||||
of your choice implementing org.apache.cassandra.db.marshal.IType.
|
||||
|
||||
if FlushPeriodInMinutes is configured and positive, it will be
|
||||
flushed to disk with that period whether it is dirty or not.
|
||||
This is intended for lightly-used columnfamilies so that they
|
||||
do not prevent commitlog segments from being purged. -->
|
||||
<ColumnFamily ColumnSort="Name" Name="Standard1" FlushPeriodInMinutes="60"/>
|
||||
<ColumnFamily ColumnSort="Name" Name="Standard2"/>
|
||||
<ColumnFamily ColumnSort="Time" Name="StandardByTime1"/>
|
||||
<ColumnFamily CompareWith="UTF8Type" Name="Standard1" FlushPeriodInMinutes="60"/>
|
||||
<ColumnFamily CompareWith="UTF8Type" Name="Standard2"/>
|
||||
<ColumnFamily CompareWith="UUIDType" Name="StandardByTime1"/>
|
||||
<ColumnFamily ColumnType="Super" Name="Super1"/>
|
||||
</Table>
|
||||
</Tables>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace php cassandra
|
|||
#
|
||||
|
||||
struct Column {
|
||||
1: string name,
|
||||
1: binary name,
|
||||
2: binary value,
|
||||
3: i64 timestamp,
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ struct BatchMutation {
|
|||
}
|
||||
|
||||
struct SuperColumn {
|
||||
1: string name,
|
||||
1: binary name,
|
||||
2: list<Column> columns,
|
||||
}
|
||||
|
||||
|
|
@ -91,32 +91,32 @@ exception UnavailableException {
|
|||
|
||||
struct ColumnParent {
|
||||
3: string column_family,
|
||||
4: optional string super_column,
|
||||
4: optional binary super_column,
|
||||
}
|
||||
|
||||
struct ColumnPath {
|
||||
3: string column_family,
|
||||
4: optional string super_column,
|
||||
5: string column,
|
||||
4: optional binary super_column,
|
||||
5: binary column,
|
||||
}
|
||||
|
||||
struct SuperColumnPath {
|
||||
3: string column_family,
|
||||
4: string super_column,
|
||||
4: binary super_column,
|
||||
}
|
||||
|
||||
struct ColumnPathOrParent {
|
||||
3: string column_family,
|
||||
4: optional string super_column,
|
||||
5: optional string column,
|
||||
4: optional binary super_column,
|
||||
5: optional binary column,
|
||||
}
|
||||
|
||||
|
||||
service Cassandra {
|
||||
list<Column> get_slice_by_names(1:string table, 2:string key, 3:ColumnParent column_parent, 4:list<string> column_names)
|
||||
list<Column> get_slice_by_names(1:string table, 2:string key, 3:ColumnParent column_parent, 4:list<binary> column_names)
|
||||
throws (1: InvalidRequestException ire, 2: NotFoundException nfe),
|
||||
|
||||
list<Column> get_slice(1:string table, 2:string key, 3:ColumnParent column_parent, 4:string start, 5:string finish, 6:bool is_ascending, 7:i32 count=100)
|
||||
list<Column> get_slice(1:string table, 2:string key, 3:ColumnParent column_parent, 4:binary start, 5:binary finish, 6:bool is_ascending, 7:i32 count=100)
|
||||
throws (1: InvalidRequestException ire, 2: NotFoundException nfe),
|
||||
|
||||
Column get_column(1:string table, 2:string key, 3:ColumnPath column_path)
|
||||
|
|
@ -134,10 +134,10 @@ service Cassandra {
|
|||
void remove(1:string table, 2:string key, 3:ColumnPathOrParent column_path_or_parent, 4:i64 timestamp, 5:i32 block_for=0)
|
||||
throws (1: InvalidRequestException ire, 2: UnavailableException ue),
|
||||
|
||||
list<SuperColumn> get_slice_super(1:string table, 2:string key, 3:string column_family, 4:string start, 5:string finish, 6:bool is_ascending, 7:i32 count=100)
|
||||
list<SuperColumn> get_slice_super(1:string table, 2:string key, 3:string column_family, 4:binary start, 5:binary finish, 6:bool is_ascending, 7:i32 count=100)
|
||||
throws (1: InvalidRequestException ire),
|
||||
|
||||
list<SuperColumn> get_slice_super_by_names(1:string table, 2:string key, 3:string column_family, 4:list<string> super_column_names)
|
||||
list<SuperColumn> get_slice_super_by_names(1:string table, 2:string key, 3:string column_family, 4:list<binary> super_column_names)
|
||||
throws (1: InvalidRequestException ire),
|
||||
|
||||
SuperColumn get_super_column(1:string table, 2:string key, 3:SuperColumnPath super_column_path)
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ public class Cassandra {
|
|||
|
||||
public interface Iface {
|
||||
|
||||
public List<Column> get_slice_by_names(String table, String key, ColumnParent column_parent, List<String> column_names) throws InvalidRequestException, NotFoundException, TException;
|
||||
public List<Column> get_slice_by_names(String table, String key, ColumnParent column_parent, List<byte[]> column_names) throws InvalidRequestException, NotFoundException, TException;
|
||||
|
||||
public List<Column> get_slice(String table, String key, ColumnParent column_parent, String start, String finish, boolean is_ascending, int count) throws InvalidRequestException, NotFoundException, TException;
|
||||
public List<Column> get_slice(String table, String key, ColumnParent column_parent, byte[] start, byte[] finish, boolean is_ascending, int count) throws InvalidRequestException, NotFoundException, TException;
|
||||
|
||||
public Column get_column(String table, String key, ColumnPath column_path) throws InvalidRequestException, NotFoundException, TException;
|
||||
|
||||
|
|
@ -36,9 +36,9 @@ public class Cassandra {
|
|||
|
||||
public void remove(String table, String key, ColumnPathOrParent column_path_or_parent, long timestamp, int block_for) throws InvalidRequestException, UnavailableException, TException;
|
||||
|
||||
public List<SuperColumn> get_slice_super(String table, String key, String column_family, String start, String finish, boolean is_ascending, int count) throws InvalidRequestException, TException;
|
||||
public List<SuperColumn> get_slice_super(String table, String key, String column_family, byte[] start, byte[] finish, boolean is_ascending, int count) throws InvalidRequestException, TException;
|
||||
|
||||
public List<SuperColumn> get_slice_super_by_names(String table, String key, String column_family, List<String> super_column_names) throws InvalidRequestException, TException;
|
||||
public List<SuperColumn> get_slice_super_by_names(String table, String key, String column_family, List<byte[]> super_column_names) throws InvalidRequestException, TException;
|
||||
|
||||
public SuperColumn get_super_column(String table, String key, SuperColumnPath super_column_path) throws InvalidRequestException, NotFoundException, TException;
|
||||
|
||||
|
|
@ -83,13 +83,13 @@ public class Cassandra {
|
|||
return this.oprot_;
|
||||
}
|
||||
|
||||
public List<Column> get_slice_by_names(String table, String key, ColumnParent column_parent, List<String> column_names) throws InvalidRequestException, NotFoundException, TException
|
||||
public List<Column> get_slice_by_names(String table, String key, ColumnParent column_parent, List<byte[]> column_names) throws InvalidRequestException, NotFoundException, TException
|
||||
{
|
||||
send_get_slice_by_names(table, key, column_parent, column_names);
|
||||
return recv_get_slice_by_names();
|
||||
}
|
||||
|
||||
public void send_get_slice_by_names(String table, String key, ColumnParent column_parent, List<String> column_names) throws TException
|
||||
public void send_get_slice_by_names(String table, String key, ColumnParent column_parent, List<byte[]> column_names) throws TException
|
||||
{
|
||||
oprot_.writeMessageBegin(new TMessage("get_slice_by_names", TMessageType.CALL, seqid_));
|
||||
get_slice_by_names_args args = new get_slice_by_names_args();
|
||||
|
|
@ -125,13 +125,13 @@ public class Cassandra {
|
|||
throw new TApplicationException(TApplicationException.MISSING_RESULT, "get_slice_by_names failed: unknown result");
|
||||
}
|
||||
|
||||
public List<Column> get_slice(String table, String key, ColumnParent column_parent, String start, String finish, boolean is_ascending, int count) throws InvalidRequestException, NotFoundException, TException
|
||||
public List<Column> get_slice(String table, String key, ColumnParent column_parent, byte[] start, byte[] finish, boolean is_ascending, int count) throws InvalidRequestException, NotFoundException, TException
|
||||
{
|
||||
send_get_slice(table, key, column_parent, start, finish, is_ascending, count);
|
||||
return recv_get_slice();
|
||||
}
|
||||
|
||||
public void send_get_slice(String table, String key, ColumnParent column_parent, String start, String finish, boolean is_ascending, int count) throws TException
|
||||
public void send_get_slice(String table, String key, ColumnParent column_parent, byte[] start, byte[] finish, boolean is_ascending, int count) throws TException
|
||||
{
|
||||
oprot_.writeMessageBegin(new TMessage("get_slice", TMessageType.CALL, seqid_));
|
||||
get_slice_args args = new get_slice_args();
|
||||
|
|
@ -368,13 +368,13 @@ public class Cassandra {
|
|||
return;
|
||||
}
|
||||
|
||||
public List<SuperColumn> get_slice_super(String table, String key, String column_family, String start, String finish, boolean is_ascending, int count) throws InvalidRequestException, TException
|
||||
public List<SuperColumn> get_slice_super(String table, String key, String column_family, byte[] start, byte[] finish, boolean is_ascending, int count) throws InvalidRequestException, TException
|
||||
{
|
||||
send_get_slice_super(table, key, column_family, start, finish, is_ascending, count);
|
||||
return recv_get_slice_super();
|
||||
}
|
||||
|
||||
public void send_get_slice_super(String table, String key, String column_family, String start, String finish, boolean is_ascending, int count) throws TException
|
||||
public void send_get_slice_super(String table, String key, String column_family, byte[] start, byte[] finish, boolean is_ascending, int count) throws TException
|
||||
{
|
||||
oprot_.writeMessageBegin(new TMessage("get_slice_super", TMessageType.CALL, seqid_));
|
||||
get_slice_super_args args = new get_slice_super_args();
|
||||
|
|
@ -410,13 +410,13 @@ public class Cassandra {
|
|||
throw new TApplicationException(TApplicationException.MISSING_RESULT, "get_slice_super failed: unknown result");
|
||||
}
|
||||
|
||||
public List<SuperColumn> get_slice_super_by_names(String table, String key, String column_family, List<String> super_column_names) throws InvalidRequestException, TException
|
||||
public List<SuperColumn> get_slice_super_by_names(String table, String key, String column_family, List<byte[]> super_column_names) throws InvalidRequestException, TException
|
||||
{
|
||||
send_get_slice_super_by_names(table, key, column_family, super_column_names);
|
||||
return recv_get_slice_super_by_names();
|
||||
}
|
||||
|
||||
public void send_get_slice_super_by_names(String table, String key, String column_family, List<String> super_column_names) throws TException
|
||||
public void send_get_slice_super_by_names(String table, String key, String column_family, List<byte[]> super_column_names) throws TException
|
||||
{
|
||||
oprot_.writeMessageBegin(new TMessage("get_slice_super_by_names", TMessageType.CALL, seqid_));
|
||||
get_slice_super_by_names_args args = new get_slice_super_by_names_args();
|
||||
|
|
@ -1196,7 +1196,7 @@ public class Cassandra {
|
|||
public static final int KEY = 2;
|
||||
public ColumnParent column_parent;
|
||||
public static final int COLUMN_PARENT = 3;
|
||||
public List<String> column_names;
|
||||
public List<byte[]> column_names;
|
||||
public static final int COLUMN_NAMES = 4;
|
||||
|
||||
private final Isset __isset = new Isset();
|
||||
|
|
@ -1226,7 +1226,7 @@ public class Cassandra {
|
|||
String table,
|
||||
String key,
|
||||
ColumnParent column_parent,
|
||||
List<String> column_names)
|
||||
List<byte[]> column_names)
|
||||
{
|
||||
this();
|
||||
this.table = table;
|
||||
|
|
@ -1249,9 +1249,11 @@ public class Cassandra {
|
|||
this.column_parent = new ColumnParent(other.column_parent);
|
||||
}
|
||||
if (other.isSetColumn_names()) {
|
||||
List<String> __this__column_names = new ArrayList<String>();
|
||||
for (String other_element : other.column_names) {
|
||||
__this__column_names.add(other_element);
|
||||
List<byte[]> __this__column_names = new ArrayList<byte[]>();
|
||||
for (byte[] other_element : other.column_names) {
|
||||
byte[] temp_binary_element = new byte[other_element.length];
|
||||
System.arraycopy(other_element, 0, temp_binary_element, 0, other_element.length);
|
||||
__this__column_names.add(temp_binary_element);
|
||||
}
|
||||
this.column_names = __this__column_names;
|
||||
}
|
||||
|
|
@ -1335,22 +1337,22 @@ public class Cassandra {
|
|||
return (this.column_names == null) ? 0 : this.column_names.size();
|
||||
}
|
||||
|
||||
public java.util.Iterator<String> getColumn_namesIterator() {
|
||||
public java.util.Iterator<byte[]> getColumn_namesIterator() {
|
||||
return (this.column_names == null) ? null : this.column_names.iterator();
|
||||
}
|
||||
|
||||
public void addToColumn_names(String elem) {
|
||||
public void addToColumn_names(byte[] elem) {
|
||||
if (this.column_names == null) {
|
||||
this.column_names = new ArrayList<String>();
|
||||
this.column_names = new ArrayList<byte[]>();
|
||||
}
|
||||
this.column_names.add(elem);
|
||||
}
|
||||
|
||||
public List<String> getColumn_names() {
|
||||
public List<byte[]> getColumn_names() {
|
||||
return this.column_names;
|
||||
}
|
||||
|
||||
public void setColumn_names(List<String> column_names) {
|
||||
public void setColumn_names(List<byte[]> column_names) {
|
||||
this.column_names = column_names;
|
||||
}
|
||||
|
||||
|
|
@ -1399,7 +1401,7 @@ public class Cassandra {
|
|||
if (value == null) {
|
||||
unsetColumn_names();
|
||||
} else {
|
||||
setColumn_names((List<String>)value);
|
||||
setColumn_names((List<byte[]>)value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1537,11 +1539,11 @@ public class Cassandra {
|
|||
if (field.type == TType.LIST) {
|
||||
{
|
||||
TList _list31 = iprot.readListBegin();
|
||||
this.column_names = new ArrayList<String>(_list31.size);
|
||||
this.column_names = new ArrayList<byte[]>(_list31.size);
|
||||
for (int _i32 = 0; _i32 < _list31.size; ++_i32)
|
||||
{
|
||||
String _elem33;
|
||||
_elem33 = iprot.readString();
|
||||
byte[] _elem33;
|
||||
_elem33 = iprot.readBinary();
|
||||
this.column_names.add(_elem33);
|
||||
}
|
||||
iprot.readListEnd();
|
||||
|
|
@ -1586,8 +1588,8 @@ public class Cassandra {
|
|||
oprot.writeFieldBegin(COLUMN_NAMES_FIELD_DESC);
|
||||
{
|
||||
oprot.writeListBegin(new TList(TType.STRING, this.column_names.size()));
|
||||
for (String _iter34 : this.column_names) {
|
||||
oprot.writeString(_iter34);
|
||||
for (byte[] _iter34 : this.column_names) {
|
||||
oprot.writeBinary(_iter34);
|
||||
}
|
||||
oprot.writeListEnd();
|
||||
}
|
||||
|
|
@ -2045,9 +2047,9 @@ public class Cassandra {
|
|||
public static final int KEY = 2;
|
||||
public ColumnParent column_parent;
|
||||
public static final int COLUMN_PARENT = 3;
|
||||
public String start;
|
||||
public byte[] start;
|
||||
public static final int START = 4;
|
||||
public String finish;
|
||||
public byte[] finish;
|
||||
public static final int FINISH = 5;
|
||||
public boolean is_ascending;
|
||||
public static final int IS_ASCENDING = 6;
|
||||
|
|
@ -2090,8 +2092,8 @@ public class Cassandra {
|
|||
String table,
|
||||
String key,
|
||||
ColumnParent column_parent,
|
||||
String start,
|
||||
String finish,
|
||||
byte[] start,
|
||||
byte[] finish,
|
||||
boolean is_ascending,
|
||||
int count)
|
||||
{
|
||||
|
|
@ -2121,10 +2123,12 @@ public class Cassandra {
|
|||
this.column_parent = new ColumnParent(other.column_parent);
|
||||
}
|
||||
if (other.isSetStart()) {
|
||||
this.start = other.start;
|
||||
this.start = new byte[other.start.length];
|
||||
System.arraycopy(other.start, 0, start, 0, other.start.length);
|
||||
}
|
||||
if (other.isSetFinish()) {
|
||||
this.finish = other.finish;
|
||||
this.finish = new byte[other.finish.length];
|
||||
System.arraycopy(other.finish, 0, finish, 0, other.finish.length);
|
||||
}
|
||||
__isset.is_ascending = other.__isset.is_ascending;
|
||||
this.is_ascending = other.is_ascending;
|
||||
|
|
@ -2206,11 +2210,11 @@ public class Cassandra {
|
|||
}
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
public byte[] getStart() {
|
||||
return this.start;
|
||||
}
|
||||
|
||||
public void setStart(String start) {
|
||||
public void setStart(byte[] start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
|
|
@ -2229,11 +2233,11 @@ public class Cassandra {
|
|||
}
|
||||
}
|
||||
|
||||
public String getFinish() {
|
||||
public byte[] getFinish() {
|
||||
return this.finish;
|
||||
}
|
||||
|
||||
public void setFinish(String finish) {
|
||||
public void setFinish(byte[] finish) {
|
||||
this.finish = finish;
|
||||
}
|
||||
|
||||
|
|
@ -2326,7 +2330,7 @@ public class Cassandra {
|
|||
if (value == null) {
|
||||
unsetStart();
|
||||
} else {
|
||||
setStart((String)value);
|
||||
setStart((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -2334,7 +2338,7 @@ public class Cassandra {
|
|||
if (value == null) {
|
||||
unsetFinish();
|
||||
} else {
|
||||
setFinish((String)value);
|
||||
setFinish((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -2454,7 +2458,7 @@ public class Cassandra {
|
|||
if (this_present_start || that_present_start) {
|
||||
if (!(this_present_start && that_present_start))
|
||||
return false;
|
||||
if (!this.start.equals(that.start))
|
||||
if (!java.util.Arrays.equals(this.start, that.start))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -2463,7 +2467,7 @@ public class Cassandra {
|
|||
if (this_present_finish || that_present_finish) {
|
||||
if (!(this_present_finish && that_present_finish))
|
||||
return false;
|
||||
if (!this.finish.equals(that.finish))
|
||||
if (!java.util.Arrays.equals(this.finish, that.finish))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -2528,14 +2532,14 @@ public class Cassandra {
|
|||
break;
|
||||
case START:
|
||||
if (field.type == TType.STRING) {
|
||||
this.start = iprot.readString();
|
||||
this.start = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
case FINISH:
|
||||
if (field.type == TType.STRING) {
|
||||
this.finish = iprot.readString();
|
||||
this.finish = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -2590,12 +2594,12 @@ public class Cassandra {
|
|||
}
|
||||
if (this.start != null) {
|
||||
oprot.writeFieldBegin(START_FIELD_DESC);
|
||||
oprot.writeString(this.start);
|
||||
oprot.writeBinary(this.start);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.finish != null) {
|
||||
oprot.writeFieldBegin(FINISH_FIELD_DESC);
|
||||
oprot.writeString(this.finish);
|
||||
oprot.writeBinary(this.finish);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldBegin(IS_ASCENDING_FIELD_DESC);
|
||||
|
|
@ -2641,7 +2645,12 @@ public class Cassandra {
|
|||
if (this.start == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.start);
|
||||
int __start_size = Math.min(this.start.length, 128);
|
||||
for (int i = 0; i < __start_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.start[i]).length() > 1 ? Integer.toHexString(this.start[i]).substring(Integer.toHexString(this.start[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.start[i]).toUpperCase());
|
||||
}
|
||||
if (this.start.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
if (!first) sb.append(", ");
|
||||
|
|
@ -2649,7 +2658,12 @@ public class Cassandra {
|
|||
if (this.finish == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.finish);
|
||||
int __finish_size = Math.min(this.finish.length, 128);
|
||||
for (int i = 0; i < __finish_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.finish[i]).length() > 1 ? Integer.toHexString(this.finish[i]).substring(Integer.toHexString(this.finish[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.finish[i]).toUpperCase());
|
||||
}
|
||||
if (this.finish.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
if (!first) sb.append(", ");
|
||||
|
|
@ -6625,9 +6639,9 @@ public class Cassandra {
|
|||
public static final int KEY = 2;
|
||||
public String column_family;
|
||||
public static final int COLUMN_FAMILY = 3;
|
||||
public String start;
|
||||
public byte[] start;
|
||||
public static final int START = 4;
|
||||
public String finish;
|
||||
public byte[] finish;
|
||||
public static final int FINISH = 5;
|
||||
public boolean is_ascending;
|
||||
public static final int IS_ASCENDING = 6;
|
||||
|
|
@ -6670,8 +6684,8 @@ public class Cassandra {
|
|||
String table,
|
||||
String key,
|
||||
String column_family,
|
||||
String start,
|
||||
String finish,
|
||||
byte[] start,
|
||||
byte[] finish,
|
||||
boolean is_ascending,
|
||||
int count)
|
||||
{
|
||||
|
|
@ -6701,10 +6715,12 @@ public class Cassandra {
|
|||
this.column_family = other.column_family;
|
||||
}
|
||||
if (other.isSetStart()) {
|
||||
this.start = other.start;
|
||||
this.start = new byte[other.start.length];
|
||||
System.arraycopy(other.start, 0, start, 0, other.start.length);
|
||||
}
|
||||
if (other.isSetFinish()) {
|
||||
this.finish = other.finish;
|
||||
this.finish = new byte[other.finish.length];
|
||||
System.arraycopy(other.finish, 0, finish, 0, other.finish.length);
|
||||
}
|
||||
__isset.is_ascending = other.__isset.is_ascending;
|
||||
this.is_ascending = other.is_ascending;
|
||||
|
|
@ -6786,11 +6802,11 @@ public class Cassandra {
|
|||
}
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
public byte[] getStart() {
|
||||
return this.start;
|
||||
}
|
||||
|
||||
public void setStart(String start) {
|
||||
public void setStart(byte[] start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
|
|
@ -6809,11 +6825,11 @@ public class Cassandra {
|
|||
}
|
||||
}
|
||||
|
||||
public String getFinish() {
|
||||
public byte[] getFinish() {
|
||||
return this.finish;
|
||||
}
|
||||
|
||||
public void setFinish(String finish) {
|
||||
public void setFinish(byte[] finish) {
|
||||
this.finish = finish;
|
||||
}
|
||||
|
||||
|
|
@ -6906,7 +6922,7 @@ public class Cassandra {
|
|||
if (value == null) {
|
||||
unsetStart();
|
||||
} else {
|
||||
setStart((String)value);
|
||||
setStart((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -6914,7 +6930,7 @@ public class Cassandra {
|
|||
if (value == null) {
|
||||
unsetFinish();
|
||||
} else {
|
||||
setFinish((String)value);
|
||||
setFinish((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -7034,7 +7050,7 @@ public class Cassandra {
|
|||
if (this_present_start || that_present_start) {
|
||||
if (!(this_present_start && that_present_start))
|
||||
return false;
|
||||
if (!this.start.equals(that.start))
|
||||
if (!java.util.Arrays.equals(this.start, that.start))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -7043,7 +7059,7 @@ public class Cassandra {
|
|||
if (this_present_finish || that_present_finish) {
|
||||
if (!(this_present_finish && that_present_finish))
|
||||
return false;
|
||||
if (!this.finish.equals(that.finish))
|
||||
if (!java.util.Arrays.equals(this.finish, that.finish))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -7107,14 +7123,14 @@ public class Cassandra {
|
|||
break;
|
||||
case START:
|
||||
if (field.type == TType.STRING) {
|
||||
this.start = iprot.readString();
|
||||
this.start = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
case FINISH:
|
||||
if (field.type == TType.STRING) {
|
||||
this.finish = iprot.readString();
|
||||
this.finish = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -7169,12 +7185,12 @@ public class Cassandra {
|
|||
}
|
||||
if (this.start != null) {
|
||||
oprot.writeFieldBegin(START_FIELD_DESC);
|
||||
oprot.writeString(this.start);
|
||||
oprot.writeBinary(this.start);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.finish != null) {
|
||||
oprot.writeFieldBegin(FINISH_FIELD_DESC);
|
||||
oprot.writeString(this.finish);
|
||||
oprot.writeBinary(this.finish);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldBegin(IS_ASCENDING_FIELD_DESC);
|
||||
|
|
@ -7220,7 +7236,12 @@ public class Cassandra {
|
|||
if (this.start == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.start);
|
||||
int __start_size = Math.min(this.start.length, 128);
|
||||
for (int i = 0; i < __start_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.start[i]).length() > 1 ? Integer.toHexString(this.start[i]).substring(Integer.toHexString(this.start[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.start[i]).toUpperCase());
|
||||
}
|
||||
if (this.start.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
if (!first) sb.append(", ");
|
||||
|
|
@ -7228,7 +7249,12 @@ public class Cassandra {
|
|||
if (this.finish == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.finish);
|
||||
int __finish_size = Math.min(this.finish.length, 128);
|
||||
for (int i = 0; i < __finish_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.finish[i]).length() > 1 ? Integer.toHexString(this.finish[i]).substring(Integer.toHexString(this.finish[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.finish[i]).toUpperCase());
|
||||
}
|
||||
if (this.finish.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
if (!first) sb.append(", ");
|
||||
|
|
@ -7573,7 +7599,7 @@ public class Cassandra {
|
|||
public static final int KEY = 2;
|
||||
public String column_family;
|
||||
public static final int COLUMN_FAMILY = 3;
|
||||
public List<String> super_column_names;
|
||||
public List<byte[]> super_column_names;
|
||||
public static final int SUPER_COLUMN_NAMES = 4;
|
||||
|
||||
private final Isset __isset = new Isset();
|
||||
|
|
@ -7603,7 +7629,7 @@ public class Cassandra {
|
|||
String table,
|
||||
String key,
|
||||
String column_family,
|
||||
List<String> super_column_names)
|
||||
List<byte[]> super_column_names)
|
||||
{
|
||||
this();
|
||||
this.table = table;
|
||||
|
|
@ -7626,9 +7652,11 @@ public class Cassandra {
|
|||
this.column_family = other.column_family;
|
||||
}
|
||||
if (other.isSetSuper_column_names()) {
|
||||
List<String> __this__super_column_names = new ArrayList<String>();
|
||||
for (String other_element : other.super_column_names) {
|
||||
__this__super_column_names.add(other_element);
|
||||
List<byte[]> __this__super_column_names = new ArrayList<byte[]>();
|
||||
for (byte[] other_element : other.super_column_names) {
|
||||
byte[] temp_binary_element = new byte[other_element.length];
|
||||
System.arraycopy(other_element, 0, temp_binary_element, 0, other_element.length);
|
||||
__this__super_column_names.add(temp_binary_element);
|
||||
}
|
||||
this.super_column_names = __this__super_column_names;
|
||||
}
|
||||
|
|
@ -7712,22 +7740,22 @@ public class Cassandra {
|
|||
return (this.super_column_names == null) ? 0 : this.super_column_names.size();
|
||||
}
|
||||
|
||||
public java.util.Iterator<String> getSuper_column_namesIterator() {
|
||||
public java.util.Iterator<byte[]> getSuper_column_namesIterator() {
|
||||
return (this.super_column_names == null) ? null : this.super_column_names.iterator();
|
||||
}
|
||||
|
||||
public void addToSuper_column_names(String elem) {
|
||||
public void addToSuper_column_names(byte[] elem) {
|
||||
if (this.super_column_names == null) {
|
||||
this.super_column_names = new ArrayList<String>();
|
||||
this.super_column_names = new ArrayList<byte[]>();
|
||||
}
|
||||
this.super_column_names.add(elem);
|
||||
}
|
||||
|
||||
public List<String> getSuper_column_names() {
|
||||
public List<byte[]> getSuper_column_names() {
|
||||
return this.super_column_names;
|
||||
}
|
||||
|
||||
public void setSuper_column_names(List<String> super_column_names) {
|
||||
public void setSuper_column_names(List<byte[]> super_column_names) {
|
||||
this.super_column_names = super_column_names;
|
||||
}
|
||||
|
||||
|
|
@ -7776,7 +7804,7 @@ public class Cassandra {
|
|||
if (value == null) {
|
||||
unsetSuper_column_names();
|
||||
} else {
|
||||
setSuper_column_names((List<String>)value);
|
||||
setSuper_column_names((List<byte[]>)value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -7913,11 +7941,11 @@ public class Cassandra {
|
|||
if (field.type == TType.LIST) {
|
||||
{
|
||||
TList _list47 = iprot.readListBegin();
|
||||
this.super_column_names = new ArrayList<String>(_list47.size);
|
||||
this.super_column_names = new ArrayList<byte[]>(_list47.size);
|
||||
for (int _i48 = 0; _i48 < _list47.size; ++_i48)
|
||||
{
|
||||
String _elem49;
|
||||
_elem49 = iprot.readString();
|
||||
byte[] _elem49;
|
||||
_elem49 = iprot.readBinary();
|
||||
this.super_column_names.add(_elem49);
|
||||
}
|
||||
iprot.readListEnd();
|
||||
|
|
@ -7962,8 +7990,8 @@ public class Cassandra {
|
|||
oprot.writeFieldBegin(SUPER_COLUMN_NAMES_FIELD_DESC);
|
||||
{
|
||||
oprot.writeListBegin(new TList(TType.STRING, this.super_column_names.size()));
|
||||
for (String _iter50 : this.super_column_names) {
|
||||
oprot.writeString(_iter50);
|
||||
for (byte[] _iter50 : this.super_column_names) {
|
||||
oprot.writeBinary(_iter50);
|
||||
}
|
||||
oprot.writeListEnd();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
private static final TField VALUE_FIELD_DESC = new TField("value", TType.STRING, (short)2);
|
||||
private static final TField TIMESTAMP_FIELD_DESC = new TField("timestamp", TType.I64, (short)3);
|
||||
|
||||
public String name;
|
||||
public byte[] name;
|
||||
public static final int NAME = 1;
|
||||
public byte[] value;
|
||||
public static final int VALUE = 2;
|
||||
|
|
@ -53,7 +53,7 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
|
||||
public Column(
|
||||
String name,
|
||||
byte[] name,
|
||||
byte[] value,
|
||||
long timestamp)
|
||||
{
|
||||
|
|
@ -69,7 +69,8 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
*/
|
||||
public Column(Column other) {
|
||||
if (other.isSetName()) {
|
||||
this.name = other.name;
|
||||
this.name = new byte[other.name.length];
|
||||
System.arraycopy(other.name, 0, name, 0, other.name.length);
|
||||
}
|
||||
if (other.isSetValue()) {
|
||||
this.value = new byte[other.value.length];
|
||||
|
|
@ -84,11 +85,11 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
return new Column(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public byte[] getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void setName(byte[] name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +159,7 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
if (value == null) {
|
||||
unsetName();
|
||||
} else {
|
||||
setName((String)value);
|
||||
setName((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -231,7 +232,7 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this_present_name || that_present_name) {
|
||||
if (!(this_present_name && that_present_name))
|
||||
return false;
|
||||
if (!this.name.equals(that.name))
|
||||
if (!java.util.Arrays.equals(this.name, that.name))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +275,7 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
{
|
||||
case NAME:
|
||||
if (field.type == TType.STRING) {
|
||||
this.name = iprot.readString();
|
||||
this.name = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -313,7 +314,7 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
oprot.writeStructBegin(STRUCT_DESC);
|
||||
if (this.name != null) {
|
||||
oprot.writeFieldBegin(NAME_FIELD_DESC);
|
||||
oprot.writeString(this.name);
|
||||
oprot.writeBinary(this.name);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.value != null) {
|
||||
|
|
@ -337,7 +338,12 @@ public class Column implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this.name == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.name);
|
||||
int __name_size = Math.min(this.name.length, 128);
|
||||
for (int i = 0; i < __name_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.name[i]).length() > 1 ? Integer.toHexString(this.name[i]).substring(Integer.toHexString(this.name[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.name[i]).toUpperCase());
|
||||
}
|
||||
if (this.name.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
if (!first) sb.append(", ");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
public String column_family;
|
||||
public static final int COLUMN_FAMILY = 3;
|
||||
public String super_column;
|
||||
public byte[] super_column;
|
||||
public static final int SUPER_COLUMN = 4;
|
||||
|
||||
private final Isset __isset = new Isset();
|
||||
|
|
@ -48,7 +48,7 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
public ColumnParent(
|
||||
String column_family,
|
||||
String super_column)
|
||||
byte[] super_column)
|
||||
{
|
||||
this();
|
||||
this.column_family = column_family;
|
||||
|
|
@ -63,7 +63,8 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
this.column_family = other.column_family;
|
||||
}
|
||||
if (other.isSetSuper_column()) {
|
||||
this.super_column = other.super_column;
|
||||
this.super_column = new byte[other.super_column.length];
|
||||
System.arraycopy(other.super_column, 0, super_column, 0, other.super_column.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +96,11 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public String getSuper_column() {
|
||||
public byte[] getSuper_column() {
|
||||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(String super_column) {
|
||||
public void setSuper_column(byte[] super_column) {
|
||||
this.super_column = super_column;
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +133,7 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
if (value == null) {
|
||||
unsetSuper_column();
|
||||
} else {
|
||||
setSuper_column((String)value);
|
||||
setSuper_column((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -193,7 +194,7 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
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))
|
||||
if (!java.util.Arrays.equals(this.super_column, that.super_column))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +226,7 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
break;
|
||||
case SUPER_COLUMN:
|
||||
if (field.type == TType.STRING) {
|
||||
this.super_column = iprot.readString();
|
||||
this.super_column = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -254,7 +255,7 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeString(this.super_column);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
|
|
@ -279,7 +280,12 @@ public class ColumnParent implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this.super_column == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.super_column);
|
||||
int __super_column_size = Math.min(this.super_column.length, 128);
|
||||
for (int i = 0; i < __super_column_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.super_column[i]).length() > 1 ? Integer.toHexString(this.super_column[i]).substring(Integer.toHexString(this.super_column[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.super_column[i]).toUpperCase());
|
||||
}
|
||||
if (this.super_column.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
public String column_family;
|
||||
public static final int COLUMN_FAMILY = 3;
|
||||
public String super_column;
|
||||
public byte[] super_column;
|
||||
public static final int SUPER_COLUMN = 4;
|
||||
public String column;
|
||||
public byte[] column;
|
||||
public static final int COLUMN = 5;
|
||||
|
||||
private final Isset __isset = new Isset();
|
||||
|
|
@ -53,8 +53,8 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
public ColumnPath(
|
||||
String column_family,
|
||||
String super_column,
|
||||
String column)
|
||||
byte[] super_column,
|
||||
byte[] column)
|
||||
{
|
||||
this();
|
||||
this.column_family = column_family;
|
||||
|
|
@ -70,10 +70,12 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
this.column_family = other.column_family;
|
||||
}
|
||||
if (other.isSetSuper_column()) {
|
||||
this.super_column = other.super_column;
|
||||
this.super_column = new byte[other.super_column.length];
|
||||
System.arraycopy(other.super_column, 0, super_column, 0, other.super_column.length);
|
||||
}
|
||||
if (other.isSetColumn()) {
|
||||
this.column = other.column;
|
||||
this.column = new byte[other.column.length];
|
||||
System.arraycopy(other.column, 0, column, 0, other.column.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,11 +107,11 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public String getSuper_column() {
|
||||
public byte[] getSuper_column() {
|
||||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(String super_column) {
|
||||
public void setSuper_column(byte[] super_column) {
|
||||
this.super_column = super_column;
|
||||
}
|
||||
|
||||
|
|
@ -128,11 +130,11 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public String getColumn() {
|
||||
public byte[] getColumn() {
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
public void setColumn(byte[] column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +167,7 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (value == null) {
|
||||
unsetSuper_column();
|
||||
} else {
|
||||
setSuper_column((String)value);
|
||||
setSuper_column((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -173,7 +175,7 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (value == null) {
|
||||
unsetColumn();
|
||||
} else {
|
||||
setColumn((String)value);
|
||||
setColumn((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -239,7 +241,7 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
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))
|
||||
if (!java.util.Arrays.equals(this.super_column, that.super_column))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +250,7 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this_present_column || that_present_column) {
|
||||
if (!(this_present_column && that_present_column))
|
||||
return false;
|
||||
if (!this.column.equals(that.column))
|
||||
if (!java.util.Arrays.equals(this.column, that.column))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -280,14 +282,14 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
break;
|
||||
case SUPER_COLUMN:
|
||||
if (field.type == TType.STRING) {
|
||||
this.super_column = iprot.readString();
|
||||
this.super_column = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
case COLUMN:
|
||||
if (field.type == TType.STRING) {
|
||||
this.column = iprot.readString();
|
||||
this.column = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -316,12 +318,12 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeString(this.super_column);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.column != null) {
|
||||
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
|
||||
oprot.writeString(this.column);
|
||||
oprot.writeBinary(this.column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
|
|
@ -346,7 +348,12 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this.super_column == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.super_column);
|
||||
int __super_column_size = Math.min(this.super_column.length, 128);
|
||||
for (int i = 0; i < __super_column_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.super_column[i]).length() > 1 ? Integer.toHexString(this.super_column[i]).substring(Integer.toHexString(this.super_column[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.super_column[i]).toUpperCase());
|
||||
}
|
||||
if (this.super_column.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
|
@ -355,7 +362,12 @@ public class ColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this.column == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.column);
|
||||
int __column_size = Math.min(this.column.length, 128);
|
||||
for (int i = 0; i < __column_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.column[i]).length() > 1 ? Integer.toHexString(this.column[i]).substring(Integer.toHexString(this.column[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.column[i]).toUpperCase());
|
||||
}
|
||||
if (this.column.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
sb.append(")");
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
|
||||
public String column_family;
|
||||
public static final int COLUMN_FAMILY = 3;
|
||||
public String super_column;
|
||||
public byte[] super_column;
|
||||
public static final int SUPER_COLUMN = 4;
|
||||
public String column;
|
||||
public byte[] column;
|
||||
public static final int COLUMN = 5;
|
||||
|
||||
private final Isset __isset = new Isset();
|
||||
|
|
@ -53,8 +53,8 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
|
||||
public ColumnPathOrParent(
|
||||
String column_family,
|
||||
String super_column,
|
||||
String column)
|
||||
byte[] super_column,
|
||||
byte[] column)
|
||||
{
|
||||
this();
|
||||
this.column_family = column_family;
|
||||
|
|
@ -70,10 +70,12 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
this.column_family = other.column_family;
|
||||
}
|
||||
if (other.isSetSuper_column()) {
|
||||
this.super_column = other.super_column;
|
||||
this.super_column = new byte[other.super_column.length];
|
||||
System.arraycopy(other.super_column, 0, super_column, 0, other.super_column.length);
|
||||
}
|
||||
if (other.isSetColumn()) {
|
||||
this.column = other.column;
|
||||
this.column = new byte[other.column.length];
|
||||
System.arraycopy(other.column, 0, column, 0, other.column.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,11 +107,11 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
}
|
||||
}
|
||||
|
||||
public String getSuper_column() {
|
||||
public byte[] getSuper_column() {
|
||||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(String super_column) {
|
||||
public void setSuper_column(byte[] super_column) {
|
||||
this.super_column = super_column;
|
||||
}
|
||||
|
||||
|
|
@ -128,11 +130,11 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
}
|
||||
}
|
||||
|
||||
public String getColumn() {
|
||||
public byte[] getColumn() {
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
public void setColumn(byte[] column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +167,7 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
if (value == null) {
|
||||
unsetSuper_column();
|
||||
} else {
|
||||
setSuper_column((String)value);
|
||||
setSuper_column((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -173,7 +175,7 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
if (value == null) {
|
||||
unsetColumn();
|
||||
} else {
|
||||
setColumn((String)value);
|
||||
setColumn((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -239,7 +241,7 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
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))
|
||||
if (!java.util.Arrays.equals(this.super_column, that.super_column))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +250,7 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
if (this_present_column || that_present_column) {
|
||||
if (!(this_present_column && that_present_column))
|
||||
return false;
|
||||
if (!this.column.equals(that.column))
|
||||
if (!java.util.Arrays.equals(this.column, that.column))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -280,14 +282,14 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
break;
|
||||
case SUPER_COLUMN:
|
||||
if (field.type == TType.STRING) {
|
||||
this.super_column = iprot.readString();
|
||||
this.super_column = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
case COLUMN:
|
||||
if (field.type == TType.STRING) {
|
||||
this.column = iprot.readString();
|
||||
this.column = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -316,12 +318,12 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeString(this.super_column);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.column != null) {
|
||||
oprot.writeFieldBegin(COLUMN_FIELD_DESC);
|
||||
oprot.writeString(this.column);
|
||||
oprot.writeBinary(this.column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
|
|
@ -346,7 +348,12 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
if (this.super_column == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.super_column);
|
||||
int __super_column_size = Math.min(this.super_column.length, 128);
|
||||
for (int i = 0; i < __super_column_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.super_column[i]).length() > 1 ? Integer.toHexString(this.super_column[i]).substring(Integer.toHexString(this.super_column[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.super_column[i]).toUpperCase());
|
||||
}
|
||||
if (this.super_column.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
|
@ -356,7 +363,12 @@ public class ColumnPathOrParent implements TBase, java.io.Serializable, Cloneabl
|
|||
if (this.column == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.column);
|
||||
int __column_size = Math.min(this.column.length, 128);
|
||||
for (int i = 0; i < __column_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.column[i]).length() > 1 ? Integer.toHexString(this.column[i]).substring(Integer.toHexString(this.column[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.column[i]).toUpperCase());
|
||||
}
|
||||
if (this.column.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)1);
|
||||
private static final TField COLUMNS_FIELD_DESC = new TField("columns", TType.LIST, (short)2);
|
||||
|
||||
public String name;
|
||||
public byte[] name;
|
||||
public static final int NAME = 1;
|
||||
public List<Column> columns;
|
||||
public static final int COLUMNS = 2;
|
||||
|
|
@ -48,7 +48,7 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
|
||||
public SuperColumn(
|
||||
String name,
|
||||
byte[] name,
|
||||
List<Column> columns)
|
||||
{
|
||||
this();
|
||||
|
|
@ -61,7 +61,8 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
*/
|
||||
public SuperColumn(SuperColumn other) {
|
||||
if (other.isSetName()) {
|
||||
this.name = other.name;
|
||||
this.name = new byte[other.name.length];
|
||||
System.arraycopy(other.name, 0, name, 0, other.name.length);
|
||||
}
|
||||
if (other.isSetColumns()) {
|
||||
List<Column> __this__columns = new ArrayList<Column>();
|
||||
|
|
@ -77,11 +78,11 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
return new SuperColumn(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public byte[] getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void setName(byte[] name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +145,7 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
if (value == null) {
|
||||
unsetName();
|
||||
} else {
|
||||
setName((String)value);
|
||||
setName((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -204,7 +205,7 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this_present_name || that_present_name) {
|
||||
if (!(this_present_name && that_present_name))
|
||||
return false;
|
||||
if (!this.name.equals(that.name))
|
||||
if (!java.util.Arrays.equals(this.name, that.name))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +239,7 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
{
|
||||
case NAME:
|
||||
if (field.type == TType.STRING) {
|
||||
this.name = iprot.readString();
|
||||
this.name = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -280,7 +281,7 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
oprot.writeStructBegin(STRUCT_DESC);
|
||||
if (this.name != null) {
|
||||
oprot.writeFieldBegin(NAME_FIELD_DESC);
|
||||
oprot.writeString(this.name);
|
||||
oprot.writeBinary(this.name);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
if (this.columns != null) {
|
||||
|
|
@ -307,7 +308,12 @@ public class SuperColumn implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this.name == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.name);
|
||||
int __name_size = Math.min(this.name.length, 128);
|
||||
for (int i = 0; i < __name_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.name[i]).length() > 1 ? Integer.toHexString(this.name[i]).substring(Integer.toHexString(this.name[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.name[i]).toUpperCase());
|
||||
}
|
||||
if (this.name.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
if (!first) sb.append(", ");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
public String column_family;
|
||||
public static final int COLUMN_FAMILY = 3;
|
||||
public String super_column;
|
||||
public byte[] super_column;
|
||||
public static final int SUPER_COLUMN = 4;
|
||||
|
||||
private final Isset __isset = new Isset();
|
||||
|
|
@ -48,7 +48,7 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
|
||||
public SuperColumnPath(
|
||||
String column_family,
|
||||
String super_column)
|
||||
byte[] super_column)
|
||||
{
|
||||
this();
|
||||
this.column_family = column_family;
|
||||
|
|
@ -63,7 +63,8 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
this.column_family = other.column_family;
|
||||
}
|
||||
if (other.isSetSuper_column()) {
|
||||
this.super_column = other.super_column;
|
||||
this.super_column = new byte[other.super_column.length];
|
||||
System.arraycopy(other.super_column, 0, super_column, 0, other.super_column.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +96,11 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
public String getSuper_column() {
|
||||
public byte[] getSuper_column() {
|
||||
return this.super_column;
|
||||
}
|
||||
|
||||
public void setSuper_column(String super_column) {
|
||||
public void setSuper_column(byte[] super_column) {
|
||||
this.super_column = super_column;
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +133,7 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (value == null) {
|
||||
unsetSuper_column();
|
||||
} else {
|
||||
setSuper_column((String)value);
|
||||
setSuper_column((byte[])value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -193,7 +194,7 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
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))
|
||||
if (!java.util.Arrays.equals(this.super_column, that.super_column))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +226,7 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
break;
|
||||
case SUPER_COLUMN:
|
||||
if (field.type == TType.STRING) {
|
||||
this.super_column = iprot.readString();
|
||||
this.super_column = iprot.readBinary();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
|
|
@ -254,7 +255,7 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
}
|
||||
if (this.super_column != null) {
|
||||
oprot.writeFieldBegin(SUPER_COLUMN_FIELD_DESC);
|
||||
oprot.writeString(this.super_column);
|
||||
oprot.writeBinary(this.super_column);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
|
|
@ -278,7 +279,12 @@ public class SuperColumnPath implements TBase, java.io.Serializable, Cloneable {
|
|||
if (this.super_column == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(this.super_column);
|
||||
int __super_column_size = Math.min(this.super_column.length, 128);
|
||||
for (int i = 0; i < __super_column_size; i++) {
|
||||
if (i != 0) sb.append(" ");
|
||||
sb.append(Integer.toHexString(this.super_column[i]).length() > 1 ? Integer.toHexString(this.super_column[i]).substring(Integer.toHexString(this.super_column[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.super_column[i]).toUpperCase());
|
||||
}
|
||||
if (this.super_column.length > 128) sb.append(" ...");
|
||||
}
|
||||
first = false;
|
||||
sb.append(")");
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ import org.apache.cassandra.service.*;
|
|||
import org.apache.cassandra.utils.LogUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
// Cli Client Side Library
|
||||
public class CliClient
|
||||
|
|
@ -135,7 +138,7 @@ public class CliClient
|
|||
{
|
||||
// table.cf['key']
|
||||
List<Column> columns = new ArrayList<Column>();
|
||||
columns = thriftClient_.get_slice(tableName, key, new ColumnParent(columnFamily, null), "", "", true, 1000000);
|
||||
columns = thriftClient_.get_slice(tableName, key, new ColumnParent(columnFamily, null), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 1000000);
|
||||
int size = columns.size();
|
||||
for (Iterator<Column> colIter = columns.iterator(); colIter.hasNext(); )
|
||||
{
|
||||
|
|
@ -151,7 +154,14 @@ public class CliClient
|
|||
// table.cf['key']['column']
|
||||
String columnName = CliCompiler.getColumn(columnFamilySpec, 0);
|
||||
Column column = new Column();
|
||||
column = thriftClient_.get_column(tableName, key, new ColumnPath(columnFamily, null, columnName));
|
||||
try
|
||||
{
|
||||
column = thriftClient_.get_column(tableName, key, new ColumnPath(columnFamily, null, columnName.getBytes("UTF-8")));
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
css_.out.printf("==> (name=%s, value=%s; timestamp=%d)\n",
|
||||
column.name, column.value, column.timestamp);
|
||||
}
|
||||
|
|
@ -184,8 +194,15 @@ public class CliClient
|
|||
String columnName = CliCompiler.getColumn(columnFamilySpec, 0);
|
||||
|
||||
// do the insert
|
||||
thriftClient_.insert(tableName, key, new ColumnPath(columnFamily, null, columnName),
|
||||
value.getBytes(), System.currentTimeMillis(), 1);
|
||||
try
|
||||
{
|
||||
thriftClient_.insert(tableName, key, new ColumnPath(columnFamily, null, columnName.getBytes("UTF-8")),
|
||||
value.getBytes(), System.currentTimeMillis(), 1);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
css_.out.println("Value inserted.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@
|
|||
|
||||
package org.apache.cassandra.config;
|
||||
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
public class CFMetaData
|
||||
{
|
||||
public String tableName; // name of table which has this column family
|
||||
public String cfName; // name of the column family
|
||||
public String columnType; // type: super, standard, etc.
|
||||
public String indexProperty_; // name sorted, time stamp sorted etc.
|
||||
public AbstractType comparator; // name sorted, time stamp sorted etc.
|
||||
|
||||
// The user chosen names (n_) for various parts of data in a column family.
|
||||
// CQL queries, for instance, will refer to/extract data within a column
|
||||
|
|
@ -36,7 +38,7 @@ public class CFMetaData
|
|||
public String n_columnValue;
|
||||
public String n_columnTimestamp;
|
||||
public int flushPeriodInMinutes = 0; // flush interval, if <=0, no periodic flusher is scheduled
|
||||
|
||||
|
||||
// a quick and dirty pretty printer for describing the column family...
|
||||
public String pretty()
|
||||
{
|
||||
|
|
@ -49,7 +51,7 @@ public class CFMetaData
|
|||
desc = tableName + "." + cfName + "(" + n_rowKey + ", " + desc + ")\n";
|
||||
|
||||
desc += "Column Family Type: " + columnType + "\n" +
|
||||
"Columns Sorted By: " + indexProperty_ + "\n";
|
||||
"Columns Sorted By: " + comparator + "\n";
|
||||
desc += "flush period: " + flushPeriodInMinutes + " minutes\n";
|
||||
return desc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ import java.io.*;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.AsciiType;
|
||||
import org.apache.cassandra.db.marshal.UTF8Type;
|
||||
import org.apache.cassandra.utils.FileUtils;
|
||||
import org.apache.cassandra.utils.XMLUtils;
|
||||
import org.w3c.dom.Node;
|
||||
|
|
@ -332,21 +335,31 @@ public class DatabaseDescriptor
|
|||
throw new ConfigurationException("Column " + cName + " has invalid type " + rawColumnType);
|
||||
}
|
||||
|
||||
// Parse out the column family sorting property for columns
|
||||
String rawColumnIndexType = XMLUtils.getAttributeValue(columnFamily, "ColumnSort");
|
||||
String columnIndexType = ColumnFamily.getColumnSortProperty(rawColumnIndexType);
|
||||
if (columnIndexType == null)
|
||||
if (XMLUtils.getAttributeValue(columnFamily, "ColumnSort") != null)
|
||||
{
|
||||
throw new ConfigurationException("invalid column sort value " + rawColumnIndexType);
|
||||
throw new ConfigurationException("ColumnSort is no longer an accepted attribute. Use CompareWith instead.");
|
||||
}
|
||||
if ("Super".equals(columnType))
|
||||
|
||||
// Parse out the column comparator
|
||||
Class<? extends AbstractType> typeClass;
|
||||
String compareWith = XMLUtils.getAttributeValue(columnFamily, "CompareWith");
|
||||
if (compareWith == null)
|
||||
{
|
||||
if (rawColumnIndexType != null)
|
||||
typeClass = org.apache.cassandra.db.marshal.AsciiType.class;
|
||||
}
|
||||
else
|
||||
{
|
||||
String className = compareWith.contains(".") ? compareWith : "org.apache.cassandra.db.marshal." + compareWith;
|
||||
try
|
||||
{
|
||||
throw new ConfigurationException("Super columnfamilies are always name-sorted, and their subcolumns are always time-sorted. You may not specify the ColumnSort attribute on a SuperColumn.");
|
||||
typeClass = (Class<? extends AbstractType>)Class.forName(className);
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new ConfigurationException("Unable to load class " + className + " for CompareWith attribute");
|
||||
}
|
||||
columnIndexType = "Name";
|
||||
}
|
||||
AbstractType columnComparator = typeClass.getConstructor().newInstance();
|
||||
|
||||
// see if flush period is set
|
||||
String flushPeriodInMinutes = XMLUtils.getAttributeValue(columnFamily, "FlushPeriodInMinutes");
|
||||
|
|
@ -389,7 +402,7 @@ public class DatabaseDescriptor
|
|||
cfMetaData.cfName = cName;
|
||||
|
||||
cfMetaData.columnType = columnType;
|
||||
cfMetaData.indexProperty_ = columnIndexType;
|
||||
cfMetaData.comparator = columnComparator;
|
||||
|
||||
cfMetaData.n_rowKey = n_rowKey;
|
||||
cfMetaData.n_columnMap = n_columnMap;
|
||||
|
|
@ -407,6 +420,19 @@ public class DatabaseDescriptor
|
|||
}
|
||||
}
|
||||
|
||||
// Hardcoded system tables
|
||||
Map<String, CFMetaData> systemMetadata = new HashMap<String, CFMetaData>();
|
||||
|
||||
CFMetaData data = new CFMetaData();
|
||||
data.comparator = new AsciiType();
|
||||
systemMetadata.put(SystemTable.LOCATION_CF, data);
|
||||
|
||||
data = new CFMetaData();
|
||||
data.columnType = "Super";
|
||||
data.comparator = new UTF8Type();
|
||||
systemMetadata.put(HintedHandOffManager.HINTS_CF, data);
|
||||
|
||||
tableToCFMetaDataMap_.put("system", systemMetadata);
|
||||
|
||||
/* make sure we have a directory for each table */
|
||||
createTableDirectories();
|
||||
|
|
@ -450,6 +476,7 @@ public class DatabaseDescriptor
|
|||
* the table name and the column families that make up the table.
|
||||
* Each column family also has an associated ID which is an int.
|
||||
*/
|
||||
// TODO duplicating data b/t tablemetadata and CFMetaData is confusing and error-prone
|
||||
public static void storeMetadata() throws IOException
|
||||
{
|
||||
int cfId = 0;
|
||||
|
|
@ -470,11 +497,6 @@ public class DatabaseDescriptor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hardcoded system table
|
||||
Table.TableMetadata tmetadata = Table.TableMetadata.instance(Table.SYSTEM_TABLE);
|
||||
tmetadata.add(SystemTable.LOCATION_CF, cfId++);
|
||||
tmetadata.add(HintedHandOffManager.HINTS_CF, cfId++, ColumnFamily.getColumnType("Super"));
|
||||
}
|
||||
|
||||
public static int getGcGraceInSeconds()
|
||||
|
|
@ -587,17 +609,6 @@ public class DatabaseDescriptor
|
|||
return cfMetaData.flushPeriodInMinutes;
|
||||
}
|
||||
|
||||
public static boolean isTimeSortingEnabled(String tableName, String cfName)
|
||||
{
|
||||
assert tableName != null;
|
||||
CFMetaData cfMetaData = getCFMetaData(tableName, cfName);
|
||||
|
||||
if (cfMetaData == null)
|
||||
return false;
|
||||
|
||||
return "Time".equals(cfMetaData.indexProperty_);
|
||||
}
|
||||
|
||||
public static List<String> getTables()
|
||||
{
|
||||
return tables_;
|
||||
|
|
@ -759,10 +770,10 @@ public class DatabaseDescriptor
|
|||
return dataFileDirectory;
|
||||
}
|
||||
|
||||
public static ColumnComparatorFactory.ComparatorType getTypeInfo(String tableName, String cfName)
|
||||
public static AbstractType getType(String tableName, String cfName)
|
||||
{
|
||||
assert tableName != null;
|
||||
return ColumnComparatorFactory.ComparatorType.NAME;
|
||||
return getCFMetaData(tableName, cfName).comparator;
|
||||
}
|
||||
|
||||
public static Map<String, Map<String, CFMetaData>> getTableToColumnFamilyMap()
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
|
|
@ -32,6 +33,7 @@ import org.apache.cassandra.service.StorageProxy;
|
|||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* A Row Source Defintion (RSD) for doing a range query on a column map
|
||||
|
|
@ -75,7 +77,7 @@ public class ColumnRangeQueryRSD extends RowSourceDef
|
|||
limit_ = limit;
|
||||
}
|
||||
|
||||
public List<Map<String,String>> getRows()
|
||||
public List<Map<String,String>> getRows() throws UnsupportedEncodingException
|
||||
{
|
||||
QueryPath path;
|
||||
String superColumnKey = null;
|
||||
|
|
@ -83,7 +85,7 @@ public class ColumnRangeQueryRSD extends RowSourceDef
|
|||
if (superColumnKey_ != null)
|
||||
{
|
||||
superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey);
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -94,7 +96,7 @@ public class ColumnRangeQueryRSD extends RowSourceDef
|
|||
try
|
||||
{
|
||||
String key = (String)(rowKey_.get());
|
||||
ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, path, "", "", true, limit_);
|
||||
ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, path, ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, limit_);
|
||||
row = StorageProxy.readProtocol(readCommand, StorageService.ConsistencyLevel.WEAK);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -113,13 +115,13 @@ public class ColumnRangeQueryRSD extends RowSourceDef
|
|||
if (superColumnKey_ != null)
|
||||
{
|
||||
// this is the super column case
|
||||
IColumn column = cfamily.getColumn(superColumnKey);
|
||||
IColumn column = cfamily.getColumn(superColumnKey.getBytes("UTF-8"));
|
||||
if (column != null)
|
||||
columns = column.getSubColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
columns = cfamily.getAllColumns();
|
||||
columns = cfamily.getSortedColumns();
|
||||
}
|
||||
|
||||
if (columns != null && columns.size() > 0)
|
||||
|
|
@ -128,7 +130,7 @@ public class ColumnRangeQueryRSD extends RowSourceDef
|
|||
{
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
|
||||
result.put(cfMetaData_.n_columnKey, column.name());
|
||||
result.put(cfMetaData_.n_columnKey, new String(column.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnValue, new String(column.value()));
|
||||
result.put(cfMetaData_.n_columnTimestamp, Long.toString(column.timestamp()));
|
||||
|
||||
|
|
@ -155,6 +157,6 @@ public class ColumnRangeQueryRSD extends RowSourceDef
|
|||
rowKey_.explain(),
|
||||
(superColumnKey_ == null) ? "" : " SuperColumnKey: " + superColumnKey_.explain() + "\n",
|
||||
limit_,
|
||||
cfMetaData_.indexProperty_);
|
||||
cfMetaData_.comparator);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.apache.cassandra.cql.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* Abstract class representing the shared execution plan for a CQL
|
||||
* statement (query or DML operation).
|
||||
|
|
@ -25,6 +27,6 @@ package org.apache.cassandra.cql.common;
|
|||
*/
|
||||
public abstract class Plan
|
||||
{
|
||||
public abstract CqlResult execute();
|
||||
public abstract CqlResult execute() throws UnsupportedEncodingException;
|
||||
public abstract String explainPlan();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.apache.cassandra.cql.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +40,14 @@ public class QueryPlan extends Plan
|
|||
{
|
||||
if (root != null)
|
||||
{
|
||||
return new CqlResult(root.getRows());
|
||||
try
|
||||
{
|
||||
return new CqlResult(root.getRows());
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
logger_.error("No rowsource to execute");
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.cassandra.cql.common;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* The abstract notion of a row source definition. A row source
|
||||
|
|
@ -43,6 +44,6 @@ import java.util.Map;
|
|||
*/
|
||||
public abstract class RowSourceDef
|
||||
{
|
||||
public abstract List<Map<String,String>> getRows();
|
||||
public abstract List<Map<String,String>> getRows() throws UnsupportedEncodingException;
|
||||
public abstract String explainPlan();
|
||||
}
|
||||
|
|
@ -84,11 +84,11 @@ public class SetColumnMap extends DMLPlan
|
|||
if (superColumnKey_ != null)
|
||||
{
|
||||
String superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey, (String)columnKey.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"), ((String)columnKey.get()).getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new QueryPath(cfMetaData_.cfName, null, (String)columnKey.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, null, ((String)columnKey.get()).getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
rm.add(path, ((String)value.get()).getBytes(), time);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class SetSuperColumnMap extends DMLPlan
|
|||
{
|
||||
OperandDef columnKey = entry.getFirst();
|
||||
OperandDef value = entry.getSecond();
|
||||
QueryPath path = new QueryPath(cfMetaData_.cfName, (String)(superColumnKey.get()), (String)(columnKey.get()));
|
||||
QueryPath path = new QueryPath(cfMetaData_.cfName, ((String)(superColumnKey.get())).getBytes("UTF-8"), ((String)(columnKey.get())).getBytes("UTF-8"));
|
||||
rm.add(path, ((String)value.get()).getBytes(), time);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.apache.cassandra.cql.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
|
|
@ -69,7 +71,7 @@ public class SetUniqueKey extends DMLPlan
|
|||
value_ = value;
|
||||
}
|
||||
|
||||
public CqlResult execute()
|
||||
public CqlResult execute() throws UnsupportedEncodingException
|
||||
{
|
||||
String columnKey = (String)(columnKey_.get());
|
||||
QueryPath path;
|
||||
|
|
@ -77,11 +79,11 @@ public class SetUniqueKey extends DMLPlan
|
|||
if (superColumnKey_ != null)
|
||||
{
|
||||
String superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey, columnKey);
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"), columnKey.getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new QueryPath(cfMetaData_.cfName, null, columnKey);
|
||||
path = new QueryPath(cfMetaData_.cfName, null, columnKey.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
|
|
@ -32,6 +33,7 @@ import org.apache.cassandra.service.StorageProxy;
|
|||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* A Row Source Definition (RSD) for doing a super column range query on a Super Column Family.
|
||||
|
|
@ -58,13 +60,13 @@ public class SuperColumnRangeQueryRSD extends RowSourceDef
|
|||
limit_ = limit;
|
||||
}
|
||||
|
||||
public List<Map<String,String>> getRows()
|
||||
public List<Map<String,String>> getRows() throws UnsupportedEncodingException
|
||||
{
|
||||
Row row = null;
|
||||
try
|
||||
{
|
||||
String key = (String)(rowKey_.get());
|
||||
ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, new QueryPath(cfMetaData_.cfName), "", "", true, limit_);
|
||||
ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, new QueryPath(cfMetaData_.cfName), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, limit_);
|
||||
row = StorageProxy.readProtocol(readCommand, StorageService.ConsistencyLevel.WEAK);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -79,7 +81,7 @@ public class SuperColumnRangeQueryRSD extends RowSourceDef
|
|||
ColumnFamily cfamily = row.getColumnFamily(cfMetaData_.cfName);
|
||||
if (cfamily != null)
|
||||
{
|
||||
Collection<IColumn> columns = cfamily.getAllColumns();
|
||||
Collection<IColumn> columns = cfamily.getSortedColumns();
|
||||
if (columns != null && columns.size() > 0)
|
||||
{
|
||||
for (IColumn column : columns)
|
||||
|
|
@ -88,8 +90,8 @@ public class SuperColumnRangeQueryRSD extends RowSourceDef
|
|||
for( IColumn subColumn : subColumns )
|
||||
{
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put(cfMetaData_.n_superColumnKey, column.name());
|
||||
result.put(cfMetaData_.n_columnKey, subColumn.name());
|
||||
result.put(cfMetaData_.n_superColumnKey, new String(column.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnKey, new String(subColumn.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnValue, new String(subColumn.value()));
|
||||
result.put(cfMetaData_.n_columnTimestamp, Long.toString(subColumn.timestamp()));
|
||||
rows.add(result);
|
||||
|
|
@ -114,6 +116,6 @@ public class SuperColumnRangeQueryRSD extends RowSourceDef
|
|||
cfMetaData_.cfName,
|
||||
rowKey_.explain(),
|
||||
limit_,
|
||||
cfMetaData_.indexProperty_);
|
||||
cfMetaData_.comparator);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.cassandra.cql.common;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.cql.execution.RuntimeErrorMsg;
|
||||
|
|
@ -59,7 +60,7 @@ public class UniqueKeyQueryRSD extends RowSourceDef
|
|||
}
|
||||
|
||||
// specific column lookup
|
||||
public List<Map<String,String>> getRows() throws RuntimeException
|
||||
public List<Map<String,String>> getRows() throws UnsupportedEncodingException
|
||||
{
|
||||
String columnKey = (String)(columnKey_.get());
|
||||
QueryPath path = null;
|
||||
|
|
@ -68,7 +69,7 @@ public class UniqueKeyQueryRSD extends RowSourceDef
|
|||
if (superColumnKey_ != null)
|
||||
{
|
||||
superColumnKey = (String)(superColumnKey_.get());
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey);
|
||||
path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -79,7 +80,7 @@ public class UniqueKeyQueryRSD extends RowSourceDef
|
|||
try
|
||||
{
|
||||
String key = (String)(rowKey_.get());
|
||||
ReadCommand readCommand = new SliceByNamesReadCommand(cfMetaData_.tableName, key, path, Arrays.asList(columnKey));
|
||||
ReadCommand readCommand = new SliceByNamesReadCommand(cfMetaData_.tableName, key, path, Arrays.asList(columnKey.getBytes("UTF-8")));
|
||||
row = StorageProxy.readProtocol(readCommand, StorageService.ConsistencyLevel.WEAK);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -97,13 +98,13 @@ public class UniqueKeyQueryRSD extends RowSourceDef
|
|||
if (superColumnKey_ != null)
|
||||
{
|
||||
// this is the super column case
|
||||
IColumn column = cfamily.getColumn(superColumnKey);
|
||||
IColumn column = cfamily.getColumn(superColumnKey.getBytes("UTF-8"));
|
||||
if (column != null)
|
||||
columns = column.getSubColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
columns = cfamily.getAllColumns();
|
||||
columns = cfamily.getSortedColumns();
|
||||
}
|
||||
|
||||
if (columns != null && columns.size() > 0)
|
||||
|
|
@ -120,7 +121,7 @@ public class UniqueKeyQueryRSD extends RowSourceDef
|
|||
List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put(cfMetaData_.n_columnKey, column.name());
|
||||
result.put(cfMetaData_.n_columnKey, new String(column.name(), "UTF-8"));
|
||||
result.put(cfMetaData_.n_columnValue, new String(column.value()));
|
||||
result.put(cfMetaData_.n_columnTimestamp, Long.toString(column.timestamp()));
|
||||
|
||||
|
|
|
|||
|
|
@ -18,16 +18,12 @@
|
|||
|
||||
package org.apache.cassandra.db;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.io.ICompactSerializer;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -47,27 +43,27 @@ public final class Column implements IColumn
|
|||
return serializer_;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final byte[] name;
|
||||
private final byte[] value;
|
||||
private final long timestamp;
|
||||
private final boolean isMarkedForDelete;
|
||||
|
||||
Column(String name)
|
||||
Column(byte[] name)
|
||||
{
|
||||
this(name, ArrayUtils.EMPTY_BYTE_ARRAY);
|
||||
}
|
||||
|
||||
Column(String name, byte[] value)
|
||||
Column(byte[] name, byte[] value)
|
||||
{
|
||||
this(name, value, 0);
|
||||
}
|
||||
|
||||
public Column(String name, byte[] value, long timestamp)
|
||||
public Column(byte[] name, byte[] value, long timestamp)
|
||||
{
|
||||
this(name, value, timestamp, false);
|
||||
}
|
||||
|
||||
public Column(String name, byte[] value, long timestamp, boolean isDeleted)
|
||||
public Column(byte[] name, byte[] value, long timestamp, boolean isDeleted)
|
||||
{
|
||||
assert name != null;
|
||||
assert value != null;
|
||||
|
|
@ -77,12 +73,12 @@ public final class Column implements IColumn
|
|||
isMarkedForDelete = isDeleted;
|
||||
}
|
||||
|
||||
public String name()
|
||||
public byte[] name()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public IColumn getSubColumn(String columnName)
|
||||
public Column getSubColumn(byte[] columnName)
|
||||
{
|
||||
throw new UnsupportedOperationException("This operation is unsupported on simple columns.");
|
||||
}
|
||||
|
|
@ -92,7 +88,7 @@ public final class Column implements IColumn
|
|||
return value;
|
||||
}
|
||||
|
||||
public byte[] value(String key)
|
||||
public byte[] value(byte[] key)
|
||||
{
|
||||
throw new UnsupportedOperationException("This operation is unsupported on simple columns.");
|
||||
}
|
||||
|
|
@ -112,7 +108,7 @@ public final class Column implements IColumn
|
|||
return timestamp;
|
||||
}
|
||||
|
||||
public long timestamp(String key)
|
||||
public long timestamp(byte[] key)
|
||||
{
|
||||
throw new UnsupportedOperationException("This operation is unsupported on simple columns.");
|
||||
}
|
||||
|
|
@ -146,7 +142,7 @@ public final class Column implements IColumn
|
|||
* We store the string as UTF-8 encoded, so when we calculate the length, it
|
||||
* should be converted to UTF-8.
|
||||
*/
|
||||
return IColumn.UtfPrefix_ + FBUtilities.getUTF8Length(name) + DBConstants.boolSize_ + DBConstants.tsSize_ + DBConstants.intSize_ + value.length;
|
||||
return IColumn.UtfPrefix_ + name.length + DBConstants.boolSize_ + DBConstants.tsSize_ + DBConstants.intSize_ + value.length;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -172,19 +168,6 @@ public final class Column implements IColumn
|
|||
return null;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name);
|
||||
sb.append(":");
|
||||
sb.append(isMarkedForDelete());
|
||||
sb.append(":");
|
||||
sb.append(value().length);
|
||||
sb.append("@");
|
||||
sb.append(timestamp());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public byte[] digest()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
|
@ -210,27 +193,18 @@ public final class Column implements IColumn
|
|||
}
|
||||
return timestamp - o.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
class ColumnSerializer implements ICompactSerializer<IColumn>
|
||||
{
|
||||
public void serialize(IColumn column, DataOutputStream dos) throws IOException
|
||||
public String getString(AbstractType comparator)
|
||||
{
|
||||
dos.writeUTF(column.name());
|
||||
dos.writeBoolean(column.isMarkedForDelete());
|
||||
dos.writeLong(column.timestamp());
|
||||
dos.writeInt(column.value().length);
|
||||
dos.write(column.value());
|
||||
}
|
||||
|
||||
public IColumn deserialize(DataInputStream dis) throws IOException
|
||||
{
|
||||
String name = dis.readUTF();
|
||||
boolean delete = dis.readBoolean();
|
||||
long ts = dis.readLong();
|
||||
int size = dis.readInt();
|
||||
byte[] value = new byte[size];
|
||||
dis.readFully(value);
|
||||
return new Column(name, value, ts, delete);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(comparator.getString(name));
|
||||
sb.append(":");
|
||||
sb.append(isMarkedForDelete());
|
||||
sb.append(":");
|
||||
sb.append(value.length);
|
||||
sb.append("@");
|
||||
sb.append(timestamp());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.apache.cassandra.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
|
||||
|
||||
/**
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )
|
||||
*/
|
||||
|
||||
public class ColumnComparatorFactory
|
||||
{
|
||||
public static enum ComparatorType
|
||||
{
|
||||
NAME,
|
||||
}
|
||||
|
||||
public static final Comparator<IColumn> nameComparator_ = new ColumnNameComparator();
|
||||
|
||||
public static Comparator<IColumn> getComparator(ComparatorType comparatorType)
|
||||
{
|
||||
assert comparatorType == ComparatorType.NAME;
|
||||
return nameComparator_;
|
||||
}
|
||||
|
||||
public static Comparator<IColumn> getComparator(int comparatorTypeInt)
|
||||
{
|
||||
return getComparator(ComparatorType.values()[comparatorTypeInt]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract class AbstractColumnComparator implements Comparator<IColumn>, Serializable
|
||||
{
|
||||
protected ColumnComparatorFactory.ComparatorType comparatorType_;
|
||||
|
||||
public AbstractColumnComparator(ColumnComparatorFactory.ComparatorType comparatorType)
|
||||
{
|
||||
comparatorType_ = comparatorType;
|
||||
}
|
||||
|
||||
ColumnComparatorFactory.ComparatorType getComparatorType()
|
||||
{
|
||||
return comparatorType_;
|
||||
}
|
||||
}
|
||||
|
||||
class ColumnNameComparator extends AbstractColumnComparator
|
||||
{
|
||||
ColumnNameComparator()
|
||||
{
|
||||
super(ColumnComparatorFactory.ComparatorType.NAME);
|
||||
}
|
||||
|
||||
/* if the names are the same then sort by time-stamps */
|
||||
public int compare(IColumn column1, IColumn column2)
|
||||
{
|
||||
assert column1.getClass() == column2.getClass();
|
||||
long result = column1.name().compareTo(column2.name());
|
||||
int finalResult = 0;
|
||||
if (result == 0 && (column1 instanceof Column))
|
||||
{
|
||||
/* inverse sort by time to get the latest first */
|
||||
result = column2.timestamp() - column1.timestamp();
|
||||
}
|
||||
if (result > 0)
|
||||
{
|
||||
finalResult = 1;
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
finalResult = -1;
|
||||
}
|
||||
return finalResult;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,16 +22,16 @@ import java.io.DataInputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -39,6 +39,8 @@ import org.apache.cassandra.config.DatabaseDescriptor;
|
|||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.io.ICompactSerializer;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
|
||||
/**
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )
|
||||
|
|
@ -51,7 +53,6 @@ public final class ColumnFamily
|
|||
|
||||
private static Logger logger_ = Logger.getLogger( ColumnFamily.class );
|
||||
private static Map<String, String> columnTypes_ = new HashMap<String, String>();
|
||||
private static Map<String, String> indexTypes_ = new HashMap<String, String>();
|
||||
private String type_;
|
||||
private String table_;
|
||||
|
||||
|
|
@ -61,9 +62,6 @@ public final class ColumnFamily
|
|||
/* TODO: These are the various column types. Hard coded for now. */
|
||||
columnTypes_.put("Standard", "Standard");
|
||||
columnTypes_.put("Super", "Super");
|
||||
|
||||
indexTypes_.put("Name", "Name");
|
||||
indexTypes_.put("Time", "Time");
|
||||
}
|
||||
|
||||
public static ICompactSerializer<ColumnFamily> serializer()
|
||||
|
|
@ -87,17 +85,10 @@ public final class ColumnFamily
|
|||
return columnTypes_.get(key);
|
||||
}
|
||||
|
||||
public static String getColumnSortProperty(String columnIndexProperty)
|
||||
{
|
||||
if ( columnIndexProperty == null )
|
||||
return indexTypes_.get("Time");
|
||||
return indexTypes_.get(columnIndexProperty);
|
||||
}
|
||||
|
||||
public static ColumnFamily create(String tableName, String cfName)
|
||||
{
|
||||
String columnType = DatabaseDescriptor.getColumnFamilyType(tableName, cfName);
|
||||
Comparator<IColumn> comparator = ColumnComparatorFactory.getComparator(ColumnComparatorFactory.ComparatorType.NAME);
|
||||
AbstractType comparator = DatabaseDescriptor.getType(tableName, cfName);
|
||||
return new ColumnFamily(cfName, columnType, comparator);
|
||||
}
|
||||
|
||||
|
|
@ -107,20 +98,14 @@ public final class ColumnFamily
|
|||
private long markedForDeleteAt = Long.MIN_VALUE;
|
||||
private int localDeletionTime = Integer.MIN_VALUE;
|
||||
private AtomicInteger size_ = new AtomicInteger(0);
|
||||
private EfficientBidiMap columns_;
|
||||
private ConcurrentSkipListMap<byte[], IColumn> columns_;
|
||||
|
||||
public ColumnFamily(String cfName, String columnType, Comparator<IColumn> comparator)
|
||||
public ColumnFamily(String cfName, String columnType, AbstractType comparator)
|
||||
{
|
||||
name_ = cfName;
|
||||
type_ = columnType;
|
||||
columnSerializer_ = columnType.equals("Standard") ? Column.serializer() : SuperColumn.serializer();
|
||||
if(columns_ == null)
|
||||
columns_ = new EfficientBidiMap(comparator);
|
||||
}
|
||||
|
||||
public ColumnFamily(String cfName, String columnType, ColumnComparatorFactory.ComparatorType indexType)
|
||||
{
|
||||
this(cfName, columnType, ColumnComparatorFactory.getComparator(indexType));
|
||||
columns_ = new ConcurrentSkipListMap<byte[], IColumn>(comparator);
|
||||
}
|
||||
|
||||
public ColumnFamily cloneMeShallow()
|
||||
|
|
@ -134,7 +119,7 @@ public final class ColumnFamily
|
|||
ColumnFamily cloneMe()
|
||||
{
|
||||
ColumnFamily cf = cloneMeShallow();
|
||||
cf.columns_ = columns_.cloneMe();
|
||||
cf.columns_ = columns_.clone();
|
||||
return cf;
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +134,7 @@ public final class ColumnFamily
|
|||
*/
|
||||
void addColumns(ColumnFamily cf)
|
||||
{
|
||||
for (IColumn column : cf.getAllColumns())
|
||||
for (IColumn column : cf.getSortedColumns())
|
||||
{
|
||||
addColumn(column);
|
||||
}
|
||||
|
|
@ -163,22 +148,17 @@ public final class ColumnFamily
|
|||
int getColumnCount()
|
||||
{
|
||||
int count = 0;
|
||||
Map<String, IColumn> columns = columns_.getColumns();
|
||||
if( columns != null )
|
||||
{
|
||||
if(!isSuper())
|
||||
{
|
||||
count = columns.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<IColumn> values = columns.values();
|
||||
for(IColumn column: values)
|
||||
{
|
||||
count += column.getObjectCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isSuper())
|
||||
{
|
||||
count = columns_.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
for(IColumn column: columns_.values())
|
||||
{
|
||||
count += column.getObjectCount();
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
@ -199,12 +179,28 @@ public final class ColumnFamily
|
|||
IColumn column;
|
||||
if (path.superColumnName == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
getComparator().validate(path.columnName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MarshalException("Invalid column name in " + path.columnFamilyName + " for " + getComparator().getClass().getName());
|
||||
}
|
||||
column = new Column(path.columnName, value, timestamp, deleted);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
getComparator().validate(path.superColumnName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MarshalException("Invalid supercolumn name in " + path.columnFamilyName + " for " + getComparator().getClass().getName());
|
||||
}
|
||||
column = new SuperColumn(path.superColumnName);
|
||||
column.addColumn(new Column(path.columnName, value, timestamp, deleted));
|
||||
column.addColumn(new Column(path.columnName, value, timestamp, deleted)); // checks subcolumn name
|
||||
}
|
||||
addColumn(column);
|
||||
}
|
||||
|
|
@ -223,7 +219,7 @@ public final class ColumnFamily
|
|||
*/
|
||||
public void addColumn(IColumn column)
|
||||
{
|
||||
String name = column.name();
|
||||
byte[] name = column.name();
|
||||
IColumn oldColumn = columns_.get(name);
|
||||
if (oldColumn != null)
|
||||
{
|
||||
|
|
@ -249,22 +245,27 @@ public final class ColumnFamily
|
|||
}
|
||||
}
|
||||
|
||||
public IColumn getColumn(String name)
|
||||
public IColumn getColumn(byte[] name)
|
||||
{
|
||||
return columns_.get( name );
|
||||
return columns_.get(name);
|
||||
}
|
||||
|
||||
public SortedSet<IColumn> getAllColumns()
|
||||
public SortedSet<byte[]> getColumnNames()
|
||||
{
|
||||
return columns_.getSortedColumns();
|
||||
return columns_.keySet();
|
||||
}
|
||||
|
||||
public Map<String, IColumn> getColumns()
|
||||
public Collection<IColumn> getSortedColumns()
|
||||
{
|
||||
return columns_.getColumns();
|
||||
return columns_.values();
|
||||
}
|
||||
|
||||
public void remove(String columnName)
|
||||
public Map<byte[], IColumn> getColumnsMap()
|
||||
{
|
||||
return columns_;
|
||||
}
|
||||
|
||||
public void remove(byte[] columnName)
|
||||
{
|
||||
columns_.remove(columnName);
|
||||
}
|
||||
|
|
@ -301,50 +302,44 @@ public final class ColumnFamily
|
|||
// (don't need to worry about cfNew containing IColumns that are shadowed by
|
||||
// the delete tombstone, since cfNew was generated by CF.resolve, which
|
||||
// takes care of those for us.)
|
||||
Map<String, IColumn> columns = cfComposite.getColumns();
|
||||
Set<String> cNames = columns.keySet();
|
||||
for ( String cName : cNames )
|
||||
Map<byte[], IColumn> columns = cfComposite.getColumnsMap();
|
||||
Set<byte[]> cNames = columns.keySet();
|
||||
for (byte[] cName : cNames)
|
||||
{
|
||||
IColumn columnInternal = columns_.get(cName);
|
||||
IColumn columnExternal = columns.get(cName);
|
||||
if( columnInternal == null )
|
||||
{
|
||||
cfDiff.addColumn(columnExternal);
|
||||
}
|
||||
else
|
||||
{
|
||||
IColumn columnDiff = columnInternal.diff(columnExternal);
|
||||
if(columnDiff != null)
|
||||
{
|
||||
cfDiff.addColumn(columnDiff);
|
||||
}
|
||||
}
|
||||
IColumn columnInternal = columns_.get(cName);
|
||||
IColumn columnExternal = columns.get(cName);
|
||||
if (columnInternal == null)
|
||||
{
|
||||
cfDiff.addColumn(columnExternal);
|
||||
}
|
||||
else
|
||||
{
|
||||
IColumn columnDiff = columnInternal.diff(columnExternal);
|
||||
if (columnDiff != null)
|
||||
{
|
||||
cfDiff.addColumn(columnDiff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!cfDiff.getColumns().isEmpty() || cfDiff.isMarkedForDelete())
|
||||
if (!cfDiff.getColumnsMap().isEmpty() || cfDiff.isMarkedForDelete())
|
||||
return cfDiff;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private Comparator<IColumn> getComparator()
|
||||
public AbstractType getComparator()
|
||||
{
|
||||
return columns_.getComparator();
|
||||
}
|
||||
|
||||
public ColumnComparatorFactory.ComparatorType getComparatorType()
|
||||
{
|
||||
return ColumnComparatorFactory.ComparatorType.NAME;
|
||||
return (AbstractType)columns_.comparator();
|
||||
}
|
||||
|
||||
int size()
|
||||
{
|
||||
if ( size_.get() == 0 )
|
||||
if (size_.get() == 0)
|
||||
{
|
||||
Set<String> cNames = columns_.getColumns().keySet();
|
||||
for ( String cName : cNames )
|
||||
for (IColumn column : columns_.values())
|
||||
{
|
||||
size_.addAndGet(columns_.get(cName).size());
|
||||
size_.addAndGet(column.size());
|
||||
}
|
||||
}
|
||||
return size_.get();
|
||||
|
|
@ -374,7 +369,7 @@ public final class ColumnFamily
|
|||
}
|
||||
|
||||
sb.append(" [");
|
||||
sb.append(StringUtils.join(getAllColumns(), ", "));
|
||||
sb.append(getComparator().getColumnsString(getSortedColumns()));
|
||||
sb.append("])");
|
||||
|
||||
return sb.toString();
|
||||
|
|
@ -382,20 +377,19 @@ public final class ColumnFamily
|
|||
|
||||
public byte[] digest()
|
||||
{
|
||||
Set<IColumn> columns = columns_.getSortedColumns();
|
||||
byte[] xorHash = ArrayUtils.EMPTY_BYTE_ARRAY;
|
||||
for(IColumn column : columns)
|
||||
{
|
||||
if(xorHash.length == 0)
|
||||
{
|
||||
xorHash = column.digest();
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] xorHash = ArrayUtils.EMPTY_BYTE_ARRAY;
|
||||
for (IColumn column : columns_.values())
|
||||
{
|
||||
if (xorHash.length == 0)
|
||||
{
|
||||
xorHash = column.digest();
|
||||
}
|
||||
else
|
||||
{
|
||||
xorHash = FBUtilities.xor(xorHash, column.digest());
|
||||
}
|
||||
}
|
||||
return xorHash;
|
||||
}
|
||||
}
|
||||
return xorHash;
|
||||
}
|
||||
|
||||
public long getMarkedForDeleteAt()
|
||||
|
|
@ -462,11 +456,11 @@ public final class ColumnFamily
|
|||
*/
|
||||
public void serialize(ColumnFamily columnFamily, DataOutputStream dos) throws IOException
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
Collection<IColumn> columns = columnFamily.getSortedColumns();
|
||||
|
||||
dos.writeUTF(columnFamily.name());
|
||||
dos.writeUTF(columnFamily.type_);
|
||||
dos.writeInt(columnFamily.getComparatorType().ordinal());
|
||||
dos.writeUTF(columnFamily.getComparator().getClass().getCanonicalName());
|
||||
dos.writeInt(columnFamily.localDeletionTime);
|
||||
dos.writeLong(columnFamily.markedForDeleteAt);
|
||||
|
||||
|
|
@ -481,7 +475,7 @@ public final class ColumnFamily
|
|||
{
|
||||
ColumnFamily cf = new ColumnFamily(dis.readUTF(),
|
||||
dis.readUTF(),
|
||||
ColumnComparatorFactory.ComparatorType.values()[dis.readInt()]);
|
||||
readComparator(dis));
|
||||
cf.delete(dis.readInt(), dis.readLong());
|
||||
int size = dis.readInt();
|
||||
IColumn column;
|
||||
|
|
@ -492,6 +486,23 @@ public final class ColumnFamily
|
|||
}
|
||||
return cf;
|
||||
}
|
||||
|
||||
private AbstractType readComparator(DataInputStream dis) throws IOException
|
||||
{
|
||||
String className = dis.readUTF();
|
||||
try
|
||||
{
|
||||
return (AbstractType)Class.forName(className).getConstructor().newInstance();
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to load comparator class '" + className + "'. probably this means you have obsolete sstables lying around", e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import org.apache.cassandra.service.StorageService;
|
|||
import org.apache.cassandra.utils.*;
|
||||
import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor;
|
||||
import org.apache.cassandra.db.filter.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.collections.IteratorUtils;
|
||||
|
|
@ -534,9 +535,9 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
// either way (tombstone or non- getting priority) would be fine,
|
||||
// but we picked this way because it makes removing delivered hints
|
||||
// easier for HintedHandoffManager.
|
||||
for (String cname : new ArrayList<String>(cf.getColumns().keySet()))
|
||||
for (byte[] cname : cf.getColumnNames())
|
||||
{
|
||||
IColumn c = cf.getColumns().get(cname);
|
||||
IColumn c = cf.getColumnsMap().get(cname);
|
||||
if (c instanceof SuperColumn)
|
||||
{
|
||||
long minTimestamp = Math.max(c.getMarkedForDeleteAt(), cf.getMarkedForDeleteAt());
|
||||
|
|
@ -1411,7 +1412,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
return writeStats_.mean();
|
||||
}
|
||||
|
||||
public ColumnFamily getColumnFamily(String key, QueryPath path, String start, String finish, boolean isAscending, int limit) throws IOException
|
||||
public ColumnFamily getColumnFamily(String key, QueryPath path, byte[] start, byte[] finish, boolean isAscending, int limit) throws IOException
|
||||
{
|
||||
return getColumnFamily(new SliceQueryFilter(key, path, start, finish, isAscending, limit));
|
||||
}
|
||||
|
|
@ -1428,14 +1429,17 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
*/
|
||||
public ColumnFamily getColumnFamily(QueryFilter filter, int gcBefore) throws IOException
|
||||
{
|
||||
assert columnFamily_.equals(filter.getColumnFamilyName());
|
||||
|
||||
// if we are querying subcolumns of a supercolumn, fetch the supercolumn with NQF, then filter in-memory.
|
||||
if (filter.path.superColumnName != null)
|
||||
{
|
||||
QueryFilter nameFilter = new NamesQueryFilter(filter.key, new QueryPath(filter.path.columnFamilyName), filter.path.superColumnName);
|
||||
AbstractType comparator = DatabaseDescriptor.getType(table_, columnFamily_);
|
||||
QueryFilter nameFilter = new NamesQueryFilter(filter.key, new QueryPath(columnFamily_), filter.path.superColumnName);
|
||||
ColumnFamily cf = getColumnFamily(nameFilter);
|
||||
if (cf != null)
|
||||
{
|
||||
for (IColumn column : cf.getAllColumns())
|
||||
for (IColumn column : cf.getSortedColumns())
|
||||
{
|
||||
filter.filterSuperColumn((SuperColumn) column);
|
||||
}
|
||||
|
|
@ -1455,7 +1459,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
memtableLock_.readLock().lock();
|
||||
try
|
||||
{
|
||||
iter = filter.getMemColumnIterator(memtable_);
|
||||
iter = filter.getMemColumnIterator(memtable_, getComparator());
|
||||
returnCF = iter.getColumnFamily();
|
||||
}
|
||||
finally
|
||||
|
|
@ -1468,7 +1472,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
List<Memtable> memtables = getUnflushedMemtables(filter.getColumnFamilyName());
|
||||
for (Memtable memtable:memtables)
|
||||
{
|
||||
iter = filter.getMemColumnIterator(memtable);
|
||||
iter = filter.getMemColumnIterator(memtable, getComparator());
|
||||
returnCF.delete(iter.getColumnFamily());
|
||||
iterators.add(iter);
|
||||
}
|
||||
|
|
@ -1477,7 +1481,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
List<SSTableReader> sstables = new ArrayList<SSTableReader>(ssTables_.values());
|
||||
for (SSTableReader sstable : sstables)
|
||||
{
|
||||
iter = filter.getSSTableColumnIterator(sstable);
|
||||
iter = filter.getSSTableColumnIterator(sstable, getComparator());
|
||||
if (iter.hasNext()) // initializes iter.CF
|
||||
{
|
||||
returnCF.delete(iter.getColumnFamily());
|
||||
|
|
@ -1485,7 +1489,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
iterators.add(iter);
|
||||
}
|
||||
|
||||
Comparator<IColumn> comparator = filter.getColumnComparator();
|
||||
Comparator<IColumn> comparator = filter.getColumnComparator(getComparator());
|
||||
Iterator collated = IteratorUtils.collatedIterator(comparator, iterators);
|
||||
if (!collated.hasNext())
|
||||
return null;
|
||||
|
|
@ -1513,6 +1517,11 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
}
|
||||
}
|
||||
|
||||
public AbstractType getComparator()
|
||||
{
|
||||
return DatabaseDescriptor.getType(table_, columnFamily_);
|
||||
}
|
||||
|
||||
/**
|
||||
* for testing. no effort is made to clear historical memtables.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ import org.apache.cassandra.config.DatabaseDescriptor;
|
|||
import org.apache.cassandra.io.DataOutputBuffer;
|
||||
import org.apache.cassandra.io.IndexHelper;
|
||||
import org.apache.cassandra.utils.BloomFilter;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
|
||||
/**
|
||||
* Help to create an index for a column family based on size of columns
|
||||
* Author : Karthik Ranganathan ( kranganathan@facebook.com )
|
||||
*/
|
||||
|
||||
public class ColumnIndexer
|
||||
|
|
@ -46,7 +46,7 @@ public class ColumnIndexer
|
|||
*/
|
||||
public static void serialize(ColumnFamily columnFamily, DataOutputStream dos) throws IOException
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
Collection<IColumn> columns = columnFamily.getSortedColumns();
|
||||
BloomFilter bf = createColumnBloomFilter(columns);
|
||||
/* Write out the bloom filter. */
|
||||
DataOutputBuffer bufOut = new DataOutputBuffer();
|
||||
|
|
@ -57,7 +57,7 @@ public class ColumnIndexer
|
|||
dos.write(bufOut.getData(), 0, bufOut.getLength());
|
||||
|
||||
/* Do the indexing */
|
||||
doIndexing(columnFamily.getComparatorType(), columns, dos);
|
||||
doIndexing(columnFamily.getComparator(), columns, dos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,20 +69,20 @@ public class ColumnIndexer
|
|||
private static BloomFilter createColumnBloomFilter(Collection<IColumn> columns)
|
||||
{
|
||||
int columnCount = 0;
|
||||
for ( IColumn column : columns )
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
columnCount += column.getObjectCount();
|
||||
}
|
||||
|
||||
|
||||
BloomFilter bf = new BloomFilter(columnCount, 4);
|
||||
for ( IColumn column : columns )
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
bf.add(column.name());
|
||||
/* If this is SuperColumn type Column Family we need to get the subColumns too. */
|
||||
if ( column instanceof SuperColumn )
|
||||
if (column instanceof SuperColumn)
|
||||
{
|
||||
Collection<IColumn> subColumns = column.getSubColumns();
|
||||
for ( IColumn subColumn : subColumns )
|
||||
for (IColumn subColumn : subColumns)
|
||||
{
|
||||
bf.add(subColumn.name());
|
||||
}
|
||||
|
|
@ -90,17 +90,6 @@ public class ColumnIndexer
|
|||
}
|
||||
return bf;
|
||||
}
|
||||
|
||||
private static IndexHelper.ColumnIndexInfo getColumnIndexInfo(ColumnComparatorFactory.ComparatorType typeInfo, IColumn column)
|
||||
{
|
||||
IndexHelper.ColumnIndexInfo cIndexInfo = null;
|
||||
|
||||
cIndexInfo = IndexHelper.ColumnIndexFactory.instance(typeInfo);
|
||||
cIndexInfo.set(typeInfo == ColumnComparatorFactory.ComparatorType.NAME
|
||||
? column.name() : column.timestamp());
|
||||
|
||||
return cIndexInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the collection of columns in the Column Family,
|
||||
|
|
@ -111,7 +100,7 @@ public class ColumnIndexer
|
|||
* to be written.
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void doIndexing(ColumnComparatorFactory.ComparatorType typeInfo, Collection<IColumn> columns, DataOutputStream dos) throws IOException
|
||||
private static void doIndexing(AbstractType comparator, Collection<IColumn> columns, DataOutputStream dos) throws IOException
|
||||
{
|
||||
/* we are going to write column indexes */
|
||||
int numColumns = 0;
|
||||
|
|
@ -139,7 +128,7 @@ public class ColumnIndexer
|
|||
* SuperColumn always use the name indexing scheme for
|
||||
* the SuperColumns. We will fix this later.
|
||||
*/
|
||||
IndexHelper.ColumnIndexInfo cIndexInfo = getColumnIndexInfo(typeInfo, column);
|
||||
IndexHelper.ColumnIndexInfo cIndexInfo = new IndexHelper.ColumnIndexInfo(column.name(), 0, 0, comparator);
|
||||
cIndexInfo.position(position);
|
||||
cIndexInfo.count(numColumns);
|
||||
columnIndexList.add(cIndexInfo);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package org.apache.cassandra.db;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import org.apache.cassandra.io.ICompactSerializer;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
||||
public class ColumnSerializer implements ICompactSerializer<IColumn>
|
||||
{
|
||||
public static void writeName(byte[] name, DataOutput out) throws IOException
|
||||
{
|
||||
int length = name.length;
|
||||
assert length <= 65535;
|
||||
out.writeByte((length >> 8) & 0xFF);
|
||||
out.writeByte(length & 0xFF);
|
||||
out.write(name);
|
||||
}
|
||||
|
||||
public static byte[] readName(DataInput in) throws IOException
|
||||
{
|
||||
int length = 0;
|
||||
length |= (in.readByte() << 8);
|
||||
length |= in.readByte();
|
||||
byte[] bytes = new byte[length];
|
||||
in.readFully(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void serialize(IColumn column, DataOutputStream dos) throws IOException
|
||||
{
|
||||
ColumnSerializer.writeName(column.name(), dos);
|
||||
dos.writeBoolean(column.isMarkedForDelete());
|
||||
dos.writeLong(column.timestamp());
|
||||
FBUtilities.writeByteArray(column.value(), dos);
|
||||
}
|
||||
|
||||
public Column deserialize(DataInputStream dis) throws IOException
|
||||
{
|
||||
byte[] name = ColumnSerializer.readName(dis);
|
||||
boolean delete = dis.readBoolean();
|
||||
long ts = dis.readLong();
|
||||
byte[] value = FBUtilities.readByteArray(dis);
|
||||
return new Column(name, value, ts, delete);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.apache.cassandra.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.cliffc.high_scale_lib.NonBlockingHashMap;
|
||||
|
||||
|
||||
/**
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )
|
||||
*/
|
||||
|
||||
class EfficientBidiMap implements Serializable
|
||||
{
|
||||
private NonBlockingHashMap<String, IColumn> map_;
|
||||
private ConcurrentSkipListSet<IColumn> sortedSet_;
|
||||
private Comparator<IColumn> columnComparator_;
|
||||
|
||||
EfficientBidiMap(Comparator<IColumn> columnComparator)
|
||||
{
|
||||
this(new NonBlockingHashMap<String, IColumn>(), new ConcurrentSkipListSet<IColumn>(columnComparator), columnComparator);
|
||||
}
|
||||
|
||||
private EfficientBidiMap(NonBlockingHashMap<String, IColumn> map, ConcurrentSkipListSet<IColumn> set, Comparator<IColumn> comparator)
|
||||
{
|
||||
map_ = map;
|
||||
sortedSet_ = set;
|
||||
columnComparator_ = comparator;
|
||||
}
|
||||
|
||||
public Comparator<IColumn> getComparator()
|
||||
{
|
||||
return columnComparator_;
|
||||
}
|
||||
|
||||
public void put(String key, IColumn column)
|
||||
{
|
||||
IColumn oldColumn = map_.put(key, column);
|
||||
if (oldColumn != null)
|
||||
sortedSet_.remove(oldColumn);
|
||||
sortedSet_.add(column);
|
||||
}
|
||||
|
||||
public IColumn get(String key)
|
||||
{
|
||||
return map_.get(key);
|
||||
}
|
||||
|
||||
public SortedSet<IColumn> getSortedColumns()
|
||||
{
|
||||
return sortedSet_;
|
||||
}
|
||||
|
||||
public Map<String, IColumn> getColumns()
|
||||
{
|
||||
return map_;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return map_.size();
|
||||
}
|
||||
|
||||
public void remove (String columnName)
|
||||
{
|
||||
sortedSet_.remove(map_.get(columnName));
|
||||
map_.remove(columnName);
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
map_.clear();
|
||||
sortedSet_.clear();
|
||||
}
|
||||
|
||||
ColumnComparatorFactory.ComparatorType getComparatorType()
|
||||
{
|
||||
return ((AbstractColumnComparator)columnComparator_).getComparatorType();
|
||||
}
|
||||
|
||||
EfficientBidiMap cloneMe()
|
||||
{
|
||||
return new EfficientBidiMap((NonBlockingHashMap<String, IColumn>) map_.clone(), sortedSet_.clone(), columnComparator_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ public class HintedHandOffManager
|
|||
return quorumResponseHandler.get();
|
||||
}
|
||||
|
||||
private static void deleteEndPoint(String endpointAddress, String tableName, String key, long timestamp) throws IOException
|
||||
private static void deleteEndPoint(byte[] endpointAddress, String tableName, byte[] key, long timestamp) throws IOException
|
||||
{
|
||||
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, tableName);
|
||||
rm.delete(new QueryPath(HINTS_CF, key, endpointAddress), timestamp);
|
||||
|
|
@ -124,16 +124,15 @@ public class HintedHandOffManager
|
|||
Collection<ColumnFamily> cfs = row.getColumnFamilies();
|
||||
for (ColumnFamily cf : cfs)
|
||||
{
|
||||
Set<IColumn> columns = cf.getAllColumns();
|
||||
long maxTS = Long.MIN_VALUE;
|
||||
if (!cf.isSuper())
|
||||
{
|
||||
for (IColumn col : columns)
|
||||
for (IColumn col : cf.getSortedColumns())
|
||||
maxTS = Math.max(maxTS, col.timestamp());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (IColumn col : columns)
|
||||
for (IColumn col : cf.getSortedColumns())
|
||||
{
|
||||
maxTS = Math.max(maxTS, col.timestamp());
|
||||
Collection<IColumn> subColumns = col.getSubColumns();
|
||||
|
|
@ -166,15 +165,17 @@ public class HintedHandOffManager
|
|||
{
|
||||
continue;
|
||||
}
|
||||
Collection<IColumn> keys = hintColumnFamily.getAllColumns();
|
||||
Collection<IColumn> keys = hintColumnFamily.getSortedColumns();
|
||||
|
||||
for (IColumn keyColumn : keys)
|
||||
{
|
||||
Collection<IColumn> endpoints = keyColumn.getSubColumns();
|
||||
String keyStr = new String(keyColumn.name(), "UTF-8");
|
||||
int deleted = 0;
|
||||
for (IColumn endpoint : endpoints)
|
||||
{
|
||||
if (sendMessage(endpoint.name(), tableName, keyColumn.name()))
|
||||
String endpointStr = new String(endpoint.name(), "UTF-8");
|
||||
if (sendMessage(endpointStr, tableName, keyStr))
|
||||
{
|
||||
deleteEndPoint(endpoint.name(), tableName, keyColumn.name(), keyColumn.timestamp());
|
||||
deleted++;
|
||||
|
|
@ -182,7 +183,7 @@ public class HintedHandOffManager
|
|||
}
|
||||
if (deleted == endpoints.size())
|
||||
{
|
||||
deleteHintedData(tableName, keyColumn.name());
|
||||
deleteHintedData(tableName, keyStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -198,6 +199,7 @@ public class HintedHandOffManager
|
|||
if (logger_.isDebugEnabled())
|
||||
logger_.debug("Started hinted handoff for endPoint " + endPoint.getHost());
|
||||
|
||||
String targetEPBytes = endPoint.getHost();
|
||||
// 1. Scan through all the keys that we need to handoff
|
||||
// 2. For each key read the list of recipients if the endpoint matches send
|
||||
// 3. Delete that recipient from the key if write was successful
|
||||
|
|
@ -209,19 +211,20 @@ public class HintedHandOffManager
|
|||
{
|
||||
continue;
|
||||
}
|
||||
Collection<IColumn> keys = hintedColumnFamily.getAllColumns();
|
||||
Collection<IColumn> keys = hintedColumnFamily.getSortedColumns();
|
||||
|
||||
for (IColumn keyColumn : keys)
|
||||
{
|
||||
String keyStr = new String(keyColumn.name(), "UTF-8");
|
||||
Collection<IColumn> endpoints = keyColumn.getSubColumns();
|
||||
for (IColumn endpoint : endpoints)
|
||||
for (IColumn hintEndPoint : endpoints)
|
||||
{
|
||||
if (endpoint.name().equals(endPoint.getHost()) && sendMessage(endpoint.name(), null, keyColumn.name()))
|
||||
if (hintEndPoint.name().equals(targetEPBytes) && sendMessage(endPoint.getHost(), null, keyStr))
|
||||
{
|
||||
deleteEndPoint(endpoint.name(), tableName, keyColumn.name(), keyColumn.timestamp());
|
||||
deleteEndPoint(hintEndPoint.name(), tableName, keyColumn.name(), keyColumn.timestamp());
|
||||
if (endpoints.size() == 1)
|
||||
{
|
||||
deleteHintedData(tableName, keyColumn.name());
|
||||
deleteHintedData(tableName, keyStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
package org.apache.cassandra.db;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
/**
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )
|
||||
|
|
@ -30,18 +31,19 @@ public interface IColumn
|
|||
public static short UtfPrefix_ = 2;
|
||||
public boolean isMarkedForDelete();
|
||||
public long getMarkedForDeleteAt();
|
||||
public String name();
|
||||
public byte[] name();
|
||||
public int size();
|
||||
public int serializedSize();
|
||||
public long timestamp();
|
||||
public long timestamp(String key);
|
||||
public long timestamp(byte[] columnName);
|
||||
public byte[] value();
|
||||
public byte[] value(String key);
|
||||
public byte[] value(byte[] columnName);
|
||||
public Collection<IColumn> getSubColumns();
|
||||
public IColumn getSubColumn(String columnName);
|
||||
public IColumn getSubColumn(byte[] columnName);
|
||||
public void addColumn(IColumn column);
|
||||
public IColumn diff(IColumn column);
|
||||
public int getObjectCount();
|
||||
public byte[] digest();
|
||||
public int getLocalDeletionTime(); // for tombstone GC, so int is sufficient granularity
|
||||
public String getString(AbstractType comparator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import org.apache.cassandra.io.SSTableWriter;
|
|||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.DestructivePQIterator;
|
||||
import org.apache.cassandra.db.filter.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -279,12 +280,12 @@ public class Memtable implements Comparable<Memtable>
|
|||
/**
|
||||
* obtain an iterator of columns in this memtable in the specified order starting from a given column.
|
||||
*/
|
||||
public ColumnIterator getSliceIterator(SliceQueryFilter filter)
|
||||
public ColumnIterator getSliceIterator(SliceQueryFilter filter, AbstractType typeComparator)
|
||||
{
|
||||
ColumnFamily cf = columnFamilies_.get(filter.key);
|
||||
final ColumnFamily columnFamily = cf == null ? ColumnFamily.create(table_, filter.getColumnFamilyName()) : cf.cloneMeShallow();
|
||||
|
||||
final IColumn columns[] = (cf == null ? columnFamily : cf).getAllColumns().toArray(new IColumn[columnFamily.getAllColumns().size()]);
|
||||
final IColumn columns[] = (cf == null ? columnFamily : cf).getSortedColumns().toArray(new IColumn[columnFamily.getSortedColumns().size()]);
|
||||
// TODO if we are dealing with supercolumns, we need to clone them while we have the read lock since they can be modified later
|
||||
if (!filter.isAscending)
|
||||
ArrayUtils.reverse(columns);
|
||||
|
|
@ -296,7 +297,7 @@ public class Memtable implements Comparable<Memtable>
|
|||
|
||||
// can't use a ColumnComparatorFactory comparator since those compare on both name and time (and thus will fail to match
|
||||
// our dummy column, since the time there is arbitrary).
|
||||
Comparator<IColumn> comparator = filter.getColumnComparator();
|
||||
Comparator<IColumn> comparator = filter.getColumnComparator(typeComparator);
|
||||
int index = Arrays.binarySearch(columns, startIColumn, comparator);
|
||||
final int startIndex = index < 0 ? -(index + 1) : index;
|
||||
|
||||
|
|
@ -328,8 +329,8 @@ public class Memtable implements Comparable<Memtable>
|
|||
|
||||
return new SimpleAbstractColumnIterator()
|
||||
{
|
||||
private Iterator<String> iter = filter.columns.iterator();
|
||||
private String current;
|
||||
private Iterator<byte[]> iter = filter.columns.iterator();
|
||||
private byte[] current;
|
||||
|
||||
public ColumnFamily getColumnFamily()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import java.util.Map;
|
|||
import org.apache.cassandra.io.ICompactSerializer;
|
||||
import org.apache.cassandra.net.Message;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
|
||||
|
||||
public abstract class ReadCommand
|
||||
|
|
@ -80,6 +82,11 @@ public abstract class ReadCommand
|
|||
public abstract ReadCommand copy();
|
||||
|
||||
public abstract Row getRow(Table table) throws IOException;
|
||||
|
||||
protected AbstractType getComparator()
|
||||
{
|
||||
return DatabaseDescriptor.getType(table, getColumnFamilyName());
|
||||
}
|
||||
}
|
||||
|
||||
class ReadCommandSerializer implements ICompactSerializer<ReadCommand>
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ import org.apache.cassandra.net.Message;
|
|||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.service.BatchMutationSuper;
|
||||
import org.apache.cassandra.service.BatchMutation;
|
||||
import org.apache.cassandra.service.InvalidRequestException;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -67,11 +69,6 @@ public class RowMutation implements Serializable
|
|||
private String key_;
|
||||
protected Map<String, ColumnFamily> modifications_ = new HashMap<String, ColumnFamily>();
|
||||
|
||||
/* Ctor for JAXB */
|
||||
private RowMutation()
|
||||
{
|
||||
}
|
||||
|
||||
public RowMutation(String table, String key)
|
||||
{
|
||||
table_ = table;
|
||||
|
|
@ -110,9 +107,9 @@ public class RowMutation implements Serializable
|
|||
return modifications_.keySet();
|
||||
}
|
||||
|
||||
void addHints(String hint) throws IOException
|
||||
void addHints(String key, String host) throws IOException
|
||||
{
|
||||
QueryPath path = new QueryPath(HintedHandOffManager.HINTS_CF, null, hint);
|
||||
QueryPath path = new QueryPath(HintedHandOffManager.HINTS_CF, key.getBytes("UTF-8"), host.getBytes("UTF-8"));
|
||||
add(path, ArrayUtils.EMPTY_BYTE_ARRAY, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +258,7 @@ public class RowMutation implements Serializable
|
|||
return rm;
|
||||
}
|
||||
|
||||
public static RowMutation getRowMutation(String table, BatchMutationSuper batchMutationSuper)
|
||||
public static RowMutation getRowMutation(String table, BatchMutationSuper batchMutationSuper) throws InvalidRequestException
|
||||
{
|
||||
RowMutation rm = new RowMutation(table, batchMutationSuper.key.trim());
|
||||
for (String cfName : batchMutationSuper.cfmap.keySet())
|
||||
|
|
@ -270,7 +267,14 @@ public class RowMutation implements Serializable
|
|||
{
|
||||
for (org.apache.cassandra.service.Column column : super_column.columns)
|
||||
{
|
||||
rm.add(new QueryPath(cfName, super_column.name, column.name), column.value, column.timestamp);
|
||||
try
|
||||
{
|
||||
rm.add(new QueryPath(cfName, super_column.name, column.name), column.value, column.timestamp);
|
||||
}
|
||||
catch (MarshalException e)
|
||||
{
|
||||
throw new InvalidRequestException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class RowMutationVerbHandler implements IVerbHandler
|
|||
logger_.debug("Adding hint for " + hint);
|
||||
/* add necessary hints to this mutation */
|
||||
RowMutation hintedMutation = new RowMutation(Table.SYSTEM_TABLE, rm.table());
|
||||
hintedMutation.addHints(rm.key() + ":" + hint.getHost());
|
||||
hintedMutation.addHints(rm.key(), hint.getHost());
|
||||
hintedMutation.apply();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ package org.apache.cassandra.db;
|
|||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
|
||||
|
||||
/**
|
||||
* This class is used to loop through a retrieved column family
|
||||
|
|
@ -66,7 +64,7 @@ public class Scanner implements IScanner<IColumn>
|
|||
ColumnFamily columnFamily = table.get(key, cf);
|
||||
if ( columnFamily != null )
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
Collection<IColumn> columns = columnFamily.getSortedColumns();
|
||||
columnIt_ = columns.iterator();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,22 +27,25 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.apache.cassandra.service.ColumnParent;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.filter.NamesQueryFilter;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
|
||||
public class SliceByNamesReadCommand extends ReadCommand
|
||||
{
|
||||
public final QueryPath columnParent;
|
||||
public final SortedSet<String> columnNames;
|
||||
public final SortedSet<byte[]> columnNames;
|
||||
|
||||
public SliceByNamesReadCommand(String table, String key, ColumnParent column_parent, Collection<String> columnNames)
|
||||
public SliceByNamesReadCommand(String table, String key, ColumnParent column_parent, Collection<byte[]> columnNames)
|
||||
{
|
||||
this(table, key, new QueryPath(column_parent), columnNames);
|
||||
}
|
||||
|
||||
public SliceByNamesReadCommand(String table, String key, QueryPath path, Collection<String> columnNames)
|
||||
public SliceByNamesReadCommand(String table, String key, QueryPath path, Collection<byte[]> columnNames)
|
||||
{
|
||||
super(table, key, CMD_TYPE_GET_SLICE_BY_NAMES);
|
||||
this.columnParent = path;
|
||||
this.columnNames = new TreeSet<String>(columnNames);
|
||||
this.columnNames = new TreeSet<byte[]>(getComparator());
|
||||
this.columnNames.addAll(columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -72,7 +75,7 @@ public class SliceByNamesReadCommand extends ReadCommand
|
|||
"table='" + table + '\'' +
|
||||
", key='" + key + '\'' +
|
||||
", columnParent='" + columnParent + '\'' +
|
||||
", columns=[" + StringUtils.join(columnNames, ", ") + "]" +
|
||||
", columns=[" + getComparator().getString(columnNames) + "]" +
|
||||
')';
|
||||
}
|
||||
|
||||
|
|
@ -91,10 +94,9 @@ class SliceByNamesReadCommandSerializer extends ReadCommandSerializer
|
|||
dos.writeInt(realRM.columnNames.size());
|
||||
if (realRM.columnNames.size() > 0)
|
||||
{
|
||||
for (String cName : realRM.columnNames)
|
||||
for (byte[] cName : realRM.columnNames)
|
||||
{
|
||||
dos.writeInt(cName.getBytes().length);
|
||||
dos.write(cName.getBytes());
|
||||
ColumnSerializer.writeName(cName, dos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,12 +110,10 @@ class SliceByNamesReadCommandSerializer extends ReadCommandSerializer
|
|||
QueryPath columnParent = QueryPath.deserialize(dis);
|
||||
|
||||
int size = dis.readInt();
|
||||
List<String> columns = new ArrayList<String>();
|
||||
List<byte[]> columns = new ArrayList<byte[]>();
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
byte[] bytes = new byte[dis.readInt()];
|
||||
dis.readFully(bytes);
|
||||
columns.add(new String(bytes));
|
||||
columns.add(ColumnSerializer.readName(dis));
|
||||
}
|
||||
SliceByNamesReadCommand rm = new SliceByNamesReadCommand(table, key, columnParent, columns);
|
||||
rm.setDigestQuery(isDigest);
|
||||
|
|
|
|||
|
|
@ -28,16 +28,16 @@ import org.apache.cassandra.service.ColumnParent;
|
|||
public class SliceFromReadCommand extends ReadCommand
|
||||
{
|
||||
public final QueryPath column_parent;
|
||||
public final String start, finish;
|
||||
public final byte[] start, finish;
|
||||
public final boolean isAscending;
|
||||
public final int count;
|
||||
|
||||
public SliceFromReadCommand(String table, String key, ColumnParent column_parent, String start, String finish, boolean isAscending, int count)
|
||||
public SliceFromReadCommand(String table, String key, ColumnParent column_parent, byte[] start, byte[] finish, boolean isAscending, int count)
|
||||
{
|
||||
this(table, key, new QueryPath(column_parent), start, finish, isAscending, count);
|
||||
}
|
||||
|
||||
public SliceFromReadCommand(String table, String key, QueryPath columnParent, String start, String finish, boolean isAscending, int count)
|
||||
public SliceFromReadCommand(String table, String key, QueryPath columnParent, byte[] start, byte[] finish, boolean isAscending, int count)
|
||||
{
|
||||
super(table, key, CMD_TYPE_GET_SLICE);
|
||||
this.column_parent = columnParent;
|
||||
|
|
@ -74,8 +74,8 @@ public class SliceFromReadCommand extends ReadCommand
|
|||
"table='" + table + '\'' +
|
||||
", key='" + key + '\'' +
|
||||
", column_parent='" + column_parent + '\'' +
|
||||
", start='" + start + '\'' +
|
||||
", finish='" + finish + '\'' +
|
||||
", start='" + getComparator().getString(start) + '\'' +
|
||||
", finish='" + getComparator().getString(finish) + '\'' +
|
||||
", isAscending=" + isAscending +
|
||||
", count=" + count +
|
||||
')';
|
||||
|
|
@ -92,8 +92,8 @@ class SliceFromReadCommandSerializer extends ReadCommandSerializer
|
|||
dos.writeUTF(realRM.table);
|
||||
dos.writeUTF(realRM.key);
|
||||
realRM.column_parent.serialize(dos);
|
||||
dos.writeUTF(realRM.start);
|
||||
dos.writeUTF(realRM.finish);
|
||||
ColumnSerializer.writeName(realRM.start, dos);
|
||||
ColumnSerializer.writeName(realRM.finish, dos);
|
||||
dos.writeBoolean(realRM.isAscending);
|
||||
dos.writeInt(realRM.count);
|
||||
}
|
||||
|
|
@ -102,7 +102,13 @@ class SliceFromReadCommandSerializer extends ReadCommandSerializer
|
|||
public ReadCommand deserialize(DataInputStream dis) throws IOException
|
||||
{
|
||||
boolean isDigest = dis.readBoolean();
|
||||
SliceFromReadCommand rm = new SliceFromReadCommand(dis.readUTF(), dis.readUTF(), QueryPath.deserialize(dis), dis.readUTF(), dis.readUTF(), dis.readBoolean(), dis.readInt());
|
||||
SliceFromReadCommand rm = new SliceFromReadCommand(dis.readUTF(),
|
||||
dis.readUTF(),
|
||||
QueryPath.deserialize(dis),
|
||||
ColumnSerializer.readName(dis),
|
||||
ColumnSerializer.readName(dis),
|
||||
dis.readBoolean(),
|
||||
dis.readInt());
|
||||
rm.setDigestQuery(isDigest);
|
||||
return rm;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,17 +23,18 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.io.ICompactSerializer;
|
||||
import org.apache.cassandra.db.marshal.LongType;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
|
||||
/**
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )
|
||||
|
|
@ -49,21 +50,23 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
return serializer_;
|
||||
}
|
||||
|
||||
private String name_;
|
||||
private ConcurrentSkipListMap<String, IColumn> columns_ = new ConcurrentSkipListMap<String, IColumn>();
|
||||
private byte[] name_;
|
||||
// TODO make subcolumn comparator configurable
|
||||
private ConcurrentSkipListMap<byte[], IColumn> columns_ = new ConcurrentSkipListMap<byte[], IColumn>(new LongType());
|
||||
private int localDeletionTime = Integer.MIN_VALUE;
|
||||
private long markedForDeleteAt = Long.MIN_VALUE;
|
||||
private AtomicInteger size_ = new AtomicInteger(0);
|
||||
|
||||
SuperColumn()
|
||||
{
|
||||
}
|
||||
|
||||
SuperColumn(String name)
|
||||
SuperColumn(byte[] name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
public AbstractType getComparator()
|
||||
{
|
||||
return (AbstractType)columns_.comparator();
|
||||
}
|
||||
|
||||
public SuperColumn cloneMeShallow()
|
||||
{
|
||||
SuperColumn sc = new SuperColumn(name_);
|
||||
|
|
@ -76,7 +79,7 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
return markedForDeleteAt > Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public String name()
|
||||
public byte[] name()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
|
@ -86,19 +89,13 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
return columns_.values();
|
||||
}
|
||||
|
||||
public IColumn getSubColumn(String columnName)
|
||||
public IColumn getSubColumn(byte[] columnName)
|
||||
{
|
||||
IColumn column = columns_.get(columnName);
|
||||
assert column == null || column instanceof Column;
|
||||
return column;
|
||||
}
|
||||
|
||||
public int compareTo(IColumn superColumn)
|
||||
{
|
||||
return (name_.compareTo(superColumn.name()));
|
||||
}
|
||||
|
||||
|
||||
public int size()
|
||||
{
|
||||
/*
|
||||
|
|
@ -133,7 +130,7 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
* We need to keep the way we are calculating the column size in sync with the
|
||||
* way we are calculating the size for the column family serializer.
|
||||
*/
|
||||
return IColumn.UtfPrefix_ + FBUtilities.getUTF8Length(name_) + DBConstants.boolSize_ + DBConstants.intSize_ + DBConstants.intSize_ + getSizeOfAllColumns();
|
||||
return IColumn.UtfPrefix_ + name_.length + DBConstants.boolSize_ + DBConstants.intSize_ + DBConstants.intSize_ + getSizeOfAllColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -150,7 +147,7 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
return size;
|
||||
}
|
||||
|
||||
public void remove(String columnName)
|
||||
public void remove(byte[] columnName)
|
||||
{
|
||||
columns_.remove(columnName);
|
||||
}
|
||||
|
|
@ -160,9 +157,9 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
throw new UnsupportedOperationException("This operation is not supported for Super Columns.");
|
||||
}
|
||||
|
||||
public long timestamp(String key)
|
||||
public long timestamp(byte[] columnName)
|
||||
{
|
||||
IColumn column = columns_.get(key);
|
||||
IColumn column = columns_.get(columnName);
|
||||
if ( column instanceof SuperColumn )
|
||||
throw new UnsupportedOperationException("A super column cannot hold other super columns.");
|
||||
if ( column != null )
|
||||
|
|
@ -175,9 +172,9 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
throw new UnsupportedOperationException("This operation is not supported for Super Columns.");
|
||||
}
|
||||
|
||||
public byte[] value(String key)
|
||||
public byte[] value(byte[] columnName)
|
||||
{
|
||||
IColumn column = columns_.get(key);
|
||||
IColumn column = columns_.get(columnName);
|
||||
if ( column != null )
|
||||
return column.value();
|
||||
throw new IllegalArgumentException("Value was requested for a column that does not exist.");
|
||||
|
|
@ -187,6 +184,14 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
{
|
||||
if (!(column instanceof Column))
|
||||
throw new UnsupportedOperationException("A super column can only contain simple columns.");
|
||||
try
|
||||
{
|
||||
getComparator().validate(column.name());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MarshalException("Invalid column name in supercolumn for " + getComparator().getClass().getName());
|
||||
}
|
||||
IColumn oldColumn = columns_.get(column.name());
|
||||
if ( oldColumn == null )
|
||||
{
|
||||
|
|
@ -213,10 +218,14 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
*/
|
||||
public void putColumn(IColumn column)
|
||||
{
|
||||
if ( !(column instanceof SuperColumn))
|
||||
throw new UnsupportedOperationException("Only Super column objects should be put here");
|
||||
if( !name_.equals(column.name()))
|
||||
throw new IllegalArgumentException("The name should match the name of the current column or super column");
|
||||
if (!(column instanceof SuperColumn))
|
||||
{
|
||||
throw new UnsupportedOperationException("Only Super column objects should be put here");
|
||||
}
|
||||
if (!Arrays.equals(name_, column.name()))
|
||||
{
|
||||
throw new IllegalArgumentException("The name should match the name of the current column or super column");
|
||||
}
|
||||
|
||||
for (IColumn subColumn : column.getSubColumns())
|
||||
{
|
||||
|
|
@ -281,7 +290,7 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
byte[] xorHash = ArrayUtils.EMPTY_BYTE_ARRAY;
|
||||
if(name_ == null)
|
||||
return xorHash;
|
||||
xorHash = name_.getBytes();
|
||||
xorHash = name_.clone();
|
||||
for(IColumn column : columns_.values())
|
||||
{
|
||||
xorHash = FBUtilities.xor(xorHash, column.digest());
|
||||
|
|
@ -289,19 +298,18 @@ public final class SuperColumn implements IColumn, Serializable
|
|||
return xorHash;
|
||||
}
|
||||
|
||||
|
||||
public String toString()
|
||||
public String getString(AbstractType comparator)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SuperColumn(");
|
||||
sb.append(name_);
|
||||
sb.append(comparator.getString(name_));
|
||||
|
||||
if (isMarkedForDelete()) {
|
||||
sb.append(" -delete at " + getMarkedForDeleteAt() + "-");
|
||||
sb.append(" -delete at ").append(getMarkedForDeleteAt()).append("-");
|
||||
}
|
||||
|
||||
sb.append(" [");
|
||||
sb.append(StringUtils.join(getSubColumns(), ", "));
|
||||
sb.append(getComparator().getColumnsString(columns_.values()));
|
||||
sb.append("])");
|
||||
|
||||
return sb.toString();
|
||||
|
|
@ -324,7 +332,7 @@ class SuperColumnSerializer implements ICompactSerializer<IColumn>
|
|||
public void serialize(IColumn column, DataOutputStream dos) throws IOException
|
||||
{
|
||||
SuperColumn superColumn = (SuperColumn)column;
|
||||
dos.writeUTF(superColumn.name());
|
||||
ColumnSerializer.writeName(column.name(), dos);
|
||||
dos.writeInt(superColumn.getLocalDeletionTime());
|
||||
dos.writeLong(superColumn.getMarkedForDeleteAt());
|
||||
|
||||
|
|
@ -341,7 +349,7 @@ class SuperColumnSerializer implements ICompactSerializer<IColumn>
|
|||
|
||||
public IColumn deserialize(DataInputStream dis) throws IOException
|
||||
{
|
||||
String name = dis.readUTF();
|
||||
byte[] name = ColumnSerializer.readName(dis);
|
||||
SuperColumn superColumn = new SuperColumn(name);
|
||||
superColumn.markForDeleteAt(dis.readInt(), dis.readLong());
|
||||
assert dis.available() > 0;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.cassandra.db;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -26,9 +27,9 @@ import org.apache.cassandra.service.StorageService;
|
|||
import org.apache.cassandra.dht.Token;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
import org.apache.cassandra.utils.BasicUtilities;
|
||||
import org.apache.cassandra.db.filter.IdentityQueryFilter;
|
||||
import org.apache.cassandra.db.filter.NamesQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
|
||||
/**
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )
|
||||
|
|
@ -39,8 +40,20 @@ public class SystemTable
|
|||
private static Logger logger_ = Logger.getLogger(SystemTable.class);
|
||||
public static final String LOCATION_CF = "LocationInfo";
|
||||
private static final String LOCATION_KEY = "L"; // only one row in Location CF
|
||||
private static final String TOKEN = "Token";
|
||||
private static final String GENERATION = "Generation";
|
||||
private static final byte[] TOKEN = utf8("Token");
|
||||
private static final byte[] GENERATION = utf8("Generation");
|
||||
|
||||
private static byte[] utf8(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return str.getBytes("UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This method is used to update the SystemTable with the new token.
|
||||
|
|
@ -50,7 +63,8 @@ public class SystemTable
|
|||
IPartitioner p = StorageService.getPartitioner();
|
||||
Table table = Table.open(Table.SYSTEM_TABLE);
|
||||
/* Retrieve the "LocationInfo" column family */
|
||||
ColumnFamily cf = table.getColumnFamilyStore(LOCATION_CF).getColumnFamily(new NamesQueryFilter(LOCATION_KEY, new QueryPath(LOCATION_KEY), TOKEN));
|
||||
QueryFilter filter = new NamesQueryFilter(LOCATION_KEY, new QueryPath(LOCATION_CF), TOKEN);
|
||||
ColumnFamily cf = table.getColumnFamilyStore(LOCATION_CF).getColumnFamily(filter);
|
||||
long oldTokenColumnTimestamp = cf.getColumn(SystemTable.TOKEN).timestamp();
|
||||
/* create the "Token" whose value is the new token. */
|
||||
IColumn tokenColumn = new Column(SystemTable.TOKEN, p.getTokenFactory().toByteArray(token), oldTokenColumnTimestamp + 1);
|
||||
|
|
@ -74,7 +88,8 @@ public class SystemTable
|
|||
{
|
||||
/* Read the system table to retrieve the storage ID and the generation */
|
||||
Table table = Table.open(Table.SYSTEM_TABLE);
|
||||
ColumnFamily cf = table.getColumnFamilyStore(LOCATION_CF).getColumnFamily(new NamesQueryFilter(LOCATION_KEY, new QueryPath(LOCATION_KEY), GENERATION));
|
||||
QueryFilter filter = new NamesQueryFilter(LOCATION_KEY, new QueryPath(LOCATION_CF), GENERATION);
|
||||
ColumnFamily cf = table.getColumnFamilyStore(LOCATION_CF).getColumnFamily(filter);
|
||||
|
||||
IPartitioner p = StorageService.getPartitioner();
|
||||
if (cf == null)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException;
|
|||
|
||||
import org.apache.commons.collections.IteratorUtils;
|
||||
import org.apache.commons.collections.Predicate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.dht.BootstrapInitiateMessage;
|
||||
|
|
@ -591,7 +592,7 @@ public class Table
|
|||
|
||||
for (ColumnFamily columnFamily : row.getColumnFamilies())
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
Collection<IColumn> columns = columnFamily.getSortedColumns();
|
||||
for(IColumn column : columns)
|
||||
{
|
||||
ColumnFamilyStore cfStore = columnFamilyStores_.get(column.name());
|
||||
|
|
@ -704,7 +705,8 @@ public class Table
|
|||
}
|
||||
// make sure there is actually non-tombstone content associated w/ this key
|
||||
// TODO record the key source(s) somehow and only check that source (e.g., memtable or sstable)
|
||||
if (cfs.getColumnFamily(new SliceQueryFilter(current, new QueryPath(cfName), "", "", true, 1), Integer.MAX_VALUE) != null)
|
||||
QueryFilter filter = new SliceQueryFilter(current, new QueryPath(cfName), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 1);
|
||||
if (cfs.getColumnFamily(filter, Integer.MAX_VALUE) != null)
|
||||
{
|
||||
keys.add(current);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.apache.cassandra.db.filter;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.apache.cassandra.db.SuperColumn;
|
||||
|
||||
public class IdentityQueryFilter extends SliceQueryFilter
|
||||
|
|
@ -9,7 +11,7 @@ public class IdentityQueryFilter extends SliceQueryFilter
|
|||
*/
|
||||
public IdentityQueryFilter(String key, QueryPath path)
|
||||
{
|
||||
super(key, path, "", "", true, Integer.MAX_VALUE);
|
||||
super(key, path, ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,36 +4,51 @@ import java.io.IOException;
|
|||
import java.util.SortedSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.apache.cassandra.io.SSTableReader;
|
||||
import org.apache.cassandra.utils.ReducingIterator;
|
||||
import org.apache.cassandra.db.filter.ColumnIterator;
|
||||
import org.apache.cassandra.db.Memtable;
|
||||
import org.apache.cassandra.db.ColumnFamily;
|
||||
import org.apache.cassandra.db.IColumn;
|
||||
import org.apache.cassandra.db.SuperColumn;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
public class NamesQueryFilter extends QueryFilter
|
||||
{
|
||||
public final SortedSet<String> columns;
|
||||
public final SortedSet<byte[]> columns;
|
||||
|
||||
public NamesQueryFilter(String key, QueryPath columnParent, SortedSet<String> columns)
|
||||
public NamesQueryFilter(String key, QueryPath columnParent, SortedSet<byte[]> columns)
|
||||
{
|
||||
super(key, columnParent);
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public NamesQueryFilter(String key, QueryPath columnParent, String column)
|
||||
public NamesQueryFilter(String key, QueryPath columnParent, byte[] column)
|
||||
{
|
||||
this(key, columnParent, new TreeSet<String>(Arrays.asList(column)));
|
||||
this(key, columnParent, getSingleColumnSet(column));
|
||||
}
|
||||
|
||||
public ColumnIterator getMemColumnIterator(Memtable memtable)
|
||||
private static TreeSet<byte[]> getSingleColumnSet(byte[] column)
|
||||
{
|
||||
Comparator<byte[]> singleColumnComparator = new Comparator<byte[]>()
|
||||
{
|
||||
public int compare(byte[] o1, byte[] o2)
|
||||
{
|
||||
return Arrays.equals(o1, o2) ? 0 : -1;
|
||||
}
|
||||
};
|
||||
TreeSet<byte[]> set = new TreeSet<byte[]>(singleColumnComparator);
|
||||
set.add(column);
|
||||
return set;
|
||||
}
|
||||
|
||||
public ColumnIterator getMemColumnIterator(Memtable memtable, AbstractType comparator)
|
||||
{
|
||||
return memtable.getNamesIterator(this);
|
||||
}
|
||||
|
||||
public ColumnIterator getSSTableColumnIterator(SSTableReader sstable) throws IOException
|
||||
public ColumnIterator getSSTableColumnIterator(SSTableReader sstable, AbstractType comparator) throws IOException
|
||||
{
|
||||
return new SSTableNamesIterator(sstable.getFilename(), key, getColumnFamilyName(), columns);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package org.apache.cassandra.db.filter;
|
|||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.cassandra.io.SSTableReader;
|
||||
import org.apache.cassandra.utils.ReducingIterator;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
public abstract class QueryFilter
|
||||
{
|
||||
|
|
@ -23,13 +25,13 @@ public abstract class QueryFilter
|
|||
* returns an iterator that returns columns from the given memtable
|
||||
* matching the Filter criteria in sorted order.
|
||||
*/
|
||||
public abstract ColumnIterator getMemColumnIterator(Memtable memtable);
|
||||
public abstract ColumnIterator getMemColumnIterator(Memtable memtable, AbstractType comparator);
|
||||
|
||||
/**
|
||||
* returns an iterator that returns columns from the given SSTable
|
||||
* matching the Filter criteria in sorted order.
|
||||
*/
|
||||
public abstract ColumnIterator getSSTableColumnIterator(SSTableReader sstable) throws IOException;
|
||||
public abstract ColumnIterator getSSTableColumnIterator(SSTableReader sstable, AbstractType comparator) throws IOException;
|
||||
|
||||
/**
|
||||
* collects columns from reducedColumns into returnCF. Termination is determined
|
||||
|
|
@ -44,13 +46,13 @@ public abstract class QueryFilter
|
|||
*/
|
||||
public abstract void filterSuperColumn(SuperColumn superColumn);
|
||||
|
||||
public Comparator<IColumn> getColumnComparator()
|
||||
public Comparator<IColumn> getColumnComparator(final AbstractType comparator)
|
||||
{
|
||||
return new Comparator<IColumn>()
|
||||
{
|
||||
public int compare(IColumn c1, IColumn c2)
|
||||
{
|
||||
return c1.name().compareTo(c2.name());
|
||||
return comparator.compare(c1.name(), c2.name());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -63,9 +65,9 @@ public abstract class QueryFilter
|
|||
{
|
||||
ColumnFamily curCF = returnCF.cloneMeShallow();
|
||||
|
||||
protected Object getKey(IColumn o)
|
||||
protected boolean isEqual(IColumn o1, IColumn o2)
|
||||
{
|
||||
return o == null ? null : o.name();
|
||||
return Arrays.equals(o1.name(), o2.name());
|
||||
}
|
||||
|
||||
public void reduce(IColumn current)
|
||||
|
|
@ -75,7 +77,7 @@ public abstract class QueryFilter
|
|||
|
||||
protected IColumn getReduced()
|
||||
{
|
||||
IColumn c = curCF.getAllColumns().first();
|
||||
IColumn c = curCF.getSortedColumns().iterator().next();
|
||||
curCF.clear();
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +4,22 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.apache.cassandra.service.ColumnParent;
|
||||
import org.apache.cassandra.service.ColumnPath;
|
||||
import org.apache.cassandra.service.ColumnPathOrParent;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.db.ColumnSerializer;
|
||||
|
||||
public class QueryPath
|
||||
{
|
||||
public final String columnFamilyName;
|
||||
public final String superColumnName;
|
||||
public final String columnName;
|
||||
public final byte[] superColumnName;
|
||||
public final byte[] columnName;
|
||||
|
||||
public QueryPath(String columnFamilyName, String superColumnName, String columnName)
|
||||
public QueryPath(String columnFamilyName, byte[] superColumnName, byte[] columnName)
|
||||
{
|
||||
// TODO remove these when we're sure the last vestiges of the old api are gone
|
||||
assert columnFamilyName == null || !columnFamilyName.contains(":");
|
||||
assert superColumnName == null || !superColumnName.contains(":");
|
||||
assert columnName == null || !columnName.contains(":");
|
||||
|
||||
this.columnFamilyName = columnFamilyName;
|
||||
this.superColumnName = superColumnName;
|
||||
this.columnName = columnName;
|
||||
|
|
@ -31,7 +30,7 @@ public class QueryPath
|
|||
this(columnParent.column_family, columnParent.super_column, null);
|
||||
}
|
||||
|
||||
public QueryPath(String columnFamilyName, String superColumnName)
|
||||
public QueryPath(String columnFamilyName, byte[] superColumnName)
|
||||
{
|
||||
this(columnFamilyName, superColumnName, null);
|
||||
}
|
||||
|
|
@ -51,7 +50,7 @@ public class QueryPath
|
|||
this(column_path_or_parent.column_family, column_path_or_parent.super_column, column_path_or_parent.column);
|
||||
}
|
||||
|
||||
public static QueryPath column(String columnName)
|
||||
public static QueryPath column(byte[] columnName)
|
||||
{
|
||||
return new QueryPath(null, null, columnName);
|
||||
}
|
||||
|
|
@ -69,18 +68,18 @@ public class QueryPath
|
|||
public void serialize(DataOutputStream dos) throws IOException
|
||||
{
|
||||
assert !"".equals(columnFamilyName);
|
||||
assert !"".equals(superColumnName);
|
||||
assert !"".equals(columnName);
|
||||
assert superColumnName == null || superColumnName.length > 0;
|
||||
assert columnName == null || columnName.length > 0;
|
||||
dos.writeUTF(columnFamilyName == null ? "" : columnFamilyName);
|
||||
dos.writeUTF(superColumnName == null ? "" : superColumnName);
|
||||
dos.writeUTF(columnName == null ? "" : columnName);
|
||||
ColumnSerializer.writeName(superColumnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY : superColumnName, dos);
|
||||
ColumnSerializer.writeName(columnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY : columnName, dos);
|
||||
}
|
||||
|
||||
public static QueryPath deserialize(DataInputStream din) throws IOException
|
||||
{
|
||||
String cfName = din.readUTF();
|
||||
String scName = din.readUTF();
|
||||
String cName = din.readUTF();
|
||||
return new QueryPath(cfName.isEmpty() ? null : cfName, scName.isEmpty() ? null : scName, cName.isEmpty() ? null : cName);
|
||||
byte[] scName = ColumnSerializer.readName(din);
|
||||
byte[] cName = ColumnSerializer.readName(din);
|
||||
return new QueryPath(cfName.isEmpty() ? null : cfName, scName.length == 0 ? null : scName, cName.length == 0 ? null : cName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
|
|||
{
|
||||
private ColumnFamily cf;
|
||||
private Iterator<IColumn> iter;
|
||||
public final SortedSet<String> columns;
|
||||
public final SortedSet<byte[]> columns;
|
||||
|
||||
// TODO make this actually iterate so we don't have to read + deserialize + filter data that we don't need due to merging other sstables
|
||||
public SSTableNamesIterator(String filename, String key, String cfName, SortedSet<String> columns) throws IOException
|
||||
public SSTableNamesIterator(String filename, String key, String cfName, SortedSet<byte[]> columns) throws IOException
|
||||
{
|
||||
this.columns = columns;
|
||||
SSTableReader ssTable = SSTableReader.open(filename);
|
||||
|
|
@ -24,7 +24,7 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
|
|||
if (buffer.getLength() > 0)
|
||||
{
|
||||
cf = ColumnFamily.serializer().deserialize(buffer);
|
||||
iter = cf.getAllColumns().iterator();
|
||||
iter = cf.getSortedColumns().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||
|
||||
import org.apache.cassandra.db.IColumn;
|
||||
import org.apache.cassandra.db.ColumnFamily;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.io.DataOutputBuffer;
|
||||
import org.apache.cassandra.io.DataInputBuffer;
|
||||
import org.apache.cassandra.io.SequenceFile;
|
||||
|
|
@ -17,20 +18,22 @@ import com.google.common.collect.AbstractIterator;
|
|||
class SSTableSliceIterator extends AbstractIterator<IColumn> implements ColumnIterator
|
||||
{
|
||||
protected boolean isAscending;
|
||||
private String startColumn;
|
||||
private byte[] startColumn;
|
||||
private DataOutputBuffer outBuf = new DataOutputBuffer();
|
||||
private DataInputBuffer inBuf = new DataInputBuffer();
|
||||
private int curColumnIndex;
|
||||
private ColumnFamily curCF = null;
|
||||
private ArrayList<IColumn> curColumns = new ArrayList<IColumn>();
|
||||
private SequenceFile.ColumnGroupReader reader;
|
||||
private AbstractType comparator;
|
||||
|
||||
public SSTableSliceIterator(String filename, String key, String cfName, String startColumn, boolean isAscending)
|
||||
public SSTableSliceIterator(String filename, String key, String cfName, AbstractType comparator, byte[] startColumn, boolean isAscending)
|
||||
throws IOException
|
||||
{
|
||||
this.isAscending = isAscending;
|
||||
SSTableReader ssTable = SSTableReader.open(filename);
|
||||
reader = ssTable.getColumnGroupReader(key, cfName, startColumn, isAscending);
|
||||
this.comparator = comparator;
|
||||
this.startColumn = startColumn;
|
||||
curColumnIndex = isAscending ? 0 : -1;
|
||||
}
|
||||
|
|
@ -38,9 +41,9 @@ class SSTableSliceIterator extends AbstractIterator<IColumn> implements ColumnIt
|
|||
private boolean isColumnNeeded(IColumn column)
|
||||
{
|
||||
if (isAscending)
|
||||
return (column.name().compareTo(startColumn) >= 0);
|
||||
return comparator.compare(column.name(), startColumn) >= 0;
|
||||
else
|
||||
return (column.name().compareTo(startColumn) <= 0);
|
||||
return comparator.compare(column.name(), startColumn) <= 0;
|
||||
}
|
||||
|
||||
private void getColumnsFromBuffer() throws IOException
|
||||
|
|
@ -51,7 +54,7 @@ class SSTableSliceIterator extends AbstractIterator<IColumn> implements ColumnIt
|
|||
if (curCF == null)
|
||||
curCF = columnFamily.cloneMeShallow();
|
||||
curColumns.clear();
|
||||
for (IColumn column : columnFamily.getAllColumns())
|
||||
for (IColumn column : columnFamily.getSortedColumns())
|
||||
if (isColumnNeeded(column))
|
||||
curColumns.add(column);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,15 @@ import org.apache.commons.collections.comparators.ReverseComparator;
|
|||
import org.apache.cassandra.io.SSTableReader;
|
||||
import org.apache.cassandra.utils.ReducingIterator;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
public class SliceQueryFilter extends QueryFilter
|
||||
{
|
||||
public final String start, finish;
|
||||
public final byte[] start, finish;
|
||||
public final boolean isAscending;
|
||||
public final int count;
|
||||
|
||||
public SliceQueryFilter(String key, QueryPath columnParent, String start, String finish, boolean ascending, int count)
|
||||
public SliceQueryFilter(String key, QueryPath columnParent, byte[] start, byte[] finish, boolean ascending, int count)
|
||||
{
|
||||
super(key, columnParent);
|
||||
this.start = start;
|
||||
|
|
@ -24,14 +25,14 @@ public class SliceQueryFilter extends QueryFilter
|
|||
this.count = count;
|
||||
}
|
||||
|
||||
public ColumnIterator getMemColumnIterator(Memtable memtable)
|
||||
public ColumnIterator getMemColumnIterator(Memtable memtable, AbstractType comparator)
|
||||
{
|
||||
return memtable.getSliceIterator(this);
|
||||
return memtable.getSliceIterator(this, comparator);
|
||||
}
|
||||
|
||||
public ColumnIterator getSSTableColumnIterator(SSTableReader sstable) throws IOException
|
||||
public ColumnIterator getSSTableColumnIterator(SSTableReader sstable, AbstractType comparator) throws IOException
|
||||
{
|
||||
return new SSTableSliceIterator(sstable.getFilename(), key, getColumnFamilyName(), start, isAscending);
|
||||
return new SSTableSliceIterator(sstable.getFilename(), key, getColumnFamilyName(), comparator, start, isAscending);
|
||||
}
|
||||
|
||||
public void filterSuperColumn(SuperColumn superColumn)
|
||||
|
|
@ -41,23 +42,23 @@ public class SliceQueryFilter extends QueryFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public Comparator<IColumn> getColumnComparator()
|
||||
public Comparator<IColumn> getColumnComparator(AbstractType comparator)
|
||||
{
|
||||
Comparator<IColumn> comparator = super.getColumnComparator();
|
||||
return isAscending ? comparator : new ReverseComparator(comparator);
|
||||
return isAscending ? super.getColumnComparator(comparator) : new ReverseComparator(super.getColumnComparator(comparator));
|
||||
}
|
||||
|
||||
public void collectColumns(ColumnFamily returnCF, ReducingIterator<IColumn> reducedColumns, int gcBefore)
|
||||
{
|
||||
int liveColumns = 0;
|
||||
AbstractType comparator = returnCF.getComparator();
|
||||
|
||||
for (IColumn column : reducedColumns)
|
||||
{
|
||||
if (liveColumns >= count)
|
||||
break;
|
||||
if (!finish.isEmpty()
|
||||
&& ((isAscending && column.name().compareTo(finish) > 0))
|
||||
|| (!isAscending && column.name().compareTo(finish) < 0))
|
||||
if (finish.length > 0
|
||||
&& ((isAscending && comparator.compare(column.name(), finish) > 0))
|
||||
|| (!isAscending && comparator.compare(column.name(), finish) < 0))
|
||||
break;
|
||||
|
||||
if (!column.isMarkedForDelete())
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.cassandra.db.IColumn;
|
||||
import org.apache.cassandra.db.SuperColumn;
|
||||
|
||||
public abstract class AbstractType implements Comparator<byte[]>
|
||||
{
|
||||
/** get a string representation of the bytes suitable for log messages */
|
||||
public abstract String getString(byte[] bytes);
|
||||
|
||||
/** validate that the byte array is a valid sequence for the type we are supposed to be comparing */
|
||||
public void validate(byte[] bytes)
|
||||
{
|
||||
getString(bytes);
|
||||
}
|
||||
|
||||
/** convenience method */
|
||||
public String getString(Collection<byte[]> names)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (byte[] name : names)
|
||||
{
|
||||
builder.append(getString(name)).append(",");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/** convenience method */
|
||||
public String getColumnsString(Collection<IColumn> columns)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
builder.append(getString(column.name())).append(",");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class AsciiType extends AbstractType
|
||||
{
|
||||
public int compare(byte[] o1, byte[] o2)
|
||||
{
|
||||
int length = Math.max(o1.length, o2.length);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int index = i + 1;
|
||||
if (index > o1.length && index <= o2.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (index > o2.length && index <= o1.length)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int delta = o1[i] - o2[i];
|
||||
if (delta != 0)
|
||||
{
|
||||
return delta;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getString(byte[] bytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new String(bytes, "US-ASCII");
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class LongType extends AbstractType
|
||||
{
|
||||
public int compare(byte[] o1, byte[] o2)
|
||||
{
|
||||
long L1 = ByteBuffer.wrap(o1).order(ByteOrder.LITTLE_ENDIAN).getLong();
|
||||
long L2 = ByteBuffer.wrap(o2).order(ByteOrder.LITTLE_ENDIAN).getLong();
|
||||
return new Long(L1).compareTo(L2);
|
||||
}
|
||||
|
||||
public String getString(byte[] bytes)
|
||||
{
|
||||
return String.valueOf(ByteBuffer.wrap(bytes).getLong());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
public class MarshalException extends RuntimeException
|
||||
{
|
||||
public MarshalException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class UTF8Type extends AbstractType
|
||||
{
|
||||
public int compare(byte[] o1, byte[] o2)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new String(o1, "UTF-8").compareTo(new String(o2, "UTF-8"));
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(byte[] bytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new String(bytes, "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class UUIDType extends AbstractType
|
||||
{
|
||||
private UUID getUUID(byte[] bytes)
|
||||
{
|
||||
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
return new UUID(bb.getLong(), bb.getLong());
|
||||
}
|
||||
|
||||
public int compare(byte[] o1, byte[] o2)
|
||||
{
|
||||
return getUUID(o1).compareTo(getUUID(o2));
|
||||
}
|
||||
|
||||
public String getString(byte[] bytes)
|
||||
{
|
||||
return getUUID(bytes).toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ public interface IFileReader
|
|||
* @param columnNames - The list of columns in the cfName column family
|
||||
* that we want to return
|
||||
*/
|
||||
public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, SortedSet<String> columnNames, long position) throws IOException;
|
||||
public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, SortedSet<byte[]> columnNames, long position) throws IOException;
|
||||
|
||||
/**
|
||||
* Close the file after reading.
|
||||
|
|
|
|||
|
|
@ -25,9 +25,8 @@ import java.io.IOException;
|
|||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.IColumn;
|
||||
import org.apache.cassandra.db.ColumnComparatorFactory;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.db.ColumnSerializer;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -152,21 +151,21 @@ public class IndexHelper
|
|||
DataInputBuffer indexIn = new DataInputBuffer();
|
||||
indexIn.reset(indexOut.getData(), indexOut.getLength());
|
||||
|
||||
ColumnComparatorFactory.ComparatorType typeInfo = DatabaseDescriptor.getTypeInfo(tableName, cfName);
|
||||
AbstractType comparator = DatabaseDescriptor.getType(tableName, cfName);
|
||||
|
||||
while(indexIn.available() > 0)
|
||||
{
|
||||
ColumnIndexInfo cIndexInfo = ColumnIndexFactory.instance(typeInfo);
|
||||
cIndexInfo = cIndexInfo.deserialize(indexIn);
|
||||
columnIndexList.add(cIndexInfo);
|
||||
while (indexIn.available() > 0)
|
||||
{
|
||||
// TODO this is all kinds of messed up
|
||||
ColumnIndexInfo cIndexInfo = new ColumnIndexInfo(comparator);
|
||||
cIndexInfo = cIndexInfo.deserialize(indexIn);
|
||||
columnIndexList.add(cIndexInfo);
|
||||
}
|
||||
|
||||
return totalBytesRead;
|
||||
return totalBytesRead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the range in which a given column falls in the index
|
||||
* @param column The column whose range needs to be found
|
||||
* @param columnIndexList the in-memory representation of the column index
|
||||
* @param dataSize the total size of the data
|
||||
* @param totalNumCols total number of columns
|
||||
|
|
@ -221,40 +220,31 @@ public class IndexHelper
|
|||
* @param totalNumCols the total number of columns
|
||||
* @return a list of subranges which contain all the columns in columnNames
|
||||
*/
|
||||
static List<ColumnRange> getMultiColumnRangesFromNameIndex(SortedSet<String> columnNames, List<IndexHelper.ColumnIndexInfo> columnIndexList, int dataSize, int totalNumCols)
|
||||
static List<ColumnRange> getMultiColumnRangesFromNameIndex(SortedSet<byte[]> columnNames, List<IndexHelper.ColumnIndexInfo> columnIndexList, int dataSize, int totalNumCols)
|
||||
{
|
||||
List<ColumnRange> columnRanges = new ArrayList<ColumnRange>();
|
||||
List<ColumnRange> columnRanges = new ArrayList<ColumnRange>();
|
||||
|
||||
if ( columnIndexList.size() == 0 )
|
||||
if (columnIndexList.size() == 0)
|
||||
{
|
||||
columnRanges.add( new ColumnRange(0, dataSize, totalNumCols) );
|
||||
columnRanges.add(new ColumnRange(0, dataSize, totalNumCols));
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<Long, Boolean> offset = new HashMap<Long, Boolean>();
|
||||
for(String column : columnNames)
|
||||
{
|
||||
IndexHelper.ColumnIndexInfo cIndexInfo = new IndexHelper.ColumnNameIndexInfo(column);
|
||||
ColumnRange columnRange = getColumnRangeFromNameIndex(cIndexInfo, columnIndexList, dataSize, totalNumCols);
|
||||
if ( offset.get( columnRange.coordinate().start_ ) == null )
|
||||
for (byte[] column : columnNames)
|
||||
{
|
||||
IndexHelper.ColumnIndexInfo cIndexInfo = new IndexHelper.ColumnIndexInfo(column, 0, 0, (AbstractType)columnNames.comparator());
|
||||
ColumnRange columnRange = getColumnRangeFromNameIndex(cIndexInfo, columnIndexList, dataSize, totalNumCols);
|
||||
if (offset.get(columnRange.coordinate().start_) == null)
|
||||
{
|
||||
columnRanges.add(columnRange);
|
||||
offset.put(columnRange.coordinate().start_, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return columnRanges;
|
||||
return columnRanges;
|
||||
}
|
||||
|
||||
public static class ColumnIndexFactory
|
||||
{
|
||||
public static ColumnIndexInfo instance(ColumnComparatorFactory.ComparatorType typeInfo)
|
||||
{
|
||||
return typeInfo == ColumnComparatorFactory.ComparatorType.NAME
|
||||
? new ColumnNameIndexInfo() : new ColumnTimestampIndexInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -290,13 +280,22 @@ public class IndexHelper
|
|||
* A helper class to generate indexes while
|
||||
* the columns are sorted by name on disk.
|
||||
*/
|
||||
public static abstract class ColumnIndexInfo implements Comparable<ColumnIndexInfo>
|
||||
public static class ColumnIndexInfo implements Comparable<ColumnIndexInfo>
|
||||
{
|
||||
private long position_;
|
||||
private int columnCount_;
|
||||
|
||||
ColumnIndexInfo(long position, int columnCount)
|
||||
private int columnCount_;
|
||||
private byte[] name_;
|
||||
private AbstractType comparator_;
|
||||
|
||||
public ColumnIndexInfo(AbstractType comparator_)
|
||||
{
|
||||
this.comparator_ = comparator_;
|
||||
}
|
||||
|
||||
public ColumnIndexInfo(byte[] name, long position, int columnCount, AbstractType comparator)
|
||||
{
|
||||
this(comparator);
|
||||
name_ = name;
|
||||
position_ = position;
|
||||
columnCount_ = columnCount;
|
||||
}
|
||||
|
|
@ -320,135 +319,36 @@ public class IndexHelper
|
|||
{
|
||||
columnCount_ = count;
|
||||
}
|
||||
|
||||
public abstract void set(Object o);
|
||||
public abstract void serialize(DataOutputStream dos) throws IOException;
|
||||
public abstract ColumnIndexInfo deserialize(DataInputStream dis) throws IOException;
|
||||
|
||||
public int size()
|
||||
{
|
||||
/* size of long for "position_" + size of columnCount_ */
|
||||
return (8 + 4);
|
||||
}
|
||||
}
|
||||
|
||||
static class ColumnNameIndexInfo extends ColumnIndexInfo
|
||||
{
|
||||
private String name_;
|
||||
|
||||
ColumnNameIndexInfo()
|
||||
{
|
||||
super(0L, 0);
|
||||
}
|
||||
|
||||
ColumnNameIndexInfo(String name)
|
||||
{
|
||||
this(name, 0L, 0);
|
||||
}
|
||||
|
||||
ColumnNameIndexInfo(String name, long position, int columnCount)
|
||||
{
|
||||
super(position, columnCount);
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
String name()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
public void set(Object o)
|
||||
{
|
||||
name_ = (String)o;
|
||||
}
|
||||
|
||||
public int compareTo(ColumnIndexInfo rhs)
|
||||
{
|
||||
IndexHelper.ColumnNameIndexInfo cIndexInfo = (IndexHelper.ColumnNameIndexInfo)rhs;
|
||||
return name_.compareTo(cIndexInfo.name_);
|
||||
return comparator_.compare(name_, rhs.name_);
|
||||
}
|
||||
|
||||
public void serialize(DataOutputStream dos) throws IOException
|
||||
{
|
||||
dos.writeLong(position());
|
||||
dos.writeInt(count());
|
||||
dos.writeUTF(name_);
|
||||
}
|
||||
|
||||
public ColumnNameIndexInfo deserialize(DataInputStream dis) throws IOException
|
||||
{
|
||||
long position = dis.readLong();
|
||||
int columnCount = dis.readInt();
|
||||
String name = dis.readUTF();
|
||||
return new ColumnNameIndexInfo(name, position, columnCount);
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
int size = super.size();
|
||||
/* Size of the name_ as an UTF8 and the actual length as a short for the readUTF. */
|
||||
size += FBUtilities.getUTF8Length(name_) + IColumn.UtfPrefix_;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
static class ColumnTimestampIndexInfo extends ColumnIndexInfo
|
||||
{
|
||||
private long timestamp_;
|
||||
|
||||
ColumnTimestampIndexInfo()
|
||||
{
|
||||
super(0L, 0);
|
||||
}
|
||||
|
||||
ColumnTimestampIndexInfo(long timestamp)
|
||||
{
|
||||
this(timestamp, 0L, 0);
|
||||
}
|
||||
|
||||
ColumnTimestampIndexInfo(long timestamp, long position, int columnCount)
|
||||
{
|
||||
super(position, columnCount);
|
||||
timestamp_ = timestamp;
|
||||
}
|
||||
|
||||
public long timestamp()
|
||||
{
|
||||
return timestamp_;
|
||||
}
|
||||
|
||||
public void set(Object o)
|
||||
{
|
||||
timestamp_ = (Long)o;
|
||||
}
|
||||
|
||||
public int compareTo(ColumnIndexInfo rhs)
|
||||
{
|
||||
ColumnTimestampIndexInfo cIndexInfo = (ColumnTimestampIndexInfo)rhs;
|
||||
return Long.valueOf(timestamp_).compareTo(Long.valueOf(cIndexInfo.timestamp_));
|
||||
}
|
||||
|
||||
public void serialize(DataOutputStream dos) throws IOException
|
||||
{
|
||||
dos.writeLong(position());
|
||||
dos.writeLong(position());
|
||||
dos.writeInt(count());
|
||||
dos.writeLong(timestamp_);
|
||||
ColumnSerializer.writeName(name_, dos);
|
||||
}
|
||||
|
||||
public ColumnTimestampIndexInfo deserialize(DataInputStream dis) throws IOException
|
||||
|
||||
public ColumnIndexInfo deserialize(DataInputStream dis) throws IOException
|
||||
{
|
||||
long position = dis.readLong();
|
||||
int columnCount = dis.readInt();
|
||||
long timestamp = dis.readLong();
|
||||
return new ColumnTimestampIndexInfo(timestamp, position, columnCount);
|
||||
byte[] name = ColumnSerializer.readName(dis);
|
||||
return new ColumnIndexInfo(name, position, columnCount, comparator_);
|
||||
}
|
||||
|
||||
|
||||
public int size()
|
||||
{
|
||||
int size = super.size();
|
||||
/* add the size of the timestamp which is a long */
|
||||
size += 8;
|
||||
return size;
|
||||
// serialized size -- CS.writeName includes a 2-byte length prefix
|
||||
return 8 + 4 + 2 + name_.length;
|
||||
}
|
||||
|
||||
public byte[] name()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.*;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
import org.apache.cassandra.io.SequenceFile.ColumnGroupReader;
|
||||
import org.apache.cassandra.utils.BloomFilter;
|
||||
|
|
@ -285,7 +285,7 @@ public class SSTableReader extends SSTable
|
|||
}
|
||||
}
|
||||
|
||||
public DataInputBuffer next(final String clientKey, String cfName, SortedSet<String> columnNames) throws IOException
|
||||
public DataInputBuffer next(final String clientKey, String cfName, SortedSet<byte[]> columnNames) throws IOException
|
||||
{
|
||||
IFileReader dataReader = null;
|
||||
try
|
||||
|
|
@ -318,18 +318,10 @@ public class SSTableReader extends SSTable
|
|||
}
|
||||
}
|
||||
|
||||
public DataInputBuffer next(String clientKey, String columnFamilyColumn) throws IOException
|
||||
{
|
||||
String[] values = RowMutation.getColumnAndColumnFamily(columnFamilyColumn);
|
||||
String columnFamilyName = values[0];
|
||||
SortedSet<String> columnNames = (values.length == 1) ? null : new TreeSet<String>(Arrays.asList(values[1]));
|
||||
return next(clientKey, columnFamilyName, columnNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* obtain a BlockReader for the getColumnSlice call.
|
||||
*/
|
||||
public ColumnGroupReader getColumnGroupReader(String key, String cfName, String startColumn, boolean isAscending) throws IOException
|
||||
public ColumnGroupReader getColumnGroupReader(String key, String cfName, byte[] startColumn, boolean isAscending) throws IOException
|
||||
{
|
||||
IFileReader dataReader = SequenceFile.reader(dataFile);
|
||||
|
||||
|
|
@ -338,7 +330,8 @@ public class SSTableReader extends SSTable
|
|||
/* Morph key into actual key based on the partition type. */
|
||||
String decoratedKey = partitioner.decorateKey(key);
|
||||
long position = getPosition(decoratedKey, partitioner);
|
||||
return new ColumnGroupReader(dataFile, decoratedKey, cfName, startColumn, isAscending, position);
|
||||
AbstractType comparator = DatabaseDescriptor.getType(getTableName(), cfName);
|
||||
return new ColumnGroupReader(dataFile, decoratedKey, cfName, comparator, startColumn, isAscending, position);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -380,6 +373,11 @@ public class SSTableReader extends SSTable
|
|||
return new FileStruct(this);
|
||||
}
|
||||
|
||||
public String getTableName()
|
||||
{
|
||||
return parseTableName(dataFile);
|
||||
}
|
||||
|
||||
public static void deleteAll() throws IOException
|
||||
{
|
||||
for (SSTableReader sstable : openedFiles.values())
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@
|
|||
package org.apache.cassandra.io;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.utils.BloomFilter;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* This class writes key/value pairs sequentially to disk. It is
|
||||
|
|
@ -33,8 +34,6 @@ import org.apache.log4j.Logger;
|
|||
* jump to random positions to read data from the file. This class
|
||||
* also has many implementations of the IFileWriter and IFileReader
|
||||
* interfaces which are exposed through factory methods.
|
||||
* <p/>
|
||||
* Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com ) & Karthik Ranganathan ( kranganathan@facebook.com )
|
||||
*/
|
||||
|
||||
public class SequenceFile
|
||||
|
|
@ -177,7 +176,6 @@ public class SequenceFile
|
|||
|
||||
public void close(byte[] footer, int size) throws IOException
|
||||
{
|
||||
file_.writeUTF(SequenceFile.marker_);
|
||||
file_.writeInt(size);
|
||||
file_.write(footer, 0, size);
|
||||
}
|
||||
|
|
@ -230,7 +228,7 @@ public class SequenceFile
|
|||
private String key_;
|
||||
private String cfName_;
|
||||
private String cfType_;
|
||||
private int indexType_;
|
||||
private AbstractType comparator_;
|
||||
private boolean isAscending_;
|
||||
|
||||
private List<IndexHelper.ColumnIndexInfo> columnIndexList_;
|
||||
|
|
@ -240,10 +238,11 @@ public class SequenceFile
|
|||
private int localDeletionTime_;
|
||||
private long markedForDeleteAt_;
|
||||
|
||||
ColumnGroupReader(String filename, String key, String cfName, String startColumn, boolean isAscending, long position) throws IOException
|
||||
ColumnGroupReader(String filename, String key, String cfName, AbstractType comparator, byte[] startColumn, boolean isAscending, long position) throws IOException
|
||||
{
|
||||
super(filename, 128 * 1024);
|
||||
this.cfName_ = cfName;
|
||||
this.comparator_ = comparator;
|
||||
this.key_ = key;
|
||||
this.isAscending_ = isAscending;
|
||||
init(startColumn, position);
|
||||
|
|
@ -257,7 +256,7 @@ public class SequenceFile
|
|||
if (columnIndexList.size() == 0)
|
||||
{
|
||||
/* if there is no column index, add an index entry that covers the full space. */
|
||||
return Arrays.asList(new IndexHelper.ColumnIndexInfo[]{new IndexHelper.ColumnNameIndexInfo("", 0, totalNumCols)});
|
||||
return Arrays.asList(new IndexHelper.ColumnIndexInfo(ArrayUtils.EMPTY_BYTE_ARRAY, 0, totalNumCols, comparator_));
|
||||
}
|
||||
|
||||
List<IndexHelper.ColumnIndexInfo> fullColIndexList = new ArrayList<IndexHelper.ColumnIndexInfo>();
|
||||
|
|
@ -266,22 +265,24 @@ public class SequenceFile
|
|||
accumulatededCols += colPosInfo.count();
|
||||
int remainingCols = totalNumCols - accumulatededCols;
|
||||
|
||||
fullColIndexList.add(new IndexHelper.ColumnNameIndexInfo("", 0, columnIndexList.get(0).count()));
|
||||
fullColIndexList.add(new IndexHelper.ColumnIndexInfo(ArrayUtils.EMPTY_BYTE_ARRAY, 0, columnIndexList.get(0).count(), comparator_));
|
||||
for (int i = 0; i < columnIndexList.size() - 1; i++)
|
||||
{
|
||||
IndexHelper.ColumnNameIndexInfo colPosInfo = (IndexHelper.ColumnNameIndexInfo)columnIndexList.get(i);
|
||||
fullColIndexList.add(new IndexHelper.ColumnNameIndexInfo(colPosInfo.name(),
|
||||
colPosInfo.position(),
|
||||
columnIndexList.get(i + 1).count()));
|
||||
IndexHelper.ColumnIndexInfo colPosInfo = columnIndexList.get(i);
|
||||
fullColIndexList.add(new IndexHelper.ColumnIndexInfo(colPosInfo.name(),
|
||||
colPosInfo.position(),
|
||||
columnIndexList.get(i + 1).count(),
|
||||
comparator_));
|
||||
}
|
||||
String columnName = ((IndexHelper.ColumnNameIndexInfo)columnIndexList.get(columnIndexList.size() - 1)).name();
|
||||
fullColIndexList.add(new IndexHelper.ColumnNameIndexInfo(columnName,
|
||||
columnIndexList.get(columnIndexList.size() - 1).position(),
|
||||
remainingCols));
|
||||
byte[] columnName = columnIndexList.get(columnIndexList.size() - 1).name();
|
||||
fullColIndexList.add(new IndexHelper.ColumnIndexInfo(columnName,
|
||||
columnIndexList.get(columnIndexList.size() - 1).position(),
|
||||
remainingCols,
|
||||
comparator_));
|
||||
return fullColIndexList;
|
||||
}
|
||||
|
||||
private void init(String startColumn, long position) throws IOException
|
||||
private void init(byte[] startColumn, long position) throws IOException
|
||||
{
|
||||
String keyInDisk = null;
|
||||
if (seekTo(position) >= 0)
|
||||
|
|
@ -307,16 +308,17 @@ public class SequenceFile
|
|||
* 2. calculate the size of all columns */
|
||||
String cfName = file_.readUTF();
|
||||
cfType_ = file_.readUTF();
|
||||
indexType_ = file_.readInt();
|
||||
String comparatorName = file_.readUTF();
|
||||
assert comparatorName.equals(comparator_.getClass().getCanonicalName());
|
||||
localDeletionTime_ = file_.readInt();
|
||||
markedForDeleteAt_ = file_.readLong();
|
||||
int totalNumCols = file_.readInt();
|
||||
allColumnsSize_ = dataSize - (totalBytesRead + 2 * utfPrefix_ + cfName.length() + cfType_.length() + 4 + 4 + 8 + 4);
|
||||
allColumnsSize_ = dataSize - (totalBytesRead + 3 * utfPrefix_ + cfName.length() + cfType_.length() + comparatorName.length() + 4 + 8 + 4);
|
||||
|
||||
columnStartPosition_ = file_.getFilePointer();
|
||||
columnIndexList_ = getFullColumnIndexList(colIndexList, totalNumCols);
|
||||
|
||||
int index = Collections.binarySearch(columnIndexList_, new IndexHelper.ColumnNameIndexInfo(startColumn));
|
||||
int index = Collections.binarySearch(columnIndexList_, new IndexHelper.ColumnIndexInfo(startColumn, 0, 0, comparator_));
|
||||
curRangeIndex_ = index < 0 ? (++index) * (-1) - 1 : index;
|
||||
}
|
||||
else
|
||||
|
|
@ -345,7 +347,7 @@ public class SequenceFile
|
|||
// write CF info
|
||||
bufOut.writeUTF(cfName_);
|
||||
bufOut.writeUTF(cfType_);
|
||||
bufOut.writeInt(indexType_);
|
||||
bufOut.writeUTF(comparator_.getClass().getCanonicalName());
|
||||
bufOut.writeInt(localDeletionTime_);
|
||||
bufOut.writeLong(markedForDeleteAt_);
|
||||
// now write the columns
|
||||
|
|
@ -432,34 +434,6 @@ public class SequenceFile
|
|||
return totalBytesRead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the column name indexes if present. If the
|
||||
* indexes are based on time then skip over them.
|
||||
*
|
||||
* @param cfName
|
||||
* @return
|
||||
*/
|
||||
private int handleColumnTimeIndexes(String cfName, List<IndexHelper.ColumnIndexInfo> columnIndexList) throws IOException
|
||||
{
|
||||
/* check if we have an index */
|
||||
boolean hasColumnIndexes = file_.readBoolean();
|
||||
int totalBytesRead = 1;
|
||||
/* if we do then deserialize the index */
|
||||
if (hasColumnIndexes)
|
||||
{
|
||||
if (DatabaseDescriptor.isTimeSortingEnabled(null, cfName))
|
||||
{
|
||||
/* read the index */
|
||||
totalBytesRead += IndexHelper.deserializeIndex(getTableName(), cfName, file_, columnIndexList);
|
||||
}
|
||||
else
|
||||
{
|
||||
totalBytesRead += IndexHelper.skipIndex(file_);
|
||||
}
|
||||
}
|
||||
return totalBytesRead;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method dumps the next key/value into the DataOuputStream
|
||||
* passed in. Always use this method to query for application
|
||||
|
|
@ -470,7 +444,7 @@ public class SequenceFile
|
|||
* @param columnFamilyName name of the columnFamily
|
||||
* @param columnNames columnNames we are interested in
|
||||
*/
|
||||
public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, SortedSet<String> columnNames, long position) throws IOException
|
||||
public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, SortedSet<byte[]> columnNames, long position) throws IOException
|
||||
{
|
||||
assert columnNames != null;
|
||||
|
||||
|
|
@ -514,8 +488,8 @@ public class SequenceFile
|
|||
return bytesRead;
|
||||
}
|
||||
|
||||
private void readColumns(String key, DataOutputBuffer bufOut, String columnFamilyName, SortedSet<String> cNames)
|
||||
throws IOException
|
||||
private void readColumns(String key, DataOutputBuffer bufOut, String columnFamilyName, SortedSet<byte[]> cNames)
|
||||
throws IOException
|
||||
{
|
||||
int dataSize = file_.readInt();
|
||||
|
||||
|
|
@ -556,8 +530,8 @@ public class SequenceFile
|
|||
String cfType = file_.readUTF();
|
||||
dataSize -= (utfPrefix_ + cfType.length());
|
||||
|
||||
int indexType = file_.readInt();
|
||||
dataSize -= 4;
|
||||
String comparatorName = file_.readUTF();
|
||||
dataSize -= (utfPrefix_ + comparatorName.length());
|
||||
|
||||
/* read local deletion time */
|
||||
int localDeletionTime = file_.readInt();
|
||||
|
|
@ -590,7 +564,7 @@ public class SequenceFile
|
|||
// echo back the CF data we read
|
||||
bufOut.writeUTF(cfName);
|
||||
bufOut.writeUTF(cfType);
|
||||
bufOut.writeInt(indexType);
|
||||
bufOut.writeUTF(comparatorName);
|
||||
bufOut.writeInt(localDeletionTime);
|
||||
bufOut.writeLong(markedForDeleteAt);
|
||||
/* write number of columns */
|
||||
|
|
@ -636,15 +610,6 @@ public class SequenceFile
|
|||
bytesRead = endPosition - startPosition;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have read the bloom filter in the data
|
||||
* file we know we are at the end of the file
|
||||
* and no further key processing is required. So
|
||||
* we return -1 indicating we are at the end of
|
||||
* the file.
|
||||
*/
|
||||
if (key.equals(SequenceFile.marker_))
|
||||
bytesRead = -1L;
|
||||
return bytesRead;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ public class CassandraDaemon
|
|||
Set<String> tables = DatabaseDescriptor.getTableToColumnFamilyMap().keySet();
|
||||
for (String table : tables)
|
||||
{
|
||||
logger.debug("opening table " + table);
|
||||
Table tbl = Table.open(table);
|
||||
tbl.onStart();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,14 @@ import java.util.concurrent.TimeoutException;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.cql.common.CqlResult;
|
||||
import org.apache.cassandra.cql.driver.CqlDriver;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.utils.LogUtil;
|
||||
import org.apache.cassandra.dht.OrderPreservingPartitioner;
|
||||
|
|
@ -121,19 +124,19 @@ public class CassandraServer implements Cassandra.Iface
|
|||
private List<Column> getSlice(ReadCommand command) throws InvalidRequestException
|
||||
{
|
||||
ColumnFamily cfamily = readColumnFamily(command);
|
||||
if (cfamily == null || cfamily.getColumns().size() == 0)
|
||||
if (cfamily == null || cfamily.getColumnsMap().size() == 0)
|
||||
{
|
||||
return EMPTY_COLUMNS;
|
||||
}
|
||||
if (cfamily.isSuper())
|
||||
{
|
||||
IColumn column = cfamily.getColumns().values().iterator().next();
|
||||
IColumn column = cfamily.getColumnsMap().values().iterator().next();
|
||||
return thriftifyColumns(column.getSubColumns());
|
||||
}
|
||||
return thriftifyColumns(cfamily.getAllColumns());
|
||||
return thriftifyColumns(cfamily.getSortedColumns());
|
||||
}
|
||||
|
||||
public List<Column> get_slice_by_names(String table, String key, ColumnParent column_parent, List<String> column_names)
|
||||
public List<Column> get_slice_by_names(String table, String key, ColumnParent column_parent, List<byte[]> column_names)
|
||||
throws InvalidRequestException, NotFoundException
|
||||
{
|
||||
logger.debug("get_slice_by_names");
|
||||
|
|
@ -141,7 +144,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
return getSlice(new SliceByNamesReadCommand(table, key, column_parent, column_names));
|
||||
}
|
||||
|
||||
public List<Column> get_slice(String table, String key, ColumnParent column_parent, String start, String finish, boolean is_ascending, int count)
|
||||
public List<Column> get_slice(String table, String key, ColumnParent column_parent, byte[] start, byte[] finish, boolean is_ascending, int count)
|
||||
throws InvalidRequestException, NotFoundException
|
||||
{
|
||||
logger.debug("get_slice_from");
|
||||
|
|
@ -151,8 +154,6 @@ public class CassandraServer implements Cassandra.Iface
|
|||
throw new InvalidRequestException("get_slice does not yet support super columns (we need to fix this)");
|
||||
if (count <= 0)
|
||||
throw new InvalidRequestException("get_slice requires positive count");
|
||||
if (!"Name".equals(DatabaseDescriptor.getCFMetaData(table, column_parent.column_family).indexProperty_))
|
||||
throw new InvalidRequestException("get_slice requires CF indexed by name");
|
||||
|
||||
return getSlice(new SliceFromReadCommand(table, key, column_parent, start, finish, is_ascending, count));
|
||||
}
|
||||
|
|
@ -181,7 +182,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
}
|
||||
else
|
||||
{
|
||||
columns = cfamily.getAllColumns();
|
||||
columns = cfamily.getSortedColumns();
|
||||
}
|
||||
if (columns == null || columns.size() == 0)
|
||||
{
|
||||
|
|
@ -212,7 +213,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
}
|
||||
|
||||
ColumnFamily cfamily;
|
||||
cfamily = readColumnFamily(new SliceFromReadCommand(table, key, column_parent, "", "", true, Integer.MAX_VALUE));
|
||||
cfamily = readColumnFamily(new SliceFromReadCommand(table, key, column_parent, ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, Integer.MAX_VALUE));
|
||||
if (cfamily == null)
|
||||
{
|
||||
return 0;
|
||||
|
|
@ -228,7 +229,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
}
|
||||
else
|
||||
{
|
||||
columns = cfamily.getAllColumns();
|
||||
columns = cfamily.getSortedColumns();
|
||||
}
|
||||
if (columns == null || columns.size() == 0)
|
||||
{
|
||||
|
|
@ -245,7 +246,14 @@ public class CassandraServer implements Cassandra.Iface
|
|||
ThriftValidation.validateColumnPath(table, column_path);
|
||||
|
||||
RowMutation rm = new RowMutation(table, key.trim());
|
||||
rm.add(new QueryPath(column_path), value, timestamp);
|
||||
try
|
||||
{
|
||||
rm.add(new QueryPath(column_path), value, timestamp);
|
||||
}
|
||||
catch (MarshalException e)
|
||||
{
|
||||
throw new InvalidRequestException(e.getMessage());
|
||||
}
|
||||
doInsert(block_for, rm);
|
||||
}
|
||||
|
||||
|
|
@ -284,7 +292,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
}
|
||||
}
|
||||
|
||||
public List<SuperColumn> get_slice_super_by_names(String table, String key, String column_family, List<String> super_column_names)
|
||||
public List<SuperColumn> get_slice_super_by_names(String table, String key, String column_family, List<byte[]> super_column_names)
|
||||
throws InvalidRequestException
|
||||
{
|
||||
logger.debug("get_slice_super_by_names");
|
||||
|
|
@ -295,7 +303,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
{
|
||||
return EMPTY_SUPERCOLUMNS;
|
||||
}
|
||||
return thriftifySuperColumns(cfamily.getAllColumns());
|
||||
return thriftifySuperColumns(cfamily.getSortedColumns());
|
||||
}
|
||||
|
||||
private List<SuperColumn> thriftifySuperColumns(Collection<IColumn> columns)
|
||||
|
|
@ -319,7 +327,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
return thriftSuperColumns;
|
||||
}
|
||||
|
||||
public List<SuperColumn> get_slice_super(String table, String key, String column_family, String start, String finish, boolean is_ascending, int count)
|
||||
public List<SuperColumn> get_slice_super(String table, String key, String column_family, byte[] start, byte[] finish, boolean is_ascending, int count)
|
||||
throws InvalidRequestException
|
||||
{
|
||||
logger.debug("get_slice_super");
|
||||
|
|
@ -333,7 +341,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
{
|
||||
return EMPTY_SUPERCOLUMNS;
|
||||
}
|
||||
Collection<IColumn> columns = cfamily.getAllColumns();
|
||||
Collection<IColumn> columns = cfamily.getSortedColumns();
|
||||
return thriftifySuperColumns(columns);
|
||||
}
|
||||
|
||||
|
|
@ -349,7 +357,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
Collection<IColumn> columns = cfamily.getAllColumns();
|
||||
Collection<IColumn> columns = cfamily.getSortedColumns();
|
||||
if (columns == null || columns.size() == 0)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
|
|
@ -458,7 +466,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
columnFamilyMetaData.n_rowKey + ", " + desc + ")";
|
||||
|
||||
columnMap.put("desc", desc);
|
||||
columnMap.put("sort", columnFamilyMetaData.indexProperty_);
|
||||
columnMap.put("type", columnFamilyMetaData.comparator.getClass().getName());
|
||||
columnMap.put("flushperiod", columnFamilyMetaData.flushPeriodInMinutes + "");
|
||||
columnFamiliesMap.put(columnFamilyMetaData.cfName, columnMap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,14 @@ public class BloomFilter extends Filter
|
|||
}
|
||||
}
|
||||
|
||||
public void add(byte[] key)
|
||||
{
|
||||
for (int bucketIndex : getHashBuckets(key))
|
||||
{
|
||||
filter_.set(bucketIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return filter_.toString();
|
||||
|
|
|
|||
|
|
@ -18,14 +18,7 @@
|
|||
|
||||
package org.apache.cassandra.utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
|
@ -377,4 +370,18 @@ public class FBUtilities
|
|||
|
||||
return length;
|
||||
}
|
||||
|
||||
public static void writeByteArray(byte[] bytes, DataOutput out) throws IOException
|
||||
{
|
||||
out.writeInt(bytes.length);
|
||||
out.write(bytes);
|
||||
}
|
||||
|
||||
public static byte[] readByteArray(DataInput in) throws IOException
|
||||
{
|
||||
int length = in.readInt();
|
||||
byte[] bytes = new byte[length];
|
||||
in.readFully(bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ public abstract class Filter
|
|||
return Filter.getHashBuckets(key, hashCount, buckets());
|
||||
}
|
||||
|
||||
public int[] getHashBuckets(byte[] key)
|
||||
{
|
||||
return Filter.getHashBuckets(key, hashCount, buckets());
|
||||
}
|
||||
|
||||
|
||||
abstract int buckets();
|
||||
|
||||
public abstract void add(String key);
|
||||
|
|
@ -78,6 +84,11 @@ public abstract class Filter
|
|||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return getHashBuckets(b, hashCount, max);
|
||||
}
|
||||
|
||||
static int[] getHashBuckets(byte[] b, int hashCount, int max)
|
||||
{
|
||||
int[] result = new int[hashCount];
|
||||
int hash1 = hasher.hash(b, b.length, 0);
|
||||
int hash2 = hasher.hash(b, b.length, hash1);
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ public abstract class ReducingIterator<T> extends AbstractIterator<T> implements
|
|||
protected abstract T getReduced();
|
||||
|
||||
/** override this if the keys you want to base the reduce on are not the same as the object itself (but can be generated from it) */
|
||||
protected Object getKey(T o)
|
||||
protected boolean isEqual(T o1, T o2)
|
||||
{
|
||||
return o;
|
||||
return o1.equals(o2);
|
||||
}
|
||||
|
||||
protected T computeNext()
|
||||
protected T computeNext()
|
||||
{
|
||||
if (last == null && !source.hasNext())
|
||||
return endOfData();
|
||||
|
|
@ -45,7 +45,7 @@ public abstract class ReducingIterator<T> extends AbstractIterator<T> implements
|
|||
break;
|
||||
}
|
||||
T current = source.next();
|
||||
if (last != null && !getKey(current).equals(getKey(last)))
|
||||
if (last != null && !isEqual(current, last))
|
||||
keyChanged = true;
|
||||
last = current;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,16 +40,16 @@
|
|||
<MemtableObjectCountInMillions>0.00002</MemtableObjectCountInMillions> <!-- 20 -->
|
||||
<Tables>
|
||||
<Table Name = "Table1">
|
||||
<ColumnFamily ColumnSort="Name" Name="Standard1"/>
|
||||
<ColumnFamily ColumnSort="Name" Name="Standard2"/>
|
||||
<ColumnFamily ColumnSort="Time" Name="StandardByTime1"/>
|
||||
<ColumnFamily ColumnSort="Time" Name="StandardByTime2"/>
|
||||
<ColumnFamily Name="Standard1"/>
|
||||
<ColumnFamily Name="Standard2"/>
|
||||
<ColumnFamily CompareWith="LongType" Name="StandardByTime1"/>
|
||||
<ColumnFamily CompareWith="LongType" Name="StandardByTime2"/>
|
||||
<ColumnFamily ColumnType="Super" Name="Super1"/>
|
||||
<ColumnFamily ColumnType="Super" Name="Super2"/>
|
||||
</Table>
|
||||
<Table Name = "Table2">
|
||||
<ColumnFamily ColumnSort="Name" Name="Standard1"/>
|
||||
<ColumnFamily ColumnSort="Name" Name="Standard3"/>
|
||||
<ColumnFamily Name="Standard1"/>
|
||||
<ColumnFamily Name="Standard3"/>
|
||||
</Table>
|
||||
</Tables>
|
||||
<Seeds>
|
||||
|
|
|
|||
|
|
@ -17,18 +17,22 @@
|
|||
# to run a single test, run from trunk/:
|
||||
# PYTHONPATH=test nosetests --tests=system.test_server:TestMutations.test_empty_range
|
||||
|
||||
import os, sys, time
|
||||
import os, sys, time, struct
|
||||
|
||||
from . import client, root, CassandraTester
|
||||
|
||||
from thrift.Thrift import TApplicationException
|
||||
from ttypes import *
|
||||
|
||||
|
||||
def _i64(n):
|
||||
return struct.pack('<q', n) # little endian, to match cassandra.db.marshal.LongType
|
||||
|
||||
_SIMPLE_COLUMNS = [Column('c1', 'value1', 0),
|
||||
Column('c2', 'value2', 0)]
|
||||
_SUPER_COLUMNS = [SuperColumn(name='sc1', columns=[Column('c4', 'value4', 0)]),
|
||||
SuperColumn(name='sc2', columns=[Column('c5', 'value5', 0),
|
||||
Column('c6', 'value6', 0)])]
|
||||
_SUPER_COLUMNS = [SuperColumn(name='sc1', columns=[Column(_i64(4), 'value4', 0)]),
|
||||
SuperColumn(name='sc2', columns=[Column(_i64(5), 'value5', 0),
|
||||
Column(_i64(6), 'value6', 0)])]
|
||||
|
||||
def _insert_simple(block=True):
|
||||
client.insert('Table1', 'key1', ColumnPath('Standard1', column='c1'), 'value1', 0, block)
|
||||
|
|
@ -50,9 +54,9 @@ def _verify_simple():
|
|||
assert L == _SIMPLE_COLUMNS, L
|
||||
|
||||
def _insert_super():
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc1', 'c4'), 'value4', 0, False)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c5'), 'value5', 0, False)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c6'), 'value6', 0, False)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc1', _i64(4)), 'value4', 0, False)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(5)), 'value5', 0, False)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(6)), 'value6', 0, False)
|
||||
time.sleep(0.1)
|
||||
|
||||
def _insert_range():
|
||||
|
|
@ -75,7 +79,7 @@ def _verify_range():
|
|||
|
||||
|
||||
def _verify_super(supercf='Super1'):
|
||||
assert client.get_column('Table1', 'key1', ColumnPath(supercf, 'sc1', 'c4')) == Column('c4', 'value4', 0)
|
||||
assert client.get_column('Table1', 'key1', ColumnPath(supercf, 'sc1', _i64(4))) == Column(_i64(4), 'value4', 0)
|
||||
slice = client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000)
|
||||
assert slice == _SUPER_COLUMNS, slice
|
||||
|
||||
|
|
@ -203,35 +207,37 @@ class TestMutations(CassandraTester):
|
|||
_insert_super()
|
||||
|
||||
# Make sure remove clears out what it's supposed to, and _only_ that:
|
||||
client.remove('Table1', 'key1', ColumnPathOrParent('Super1', 'sc2', 'c5'), 5, True)
|
||||
_expect_missing(lambda: client.get_column('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c5')))
|
||||
client.remove('Table1', 'key1', ColumnPathOrParent('Super1', 'sc2', _i64(5)), 5, True)
|
||||
_expect_missing(lambda: client.get_column('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(5))))
|
||||
assert client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000) == \
|
||||
[SuperColumn(name='sc1', columns=[Column('c4', 'value4', 0)]),
|
||||
SuperColumn(name='sc2', columns=[Column('c6', 'value6', 0)])]
|
||||
[SuperColumn(name='sc1', columns=[Column(_i64(4), 'value4', 0)]),
|
||||
SuperColumn(name='sc2', columns=[Column(_i64(6), 'value6', 0)])]
|
||||
_verify_simple()
|
||||
|
||||
# New insert, make sure it shows up post-remove:
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c7'), 'value7', 0, True)
|
||||
scs = [SuperColumn(name='sc1', columns=[Column('c4', 'value4', 0)]),
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(7)), 'value7', 0, True)
|
||||
scs = [SuperColumn(name='sc1',
|
||||
columns=[Column(_i64(4), 'value4', 0)]),
|
||||
SuperColumn(name='sc2',
|
||||
columns=[Column('c6', 'value6', 0), Column('c7', 'value7', 0)])]
|
||||
columns=[Column(_i64(6), 'value6', 0), Column(_i64(7), 'value7', 0)])]
|
||||
|
||||
assert client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000) == scs
|
||||
actual = client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000)
|
||||
assert client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000) == scs, actual
|
||||
|
||||
# Test resurrection. First, re-insert the value w/ older timestamp,
|
||||
# and make sure it stays removed:
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c5'), 'value5', 0, True)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(5)), 'value5', 0, True)
|
||||
actual = client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000)
|
||||
assert actual == scs, actual
|
||||
|
||||
# Next, w/ a newer timestamp; it should come back
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c5'), 'value5', 6, True)
|
||||
client.insert('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(5)), 'value5', 6, True)
|
||||
actual = client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000)
|
||||
assert actual == \
|
||||
[SuperColumn(name='sc1', columns=[Column('c4', 'value4', 0)]),
|
||||
SuperColumn(name='sc2', columns=[Column('c5', 'value5', 6),
|
||||
Column('c6', 'value6', 0),
|
||||
Column('c7', 'value7', 0)])], actual
|
||||
[SuperColumn(name='sc1', columns=[Column(_i64(4), 'value4', 0)]),
|
||||
SuperColumn(name='sc2', columns=[Column(_i64(5), 'value5', 6),
|
||||
Column(_i64(6), 'value6', 0),
|
||||
Column(_i64(7), 'value7', 0)])], actual
|
||||
|
||||
def test_super_cf_remove_supercolumn(self):
|
||||
_insert_simple()
|
||||
|
|
@ -239,10 +245,10 @@ class TestMutations(CassandraTester):
|
|||
|
||||
# Make sure remove clears out what it's supposed to, and _only_ that:
|
||||
client.remove('Table1', 'key1', ColumnPathOrParent('Super1', 'sc2'), 5, True)
|
||||
_expect_missing(lambda: client.get_column('Table1', 'key1', ColumnPath('Super1', 'sc2', 'c5')))
|
||||
actual = client.get_columns_since('Table1', 'key1', ColumnParent('Super1', 'sc2'), -1)
|
||||
_expect_missing(lambda: client.get_column('Table1', 'key1', ColumnPath('Super1', 'sc2', _i64(5))))
|
||||
actual = client.get_slice('Table1', 'key1', ColumnParent('Super1', 'sc2'), '', '', True, 1000)
|
||||
assert actual == [], actual
|
||||
scs = [SuperColumn(name='sc1', columns=[Column('c4', 'value4', 0)])]
|
||||
scs = [SuperColumn(name='sc1', columns=[Column(_i64(4), 'value4', 0)])]
|
||||
actual = client.get_slice_super('Table1', 'key1', 'Super1', '', '', True, 1000)
|
||||
assert actual == scs, actual
|
||||
_verify_simple()
|
||||
|
|
@ -318,6 +324,6 @@ class TestMutations(CassandraTester):
|
|||
assert result[1].name == 'c2'
|
||||
|
||||
_insert_super()
|
||||
result = client.get_slice_by_names('Table1','key1', ColumnParent('Super1', 'sc1'), ['c4'])
|
||||
result = client.get_slice_by_names('Table1','key1', ColumnParent('Super1', 'sc1'), [_i64(4)])
|
||||
assert len(result) == 1
|
||||
assert result[0].name == 'c4'
|
||||
assert result[0].name == _i64(4)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,28 @@
|
|||
package org.apache.cassandra;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apache.cassandra.db.Column;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
|
||||
public class Util
|
||||
{
|
||||
public static Column column(String name, String value, long timestamp)
|
||||
{
|
||||
return new Column(name, value.getBytes(), timestamp);
|
||||
return new Column(name.getBytes(), value.getBytes(), timestamp);
|
||||
}
|
||||
|
||||
public static void addMutation(RowMutation rm, String columnFamilyName, String superColumnName, long columnName, String value, long timestamp)
|
||||
{
|
||||
rm.add(new QueryPath(columnFamilyName, superColumnName.getBytes(), getBytes(columnName)), value.getBytes(), timestamp);
|
||||
}
|
||||
|
||||
public static byte[] getBytes(long v)
|
||||
{
|
||||
byte[] bytes = new byte[8];
|
||||
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
bb.putLong(v);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.cassandra.db;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.apache.cassandra.Util.column;
|
||||
|
||||
public class ColumnComparatorFactoryTest {
|
||||
public Comparator<IColumn> nameComparator = ColumnComparatorFactory.getComparator(ColumnComparatorFactory.ComparatorType.NAME);
|
||||
|
||||
@Test
|
||||
public void testLT() {
|
||||
IColumn col1 = column("Column-8", "", 0);
|
||||
IColumn col2 = column("Column-9", "", 0);
|
||||
assert nameComparator.compare(col1, col2) < 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGT() {
|
||||
IColumn col1 = column("Column-9", "", 0);
|
||||
IColumn col2 = column("Column-10", "", 0);
|
||||
// tricky -- remember we're comparing _lexically_
|
||||
assert nameComparator.compare(col1, col2) > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -109,15 +109,15 @@ public class ColumnFamilyStoreTest extends CleanupHelper
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column2"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column2".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
List<SSTableReader> ssTables = table.getAllSSTablesOnDisk();
|
||||
assertEquals(1, ssTables.size());
|
||||
ssTables.get(0).forceBloomFilterFailures();
|
||||
ColumnFamily cf = store.getColumnFamily(new IdentityQueryFilter("key2", new QueryPath("Standard1", null, "Column1")));
|
||||
ColumnFamily cf = store.getColumnFamily(new IdentityQueryFilter("key2", new QueryPath("Standard1", null, "Column1".getBytes())));
|
||||
assertNull(cf);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,13 +38,10 @@ public class ColumnFamilyTest
|
|||
@Test
|
||||
public void testSingleColumn() throws IOException
|
||||
{
|
||||
Random random = new Random();
|
||||
byte[] bytes = new byte[1024];
|
||||
random.nextBytes(bytes);
|
||||
ColumnFamily cf;
|
||||
|
||||
cf = ColumnFamily.create("Table1", "Standard1");
|
||||
cf.addColumn(QueryPath.column("C"), bytes, 1);
|
||||
cf.addColumn(column("C", "v", 1));
|
||||
DataOutputBuffer bufOut = new DataOutputBuffer();
|
||||
ColumnFamily.serializer().serialize(cf, bufOut);
|
||||
|
||||
|
|
@ -53,7 +50,7 @@ public class ColumnFamilyTest
|
|||
cf = ColumnFamily.serializer().deserialize(bufIn);
|
||||
assert cf != null;
|
||||
assert cf.name().equals("Standard1");
|
||||
assert cf.getAllColumns().size() == 1;
|
||||
assert cf.getSortedColumns().size() == 1;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -61,10 +58,10 @@ public class ColumnFamilyTest
|
|||
{
|
||||
ColumnFamily cf;
|
||||
|
||||
TreeMap<String, byte[]> map = new TreeMap<String, byte[]>();
|
||||
TreeMap<String, String> map = new TreeMap<String, String>();
|
||||
for (int i = 100; i < 1000; ++i)
|
||||
{
|
||||
map.put(Integer.toString(i), ("Avinash Lakshman is a good man: " + i).getBytes());
|
||||
map.put(Integer.toString(i), "Avinash Lakshman is a good man: " + i);
|
||||
}
|
||||
|
||||
// write
|
||||
|
|
@ -72,7 +69,7 @@ public class ColumnFamilyTest
|
|||
DataOutputBuffer bufOut = new DataOutputBuffer();
|
||||
for (String cName : map.navigableKeySet())
|
||||
{
|
||||
cf.addColumn(QueryPath.column(cName), map.get(cName), 314);
|
||||
cf.addColumn(column(cName, map.get(cName), 314));
|
||||
}
|
||||
ColumnFamily.serializer().serialize(cf, bufOut);
|
||||
|
||||
|
|
@ -82,9 +79,9 @@ public class ColumnFamilyTest
|
|||
cf = ColumnFamily.serializer().deserialize(bufIn);
|
||||
for (String cName : map.navigableKeySet())
|
||||
{
|
||||
assert Arrays.equals(cf.getColumn(cName).value(), map.get(cName));
|
||||
assert new String(cf.getColumn(cName.getBytes()).value()).equals(map.get(cName));
|
||||
}
|
||||
assert new HashSet<String>(cf.getColumns().keySet()).equals(map.keySet());
|
||||
assert cf.getColumnNames().size() == map.size();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -97,7 +94,7 @@ public class ColumnFamilyTest
|
|||
cf.addColumn(column("col1", "", 3));
|
||||
|
||||
assert 2 == cf.getColumnCount();
|
||||
assert 2 == cf.getAllColumns().size();
|
||||
assert 2 == cf.getSortedColumns().size();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -109,7 +106,7 @@ public class ColumnFamilyTest
|
|||
cf.addColumn(column("col1", "val2", 2)); // same timestamp, new value
|
||||
cf.addColumn(column("col1", "val3", 1)); // older timestamp -- should be ignored
|
||||
|
||||
assert Arrays.equals("val2".getBytes(), cf.getColumn("col1").value());
|
||||
assert Arrays.equals("val2".getBytes(), cf.getColumn("col1".getBytes()).value());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -122,18 +119,18 @@ public class ColumnFamilyTest
|
|||
byte val2[] = "x value ".getBytes();
|
||||
|
||||
// exercise addColumn(QueryPath, ...)
|
||||
cf_new.addColumn(QueryPath.column("col1"), val, 3);
|
||||
cf_new.addColumn(QueryPath.column("col2"), val, 4);
|
||||
cf_new.addColumn(QueryPath.column("col1".getBytes()), val, 3);
|
||||
cf_new.addColumn(QueryPath.column("col2".getBytes()), val, 4);
|
||||
|
||||
cf_old.addColumn(QueryPath.column("col2"), val2, 1);
|
||||
cf_old.addColumn(QueryPath.column("col3"), val2, 2);
|
||||
cf_old.addColumn(QueryPath.column("col2".getBytes()), val2, 1);
|
||||
cf_old.addColumn(QueryPath.column("col3".getBytes()), val2, 2);
|
||||
|
||||
cf_result.addColumns(cf_new);
|
||||
cf_result.addColumns(cf_old);
|
||||
|
||||
assert 3 == cf_result.getColumnCount() : "Count is " + cf_new.getColumnCount();
|
||||
//addcolumns will only add if timestamp >= old timestamp
|
||||
assert Arrays.equals(val, cf_result.getColumn("col2").value());
|
||||
assert Arrays.equals(val, cf_result.getColumn("col2".getBytes()).value());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ public class CommitLogTest extends CleanupHelper
|
|||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), value, 0);
|
||||
rm.add(new QueryPath("Standard2", null, "Column1"), value, 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), value, 0);
|
||||
rm.add(new QueryPath("Standard2", null, "Column1".getBytes()), value, 0);
|
||||
rm.apply();
|
||||
}
|
||||
assert CommitLog.getSegmentCount() > 1;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class CompactionsTest extends CleanupHelper
|
|||
for (int i = 0; i < ROWS_PER_SSTABLE; i++) {
|
||||
String key = String.valueOf(i % 2);
|
||||
RowMutation rm = new RowMutation("Table1", key);
|
||||
rm.add(new QueryPath("Standard1", null, String.valueOf(i / 2)), new byte[0], j * ROWS_PER_SSTABLE + i);
|
||||
rm.add(new QueryPath("Standard1", null, String.valueOf(i / 2).getBytes()), new byte[0], j * ROWS_PER_SSTABLE + i);
|
||||
rm.apply();
|
||||
inserted.add(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,15 @@ import java.io.IOException;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import static org.apache.cassandra.Util.addMutation;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.filter.IdentityQueryFilter;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
public class NameSortTest extends CleanupHelper
|
||||
{
|
||||
|
|
@ -66,20 +70,20 @@ public class NameSortTest extends CleanupHelper
|
|||
{
|
||||
byte[] bytes = j % 2 == 0 ? "a".getBytes() : "b".getBytes();
|
||||
rm = new RowMutation("Table1", key);
|
||||
rm.add(new QueryPath("Standard1", null, "Column-" + j), bytes, j);
|
||||
rm.add(new QueryPath("Standard1", null, ("Column-" + j).getBytes()), bytes, j);
|
||||
rm.apply();
|
||||
}
|
||||
|
||||
// super
|
||||
for (int j = 0; j < 8; ++j)
|
||||
{
|
||||
rm = new RowMutation("Table1", key);
|
||||
for (int k = 0; k < 4; ++k)
|
||||
{
|
||||
byte[] bytes = (j + k) % 2 == 0 ? "a".getBytes() : "b".getBytes();
|
||||
rm = new RowMutation("Table1", key);
|
||||
rm.add(new QueryPath("Super1", "SuperColumn-" + j, "Column-" + k), bytes, k);
|
||||
rm.apply();
|
||||
String value = (j + k) % 2 == 0 ? "a" : "b";
|
||||
addMutation(rm, "Super1", "SuperColumn-" + j, k, value, k);
|
||||
}
|
||||
rm.apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,26 +102,26 @@ public class NameSortTest extends CleanupHelper
|
|||
ColumnFamily cf;
|
||||
|
||||
cf = table.get(key, "Standard1");
|
||||
Collection<IColumn> columns = cf.getAllColumns();
|
||||
Collection<IColumn> columns = cf.getSortedColumns();
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
int j = Integer.valueOf(column.name().split("-")[1]);
|
||||
int j = Integer.valueOf(new String(column.name()).split("-")[1]);
|
||||
byte[] bytes = j % 2 == 0 ? "a".getBytes() : "b".getBytes();
|
||||
assert Arrays.equals(bytes, column.value());
|
||||
}
|
||||
|
||||
cf = table.get(key, "Super1");
|
||||
assert cf != null : "key " + key + " is missing!";
|
||||
Collection<IColumn> superColumns = cf.getAllColumns();
|
||||
assert superColumns.size() == 8;
|
||||
Collection<IColumn> superColumns = cf.getSortedColumns();
|
||||
assert superColumns.size() == 8 : cf;
|
||||
for (IColumn superColumn : superColumns)
|
||||
{
|
||||
int j = Integer.valueOf(superColumn.name().split("-")[1]);
|
||||
int j = Integer.valueOf(new String(superColumn.name()).split("-")[1]);
|
||||
Collection<IColumn> subColumns = superColumn.getSubColumns();
|
||||
assert subColumns.size() == 4;
|
||||
for (IColumn subColumn : subColumns)
|
||||
{
|
||||
int k = Integer.valueOf(subColumn.name().split("-")[1]);
|
||||
long k = ByteBuffer.wrap(subColumn.name()).getLong();
|
||||
byte[] bytes = (j + k) % 2 == 0 ? "a".getBytes() : "b".getBytes();
|
||||
assert Arrays.equals(bytes, subColumn.value());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class OneCompactionTest
|
|||
for (int j = 0; j < insertsPerTable; j++) {
|
||||
String key = "0";
|
||||
RowMutation rm = new RowMutation("Table1", key);
|
||||
rm.add(new QueryPath(columnFamilyName, null, "0"), new byte[0], j);
|
||||
rm.add(new QueryPath(columnFamilyName, null, "0".getBytes()), new byte[0], j);
|
||||
rm.apply();
|
||||
inserted.add(key);
|
||||
store.forceBlockingFlush();
|
||||
|
|
|
|||
|
|
@ -24,55 +24,48 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.io.DataInputBuffer;
|
||||
import org.apache.cassandra.io.DataOutputBuffer;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.marshal.AsciiType;
|
||||
|
||||
public class ReadMessageTest
|
||||
{
|
||||
@Test
|
||||
public void testMakeReadMessage()
|
||||
public void testMakeReadMessage() throws IOException
|
||||
{
|
||||
ArrayList<String> colList = new ArrayList<String>();
|
||||
colList.add("col1");
|
||||
colList.add("col2");
|
||||
ArrayList<byte[]> colList = new ArrayList<byte[]>();
|
||||
colList.add("col1".getBytes());
|
||||
colList.add("col2".getBytes());
|
||||
|
||||
ReadCommand rm, rm2;
|
||||
|
||||
rm = new SliceByNamesReadCommand("Table1", "row1", new QueryPath("foo"), colList);
|
||||
rm = new SliceByNamesReadCommand("Table1", "row1", new QueryPath("Standard1"), colList);
|
||||
rm2 = serializeAndDeserializeReadMessage(rm);
|
||||
assert rm2.toString().equals(rm.toString());
|
||||
|
||||
rm = new SliceFromReadCommand("Table1", "row1", new QueryPath("foo"), "", "", true, 2);
|
||||
rm = new SliceFromReadCommand("Table1", "row1", new QueryPath("Standard1"), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
|
||||
rm2 = serializeAndDeserializeReadMessage(rm);
|
||||
assert rm2.toString().equals(rm.toString());
|
||||
|
||||
rm = new SliceFromReadCommand("Table1", "row1", new QueryPath("foo"), "a", "z", true, 5);
|
||||
rm = new SliceFromReadCommand("Table1", "row1", new QueryPath("Standard1"), "a".getBytes(), "z".getBytes(), true, 5);
|
||||
rm2 = serializeAndDeserializeReadMessage(rm);
|
||||
assertEquals(rm2.toString(), rm.toString());
|
||||
}
|
||||
|
||||
private ReadCommand serializeAndDeserializeReadMessage(ReadCommand rm)
|
||||
private ReadCommand serializeAndDeserializeReadMessage(ReadCommand rm) throws IOException
|
||||
{
|
||||
ReadCommand rm2 = null;
|
||||
ReadCommandSerializer rms = ReadCommand.serializer();
|
||||
DataOutputBuffer dos = new DataOutputBuffer();
|
||||
DataInputBuffer dis = new DataInputBuffer();
|
||||
|
||||
try
|
||||
{
|
||||
rms.serialize(rm, dos);
|
||||
dis.reset(dos.getData(), dos.getLength());
|
||||
rm2 = rms.deserialize(dis);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return rm2;
|
||||
rms.serialize(rm, dos);
|
||||
dis.reset(dos.getData(), dos.getLength());
|
||||
return rms.deserialize(dis);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -83,13 +76,13 @@ public class ReadMessageTest
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), "abcd".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "abcd".getBytes(), 0);
|
||||
rm.apply();
|
||||
|
||||
ReadCommand command = new SliceByNamesReadCommand("Table1", "key1", new QueryPath("Standard1"), Arrays.asList("Column1"));
|
||||
ReadCommand command = new SliceByNamesReadCommand("Table1", "key1", new QueryPath("Standard1"), Arrays.asList("Column1".getBytes()));
|
||||
Row row = command.getRow(table);
|
||||
ColumnFamily cf = row.getColumnFamily("Standard1");
|
||||
IColumn col = cf.getColumn("Column1");
|
||||
assert Arrays.equals(((Column)col).value(), "abcd".getBytes());
|
||||
IColumn col = cf.getColumn("Column1".getBytes());
|
||||
assert Arrays.equals(col.value(), "abcd".getBytes());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class RemoveColumnFamilyTest
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.apply();
|
||||
|
||||
// remove
|
||||
|
|
@ -46,9 +46,9 @@ public class RemoveColumnFamilyTest
|
|||
rm.delete(new QueryPath("Standard1"), 1);
|
||||
rm.apply();
|
||||
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Standard1", null, "Column1")));
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Standard1", null, "Column1".getBytes())));
|
||||
assert retrieved.isMarkedForDelete();
|
||||
assertNull(retrieved.getColumn("Column1"));
|
||||
assertNull(retrieved.getColumn("Column1".getBytes()));
|
||||
assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
|
@ -38,8 +38,8 @@ public class RemoveColumnFamilyWithFlush1Test
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column2"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column2".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ public class RemoveColumnFamilyWithFlush1Test
|
|||
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Standard1")));
|
||||
assert retrieved.isMarkedForDelete();
|
||||
assertNull(retrieved.getColumn("Column1"));
|
||||
assertNull(retrieved.getColumn("Column1".getBytes()));
|
||||
assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ public class RemoveColumnFamilyWithFlush2Test
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.apply();
|
||||
// remove
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
|
|
@ -46,9 +46,9 @@ public class RemoveColumnFamilyWithFlush2Test
|
|||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Standard1", null, "Column1")));
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Standard1", null, "Column1".getBytes())));
|
||||
assert retrieved.isMarkedForDelete();
|
||||
assertNull(retrieved.getColumn("Column1"));
|
||||
assertNull(retrieved.getColumn("Column1".getBytes()));
|
||||
assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
|
@ -39,17 +39,17 @@ public class RemoveColumnTest
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Standard1", null, "Column1"), "asdf".getBytes(), 0);
|
||||
rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), 0);
|
||||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
// remove
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.delete(new QueryPath("Standard1", null, "Column1"), 1);
|
||||
rm.delete(new QueryPath("Standard1", null, "Column1".getBytes()), 1);
|
||||
rm.apply();
|
||||
|
||||
ColumnFamily retrieved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Standard1"), "Column1"));
|
||||
assert retrieved.getColumn("Column1").isMarkedForDelete();
|
||||
ColumnFamily retrieved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Standard1"), "Column1".getBytes()));
|
||||
assert retrieved.getColumn("Column1".getBytes()).isMarkedForDelete();
|
||||
assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
|
||||
assertNull(ColumnFamilyStore.removeDeleted(store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Standard1"))), Integer.MAX_VALUE));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import org.junit.Test;
|
|||
import static junit.framework.Assert.assertNull;
|
||||
import org.apache.cassandra.db.filter.IdentityQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import static org.apache.cassandra.Util.addMutation;
|
||||
import static org.apache.cassandra.Util.getBytes;
|
||||
|
||||
public class RemoveSubColumnTest
|
||||
{
|
||||
|
|
@ -38,17 +40,17 @@ public class RemoveSubColumnTest
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Super1", "SC1", "Column1"), "asdf".getBytes(), 0);
|
||||
addMutation(rm, "Super1", "SC1", 1, "asdf", 0);
|
||||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
// remove
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.delete(new QueryPath("Super1", "SC1", "Column1"), 1);
|
||||
rm.delete(new QueryPath("Super1", "SC1".getBytes(), getBytes(1)), 1);
|
||||
rm.apply();
|
||||
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Super1", "SC1")));
|
||||
assert retrieved.getColumn("SC1").getSubColumn("Column1").isMarkedForDelete();
|
||||
ColumnFamily retrieved = store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Super1", "SC1".getBytes())));
|
||||
assert retrieved.getColumn("SC1".getBytes()).getSubColumn(getBytes(1)).isMarkedForDelete();
|
||||
assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
|
@ -21,10 +21,7 @@ package org.apache.cassandra.db;
|
|||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
|
@ -33,6 +30,8 @@ import static org.junit.Assert.assertEquals;
|
|||
import org.apache.cassandra.db.filter.IdentityQueryFilter;
|
||||
import org.apache.cassandra.db.filter.NamesQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import static org.apache.cassandra.Util.addMutation;
|
||||
import static org.apache.cassandra.Util.getBytes;
|
||||
|
||||
public class RemoveSuperColumnTest
|
||||
{
|
||||
|
|
@ -44,13 +43,13 @@ public class RemoveSuperColumnTest
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Super1", "SC1", "Column1"), "asdf".getBytes(), 0);
|
||||
addMutation(rm, "Super1", "SC1", 1, "val1", 0);
|
||||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
// remove
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.delete(new QueryPath("Super1", "SC1"), 1);
|
||||
rm.delete(new QueryPath("Super1", "SC1".getBytes()), 1);
|
||||
rm.apply();
|
||||
|
||||
validateRemoveTwoSources();
|
||||
|
|
@ -67,9 +66,9 @@ public class RemoveSuperColumnTest
|
|||
private void validateRemoveTwoSources() throws IOException
|
||||
{
|
||||
ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super1");
|
||||
ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Super1"), "SC1"));
|
||||
assert resolved.getAllColumns().first().getMarkedForDeleteAt() == 1;
|
||||
assert resolved.getAllColumns().first().getSubColumns().size() == 0;
|
||||
ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Super1"), "SC1".getBytes()));
|
||||
assert resolved.getSortedColumns().iterator().next().getMarkedForDeleteAt() == 1;
|
||||
assert resolved.getSortedColumns().iterator().next().getSubColumns().size() == 0;
|
||||
assertNull(ColumnFamilyStore.removeDeleted(resolved, Integer.MAX_VALUE));
|
||||
assertNull(ColumnFamilyStore.removeDeleted(store.getColumnFamily(new IdentityQueryFilter("key1", new QueryPath("Super1"))), Integer.MAX_VALUE));
|
||||
}
|
||||
|
|
@ -77,9 +76,9 @@ public class RemoveSuperColumnTest
|
|||
private void validateRemoveCompacted() throws IOException
|
||||
{
|
||||
ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super1");
|
||||
ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Super1"), "SC1"));
|
||||
assert resolved.getAllColumns().first().getMarkedForDeleteAt() == 1;
|
||||
Collection<IColumn> subColumns = resolved.getAllColumns().first().getSubColumns();
|
||||
ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Super1"), "SC1".getBytes()));
|
||||
assert resolved.getSortedColumns().iterator().next().getMarkedForDeleteAt() == 1;
|
||||
Collection<IColumn> subColumns = resolved.getSortedColumns().iterator().next().getSubColumns();
|
||||
assert subColumns.size() == 0;
|
||||
}
|
||||
|
||||
|
|
@ -91,18 +90,18 @@ public class RemoveSuperColumnTest
|
|||
|
||||
// add data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Super2", "SC1", "Column1"), "asdf".getBytes(), 0);
|
||||
addMutation(rm, "Super2", "SC1", 1, "val1", 0);
|
||||
rm.apply();
|
||||
store.forceBlockingFlush();
|
||||
|
||||
// remove
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.delete(new QueryPath("Super2", "SC1"), 1);
|
||||
rm.delete(new QueryPath("Super2", "SC1".getBytes()), 1);
|
||||
rm.apply();
|
||||
|
||||
// new data
|
||||
rm = new RowMutation("Table1", "key1");
|
||||
rm.add(new QueryPath("Super2", "SC1", "Column2"), "asdf".getBytes(), 2);
|
||||
addMutation(rm, "Super2", "SC1", 2, "val2", 2);
|
||||
rm.apply();
|
||||
|
||||
validateRemoveWithNewData();
|
||||
|
|
@ -119,14 +118,10 @@ public class RemoveSuperColumnTest
|
|||
private void validateRemoveWithNewData() throws IOException
|
||||
{
|
||||
ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super2");
|
||||
ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Super2", "SC1"), "Column2"));
|
||||
validateNewDataFamily(resolved);
|
||||
}
|
||||
|
||||
private void validateNewDataFamily(ColumnFamily resolved)
|
||||
{
|
||||
Collection<IColumn> subColumns = resolved.getAllColumns().first().getSubColumns();
|
||||
ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter("key1", new QueryPath("Super2", "SC1".getBytes()), getBytes(2)));
|
||||
Collection<IColumn> subColumns = resolved.getSortedColumns().iterator().next().getSubColumns();
|
||||
assert subColumns.size() == 1;
|
||||
assert subColumns.iterator().next().timestamp() == 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,17 +38,17 @@ public class RowTest
|
|||
cf2.delete(0, 0);
|
||||
|
||||
ColumnFamily cfDiff = cf1.diff(cf2);
|
||||
assertEquals(cfDiff.getColumns().size(), 0);
|
||||
assertEquals(cfDiff.getColumnsMap().size(), 0);
|
||||
assertEquals(cfDiff.getMarkedForDeleteAt(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiffSuperColumn()
|
||||
{
|
||||
SuperColumn sc1 = new SuperColumn("one");
|
||||
SuperColumn sc1 = new SuperColumn("one".getBytes());
|
||||
sc1.addColumn(column("subcolumn", "A", 0));
|
||||
|
||||
SuperColumn sc2 = new SuperColumn("one");
|
||||
SuperColumn sc2 = new SuperColumn("one".getBytes());
|
||||
sc2.markForDeleteAt(0, 0);
|
||||
|
||||
SuperColumn scDiff = (SuperColumn)sc1.diff(sc2);
|
||||
|
|
@ -68,15 +68,15 @@ public class RowTest
|
|||
ColumnFamily cf2 = ColumnFamily.create("Table1", "Standard1");
|
||||
cf2.addColumn(column("one", "B", 1));
|
||||
cf2.addColumn(column("two", "C", 1));
|
||||
ColumnFamily cf3 = ColumnFamily.create("Table2", "Standard2");
|
||||
ColumnFamily cf3 = ColumnFamily.create("Table2", "Standard3");
|
||||
cf3.addColumn(column("three", "D", 1));
|
||||
row2.addColumnFamily(cf2);
|
||||
row2.addColumnFamily(cf3);
|
||||
|
||||
row1.repair(row2);
|
||||
cf1 = row1.getColumnFamily("Standard1");
|
||||
assert Arrays.equals(cf1.getColumn("one").value(), "B".getBytes());
|
||||
assert Arrays.equals(cf2.getColumn("two").value(), "C".getBytes());
|
||||
assert row1.getColumnFamily("Standard2") != null;
|
||||
assert Arrays.equals(cf1.getColumn("one".getBytes()).value(), "B".getBytes());
|
||||
assert Arrays.equals(cf2.getColumn("two".getBytes()).value(), "C".getBytes());
|
||||
assert row1.getColumnFamily("Standard3") != null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,14 +23,15 @@ import org.junit.Test;
|
|||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.apache.cassandra.Util.column;
|
||||
import static org.apache.cassandra.Util.getBytes;
|
||||
|
||||
public class SuperColumnTest
|
||||
{
|
||||
@Test
|
||||
public void testMissingSubcolumn() {
|
||||
SuperColumn sc = new SuperColumn("sc1");
|
||||
sc.addColumn(column("col1","sample value",1L));
|
||||
assertNotNull(sc.getSubColumn("col1"));
|
||||
assertNull(sc.getSubColumn("col2"));
|
||||
SuperColumn sc = new SuperColumn("sc1".getBytes());
|
||||
sc.addColumn(new Column(getBytes(1), "value".getBytes(), 1));
|
||||
assertNotNull(sc.getSubColumn(getBytes(1)));
|
||||
assertNull(sc.getSubColumn(getBytes(2)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,13 @@ import java.util.*;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import static org.apache.cassandra.Util.column;
|
||||
import static org.apache.cassandra.Util.getBytes;
|
||||
import org.apache.cassandra.db.filter.NamesQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.io.SSTableReader;
|
||||
|
|
@ -76,10 +78,10 @@ public class TableTest extends CleanupHelper
|
|||
{
|
||||
ColumnFamily cf;
|
||||
|
||||
cf = cfStore.getColumnFamily(new NamesQueryFilter(TEST_KEY, new QueryPath("Standard1"), "col1"));
|
||||
cf = cfStore.getColumnFamily(new NamesQueryFilter(TEST_KEY, new QueryPath("Standard1"), "col1".getBytes()));
|
||||
assertColumns(cf, "col1");
|
||||
|
||||
cf = cfStore.getColumnFamily(new NamesQueryFilter(TEST_KEY, new QueryPath("Standard1"), "col3"));
|
||||
cf = cfStore.getColumnFamily(new NamesQueryFilter(TEST_KEY, new QueryPath("Standard1"), "col3".getBytes()));
|
||||
assertColumns(cf, "col3");
|
||||
}
|
||||
};
|
||||
|
|
@ -101,16 +103,16 @@ public class TableTest extends CleanupHelper
|
|||
rm.add(cf);
|
||||
rm.apply();
|
||||
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "b", "c", true, 100);
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "b".getBytes(), "c".getBytes(), true, 100);
|
||||
assertEquals(2, cf.getColumnCount());
|
||||
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "b", "b", true, 100);
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "b".getBytes(), "b".getBytes(), true, 100);
|
||||
assertEquals(1, cf.getColumnCount());
|
||||
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "b", "c", true, 1);
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "b".getBytes(), "c".getBytes(), true, 1);
|
||||
assertEquals(1, cf.getColumnCount());
|
||||
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "c", "b", true, 1);
|
||||
cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), "c".getBytes(), "b".getBytes(), true, 1);
|
||||
assertNull(cf);
|
||||
}
|
||||
|
||||
|
|
@ -151,11 +153,11 @@ public class TableTest extends CleanupHelper
|
|||
ColumnFamily cf;
|
||||
|
||||
// key before the rows that exists
|
||||
cf = cfStore.getColumnFamily("a", new QueryPath("Standard2"), "", "", true, 1);
|
||||
cf = cfStore.getColumnFamily("a", new QueryPath("Standard2"), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 1);
|
||||
assertColumns(cf);
|
||||
|
||||
// key after the rows that exist
|
||||
cf = cfStore.getColumnFamily("z", new QueryPath("Standard2"), "", "", true, 1);
|
||||
cf = cfStore.getColumnFamily("z", new QueryPath("Standard2"), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 1);
|
||||
assertColumns(cf);
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +184,7 @@ public class TableTest extends CleanupHelper
|
|||
rm.apply();
|
||||
|
||||
rm = new RowMutation("Table1", ROW);
|
||||
rm.delete(new QueryPath("Standard1", null, "col4"), 2L);
|
||||
rm.delete(new QueryPath("Standard1", null, "col4".getBytes()), 2L);
|
||||
rm.apply();
|
||||
}
|
||||
};
|
||||
|
|
@ -194,23 +196,23 @@ public class TableTest extends CleanupHelper
|
|||
Row result;
|
||||
ColumnFamily cf;
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col5", "", true, 2);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col5".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
|
||||
assertColumns(cf, "col5", "col7");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col4", "", true, 2);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col4".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
|
||||
assertColumns(cf, "col4", "col5", "col7");
|
||||
assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col5", "col7");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col5", "", false, 2);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col5".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 2);
|
||||
assertColumns(cf, "col3", "col4", "col5");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col6", "", false, 2);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col6".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 2);
|
||||
assertColumns(cf, "col3", "col4", "col5");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col95", "", true, 2);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col95".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
|
||||
assertColumns(cf);
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col0", "", false, 2);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col0".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 2);
|
||||
assertColumns(cf);
|
||||
}
|
||||
};
|
||||
|
|
@ -257,11 +259,11 @@ public class TableTest extends CleanupHelper
|
|||
{
|
||||
ColumnFamily cf;
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col2", "", true, 3);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col2".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 3);
|
||||
assertColumns(cf, "col2", "col3", "col4");
|
||||
assertEquals(new String(cf.getColumn("col2").value()), "valx");
|
||||
assertEquals(new String(cf.getColumn("col3").value()), "valx");
|
||||
assertEquals(new String(cf.getColumn("col4").value()), "val4");
|
||||
assertEquals(new String(cf.getColumn("col2".getBytes()).value()), "valx");
|
||||
assertEquals(new String(cf.getColumn("col3".getBytes()).value()), "valx");
|
||||
assertEquals(new String(cf.getColumn("col4".getBytes()).value()), "val4");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -283,29 +285,29 @@ public class TableTest extends CleanupHelper
|
|||
rm.apply();
|
||||
cfStore.forceBlockingFlush();
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1000", "", true, 3);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1000".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 3);
|
||||
assertColumns(cf, "col1000", "col1001", "col1002");
|
||||
assertEquals(new String(cf.getColumn("col1000").value()), "vvvvvvvvvvvvvvvv1000");
|
||||
assertEquals(new String(cf.getColumn("col1001").value()), "vvvvvvvvvvvvvvvv1001");
|
||||
assertEquals(new String(cf.getColumn("col1002").value()), "vvvvvvvvvvvvvvvv1002");
|
||||
assertEquals(new String(cf.getColumn("col1000".getBytes()).value()), "vvvvvvvvvvvvvvvv1000");
|
||||
assertEquals(new String(cf.getColumn("col1001".getBytes()).value()), "vvvvvvvvvvvvvvvv1001");
|
||||
assertEquals(new String(cf.getColumn("col1002".getBytes()).value()), "vvvvvvvvvvvvvvvv1002");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1195", "", true, 3);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1195".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 3);
|
||||
assertColumns(cf, "col1195", "col1196", "col1197");
|
||||
assertEquals(new String(cf.getColumn("col1195").value()), "vvvvvvvvvvvvvvvv1195");
|
||||
assertEquals(new String(cf.getColumn("col1196").value()), "vvvvvvvvvvvvvvvv1196");
|
||||
assertEquals(new String(cf.getColumn("col1197").value()), "vvvvvvvvvvvvvvvv1197");
|
||||
assertEquals(new String(cf.getColumn("col1195".getBytes()).value()), "vvvvvvvvvvvvvvvv1195");
|
||||
assertEquals(new String(cf.getColumn("col1196".getBytes()).value()), "vvvvvvvvvvvvvvvv1196");
|
||||
assertEquals(new String(cf.getColumn("col1197".getBytes()).value()), "vvvvvvvvvvvvvvvv1197");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1196", "", false, 3);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1196".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 3);
|
||||
assertColumns(cf, "col1194", "col1195", "col1196");
|
||||
assertEquals(new String(cf.getColumn("col1194").value()), "vvvvvvvvvvvvvvvv1194");
|
||||
assertEquals(new String(cf.getColumn("col1195").value()), "vvvvvvvvvvvvvvvv1195");
|
||||
assertEquals(new String(cf.getColumn("col1196").value()), "vvvvvvvvvvvvvvvv1196");
|
||||
assertEquals(new String(cf.getColumn("col1194".getBytes()).value()), "vvvvvvvvvvvvvvvv1194");
|
||||
assertEquals(new String(cf.getColumn("col1195".getBytes()).value()), "vvvvvvvvvvvvvvvv1195");
|
||||
assertEquals(new String(cf.getColumn("col1196".getBytes()).value()), "vvvvvvvvvvvvvvvv1196");
|
||||
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1990", "", true, 3);
|
||||
cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col1990".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 3);
|
||||
assertColumns(cf, "col1990", "col1991", "col1992");
|
||||
assertEquals(new String(cf.getColumn("col1990").value()), "vvvvvvvvvvvvvvvv1990");
|
||||
assertEquals(new String(cf.getColumn("col1991").value()), "vvvvvvvvvvvvvvvv1991");
|
||||
assertEquals(new String(cf.getColumn("col1992").value()), "vvvvvvvvvvvvvvvv1992");
|
||||
assertEquals(new String(cf.getColumn("col1990".getBytes()).value()), "vvvvvvvvvvvvvvvv1990");
|
||||
assertEquals(new String(cf.getColumn("col1991".getBytes()).value()), "vvvvvvvvvvvvvvvv1991");
|
||||
assertEquals(new String(cf.getColumn("col1992".getBytes()).value()), "vvvvvvvvvvvvvvvv1992");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -321,8 +323,8 @@ public class TableTest extends CleanupHelper
|
|||
{
|
||||
RowMutation rm = new RowMutation("Table1", ROW);
|
||||
ColumnFamily cf = ColumnFamily.create("Table1", "Super1");
|
||||
SuperColumn sc = new SuperColumn("sc1");
|
||||
sc.addColumn(column("col1", "val1", 1L));
|
||||
SuperColumn sc = new SuperColumn("sc1".getBytes());
|
||||
sc.addColumn(new Column(getBytes(1), "val1".getBytes(), 1L));
|
||||
cf.addColumn(sc);
|
||||
rm.add(cf);
|
||||
rm.apply();
|
||||
|
|
@ -333,24 +335,25 @@ public class TableTest extends CleanupHelper
|
|||
{
|
||||
public void run() throws Exception
|
||||
{
|
||||
ColumnFamily cf = cfStore.getColumnFamily(ROW, new QueryPath("Super1"), "", "", true, 10);
|
||||
ColumnFamily cf = cfStore.getColumnFamily(ROW, new QueryPath("Super1"), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 10);
|
||||
assertColumns(cf, "sc1");
|
||||
assertEquals(new String(cf.getColumn("sc1").getSubColumn("col1").value()), "val1");
|
||||
assertEquals(new String(cf.getColumn("sc1".getBytes()).getSubColumn(getBytes(1)).value()), "val1");
|
||||
}
|
||||
};
|
||||
|
||||
reTest(setup, table.getColumnFamilyStore("Standard1"), verify);
|
||||
}
|
||||
|
||||
public static void assertColumns(ColumnFamily columnFamily, String... columnNames)
|
||||
public static void assertColumns(ColumnFamily cf, String... columnNames)
|
||||
{
|
||||
SortedSet<IColumn> columns = columnFamily == null ? new TreeSet<IColumn>() : columnFamily.getAllColumns();
|
||||
Collection<IColumn> columns = cf == null ? new TreeSet<IColumn>() : cf.getSortedColumns();
|
||||
List<String> L = new ArrayList<String>();
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
L.add(column.name());
|
||||
L.add(new String(column.name()));
|
||||
}
|
||||
assert Arrays.equals(L.toArray(new String[columns.size()]), columnNames)
|
||||
: "Columns [" + StringUtils.join(columns, ", ") + "] is not expected [" + StringUtils.join(columnNames, ", ") + "]";
|
||||
: "Columns [" + ((cf == null) ? "" : cf.getComparator().getColumnsString(columns)) + "]"
|
||||
+ " is not expected [" + StringUtils.join(columnNames, ",") + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class AsciiTypeTest
|
||||
{
|
||||
@Test
|
||||
public void testCompare()
|
||||
{
|
||||
AsciiType comparator = new AsciiType();
|
||||
assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, "asdf".getBytes()) < 0;
|
||||
assert comparator.compare("z".getBytes(), "a".getBytes()) > 0;
|
||||
assert comparator.compare("asdf".getBytes(), "asdf".getBytes()) == 0;
|
||||
assert comparator.compare("asdz".getBytes(), "asdf".getBytes()) > 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue