Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change column_t value to binary from string. patch by johano; reviewe…

…d by jbellis for #29
  • Loading branch information...
commit b9b8ebcc5793469f7d527648b2ab4655a3cd1aac 1 parent c646fcf
Jonathan Ellis authored
View
4 interface/cassandra.thrift
@@ -11,7 +11,7 @@ php_namespace cassandra
struct column_t {
1: string columnName,
- 2: string value,
+ 2: binary value,
3: i64 timestamp,
}
@@ -57,7 +57,7 @@ service Cassandra {
list<column_t> get_slice_by_names(string tablename,string key,string columnFamily, list<string> columnNames) throws (1:CassandraException e),
column_t get_column(string tablename,string key,string columnFamily_column) throws (1:CassandraException e),
i32 get_column_count(string tablename,string key,string columnFamily_column) throws (1:CassandraException e),
- async void insert(string tablename,string key,string columnFamily_column, string cellData,i64 timestamp),
+ async void insert(string tablename,string key,string columnFamily_column, binary cellData,i64 timestamp),
async void batch_insert(batch_mutation_t batchMutation),
bool batch_insert_blocking(batch_mutation_t batchMutation) throws (1:CassandraException e),
bool remove(string tablename,string key,string columnFamily_column, i64 timestamp, bool block),
View
2  src/org/apache/cassandra/cli/CliClient.java
@@ -207,7 +207,7 @@ private void executeSet(CommonTree ast) throws TException
// do the insert
thriftClient_.insert(tableName, key, columnFamily + ":" + columnName,
- value, System.currentTimeMillis());
+ value.getBytes(), System.currentTimeMillis());
css_.out.println("Value inserted.");
}
View
4 src/org/apache/cassandra/db/RowMutation.java
@@ -286,7 +286,7 @@ public static RowMutation getRowMutation(batch_mutation_t batchMutation)
for (column_t columnData : list)
{
rm.add(cfname + ":" + columnData.columnName,
- columnData.value.getBytes(), columnData.timestamp);
+ columnData.value, columnData.timestamp);
}
}
@@ -310,7 +310,7 @@ public static RowMutation getRowMutation(batch_mutation_super_t batchMutationSup
for (column_t columnData : superColumnData.columns)
{
rm.add(key.toString() + ":" + superColumnData.name + ":" + columnData.columnName,
- columnData.value.getBytes(), columnData.timestamp);
+ columnData.value, columnData.timestamp);
}
}
else
View
36 src/org/apache/cassandra/service/Cassandra.java
@@ -30,7 +30,7 @@
public int get_column_count(String tablename, String key, String columnFamily_column) throws CassandraException, TException;
- public void insert(String tablename, String key, String columnFamily_column, String cellData, long timestamp) throws TException;
+ public void insert(String tablename, String key, String columnFamily_column, byte[] cellData, long timestamp) throws TException;
public void batch_insert(batch_mutation_t batchMutation) throws TException;
@@ -244,12 +244,12 @@ public int recv_get_column_count() throws CassandraException, TException
throw new TApplicationException(TApplicationException.MISSING_RESULT, "get_column_count failed: unknown result");
}
- public void insert(String tablename, String key, String columnFamily_column, String cellData, long timestamp) throws TException
+ public void insert(String tablename, String key, String columnFamily_column, byte[] cellData, long timestamp) throws TException
{
send_insert(tablename, key, columnFamily_column, cellData, timestamp);
}
- public void send_insert(String tablename, String key, String columnFamily_column, String cellData, long timestamp) throws TException
+ public void send_insert(String tablename, String key, String columnFamily_column, byte[] cellData, long timestamp) throws TException
{
oprot_.writeMessageBegin(new TMessage("insert", TMessageType.CALL, seqid_));
insert_args args = new insert_args();
@@ -3858,7 +3858,7 @@ public void validate() throws TException {
public static final int KEY = -2;
public String columnFamily_column;
public static final int COLUMNFAMILY_COLUMN = -3;
- public String cellData;
+ public byte[] cellData;
public static final int CELLDATA = -4;
public long timestamp;
public static final int TIMESTAMP = -5;
@@ -3896,7 +3896,7 @@ public insert_args(
String tablename,
String key,
String columnFamily_column,
- String cellData,
+ byte[] cellData,
long timestamp)
{
this();
@@ -3930,7 +3930,8 @@ public insert_args(insert_args other) {
}
__isset.cellData = other.__isset.cellData;
if (other.cellData != null) {
- this.cellData = other.cellData;
+ this.cellData = new byte[other.cellData.length];
+ System.arraycopy(other.cellData, 0, cellData, 0, other.cellData.length);
}
__isset.timestamp = other.__isset.timestamp;
this.timestamp = other.timestamp;
@@ -4007,11 +4008,11 @@ public void setColumnFamily_columnIsSet(boolean value) {
this.__isset.columnFamily_column = value;
}
- public String getCellData() {
+ public byte[] getCellData() {
return this.cellData;
}
- public void setCellData(String cellData) {
+ public void setCellData(byte[] cellData) {
this.cellData = cellData;
this.__isset.cellData = (cellData != null);
}
@@ -4066,7 +4067,7 @@ public void setFieldValue(int fieldID, Object value) {
break;
case CELLDATA:
- setCellData((String)value);
+ setCellData((byte[])value);
break;
case TIMESTAMP:
@@ -4163,7 +4164,7 @@ public boolean equals(insert_args that) {
if (this_present_cellData || that_present_cellData) {
if (!(this_present_cellData && that_present_cellData))
return false;
- if (!this.cellData.equals(that.cellData))
+ if (!java.util.Arrays.equals(this.cellData, that.cellData))
return false;
}
@@ -4221,7 +4222,7 @@ public void read(TProtocol iprot) throws TException {
break;
case CELLDATA:
if (field.type == TType.STRING) {
- this.cellData = iprot.readString();
+ this.cellData = iprot.readBinary();
this.__isset.cellData = true;
} else {
TProtocolUtil.skip(iprot, field.type);
@@ -4269,7 +4270,7 @@ public void write(TProtocol oprot) throws TException {
}
if (this.cellData != null) {
oprot.writeFieldBegin(CELL_DATA_FIELD_DESC);
- oprot.writeString(this.cellData);
+ oprot.writeBinary(this.cellData);
oprot.writeFieldEnd();
}
oprot.writeFieldBegin(TIMESTAMP_FIELD_DESC);
@@ -4298,7 +4299,16 @@ public String toString() {
first = false;
if (!first) sb.append(", ");
sb.append("cellData:");
- sb.append(this.cellData);
+ if (cellData == null) {
+ sb.append("null");
+ } else {
+ int __cellData_size = Math.min(this.cellData.length, 128);
+ for (int i = 0; i < __cellData_size; i++) {
+ if (i != 0) sb.append(" ");
+ sb.append(Integer.toHexString(this.cellData[i]).length() > 1 ? Integer.toHexString(this.cellData[i]).substring(Integer.toHexString(this.cellData[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.cellData[i]).toUpperCase());
+ }
+ if (this.cellData.length > 128) sb.append(" ...");
+ }
first = false;
if (!first) sb.append(", ");
sb.append("timestamp:");
View
8 src/org/apache/cassandra/service/CassandraServer.java
@@ -129,7 +129,7 @@ protected ColumnFamily get_cf(String tablename, String key, String columnFamily,
{
continue;
}
- column_t thrift_column = new column_t(column.name(), new String(column.value()), column.timestamp());
+ column_t thrift_column = new column_t(column.name(), column.value(), column.timestamp());
thriftColumns.add(thrift_column);
}
return thriftColumns;
@@ -360,7 +360,7 @@ public column_t get_column(String tablename, String key, String columnFamily_col
{
return null;
}
- return new column_t(column.name(), new String(column.value()), column.timestamp());
+ return new column_t(column.name(), column.value(), column.timestamp());
}
catch (Exception ex)
{
@@ -436,13 +436,13 @@ public int get_column_count(String tablename, String key, String columnFamily_co
return count;
}
- public void insert(String tablename, String key, String columnFamily_column, String cellData, long timestamp)
+ public void insert(String tablename, String key, String columnFamily_column, byte[] cellData, long timestamp)
{
try
{
validateTable(tablename);
RowMutation rm = new RowMutation(tablename, key.trim());
- rm.add(columnFamily_column, cellData.getBytes(), timestamp);
+ rm.add(columnFamily_column, cellData, timestamp);
StorageProxy.insert(rm);
}
catch (Exception e)
View
30 src/org/apache/cassandra/service/column_t.java
@@ -26,7 +26,7 @@
public String columnName;
public static final int COLUMNNAME = 1;
- public String value;
+ public byte[] value;
public static final int VALUE = 2;
public long timestamp;
public static final int TIMESTAMP = 3;
@@ -56,7 +56,7 @@ public column_t() {
public column_t(
String columnName,
- String value,
+ byte[] value,
long timestamp)
{
this();
@@ -78,7 +78,8 @@ public column_t(column_t other) {
}
__isset.value = other.__isset.value;
if (other.value != null) {
- this.value = other.value;
+ this.value = new byte[other.value.length];
+ System.arraycopy(other.value, 0, value, 0, other.value.length);
}
__isset.timestamp = other.__isset.timestamp;
this.timestamp = other.timestamp;
@@ -111,11 +112,11 @@ public void setColumnNameIsSet(boolean value) {
this.__isset.columnName = value;
}
- public String getValue() {
+ public byte[] getValue() {
return this.value;
}
- public void setValue(String value) {
+ public void setValue(byte[] value) {
this.value = value;
this.__isset.value = (value != null);
}
@@ -162,7 +163,7 @@ public void setFieldValue(int fieldID, Object value) {
break;
case VALUE:
- setValue((String)value);
+ setValue((byte[])value);
break;
case TIMESTAMP:
@@ -231,7 +232,7 @@ public boolean equals(column_t that) {
if (this_present_value || that_present_value) {
if (!(this_present_value && that_present_value))
return false;
- if (!this.value.equals(that.value))
+ if (!java.util.Arrays.equals(this.value, that.value))
return false;
}
@@ -273,7 +274,7 @@ public void read(TProtocol iprot) throws TException {
break;
case VALUE:
if (field.type == TType.STRING) {
- this.value = iprot.readString();
+ this.value = iprot.readBinary();
this.__isset.value = true;
} else {
TProtocolUtil.skip(iprot, field.type);
@@ -311,7 +312,7 @@ public void write(TProtocol oprot) throws TException {
}
if (this.value != null) {
oprot.writeFieldBegin(VALUE_FIELD_DESC);
- oprot.writeString(this.value);
+ oprot.writeBinary(this.value);
oprot.writeFieldEnd();
}
oprot.writeFieldBegin(TIMESTAMP_FIELD_DESC);
@@ -332,7 +333,16 @@ public String toString() {
first = false;
if (!first) sb.append(", ");
sb.append("value:");
- sb.append(this.value);
+ if (value == null) {
+ sb.append("null");
+ } else {
+ int __value_size = Math.min(this.value.length, 128);
+ for (int i = 0; i < __value_size; i++) {
+ if (i != 0) sb.append(" ");
+ sb.append(Integer.toHexString(this.value[i]).length() > 1 ? Integer.toHexString(this.value[i]).substring(Integer.toHexString(this.value[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.value[i]).toUpperCase());
+ }
+ if (this.value.length > 128) sb.append(" ...");
+ }
first = false;
if (!first) sb.append(", ");
sb.append("timestamp:");
View
10 src/org/apache/cassandra/test/DataImporter.java
@@ -131,7 +131,7 @@ public void test(String line) throws IOException {
try {
long t = System.currentTimeMillis();
peerstorageClient_.insert(tablename_, rowKey, columnFamily_ + ":"
- + column, columnValue, ts);
+ + column, columnValue.getBytes(), ts);
logger_.debug("Time taken for thrift..."
+ (System.currentTimeMillis() - t));
} catch (Exception e) {
@@ -304,7 +304,7 @@ public void testBatchRunner(String filepath) throws IOException {
}
column_t columnData = new column_t();
columnData.columnName = threadId;
- columnData.value = String.valueOf(isDeleted);
+ columnData.value = String.valueOf(isDeleted).getBytes();
columnData.timestamp = lastUpdated;
// List <MboxStruct> list = userthreadmap.get(rs.getString(1));
if (folder == 0) {
@@ -405,7 +405,7 @@ public void testMailboxBatchRunner(String filepath) throws IOException {
}
column_t columnData = new column_t();
columnData.columnName = threadId;
- columnData.value = String.valueOf(isDeleted);
+ columnData.value = String.valueOf(isDeleted).getBytes();
columnData.timestamp = lastUpdated;
List<column_t> list = rmInbox.cfmap.get("MailboxMailList"+(columnFamilyHack_%divideby_));
if (list == null) {
@@ -515,7 +515,7 @@ public void testSuperBatchRunner(String filepath) throws IOException {
}
column_t columnData = new column_t();
columnData.columnName = threadId;
- columnData.value = String.valueOf(isDeleted);
+ columnData.value = String.valueOf(isDeleted).getBytes();
columnData.timestamp = lastUpdated;
// List <MboxStruct> list = userthreadmap.get(rs.getString(1));
if (folder == 0) {
@@ -697,7 +697,7 @@ public void testSuperUserBatchRunner(String filepath) throws IOException {
}
column_t columnData = new column_t();
columnData.columnName = threadId;
- columnData.value = String.valueOf(isDeleted);
+ columnData.value = String.valueOf(isDeleted).getBytes();
columnData.timestamp = lastUpdated;
// List <MboxStruct> list = userthreadmap.get(rs.getString(1));
if (folder == 0) {
View
14 src/org/apache/cassandra/test/StressTest.java
@@ -433,11 +433,11 @@ public void applyThrift(String table, String key, String columnFamily, byte[] by
Thread.sleep(0, 1000000000/requestsPerSecond_);
else
Thread.sleep(1000/requestsPerSecond_);
- peerstorageClient_.insert(table, key, columnFamily, new String(bytes), ts);
+ peerstorageClient_.insert(table, key, columnFamily, bytes, ts);
} catch (Exception e) {
try {
peerstorageClient_ = connect();
- peerstorageClient_.insert(table, key, columnFamily, new String(bytes), ts);
+ peerstorageClient_.insert(table, key, columnFamily, bytes, ts);
} catch (Exception e1) {
e1.printStackTrace();
}
@@ -622,7 +622,7 @@ public void bulkWriteColumnThrift(int keys, int columns, int size, int tps)
for( int j = 1; j <= columns ; j++)
{
random.nextBytes(bytes);
- column_arr.add(new column_t(columnFix_ + j, bytes.toString(), ts));
+ column_arr.add(new column_t(columnFix_ + j, bytes, ts));
}
bt.cfmap.put(columnFamilyColumn_, column_arr);
apply(bt);
@@ -659,7 +659,7 @@ public void bulkWriteSuperColumnThrift(int keys, int supercolumns, int columns,
for( int j = 1; j <= columns ; j++)
{
random.nextBytes(bytes);
- column_arr.add(new column_t(columnFix_ + j, bytes.toString(), ts));
+ column_arr.add(new column_t(columnFix_ + j, bytes, ts));
}
superColumn_arr.add(new superColumn_t(superColumnFix_ + i, column_arr));
}
@@ -688,9 +688,9 @@ public void testCommitLog() throws Throwable
int key = random.nextInt();
int threadId = random.nextInt();
int word = random.nextInt();
- peerstorageClient_.insert("Mailbox", Integer.toString(key), "MailboxMailList0:" + Integer.toString(threadId), new String(bytes1), t++);
- peerstorageClient_.insert("Mailbox", Integer.toString(key), "MailboxThreadList0:" + Integer.toString(word) + ":" + Integer.toString(threadId), new String(bytes), t++);
- peerstorageClient_.insert("Mailbox", Integer.toString(key), "MailboxUserList0:"+ Integer.toString(word) + ":" + Integer.toString(threadId), new String(bytes), t++);
+ peerstorageClient_.insert("Mailbox", Integer.toString(key), "MailboxMailList0:" + Integer.toString(threadId), bytes1, t++);
+ peerstorageClient_.insert("Mailbox", Integer.toString(key), "MailboxThreadList0:" + Integer.toString(word) + ":" + Integer.toString(threadId), bytes, t++);
+ peerstorageClient_.insert("Mailbox", Integer.toString(key), "MailboxUserList0:"+ Integer.toString(word) + ":" + Integer.toString(threadId), bytes, t++);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.