diff --git a/CHANGES.txt b/CHANGES.txt index 7142055816..5d09e00ef1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -56,6 +56,7 @@ dev * move endpoint cache from snitch to strategy (CASSANDRA-1643) * fix commitlog recovery deleting the newly-created segment as well as the old ones (CASSANDRA-1644) + * upgrade to Thrift 0.5 (CASSANDRA-1367) 0.7-beta2 diff --git a/contrib/bmt_example/CassandraBulkLoader.java b/contrib/bmt_example/CassandraBulkLoader.java index 6628637a42..8cac8accc8 100644 --- a/contrib/bmt_example/CassandraBulkLoader.java +++ b/contrib/bmt_example/CassandraBulkLoader.java @@ -259,7 +259,7 @@ public class CassandraBulkLoader { byte[] data = new byte[bufOut.getLength()]; System.arraycopy(bufOut.getData(), 0, data, 0, bufOut.getLength()); - column = new Column(FBUtilities.toByteArray(cf.id()), data, 0); + column = new Column(FBUtilities.toByteBuffer(cf.id()), data, 0); baseColumnFamily.addColumn(column); } rm = new RowMutation(Keyspace, Key); diff --git a/lib/libthrift-0.5.jar b/lib/libthrift-0.5.jar new file mode 100644 index 0000000000..5c8cfac103 Binary files /dev/null and b/lib/libthrift-0.5.jar differ diff --git a/lib/libthrift-r959516.jar b/lib/libthrift-r959516.jar deleted file mode 100644 index dda8e88144..0000000000 Binary files a/lib/libthrift-r959516.jar and /dev/null differ diff --git a/libthrift-r959516.txt b/lib/licenses/libthrift-0.5.txt similarity index 100% rename from libthrift-r959516.txt rename to lib/licenses/libthrift-0.5.txt diff --git a/src/java/org/apache/cassandra/auth/Resources.java b/src/java/org/apache/cassandra/auth/Resources.java index 9307a4a16f..d905376db4 100644 --- a/src/java/org/apache/cassandra/auth/Resources.java +++ b/src/java/org/apache/cassandra/auth/Resources.java @@ -43,7 +43,7 @@ public final class Resources { buff.append("/"); if (component instanceof byte[]) - buff.append(FBUtilities.bytesToHex(ByteBuffer.wrap((byte[])component))); + buff.append(FBUtilities.bytesToHex((byte[])component)); else buff.append(component.toString()); } diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index 7d9cdd349f..7b57211420 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -20,58 +20,17 @@ package org.apache.cassandra.cli; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import org.antlr.runtime.tree.CommonTree; import org.antlr.runtime.tree.Tree; import org.apache.cassandra.auth.SimpleAuthenticator; import org.apache.cassandra.config.ConfigurationException; -import org.apache.cassandra.db.marshal.AbstractType; -import org.apache.cassandra.db.marshal.AsciiType; -import org.apache.cassandra.db.marshal.BytesType; -import org.apache.cassandra.db.marshal.IntegerType; -import org.apache.cassandra.db.marshal.LexicalUUIDType; -import org.apache.cassandra.db.marshal.LongType; -import org.apache.cassandra.db.marshal.TimeUUIDType; -import org.apache.cassandra.db.marshal.UTF8Type; -import org.apache.cassandra.thrift.AuthenticationException; -import org.apache.cassandra.thrift.AuthenticationRequest; -import org.apache.cassandra.thrift.AuthorizationException; -import org.apache.cassandra.thrift.Cassandra; -import org.apache.cassandra.thrift.CfDef; -import org.apache.cassandra.thrift.Column; -import org.apache.cassandra.thrift.ColumnDef; -import org.apache.cassandra.thrift.ColumnOrSuperColumn; -import org.apache.cassandra.thrift.ColumnParent; -import org.apache.cassandra.thrift.ColumnPath; -import org.apache.cassandra.thrift.ConsistencyLevel; -import org.apache.cassandra.thrift.IndexClause; -import org.apache.cassandra.thrift.IndexExpression; -import org.apache.cassandra.thrift.IndexOperator; -import org.apache.cassandra.thrift.IndexType; -import org.apache.cassandra.thrift.InvalidRequestException; -import org.apache.cassandra.thrift.KeyRange; -import org.apache.cassandra.thrift.KeySlice; -import org.apache.cassandra.thrift.KsDef; -import org.apache.cassandra.thrift.NotFoundException; -import org.apache.cassandra.thrift.SlicePredicate; -import org.apache.cassandra.thrift.SliceRange; -import org.apache.cassandra.thrift.SuperColumn; -import org.apache.cassandra.thrift.TimedOutException; -import org.apache.cassandra.thrift.UnavailableException; +import org.apache.cassandra.db.marshal.*; +import org.apache.cassandra.thrift.*; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.UUIDGen; -import org.apache.commons.lang.ArrayUtils; import org.apache.thrift.TException; // Cli Client Side Library @@ -674,7 +633,7 @@ public class CliClient Column column = cosc.column; validator = getValidatorForValue(cfDef, column.getName()); css_.out.printf("=> (column=%s, value=%s, timestamp=%d)\n", formatColumnName(keyspace, columnFamily, column), - validator.getString(column.value), column.timestamp); + validator.getString(column.value), column.timestamp); } } @@ -771,7 +730,7 @@ public class CliClient return; } - ByteBuffer columnNameInBytes = columnNameAsByteArray(columnName, columnFamily); + ByteBuffer columnNameInBytes = columnNameAsBytes(columnName, columnFamily); AbstractType validator = getValidatorForValue(columnFamilyDef, columnNameInBytes.array()); // Perform a get() @@ -848,7 +807,7 @@ public class CliClient try { ByteBuffer value; - ByteBuffer columnName = columnNameAsByteArray(columnNameString, columnFamily); + ByteBuffer columnName = columnNameAsBytes(columnNameString, columnFamily); if (valueTree.getType() == CliParser.FUNCTION_CALL) { @@ -857,7 +816,7 @@ public class CliClient else { String valueString = CliUtils.unescapeSQLString(valueTree.getText()); - value = columnValueAsByteArray(columnName, columnFamily, valueString); + value = columnValueAsBytes(columnName, columnFamily, valueString); } // index operator from string @@ -946,7 +905,7 @@ public class CliClient } - ByteBuffer columnNameInBytes = columnNameAsByteArray(columnName, columnFamily); + ByteBuffer columnNameInBytes = columnNameAsBytes(columnName, columnFamily); ByteBuffer columnValueInBytes; switch (valueTree.getType()) @@ -955,7 +914,7 @@ public class CliClient columnValueInBytes = convertValueByFunction(valueTree, getCfDef(columnFamily), columnNameInBytes, true); break; default: - columnValueInBytes = columnValueAsByteArray(columnNameInBytes, columnFamily, value); + columnValueInBytes = columnValueAsBytes(columnNameInBytes, columnFamily, value); } ColumnParent parent = new ColumnParent(columnFamily); @@ -1727,7 +1686,7 @@ public class CliClient throw new RuntimeException("'" + object + "' could not be translated into a LongType."); } - return FBUtilities.toByteArray(longType); + return FBUtilities.toByteBuffer(longType); } else if (comparator instanceof LexicalUUIDType || comparator instanceof TimeUUIDType) { @@ -1773,7 +1732,7 @@ public class CliClient * @throws IllegalAccessException - raised from getFormatTypeForColumn call * @throws UnsupportedEncodingException - raised from getBytes() calls */ - private ByteBuffer columnNameAsByteArray(String column, String columnFamily) throws NoSuchFieldException, InstantiationException, IllegalAccessException, UnsupportedEncodingException + private ByteBuffer columnNameAsBytes(String column, String columnFamily) throws NoSuchFieldException, InstantiationException, IllegalAccessException, UnsupportedEncodingException { CfDef columnFamilyDef = getCfDef(columnFamily); String comparatorClass = columnFamilyDef.comparator_type; @@ -1788,7 +1747,7 @@ public class CliClient * @param columnValue - actual column value * @return byte[] - value in byte array representation */ - private ByteBuffer columnValueAsByteArray(ByteBuffer columnName, String columnFamilyName, String columnValue) + private ByteBuffer columnValueAsBytes(ByteBuffer columnName, String columnFamilyName, String columnValue) { CfDef columnFamilyDef = getCfDef(columnFamilyName); diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 9917d06ef0..9bf6e0b0a9 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -97,14 +97,12 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.thrift.IndexClause; import org.apache.cassandra.thrift.IndexExpression; import org.apache.cassandra.thrift.IndexOperator; -import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.EstimatedHistogram; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.LatencyTracker; import org.apache.cassandra.utils.Pair; import org.apache.cassandra.utils.WrappedRunnable; import org.apache.commons.collections.IteratorUtils; -import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -329,7 +327,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean { throw new AssertionError(e); } - buildSecondaryIndexes(getSSTables(), FBUtilities.getSingleColumnSet(info.name)); + buildSecondaryIndexes(getSSTables(), FBUtilities.singleton(info.name)); logger.info("Index {} complete", indexedCfMetadata.cfName); SystemTable.setIndexBuilt(table.name, indexedCfMetadata.cfName); } @@ -1429,7 +1427,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean if (rows.size() == clause.count) break outer; } - if (n < clause.count || ByteBufferUtil.equals(startKey, dataKey)) + if (n < clause.count || startKey.equals(dataKey)) break; startKey = dataKey; } diff --git a/src/java/org/apache/cassandra/db/DeletedColumn.java b/src/java/org/apache/cassandra/db/DeletedColumn.java index 984085dbf9..5e7c7ec3f6 100644 --- a/src/java/org/apache/cassandra/db/DeletedColumn.java +++ b/src/java/org/apache/cassandra/db/DeletedColumn.java @@ -20,7 +20,6 @@ package org.apache.cassandra.db; import java.nio.ByteBuffer; -import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +30,7 @@ public class DeletedColumn extends Column public DeletedColumn(ByteBuffer name, int localDeletionTime, long timestamp) { - this(name, FBUtilities.toByteArray(localDeletionTime), timestamp); + this(name, FBUtilities.toByteBuffer(localDeletionTime), timestamp); } public DeletedColumn(ByteBuffer name, ByteBuffer value, long timestamp) diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java index 74e26d83c4..5da203a862 100644 --- a/src/java/org/apache/cassandra/db/SystemTable.java +++ b/src/java/org/apache/cassandra/db/SystemTable.java @@ -41,7 +41,7 @@ import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Token; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; -import org.apache.commons.lang.ArrayUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -284,13 +284,13 @@ public class SystemTable } else { - generation = Math.max(FBUtilities.byteArrayToInt(cf.getColumn(GENERATION).value()) + 1, + generation = Math.max(FBUtilities.byteBufferToInt(cf.getColumn(GENERATION).value()) + 1, (int) (System.currentTimeMillis() / 1000)); } RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY); cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.STATUS_CF); - cf.addColumn(new Column(GENERATION, FBUtilities.toByteArray(generation), FBUtilities.timestampMicros())); + cf.addColumn(new Column(GENERATION, FBUtilities.toByteBuffer(generation), FBUtilities.timestampMicros())); rm.add(cf); rm.apply(); forceBlockingFlush(STATUS_CF); diff --git a/src/java/org/apache/cassandra/db/Table.java b/src/java/org/apache/cassandra/db/Table.java index 68961284c7..11a896fab2 100644 --- a/src/java/org/apache/cassandra/db/Table.java +++ b/src/java/org/apache/cassandra/db/Table.java @@ -23,7 +23,6 @@ import java.io.IOError; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -50,7 +49,6 @@ import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; -import org.apache.commons.lang.ArrayUtils; import org.cliffc.high_scale_lib.NonBlockingHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -609,7 +607,7 @@ public class Table Collection columns = columnFamily.getSortedColumns(); for (IColumn column : columns) { - ColumnFamilyStore cfStore = columnFamilyStores.get(FBUtilities.byteArrayToInt(column.name())); + ColumnFamilyStore cfStore = columnFamilyStores.get(FBUtilities.byteBufferToInt(column.name())); cfStore.applyBinary(key, column.value()); } } diff --git a/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java b/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java index f54c90e38f..b9295152b0 100644 --- a/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java +++ b/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java @@ -51,7 +51,7 @@ public class NamesQueryFilter implements IFilter public NamesQueryFilter(ByteBuffer column) { - this(FBUtilities.getSingleColumnSet(column)); + this(FBUtilities.singleton(column)); } public IColumnIterator getMemtableColumnIterator(ColumnFamily cf, DecoratedKey key, AbstractType comparator) diff --git a/src/java/org/apache/cassandra/db/filter/QueryFilter.java b/src/java/org/apache/cassandra/db/filter/QueryFilter.java index 760357a14f..1a7a3fd607 100644 --- a/src/java/org/apache/cassandra/db/filter/QueryFilter.java +++ b/src/java/org/apache/cassandra/db/filter/QueryFilter.java @@ -22,7 +22,6 @@ package org.apache.cassandra.db.filter; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; import java.util.SortedSet; @@ -41,7 +40,6 @@ import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.util.FileDataInput; import org.apache.cassandra.thrift.SlicePredicate; import org.apache.cassandra.thrift.SliceRange; -import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.ReducingIterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -116,7 +114,7 @@ public class QueryFilter protected boolean isEqual(IColumn o1, IColumn o2) { - return ByteBufferUtil.equals(o1.name(), o2.name()); + return o1.name().equals(o2.name()); } public void reduce(IColumn current) diff --git a/src/java/org/apache/cassandra/db/marshal/BytesType.java b/src/java/org/apache/cassandra/db/marshal/BytesType.java index 5ec3ae7eb9..bbfeb620dd 100644 --- a/src/java/org/apache/cassandra/db/marshal/BytesType.java +++ b/src/java/org/apache/cassandra/db/marshal/BytesType.java @@ -39,7 +39,7 @@ public class BytesType extends AbstractType else return -1; } - return ByteBufferUtil.compare(o1, o2); + return ByteBufferUtil.compareUnsigned(o1, o2); } public String getString(ByteBuffer bytes) diff --git a/src/java/org/apache/cassandra/db/marshal/LongType.java b/src/java/org/apache/cassandra/db/marshal/LongType.java index 2ddff8dfe1..6a4a2063b7 100644 --- a/src/java/org/apache/cassandra/db/marshal/LongType.java +++ b/src/java/org/apache/cassandra/db/marshal/LongType.java @@ -47,7 +47,7 @@ public class LongType extends AbstractType return diff; - return ByteBufferUtil.compare(o1, o2); + return ByteBufferUtil.compareUnsigned(o1, o2); } public String getString(ByteBuffer bytes) diff --git a/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java b/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java index bfdf285ef2..be5da01079 100644 --- a/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java +++ b/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java @@ -85,19 +85,8 @@ public abstract class AbstractByteOrderedPartitioner implements IPartitioner bytesToken) { - return FBUtilities.bytesToHex(ByteBuffer.wrap(bytesToken.token)); + return FBUtilities.bytesToHex(bytesToken.token); } public Token fromString(String string) diff --git a/src/java/org/apache/cassandra/dht/BytesToken.java b/src/java/org/apache/cassandra/dht/BytesToken.java index e8dda0c7fc..ae7db6a92b 100644 --- a/src/java/org/apache/cassandra/dht/BytesToken.java +++ b/src/java/org/apache/cassandra/dht/BytesToken.java @@ -21,14 +21,13 @@ package org.apache.cassandra.dht; import java.nio.ByteBuffer; import java.util.Arrays; -import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; public class BytesToken extends Token { public BytesToken(ByteBuffer token) { - super(convertByteBuffer(token)); + this(convertByteBuffer(token)); } public BytesToken(byte[] token) @@ -38,32 +37,31 @@ public class BytesToken extends Token private static byte[] convertByteBuffer(ByteBuffer token) { - if(token.position() == 0 && token.arrayOffset() == 0 && - token.limit() == token.capacity()) - { - return token.array(); - } - else - { - token.mark(); - byte[] buf = new byte[token.remaining()]; - token.get(buf); - token.reset(); - - return buf; - } + if (token.position() == 0 && token.arrayOffset() == 0 && token.limit() == token.capacity()) + { + return token.array(); + } + else + { + token.mark(); + byte[] buf = new byte[token.remaining()]; + token.get(buf); + token.reset(); + + return buf; + } } @Override public String toString() { - return "Token(bytes[" + FBUtilities.bytesToHex(ByteBuffer.wrap(token)) + "])"; + return "Token(bytes[" + FBUtilities.bytesToHex(token) + "])"; } @Override public int compareTo(Token o) { - return FBUtilities.compareByteArrays(token, o.token, 0, 0, token.length, o.token.length); + return FBUtilities.compareUnsigned(token, o.token, 0, 0, token.length, o.token.length); } diff --git a/src/java/org/apache/cassandra/dht/LocalToken.java b/src/java/org/apache/cassandra/dht/LocalToken.java index 74bbc1c607..737cc8b909 100644 --- a/src/java/org/apache/cassandra/dht/LocalToken.java +++ b/src/java/org/apache/cassandra/dht/LocalToken.java @@ -19,10 +19,8 @@ package org.apache.cassandra.dht; import java.nio.ByteBuffer; -import java.util.Arrays; import org.apache.cassandra.db.marshal.AbstractType; -import org.apache.cassandra.utils.ByteBufferUtil; public class LocalToken extends Token { @@ -61,7 +59,7 @@ public class LocalToken extends Token if (!(obj instanceof LocalToken)) return false; LocalToken other = (LocalToken) obj; - return ByteBufferUtil.equals(token, other.token); + return token.equals(other.token); } } diff --git a/src/java/org/apache/cassandra/dht/Range.java b/src/java/org/apache/cassandra/dht/Range.java index 069ce02788..f138c7bbed 100644 --- a/src/java/org/apache/cassandra/dht/Range.java +++ b/src/java/org/apache/cassandra/dht/Range.java @@ -250,7 +250,7 @@ public class Range extends AbstractBounds implements Comparable, Serializ } - return FBUtilities.compareByteArrays(l, r, lo, ro, ll, rl); + return FBUtilities.compareUnsigned(l, r, lo, ro, ll, rl); } public int compareTo(Range rhs) diff --git a/src/java/org/apache/cassandra/hadoop/ConfigHelper.java b/src/java/org/apache/cassandra/hadoop/ConfigHelper.java index 8ffa00b2da..f151f27497 100644 --- a/src/java/org/apache/cassandra/hadoop/ConfigHelper.java +++ b/src/java/org/apache/cassandra/hadoop/ConfigHelper.java @@ -166,7 +166,7 @@ public class ConfigHelper TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory()); try { - return FBUtilities.bytesToHex(ByteBuffer.wrap(serializer.serialize(predicate))); + return FBUtilities.bytesToHex(serializer.serialize(predicate)); } catch (TException e) { diff --git a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java index 57251c84ca..8101e38af0 100644 --- a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java +++ b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java @@ -26,22 +26,17 @@ import java.nio.ByteBuffer; */ public class ByteBufferUtil { - public static int compare(ByteBuffer o1, ByteBuffer o2) + public static int compareUnsigned(ByteBuffer o1, ByteBuffer o2) { - return FBUtilities.compareByteArrays(o1.array(), o2.array(), o1.arrayOffset()+o1.position(), o2.arrayOffset()+o2.position(), o1.limit(), o2.limit()); + return FBUtilities.compareUnsigned(o1.array(), o2.array(), o1.arrayOffset()+o1.position(), o2.arrayOffset()+o2.position(), o1.limit(), o2.limit()); } public static int compare(byte[] o1, ByteBuffer o2) { - return FBUtilities.compareByteArrays(o1, o2.array(), 0, o2.arrayOffset()+o2.position(), o1.length, o2.limit()); + return FBUtilities.compareUnsigned(o1, o2.array(), 0, o2.arrayOffset()+o2.position(), o1.length, o2.limit()); } public static int compare(ByteBuffer o1, byte[] o2) { - return FBUtilities.compareByteArrays(o1.array(), o2, o1.arrayOffset()+o1.position(), 0, o1.limit(), o2.length); + return FBUtilities.compareUnsigned(o1.array(), o2, o1.arrayOffset()+o1.position(), 0, o1.limit(), o2.length); } - - public static boolean equals(ByteBuffer o1, ByteBuffer o2) - { - return compare(o1, o2) == 0; - } } diff --git a/src/java/org/apache/cassandra/utils/FBUtilities.java b/src/java/org/apache/cassandra/utils/FBUtilities.java index 912bc72cf1..00ae49e2be 100644 --- a/src/java/org/apache/cassandra/utils/FBUtilities.java +++ b/src/java/org/apache/cassandra/utils/FBUtilities.java @@ -158,7 +158,7 @@ public class FBUtilities return new Pair(midpoint, remainder); } - public static ByteBuffer toByteArray(int i) + public static ByteBuffer toByteBuffer(int i) { byte[] bytes = new byte[4]; bytes[0] = (byte)( ( i >>> 24 ) & 0xFF); @@ -168,14 +168,9 @@ public class FBUtilities return ByteBuffer.wrap(bytes); } - public static int byteArrayToInt(ByteBuffer bytes) + public static int byteBufferToInt(ByteBuffer bytes) { - return byteArrayToInt(bytes, 0); - } - - public static int byteArrayToInt(ByteBuffer bytes, int offset) - { - if ( bytes.remaining() - offset < 4 ) + if (bytes.remaining() < 4 ) { throw new IllegalArgumentException("An integer must be 4 bytes in size."); } @@ -183,28 +178,29 @@ public class FBUtilities for ( int i = 0; i < 4; ++i ) { n <<= 8; - n |= bytes.array()[bytes.position()+bytes.arrayOffset()+ offset + i] & 0xFF; + n |= bytes.array()[bytes.position() + bytes.arrayOffset() + i] & 0xFF; } return n; } - - public static int compareByteArrays(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2){ - if(null == bytes1){ - if(null == bytes2) return 0; - else return -1; - } - if(null == bytes2) return 1; - int minLength = Math.min(len1-offset1, len2-offset2); - for(int x=0, i = offset1, j=offset2; x < minLength; x++,i++,j++) + public static int compareUnsigned(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2) + { + if (bytes1 == null) { - if(bytes1[i] == bytes2[j]) + return bytes2 == null ? 0 : -1; + } + if (bytes2 == null) return 1; + + int minLength = Math.min(len1 - offset1, len2 - offset2); + for (int x = 0, i = offset1, j = offset2; x < minLength; x++, i++, j++) + { + if (bytes1[i] == bytes2[j]) continue; // compare non-equal bytes as unsigned return (bytes1[i] & 0xFF) < (bytes2[j] & 0xFF) ? -1 : 1; } - if((len1-offset1) == (len2-offset2)) return 0; - else return ((len1-offset1) < (len2-offset2))? -1 : 1; + if ((len1 - offset1) == (len2 - offset2)) return 0; + else return ((len1 - offset1) < (len2 - offset2)) ? -1 : 1; } /** @@ -333,6 +329,20 @@ public class FBUtilities return bytes; } + public static String bytesToHex(byte... bytes) + { + StringBuilder sb = new StringBuilder(); + for (byte b : bytes) + { + int bint = b & 0xff; + if (bint <= 0xF) + // toHexString does not 0 pad its results. + sb.append("0"); + sb.append(Integer.toHexString(bint)); + } + return sb.toString(); + } + public static String bytesToHex(ByteBuffer bytes) { StringBuilder sb = new StringBuilder(); @@ -491,7 +501,7 @@ public class FBUtilities return decoded; } - public static ByteBuffer toByteArray(long n) + public static ByteBuffer toByteBuffer(long n) { byte[] bytes = new byte[8]; ByteBuffer bb = ByteBuffer.wrap(bytes).putLong(n); @@ -665,18 +675,9 @@ public class FBUtilities } } - public static TreeSet getSingleColumnSet(ByteBuffer column) + public static SortedSet singleton(T column) { - Comparator singleColumnComparator = new Comparator() - { - public int compare(ByteBuffer o1, ByteBuffer o2) - { - return ByteBufferUtil.equals(o1, o2) ? 0 : -1; - } - }; - TreeSet set = new TreeSet(singleColumnComparator); - set.add(column); - return set; + return new TreeSet(Arrays.asList(column)); } public static String toString(Map map) diff --git a/src/java/org/apache/cassandra/utils/MerkleTree.java b/src/java/org/apache/cassandra/utils/MerkleTree.java index 4ff42c36b6..bd54696483 100644 --- a/src/java/org/apache/cassandra/utils/MerkleTree.java +++ b/src/java/org/apache/cassandra/utils/MerkleTree.java @@ -787,7 +787,7 @@ public class MerkleTree implements Serializable { if (hash == null) return "null"; - return "[" + FBUtilities.bytesToHex(ByteBuffer.wrap(hash)) + "]"; + return "[" + FBUtilities.bytesToHex(hash) + "]"; } } diff --git a/src/java/org/apache/cassandra/utils/MurmurHash.java b/src/java/org/apache/cassandra/utils/MurmurHash.java index dcd7ef2a29..c786b6aaf7 100644 --- a/src/java/org/apache/cassandra/utils/MurmurHash.java +++ b/src/java/org/apache/cassandra/utils/MurmurHash.java @@ -36,15 +36,15 @@ public class MurmurHash { int len_4 = length >> 2; - for (int i = 0; i < len_4; i++) { + for (int i = offset; i < offset + len_4; i++) { int i_4 = i << 2; - int k = data[offset + i_4 + 3]; + int k = data[i_4 + 3]; k = k << 8; - k = k | (data[offset + i_4 + 2] & 0xff); + k = k | (data[i_4 + 2] & 0xff); k = k << 8; - k = k | (data[offset + i_4 + 1] & 0xff); + k = k | (data[i_4 + 1] & 0xff); k = k << 8; - k = k | (data[offset + i_4 + 0] & 0xff); + k = k | (data[i_4 + 0] & 0xff); k *= m; k ^= k >>> r; k *= m; @@ -58,13 +58,13 @@ public class MurmurHash { if (left != 0) { if (left >= 3) { - h ^= (int) data[offset+length - 3] << 16; + h ^= (int) data[offset + length - 3] << 16; } if (left >= 2) { - h ^= (int) data[offset+length - 2] << 8; + h ^= (int) data[offset + length - 2] << 8; } if (left >= 1) { - h ^= (int) data[offset+length - 1]; + h ^= (int) data[offset + length - 1]; } h *= m; diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java index 3b9bf1a3c7..b2c83a67b0 100644 --- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java +++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java @@ -27,7 +27,6 @@ import java.util.Random; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.junit.Test; @@ -133,27 +132,27 @@ public class ColumnFamilyStoreTest extends CleanupHelper RowMutation rm; rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k2".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteArray(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(2L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k3".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteArray(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k4aaaa".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteArray(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(3L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(3L), 0); rm.apply(); // basic single-expression query - IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(1L)); + IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L)); IndexClause clause = new IndexClause(Arrays.asList(expr),FBUtilities.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); IPartitioner p = StorageService.getPartitioner(); @@ -164,11 +163,11 @@ public class ColumnFamilyStoreTest extends CleanupHelper assert rows.size() == 2 : StringUtils.join(rows, ","); assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array()); assert Arrays.equals("k3".getBytes(), rows.get(1).key.key.array()); - assert FBUtilities.toByteArray(1L).equals( rows.get(0).cf.getColumn(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).value()); - assert FBUtilities.toByteArray(1L).equals( rows.get(1).cf.getColumn(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).value()); + assert FBUtilities.toByteBuffer(1L).equals( rows.get(0).cf.getColumn(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).value()); + assert FBUtilities.toByteBuffer(1L).equals( rows.get(1).cf.getColumn(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).value()); // add a second expression - IndexExpression expr2 = new IndexExpression(ByteBuffer.wrap("notbirthdate".getBytes("UTF8")), IndexOperator.GTE, FBUtilities.toByteArray(2L)); + IndexExpression expr2 = new IndexExpression(ByteBuffer.wrap("notbirthdate".getBytes("UTF8")), IndexOperator.GTE, FBUtilities.toByteBuffer(2L)); clause = new IndexClause(Arrays.asList(expr, expr2), FBUtilities.EMPTY_BYTE_BUFFER, 100); rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, filter); @@ -192,7 +191,7 @@ public class ColumnFamilyStoreTest extends CleanupHelper // query with index hit but rejected by secondary clause, with a small enough count that just checking count // doesn't tell the scan loop that it's done - IndexExpression expr3 = new IndexExpression(ByteBuffer.wrap("notbirthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(-1L)); + IndexExpression expr3 = new IndexExpression(ByteBuffer.wrap("notbirthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(-1L)); clause = new IndexClause(Arrays.asList(expr, expr3), FBUtilities.EMPTY_BYTE_BUFFER, 1); rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, filter); @@ -206,10 +205,10 @@ public class ColumnFamilyStoreTest extends CleanupHelper RowMutation rm; rm = new RowMutation("Keyspace3", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0); rm.apply(); - IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(1L)); + IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L)); IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); IPartitioner p = StorageService.getPartitioner(); @@ -234,7 +233,7 @@ public class ColumnFamilyStoreTest extends CleanupHelper // resurrect w/ a newer timestamp rm = new RowMutation("Keyspace3", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 2); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 2); rm.apply(); rows = cfs.scan(clause, range, filter); assert rows.size() == 1 : StringUtils.join(rows, ","); @@ -256,13 +255,13 @@ public class ColumnFamilyStoreTest extends CleanupHelper // create a row and update the birthdate value, test that the index query fetches the new version RowMutation rm; rm = new RowMutation("Keyspace2", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 1); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 1); rm.apply(); rm = new RowMutation("Keyspace2", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(2L), 2); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 2); rm.apply(); - IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(1L)); + IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L)); IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); IPartitioner p = StorageService.getPartitioner(); @@ -270,14 +269,14 @@ public class ColumnFamilyStoreTest extends CleanupHelper List rows = table.getColumnFamilyStore("Indexed1").scan(clause, range, filter); assert rows.size() == 0; - expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(2L)); + expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(2L)); clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100); rows = table.getColumnFamilyStore("Indexed1").scan(clause, range, filter); assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array()); // update the birthdate value with an OLDER timestamp, and test that the index ignores this rm = new RowMutation("Keyspace2", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(3L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(3L), 0); rm.apply(); rows = table.getColumnFamilyStore("Indexed1").scan(clause, range, filter); @@ -292,7 +291,7 @@ public class ColumnFamilyStoreTest extends CleanupHelper // create a row and update the birthdate value, test that the index query fetches the new version RowMutation rm; rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed2", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 1); + rm.add(new QueryPath("Indexed2", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 1); rm.apply(); ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed2"); @@ -302,7 +301,7 @@ public class ColumnFamilyStoreTest extends CleanupHelper while (!SystemTable.isIndexBuilt("Keyspace1", cfs.getIndexedColumnFamilyStore(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).columnFamily)) TimeUnit.MILLISECONDS.sleep(100); - IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(1L)); + IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L)); IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); IPartitioner p = StorageService.getPartitioner(); diff --git a/test/unit/org/apache/cassandra/db/TableTest.java b/test/unit/org/apache/cassandra/db/TableTest.java index de6871b626..15c0334015 100644 --- a/test/unit/org/apache/cassandra/db/TableTest.java +++ b/test/unit/org/apache/cassandra/db/TableTest.java @@ -28,7 +28,6 @@ import java.util.concurrent.ExecutionException; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.ArrayUtils; import org.junit.Test; import static junit.framework.Assert.*; @@ -237,7 +236,7 @@ public class TableTest extends CleanupHelper { RowMutation rm = new RowMutation("Keyspace1", ROW.key); ColumnFamily cf = ColumnFamily.create("Keyspace1", "StandardLong1"); - cf.addColumn(new Column(FBUtilities.toByteArray((long)i), FBUtilities.EMPTY_BYTE_BUFFER, 0)); + cf.addColumn(new Column(FBUtilities.toByteBuffer((long)i), FBUtilities.EMPTY_BYTE_BUFFER, 0)); rm.add(cf); rm.apply(); } @@ -248,7 +247,7 @@ public class TableTest extends CleanupHelper { RowMutation rm = new RowMutation("Keyspace1", ROW.key); ColumnFamily cf = ColumnFamily.create("Keyspace1", "StandardLong1"); - cf.addColumn(new Column(FBUtilities.toByteArray((long)i), FBUtilities.EMPTY_BYTE_BUFFER, 0)); + cf.addColumn(new Column(FBUtilities.toByteBuffer((long)i), FBUtilities.EMPTY_BYTE_BUFFER, 0)); rm.add(cf); rm.apply(); diff --git a/test/unit/org/apache/cassandra/hadoop/ColumnFamilyInputFormatTest.java b/test/unit/org/apache/cassandra/hadoop/ColumnFamilyInputFormatTest.java index 592b365ff6..22b239bf5d 100644 --- a/test/unit/org/apache/cassandra/hadoop/ColumnFamilyInputFormatTest.java +++ b/test/unit/org/apache/cassandra/hadoop/ColumnFamilyInputFormatTest.java @@ -23,7 +23,6 @@ package org.apache.cassandra.hadoop; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.cassandra.thrift.SlicePredicate; @@ -37,7 +36,7 @@ public class ColumnFamilyInputFormatTest public void testSlicePredicate() { long columnValue = 1271253600000l; - ByteBuffer columnBytes = FBUtilities.toByteArray(columnValue); + ByteBuffer columnBytes = FBUtilities.toByteBuffer(columnValue); List columnNames = new ArrayList(); columnNames.add(columnBytes); diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java index 0de53af0b5..cbdcb17c37 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java @@ -55,12 +55,12 @@ public class SSTableWriterTest extends CleanupHelper { RowMutation rm; rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k1".getBytes())); - rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteArray(1L), 0); + rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0); rm.apply(); ColumnFamily cf = ColumnFamily.create("Keyspace1", "Indexed1"); - cf.addColumn(new Column(ByteBuffer.wrap("birthdate".getBytes()), FBUtilities.toByteArray(1L), 0)); - cf.addColumn(new Column(ByteBuffer.wrap("anydate".getBytes()), FBUtilities.toByteArray(1L), 0)); + cf.addColumn(new Column(ByteBuffer.wrap("birthdate".getBytes()), FBUtilities.toByteBuffer(1L), 0)); + cf.addColumn(new Column(ByteBuffer.wrap("anydate".getBytes()), FBUtilities.toByteBuffer(1L), 0)); Map entries = new HashMap(); @@ -69,7 +69,7 @@ public class SSTableWriterTest extends CleanupHelper { entries.put(ByteBuffer.wrap("k2".getBytes()), ByteBuffer.wrap(Arrays.copyOf(buffer.getData(), buffer.getLength()))); cf.clear(); - cf.addColumn(new Column(ByteBuffer.wrap("anydate".getBytes()), FBUtilities.toByteArray(1L), 0)); + cf.addColumn(new Column(ByteBuffer.wrap("anydate".getBytes()), FBUtilities.toByteBuffer(1L), 0)); buffer = new DataOutputBuffer(); ColumnFamily.serializer().serializeWithIndexes(cf, buffer); entries.put(ByteBuffer.wrap("k3".getBytes()), ByteBuffer.wrap(Arrays.copyOf(buffer.getData(), buffer.getLength()))); @@ -84,7 +84,7 @@ public class SSTableWriterTest extends CleanupHelper { cfs.addSSTable(sstr); cfs.buildSecondaryIndexes(cfs.getSSTables(), cfs.getIndexedColumns()); - IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(1L)); + IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L)); IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); IPartitioner p = StorageService.getPartitioner(); diff --git a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java index 3d35898a0b..60c52105e3 100644 --- a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java +++ b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java @@ -26,8 +26,6 @@ import java.net.InetAddress; import java.nio.ByteBuffer; import java.util.*; -import org.apache.commons.lang.ArrayUtils; - import org.apache.cassandra.CleanupHelper; import org.apache.cassandra.Util; import org.apache.cassandra.db.*; @@ -71,7 +69,7 @@ public class StreamingTransferTest extends CleanupHelper RowMutation rm = new RowMutation("Keyspace1", ByteBuffer.wrap(key.getBytes())); ColumnFamily cf = ColumnFamily.create(table.name, cfs.columnFamily); cf.addColumn(column(key, "v", 0)); - cf.addColumn(new Column(ByteBuffer.wrap("birthdate".getBytes("UTF8")), FBUtilities.toByteArray((long) i), 0)); + cf.addColumn(new Column(ByteBuffer.wrap("birthdate".getBytes("UTF8")), FBUtilities.toByteBuffer((long) i), 0)); rm.add(cf); rm.apply(); } @@ -103,7 +101,7 @@ public class StreamingTransferTest extends CleanupHelper assert null != cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key3"), new QueryPath(cfs.columnFamily))); // and that the secondary index works - IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteArray(3L)); + IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(3L)); IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); Range range = new Range(p.getMinimumToken(), p.getMinimumToken()); diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java index 7632557e6e..2d42c920e2 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java @@ -52,7 +52,7 @@ public class SSTableExportTest extends SchemaLoader { public String asHex(String str) { - return bytesToHex(ByteBuffer.wrap(str.getBytes())); + return bytesToHex(str.getBytes()); } @Test diff --git a/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java b/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java index 2514851e94..2d15fbf4b3 100644 --- a/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java +++ b/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java @@ -36,7 +36,7 @@ public class FBUtilitiesTest for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { byte[] b = new byte[]{ (byte)i }; - String s = FBUtilities.bytesToHex(ByteBuffer.wrap(b)); + String s = FBUtilities.bytesToHex(b); byte[] c = FBUtilities.hexToBytes(s); assertArrayEquals(b, c); } @@ -79,8 +79,8 @@ public class FBUtilitiesTest }; for (int i : ints) { - ByteBuffer ba = FBUtilities.toByteArray(i); - int actual = FBUtilities.byteArrayToInt(ba); + ByteBuffer ba = FBUtilities.toByteBuffer(i); + int actual = FBUtilities.byteBufferToInt(ba); assertEquals(i, actual); } } diff --git a/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java b/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java index d9d1a42c71..46fcb46d01 100644 --- a/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java +++ b/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java @@ -84,8 +84,8 @@ public class MerkleTreeTest public static void assertHashEquals(String message, final byte[] left, final byte[] right) { - String lstring = left == null ? "null" : FBUtilities.bytesToHex(ByteBuffer.wrap(left)); - String rstring = right == null ? "null" : FBUtilities.bytesToHex(ByteBuffer.wrap(right)); + String lstring = left == null ? "null" : FBUtilities.bytesToHex(left); + String rstring = right == null ? "null" : FBUtilities.bytesToHex(right); assertEquals(message, lstring, rstring); }