From 0d443b037611bd3576b21fa17fecd27366eb7878 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 23 Mar 2011 02:30:05 +0000 Subject: [PATCH 01/15] fix potential infinite loop in ByteBufferUtil.inputStream patch by jbellis; reviewed by slebresne for CASSANDRA-2365 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084461 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + src/java/org/apache/cassandra/utils/ByteBufferUtil.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3ef0b900f1..6f349048d4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,7 @@ the same threshold for TTL expiration (CASSANDRA-2349) * fix race when iterating CFs during add/drop (CASSANDRA-2350) * add ConsistencyLevel command to CLI (CASSANDRA-2354) + * fix potential infinite loop in ByteBufferUtil.inputStream (CASSANDRA-2365) 0.7.4 diff --git a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java index 2725c02a53..35ef9666f1 100644 --- a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java +++ b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java @@ -363,9 +363,11 @@ public class ByteBufferUtil @Override public int read(byte[] bytes, int off, int len) throws IOException { + if (!copy.hasRemaining()) + return -1; + len = Math.min(len, copy.remaining()); copy.get(bytes, off, len); - return len; } From a765dcb59e321f86e5ac594b171ae48decd823ae Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 23 Mar 2011 17:48:46 +0000 Subject: [PATCH 02/15] give index more time to build to avoid heisenfailures git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084652 13f79535-47bb-0310-9956-ffa450edef68 --- test/system/test_thrift_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/test_thrift_server.py b/test/system/test_thrift_server.py index 32ce34098d..2364ad6512 100644 --- a/test/system/test_thrift_server.py +++ b/test/system/test_thrift_server.py @@ -1406,7 +1406,7 @@ class TestMutations(ThriftTester): assert server_cf.column_metadata[0].index_name == modified_cd.index_name # sleep a bit to give time for the index to build. - time.sleep(0.1) + time.sleep(0.5) # simple query on one index expression cp = ColumnParent('ToBeIndexed') From ec26ee73bf05812cc79af2a3d63ba5bfac7ffd31 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 23 Mar 2011 18:13:42 +0000 Subject: [PATCH 03/15] fix encoding bugs in HintedHandoffManager, SystemTable when default charset is not UTF8 patch by slebresne; reviewed by jbellis for CASSANDRA-2367 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084660 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + contrib/bmt_example/CassandraBulkLoader.java | 9 +-- .../client_only/src/ClientOnlyExample.java | 6 +- .../cassandra/contrib/stress/Session.java | 4 +- .../stress/operations/IndexedRangeSlicer.java | 8 +-- .../contrib/stress/operations/Inserter.java | 2 +- .../stress/operations/MultiGetter.java | 8 ++- .../stress/operations/RangeSlicer.java | 14 ++-- .../contrib/stress/operations/Reader.java | 4 +- .../contrib/stress/util/Operation.java | 10 +-- contrib/word_count/src/WordCount.java | 10 +-- .../org/apache/cassandra/cli/CliClient.java | 8 +-- .../cassandra/config/DatabaseDescriptor.java | 3 +- .../org/apache/cassandra/db/DefsTable.java | 6 +- .../cassandra/db/HintedHandOffManager.java | 12 ++-- .../cassandra/db/RowMutationVerbHandler.java | 3 +- .../org/apache/cassandra/db/SystemTable.java | 22 +++--- .../cassandra/db/marshal/AsciiType.java | 2 +- .../apache/cassandra/db/marshal/UTF8Type.java | 6 +- .../cassandra/db/migration/Migration.java | 8 +-- .../CollatingOrderPreservingPartitioner.java | 4 +- .../dht/OrderPreservingPartitioner.java | 8 +-- .../cassandra/dht/RandomPartitioner.java | 4 +- .../cassandra/service/StorageProxy.java | 4 +- .../cassandra/service/StorageService.java | 2 +- .../cassandra/utils/ByteBufferUtil.java | 70 +++++++++++++++---- .../org/apache/cassandra/MovementTest.java | 10 +-- .../org/apache/cassandra/MutationTest.java | 10 +-- test/unit/org/apache/cassandra/Util.java | 19 ++--- .../cassandra/client/TestRingCache.java | 2 +- .../org/apache/cassandra/db/CleanupTest.java | 2 +- .../apache/cassandra/db/ColumnFamilyTest.java | 2 +- .../cassandra/db/CompactionsPurgeTest.java | 22 +++--- .../apache/cassandra/db/CompactionsTest.java | 2 +- .../org/apache/cassandra/db/DefsTest.java | 8 +-- .../org/apache/cassandra/db/NameSortTest.java | 6 +- .../cassandra/db/RecoveryManager2Test.java | 3 +- .../db/RecoveryManagerTruncateTest.java | 4 +- .../apache/cassandra/db/RowIterationTest.java | 2 +- .../cassandra/db/SerializationsTest.java | 24 ++++--- .../org/apache/cassandra/db/TimeSortTest.java | 2 +- .../cassandra/io/LazilyCompactedRowTest.java | 6 +- .../io/sstable/LegacySSTableTest.java | 3 +- .../io/sstable/SSTableReaderTest.java | 8 +-- .../cassandra/io/sstable/SSTableTest.java | 4 +- .../cassandra/io/sstable/SSTableUtils.java | 6 +- .../cassandra/locator/SimpleStrategyTest.java | 3 +- .../service/EmbeddedCassandraServiceTest.java | 9 +-- .../streaming/SerializationsTest.java | 7 +- .../streaming/StreamingTransferTest.java | 6 +- .../cassandra/tools/SSTableExportTest.java | 2 +- .../cassandra/utils/ByteBufferUtilTest.java | 2 +- .../apache/cassandra/utils/KeyGenerator.java | 2 +- 53 files changed, 228 insertions(+), 187 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6f349048d4..f3b4e6ef35 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,8 @@ * fix race when iterating CFs during add/drop (CASSANDRA-2350) * add ConsistencyLevel command to CLI (CASSANDRA-2354) * fix potential infinite loop in ByteBufferUtil.inputStream (CASSANDRA-2365) + * fix encoding bugs in HintedHandoffManager, SystemTable when default + charset is not UTF8 (CASSANDRA-2367) 0.7.4 diff --git a/contrib/bmt_example/CassandraBulkLoader.java b/contrib/bmt_example/CassandraBulkLoader.java index 3470d32e37..76f1e4c31e 100644 --- a/contrib/bmt_example/CassandraBulkLoader.java +++ b/contrib/bmt_example/CassandraBulkLoader.java @@ -75,6 +75,7 @@ import org.apache.cassandra.net.Message; import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.hadoop.filecache.DistributedCache; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; @@ -175,9 +176,9 @@ public class CassandraBulkLoader { String ColumnValue = fields[3]; int timestamp = 0; columnFamily.addColumn(new QueryPath(cfName, - ByteBuffer.wrap(SuperColumnName.getBytes(Charsets.UTF_8)), - ByteBuffer.wrap(ColumnName.getBytes(Charsets.UTF_8))), - ByteBuffer.wrap(ColumnValue.getBytes()), + ByteBufferUtil.bytes(SuperColumnName), + ByteBufferUtil.bytes(ColumnName)), + ByteBufferUtil.bytes(ColumnValue), timestamp); } @@ -186,7 +187,7 @@ public class CassandraBulkLoader { /* Get serialized message to send to cluster */ message = createMessage(keyspace, key.getBytes(), cfName, columnFamilies); List results = new ArrayList(); - for (InetAddress endpoint: StorageService.instance.getNaturalEndpoints(keyspace, ByteBuffer.wrap(key.getBytes()))) + for (InetAddress endpoint: StorageService.instance.getNaturalEndpoints(keyspace, ByteBufferUtil.bytes(key))) { /* Send message to end point */ results.add(MessagingService.instance().sendRR(message, endpoint)); diff --git a/contrib/client_only/src/ClientOnlyExample.java b/contrib/client_only/src/ClientOnlyExample.java index 7bb4d20b16..fa69965fb9 100644 --- a/contrib/client_only/src/ClientOnlyExample.java +++ b/contrib/client_only/src/ClientOnlyExample.java @@ -63,9 +63,9 @@ public class ClientOnlyExample // do some writing. for (int i = 0; i < 100; i++) { - RowMutation change = new RowMutation(KEYSPACE, ByteBuffer.wrap(("key" + i).getBytes())); + RowMutation change = new RowMutation(KEYSPACE, ByteBufferUtil.bytes(("key" + i))); ColumnPath cp = new ColumnPath(COLUMN_FAMILY).setColumn(("colb").getBytes()); - change.add(new QueryPath(cp), ByteBuffer.wrap(("value" + i).getBytes()), 0); + change.add(new QueryPath(cp), ByteBufferUtil.bytes(("value" + i)), 0); // don't call change.apply(). The reason is that is makes a static call into Table, which will perform // local storage initialization, which creates local directories. @@ -87,7 +87,7 @@ public class ClientOnlyExample for (int i = 0; i < 100; i++) { List commands = new ArrayList(); - SliceByNamesReadCommand readCommand = new SliceByNamesReadCommand(KEYSPACE, ByteBuffer.wrap(("key" + i).getBytes()), + SliceByNamesReadCommand readCommand = new SliceByNamesReadCommand(KEYSPACE, ByteBufferUtil.bytes(("key" + i)), new QueryPath(COLUMN_FAMILY, null, null), cols); readCommand.setDigestQuery(false); commands.add(readCommand); diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/Session.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/Session.java index 9b9e47221e..adad267c37 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/Session.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/Session.java @@ -28,6 +28,8 @@ import org.apache.commons.cli.*; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.thrift.*; import org.apache.commons.lang.StringUtils; + +import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.transport.TFramedTransport; import org.apache.thrift.transport.TSocket; @@ -372,7 +374,7 @@ public class Session standardCfDef.setComparator_type("AsciiType").setDefault_validation_class("BytesType"); if (indexType != null) { - ColumnDef standardColumn = new ColumnDef(ByteBuffer.wrap("C1".getBytes()), "BytesType"); + ColumnDef standardColumn = new ColumnDef(ByteBufferUtil.bytes("C1"), "BytesType"); standardColumn.setIndex_type(indexType).setIndex_name("Idx1"); standardCfDef.setColumn_metadata(Arrays.asList(standardColumn)); } diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/IndexedRangeSlicer.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/IndexedRangeSlicer.java index 1c1b889a74..e8cd38e30a 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/IndexedRangeSlicer.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/IndexedRangeSlicer.java @@ -36,15 +36,15 @@ public class IndexedRangeSlicer extends Operation public void run(Cassandra.Client client) throws IOException { String format = "%0" + session.getTotalKeysLength() + "d"; - SlicePredicate predicate = new SlicePredicate().setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[]{}), - ByteBuffer.wrap(new byte[] {}), + SlicePredicate predicate = new SlicePredicate().setSlice_range(new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, + ByteBufferUtil.EMPTY_BYTE_BUFFER, false, session.getColumnsPerKey())); List values = super.generateValues(); ColumnParent parent = new ColumnParent("Standard1"); int expectedPerValue = session.getNumKeys() / values.size(); - ByteBuffer columnName = ByteBuffer.wrap("C1".getBytes()); + ByteBuffer columnName = ByteBufferUtil.bytes("C1"); int received = 0; @@ -56,7 +56,7 @@ public class IndexedRangeSlicer extends Operation while (received < expectedPerValue) { IndexClause clause = new IndexClause(Arrays.asList(expression), - ByteBuffer.wrap(startOffset.getBytes()), + ByteBufferUtil.bytes(startOffset), session.getKeysPerCall()); List results = null; diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Inserter.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Inserter.java index 7b932614d2..ad6d8b0f6e 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Inserter.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Inserter.java @@ -59,7 +59,7 @@ public class Inserter extends Operation for (int i = 0; i < session.getSuperColumns(); i++) { String superColumnName = "S" + Integer.toString(i); - superColumns.add(new SuperColumn(ByteBuffer.wrap(superColumnName.getBytes()), columns)); + superColumns.add(new SuperColumn(ByteBufferUtil.bytes(superColumnName), columns)); } } diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/MultiGetter.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/MultiGetter.java index cc2443063a..823b847ad4 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/MultiGetter.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/MultiGetter.java @@ -20,6 +20,7 @@ package org.apache.cassandra.contrib.stress.operations; import org.apache.cassandra.contrib.stress.util.Operation; import org.apache.cassandra.db.ColumnFamilyType; import org.apache.cassandra.thrift.*; +import org.apache.cassandra.utils.ByteBufferUtil; import java.io.IOException; import java.nio.ByteBuffer; @@ -27,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; + public class MultiGetter extends Operation { public MultiGetter(int index) @@ -36,8 +38,8 @@ public class MultiGetter extends Operation public void run(Cassandra.Client client) throws IOException { - SlicePredicate predicate = new SlicePredicate().setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[]{}), - ByteBuffer.wrap(new byte[] {}), + SlicePredicate predicate = new SlicePredicate().setSlice_range(new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, + ByteBufferUtil.EMPTY_BYTE_BUFFER, false, session.getColumnsPerKey())); int offset = index * session.getKeysPerThread(); @@ -49,7 +51,7 @@ public class MultiGetter extends Operation for (int j = 0; j < session.getSuperColumns(); j++) { - ColumnParent parent = new ColumnParent("Super1").setSuper_column(("S" + j).getBytes()); + ColumnParent parent = new ColumnParent("Super1").setSuper_column(ByteBufferUtil.bytes("S" + j)); long start = System.currentTimeMillis(); diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/RangeSlicer.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/RangeSlicer.java index b2e6ff435f..c827984d35 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/RangeSlicer.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/RangeSlicer.java @@ -42,14 +42,14 @@ public class RangeSlicer extends Operation // initial values int count = session.getColumnsPerKey(); - SlicePredicate predicate = new SlicePredicate().setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[] {}), - ByteBuffer.wrap(new byte[] {}), + SlicePredicate predicate = new SlicePredicate().setSlice_range(new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, + ByteBufferUtil.EMPTY_BYTE_BUFFER, false, count)); if (session.getColumnFamilyType() == ColumnFamilyType.Super) { - byte[] start = String.format(format, index).getBytes(); + ByteBuffer start = ByteBufferUtil.bytes(String.format(format, index)); List slices = new ArrayList(); KeyRange range = new KeyRange(count).setStart_key(start).setEnd_key(ByteBufferUtil.EMPTY_BYTE_BUFFER); @@ -57,7 +57,7 @@ public class RangeSlicer extends Operation for (int i = 0; i < session.getSuperColumns(); i++) { String superColumnName = "S" + Integer.toString(i); - ColumnParent parent = new ColumnParent("Super1").setSuper_column(ByteBuffer.wrap(superColumnName.getBytes())); + ColumnParent parent = new ColumnParent("Super1").setSuper_column(ByteBufferUtil.bytes(superColumnName)); long startTime = System.currentTimeMillis(); @@ -83,7 +83,7 @@ public class RangeSlicer extends Operation error(String.format("Operation [%d] retried %d times - error on calling get_range_slices for range offset %s %s%n", index, session.getRetryTimes(), - new String(start), + ByteBufferUtil.string(start), (exceptionMessage == null) ? "" : "(" + exceptionMessage + ")")); } @@ -97,7 +97,7 @@ public class RangeSlicer extends Operation { ColumnParent parent = new ColumnParent("Standard1"); - byte[] start = String.format(format, index).getBytes(); + ByteBuffer start = ByteBufferUtil.bytes(String.format(format, index)); List slices = new ArrayList(); KeyRange range = new KeyRange(count).setStart_key(start).setEnd_key(ByteBufferUtil.EMPTY_BYTE_BUFFER); @@ -129,7 +129,7 @@ public class RangeSlicer extends Operation error(String.format("Operation [%d] retried %d times - error on calling get_indexed_slices for range offset %s %s%n", index, session.getRetryTimes(), - new String(start), + ByteBufferUtil.string(start), (exceptionMessage == null) ? "" : "(" + exceptionMessage + ")")); } diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Reader.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Reader.java index 8478a2a130..360a2e4a58 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Reader.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/operations/Reader.java @@ -25,6 +25,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; +import static com.google.common.base.Charsets.UTF_8; + public class Reader extends Operation { public Reader(int index) @@ -63,7 +65,7 @@ public class Reader extends Operation for (int j = 0; j < session.getSuperColumns(); j++) { String superColumn = 'S' + Integer.toString(j); - ColumnParent parent = new ColumnParent("Super1").setSuper_column(superColumn.getBytes()); + ColumnParent parent = new ColumnParent("Super1").setSuper_column(superColumn.getBytes(UTF_8)); long start = System.currentTimeMillis(); diff --git a/contrib/stress/src/org/apache/cassandra/contrib/stress/util/Operation.java b/contrib/stress/src/org/apache/cassandra/contrib/stress/util/Operation.java index 3bdb72c850..b98513bf0f 100644 --- a/contrib/stress/src/org/apache/cassandra/contrib/stress/util/Operation.java +++ b/contrib/stress/src/org/apache/cassandra/contrib/stress/util/Operation.java @@ -21,16 +21,16 @@ import java.io.IOException; import java.math.BigInteger; import java.nio.ByteBuffer; import java.security.MessageDigest; - import java.util.ArrayList; import java.util.List; import java.util.Random; +import static com.google.common.base.Charsets.UTF_8; + import org.apache.cassandra.contrib.stress.Session; import org.apache.cassandra.contrib.stress.Stress; import org.apache.cassandra.thrift.Cassandra; import org.apache.cassandra.thrift.InvalidRequestException; -import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; public abstract class Operation @@ -91,7 +91,7 @@ public abstract class Operation private static byte[] generateRandomKey() { String format = "%0" + Stress.session.getTotalKeysLength() + "d"; - return String.format(format, Stress.randomizer.nextInt(Stress.session.getNumKeys() - 1)).getBytes(); + return String.format(format, Stress.randomizer.nextInt(Stress.session.getNumKeys() - 1)).getBytes(UTF_8); } /** @@ -109,7 +109,7 @@ public abstract class Operation if (0 <= token && token < session.getNumKeys()) { - return String.format(format, (int) token).getBytes(); + return String.format(format, (int) token).getBytes(UTF_8); } } } @@ -148,7 +148,7 @@ public abstract class Operation private String getMD5(String input) { MessageDigest md = FBUtilities.threadLocalMD5Digest(); - byte[] messageDigest = md.digest(input.getBytes()); + byte[] messageDigest = md.digest(input.getBytes(UTF_8)); StringBuilder hash = new StringBuilder(new BigInteger(1, messageDigest).toString(16)); while (hash.length() < 32) diff --git a/contrib/word_count/src/WordCount.java b/contrib/word_count/src/WordCount.java index 594f4a88c5..1641082b36 100644 --- a/contrib/word_count/src/WordCount.java +++ b/contrib/word_count/src/WordCount.java @@ -27,6 +27,8 @@ import org.apache.cassandra.hadoop.ColumnFamilyOutputFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static com.google.common.base.Charsets.UTF_8; + import org.apache.cassandra.db.IColumn; import org.apache.cassandra.hadoop.ColumnFamilyInputFormat; import org.apache.cassandra.hadoop.ConfigHelper; @@ -82,7 +84,7 @@ public class WordCount extends Configured implements Tool protected void setup(org.apache.hadoop.mapreduce.Mapper.Context context) throws IOException, InterruptedException { - sourceColumn = ByteBuffer.wrap(context.getConfiguration().get(CONF_COLUMN_NAME).getBytes()); + sourceColumn = ByteBufferUtil.bytes(context.getConfiguration().get(CONF_COLUMN_NAME)); } public void map(ByteBuffer key, SortedMap columns, Context context) throws IOException, InterruptedException @@ -120,7 +122,7 @@ public class WordCount extends Configured implements Tool protected void setup(org.apache.hadoop.mapreduce.Reducer.Context context) throws IOException, InterruptedException { - outputKey = ByteBuffer.wrap(context.getConfiguration().get(CONF_COLUMN_NAME).getBytes()); + outputKey = ByteBufferUtil.bytes(context.getConfiguration().get(CONF_COLUMN_NAME)); } public void reduce(Text word, Iterable values, Context context) throws IOException, InterruptedException @@ -135,7 +137,7 @@ public class WordCount extends Configured implements Tool { Column c = new Column(); c.name = ByteBuffer.wrap(Arrays.copyOf(word.getBytes(), word.getLength())); - c.value = ByteBuffer.wrap(String.valueOf(sum).getBytes()); + c.value = ByteBufferUtil.bytes(String.valueOf(sum)); c.timestamp = System.currentTimeMillis() * 1000; Mutation m = new Mutation(); @@ -194,7 +196,7 @@ public class WordCount extends Configured implements Tool ConfigHelper.setInitialAddress(job.getConfiguration(), "localhost"); ConfigHelper.setPartitioner(job.getConfiguration(), "org.apache.cassandra.dht.RandomPartitioner"); ConfigHelper.setInputColumnFamily(job.getConfiguration(), KEYSPACE, COLUMN_FAMILY); - SlicePredicate predicate = new SlicePredicate().setColumn_names(Arrays.asList(ByteBuffer.wrap(columnName.getBytes()))); + SlicePredicate predicate = new SlicePredicate().setColumn_names(Arrays.asList(ByteBufferUtil.bytes(columnName))); ConfigHelper.setInputSlicePredicate(job.getConfiguration(), predicate); job.waitForCompletion(true); diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index 3500ab2eca..4dadb21ed3 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -252,7 +252,7 @@ public class CliClient extends CliUserHelp SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, Integer.MAX_VALUE); SlicePredicate predicate = new SlicePredicate().setColumn_names(null).setSlice_range(range); - int count = thriftClient.get_count(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)), colParent, predicate, consistencyLevel); + int count = thriftClient.get_count(ByteBufferUtil.bytes(key), colParent, predicate, consistencyLevel); sessionState.out.printf("%d columns%n", count); } @@ -301,7 +301,7 @@ public class CliClient extends CliUserHelp if (columnName != null) path.setColumn(columnName); - thriftClient.remove(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)), path, + thriftClient.remove(ByteBufferUtil.bytes(key), path, FBUtilities.timestampMicros(), consistencyLevel); sessionState.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row" : "column")); } @@ -1770,7 +1770,7 @@ public class CliClient extends CliUserHelp } // if no validation were set returning simple .getBytes() - return ByteBuffer.wrap(columnValue.getBytes()); + return ByteBufferUtil.bytes(columnValue); } /** @@ -1993,7 +1993,7 @@ public class CliClient extends CliUserHelp for (KeySlice ks : slices) { - String keyName = (keyComparator == null) ? ByteBufferUtil.string(ks.key, Charsets.UTF_8) : keyComparator.getString(ks.key); + String keyName = (keyComparator == null) ? ByteBufferUtil.string(ks.key) : keyComparator.getString(ks.key); sessionState.out.printf("-------------------%n"); sessionState.out.printf("RowKey: %s%n", keyName); diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 718804523e..6d7d707f56 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -45,6 +45,7 @@ import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.locator.*; import org.apache.cassandra.scheduler.IRequestScheduler; import org.apache.cassandra.scheduler.NoScheduler; +import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.Pair; import org.yaml.snakeyaml.Loader; @@ -613,7 +614,7 @@ public class DatabaseDescriptor throw new ConfigurationException("index_name cannot be set if index_type is not also set"); } - ByteBuffer columnName = ByteBuffer.wrap(rcd.name.getBytes(Charsets.UTF_8)); + ByteBuffer columnName = ByteBufferUtil.bytes(rcd.name); metadata.put(columnName, new ColumnDefinition(columnName, rcd.validator_class, rcd.index_type, rcd.index_name)); } diff --git a/src/java/org/apache/cassandra/db/DefsTable.java b/src/java/org/apache/cassandra/db/DefsTable.java index 78c3b1bff3..1a678a1fc2 100644 --- a/src/java/org/apache/cassandra/db/DefsTable.java +++ b/src/java/org/apache/cassandra/db/DefsTable.java @@ -35,8 +35,6 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.UUIDGen; -import static com.google.common.base.Charsets.UTF_8; - public class DefsTable { // column name for the schema storing serialized keyspace definitions @@ -57,13 +55,13 @@ public class DefsTable for (String ksname : ksnames) { KSMetaData ksm = DatabaseDescriptor.getTableDefinition(ksname); - rm.add(new QueryPath(Migration.SCHEMA_CF, null, ByteBuffer.wrap(ksm.name.getBytes(UTF_8))), SerDeUtils.serialize(ksm.deflate()), now); + rm.add(new QueryPath(Migration.SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.deflate()), now); } // add the schema rm.add(new QueryPath(Migration.SCHEMA_CF, null, DEFINITION_SCHEMA_COLUMN_NAME), - ByteBuffer.wrap(org.apache.cassandra.avro.KsDef.SCHEMA$.toString().getBytes(UTF_8)), + ByteBufferUtil.bytes(org.apache.cassandra.avro.KsDef.SCHEMA$.toString()), now); rm.apply(); diff --git a/src/java/org/apache/cassandra/db/HintedHandOffManager.java b/src/java/org/apache/cassandra/db/HintedHandOffManager.java index 4653f7f9b2..e3c0fd8fba 100644 --- a/src/java/org/apache/cassandra/db/HintedHandOffManager.java +++ b/src/java/org/apache/cassandra/db/HintedHandOffManager.java @@ -197,7 +197,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean { final String ipaddr = endpoint.getHostAddress(); final ColumnFamilyStore hintStore = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HINTS_CF); - final RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBuffer.wrap(ipaddr.getBytes())); + final RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBufferUtil.bytes(ipaddr)); rm.delete(new QueryPath(HINTS_CF), System.currentTimeMillis()); // execute asynchronously to avoid blocking caller (which may be processing gossip) @@ -230,13 +230,13 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean public static ByteBuffer makeCombinedName(String tableName, String columnFamily) { - byte[] withsep = ArrayUtils.addAll(tableName.getBytes(UTF_8), SEPARATOR.getBytes()); + byte[] withsep = ArrayUtils.addAll(tableName.getBytes(UTF_8), SEPARATOR.getBytes(UTF_8)); return ByteBuffer.wrap(ArrayUtils.addAll(withsep, columnFamily.getBytes(UTF_8))); } private static String[] getTableAndCFNames(ByteBuffer joined) { - int index = ByteBufferUtil.lastIndexOf(joined, SEPARATOR.getBytes()[0], joined.limit()); + int index = ByteBufferUtil.lastIndexOf(joined, SEPARATOR.getBytes(UTF_8)[0], joined.limit()); if (index == -1 || index < (joined.position() + 1)) throw new RuntimeException("Corrupted hint name " + ByteBufferUtil.bytesToHex(joined)); @@ -308,7 +308,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean // 3. Delete the subcolumn if the write was successful // 4. Force a flush // 5. Do major compaction to clean up all deletes etc. - ByteBuffer endpointAsUTF8 = ByteBuffer.wrap(endpoint.getHostAddress().getBytes(UTF_8)); // keys have to be UTF8 to make OPP happy + ByteBuffer endpointAsUTF8 = ByteBufferUtil.bytes(endpoint.getHostAddress()); // keys have to be UTF8 to make OPP happy DecoratedKey epkey = StorageService.getPartitioner().decorateKey(endpointAsUTF8); int rowsReplayed = 0; ColumnFamilyStore hintStore = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HINTS_CF); @@ -364,7 +364,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean /** called when a keyspace is dropped or rename. newTable==null in the case of a drop. */ public static void renameHints(String oldTable, String newTable) throws IOException { - DecoratedKey oldTableKey = StorageService.getPartitioner().decorateKey(ByteBuffer.wrap(oldTable.getBytes(UTF_8))); + DecoratedKey oldTableKey = StorageService.getPartitioner().decorateKey(ByteBufferUtil.bytes(oldTable)); // we're basically going to fetch, drop and add the scf for the old and new table. we need to do it piecemeal // though since there could be GB of data. ColumnFamilyStore hintStore = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HINTS_CF); @@ -378,7 +378,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean break; if (newTable != null) { - RowMutation insert = new RowMutation(Table.SYSTEM_TABLE, ByteBuffer.wrap(newTable.getBytes(UTF_8))); + RowMutation insert = new RowMutation(Table.SYSTEM_TABLE, ByteBufferUtil.bytes(newTable)); insert.add(cf); insert.apply(); } diff --git a/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java b/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java index 2888f23198..cf83409a76 100644 --- a/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java +++ b/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java @@ -25,7 +25,6 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; -import com.google.common.base.Charsets; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,7 +60,7 @@ public class RowMutationVerbHandler implements IVerbHandler { ByteBuffer addressBytes = ByteBufferUtil.readWithShortLength(dis); if (logger_.isDebugEnabled()) - logger_.debug("Adding hint for " + InetAddress.getByName(ByteBufferUtil.string(addressBytes, Charsets.UTF_8))); + logger_.debug("Adding hint for " + InetAddress.getByName(ByteBufferUtil.string(addressBytes))); RowMutation hintedMutation = new RowMutation(Table.SYSTEM_TABLE, addressBytes); hintedMutation.addHints(rm); hintedMutation.apply(); diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java index fbd65bbc4a..65d3eaf836 100644 --- a/src/java/org/apache/cassandra/db/SystemTable.java +++ b/src/java/org/apache/cassandra/db/SystemTable.java @@ -44,8 +44,6 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; -import static com.google.common.base.Charsets.UTF_8; - public class SystemTable { private static Logger logger = LoggerFactory.getLogger(SystemTable.class); @@ -239,8 +237,8 @@ public class SystemTable // no system files. this is a new node. RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY); cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.STATUS_CF); - cf.addColumn(new Column(PARTITIONER, ByteBuffer.wrap(DatabaseDescriptor.getPartitioner().getClass().getName().getBytes(UTF_8)), FBUtilities.timestampMicros())); - cf.addColumn(new Column(CLUSTERNAME, ByteBuffer.wrap(DatabaseDescriptor.getClusterName().getBytes()), FBUtilities.timestampMicros())); + cf.addColumn(new Column(PARTITIONER, ByteBufferUtil.bytes(DatabaseDescriptor.getPartitioner().getClass().getName()), FBUtilities.timestampMicros())); + cf.addColumn(new Column(CLUSTERNAME, ByteBufferUtil.bytes(DatabaseDescriptor.getClusterName()), FBUtilities.timestampMicros())); rm.add(cf); rm.apply(); @@ -252,9 +250,9 @@ public class SystemTable IColumn clusterCol = cf.getColumn(CLUSTERNAME); assert partitionerCol != null; assert clusterCol != null; - if (!DatabaseDescriptor.getPartitioner().getClass().getName().equals(ByteBufferUtil.string(partitionerCol.value(), UTF_8))) + if (!DatabaseDescriptor.getPartitioner().getClass().getName().equals(ByteBufferUtil.string(partitionerCol.value()))) throw new ConfigurationException("Detected partitioner mismatch! Did you change the partitioner?"); - String savedClusterName = ByteBufferUtil.string(clusterCol.value(), UTF_8); + String savedClusterName = ByteBufferUtil.string(clusterCol.value()); if (!DatabaseDescriptor.getClusterName().equals(savedClusterName)) throw new ConfigurationException("Saved cluster name " + savedClusterName + " != configured name " + DatabaseDescriptor.getClusterName()); } @@ -331,17 +329,17 @@ public class SystemTable public static boolean isIndexBuilt(String table, String indexName) { ColumnFamilyStore cfs = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(INDEX_CF); - QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBuffer.wrap(table.getBytes(UTF_8))), + QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBufferUtil.bytes(table)), new QueryPath(INDEX_CF), - ByteBuffer.wrap(indexName.getBytes(UTF_8))); + ByteBufferUtil.bytes(indexName)); return cfs.getColumnFamily(filter) != null; } public static void setIndexBuilt(String table, String indexName) { ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, INDEX_CF); - cf.addColumn(new Column(ByteBuffer.wrap(indexName.getBytes(UTF_8)), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis())); - RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBuffer.wrap(table.getBytes(UTF_8))); + cf.addColumn(new Column(ByteBufferUtil.bytes(indexName), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis())); + RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBufferUtil.bytes(table)); rm.add(cf); try { @@ -357,8 +355,8 @@ public class SystemTable public static void setIndexRemoved(String table, String indexName) { - RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBuffer.wrap(table.getBytes(UTF_8))); - rm.delete(new QueryPath(INDEX_CF, null, ByteBuffer.wrap(indexName.getBytes(UTF_8))), System.currentTimeMillis()); + RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBufferUtil.bytes(table)); + rm.delete(new QueryPath(INDEX_CF, null, ByteBufferUtil.bytes(indexName)), System.currentTimeMillis()); try { rm.apply(); diff --git a/src/java/org/apache/cassandra/db/marshal/AsciiType.java b/src/java/org/apache/cassandra/db/marshal/AsciiType.java index 5a6821bbab..d797429620 100644 --- a/src/java/org/apache/cassandra/db/marshal/AsciiType.java +++ b/src/java/org/apache/cassandra/db/marshal/AsciiType.java @@ -49,7 +49,7 @@ public class AsciiType extends BytesType public ByteBuffer fromString(String source) { - return ByteBuffer.wrap(source.getBytes(Charsets.US_ASCII)); + return ByteBufferUtil.bytes(source, Charsets.US_ASCII); } public void validate(ByteBuffer bytes) throws MarshalException diff --git a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java index c4ee5b6d42..3f94486d96 100644 --- a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java +++ b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java @@ -23,8 +23,6 @@ package org.apache.cassandra.db.marshal; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; -import com.google.common.base.Charsets; - import org.apache.cassandra.utils.ByteBufferUtil; public class UTF8Type extends BytesType @@ -37,7 +35,7 @@ public class UTF8Type extends BytesType { try { - return ByteBufferUtil.string(bytes, Charsets.UTF_8); + return ByteBufferUtil.string(bytes); } catch (CharacterCodingException e) { @@ -47,7 +45,7 @@ public class UTF8Type extends BytesType public ByteBuffer fromString(String source) { - return ByteBuffer.wrap(source.getBytes(Charsets.UTF_8)); + return ByteBufferUtil.bytes(source); } public void validate(ByteBuffer bytes) throws MarshalException diff --git a/src/java/org/apache/cassandra/db/migration/Migration.java b/src/java/org/apache/cassandra/db/migration/Migration.java index bb601e59d1..fe3ff95811 100644 --- a/src/java/org/apache/cassandra/db/migration/Migration.java +++ b/src/java/org/apache/cassandra/db/migration/Migration.java @@ -45,8 +45,6 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.UUIDGen; -import static com.google.common.base.Charsets.UTF_8; - /** * A migration represents a single metadata mutation (cf dropped, added, etc.). Migrations can be applied locally, or * serialized and sent to another machine where it can be applied there. Each migration has a version represented by @@ -237,12 +235,12 @@ public abstract class Migration long now = System.currentTimeMillis(); // add a column for each keyspace for (KSMetaData ksm : ksms) - rm.add(new QueryPath(SCHEMA_CF, null, ByteBuffer.wrap(ksm.name.getBytes(UTF_8))), SerDeUtils.serialize(ksm.deflate()), now); + rm.add(new QueryPath(SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.deflate()), now); // add the schema rm.add(new QueryPath(SCHEMA_CF, null, DefsTable.DEFINITION_SCHEMA_COLUMN_NAME), - ByteBuffer.wrap(org.apache.cassandra.avro.KsDef.SCHEMA$.toString().getBytes(UTF_8)), + ByteBufferUtil.bytes(org.apache.cassandra.avro.KsDef.SCHEMA$.toString()), now); return rm; } @@ -323,7 +321,7 @@ public abstract class Migration public static ByteBuffer toUTF8Bytes(UUID version) { - return ByteBuffer.wrap(version.toString().getBytes(UTF_8)); + return ByteBufferUtil.bytes(version.toString()); } public static boolean isLegalName(String s) diff --git a/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java b/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java index 5c890b55a5..a12bcd75ab 100644 --- a/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java +++ b/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java @@ -25,8 +25,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import com.google.common.base.Charsets; - import org.apache.cassandra.utils.ByteBufferUtil; public class CollatingOrderPreservingPartitioner extends AbstractByteOrderedPartitioner @@ -41,7 +39,7 @@ public class CollatingOrderPreservingPartitioner extends AbstractByteOrderedPart String skey; try { - skey = ByteBufferUtil.string(key, Charsets.UTF_8); + skey = ByteBufferUtil.string(key); } catch (CharacterCodingException e) { diff --git a/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java b/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java index 75695bb269..5a2e6b3bad 100644 --- a/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java +++ b/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java @@ -23,8 +23,6 @@ import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; import java.util.*; -import com.google.common.base.Charsets; - import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.DecoratedKey; @@ -118,14 +116,14 @@ public class OrderPreservingPartitioner implements IPartitioner { public ByteBuffer toByteArray(Token stringToken) { - return ByteBuffer.wrap(stringToken.token.getBytes(Charsets.UTF_8)); + return ByteBufferUtil.bytes(stringToken.token); } public Token fromByteArray(ByteBuffer bytes) { try { - return new StringToken(ByteBufferUtil.string(bytes, Charsets.UTF_8)); + return new StringToken(ByteBufferUtil.string(bytes)); } catch (CharacterCodingException e) { @@ -159,7 +157,7 @@ public class OrderPreservingPartitioner implements IPartitioner String skey; try { - skey = ByteBufferUtil.string(key, Charsets.UTF_8); + skey = ByteBufferUtil.string(key); } catch (CharacterCodingException e) { diff --git a/src/java/org/apache/cassandra/dht/RandomPartitioner.java b/src/java/org/apache/cassandra/dht/RandomPartitioner.java index 61bb674436..aeec66b2e6 100644 --- a/src/java/org/apache/cassandra/dht/RandomPartitioner.java +++ b/src/java/org/apache/cassandra/dht/RandomPartitioner.java @@ -30,8 +30,6 @@ import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.GuidGenerator; import org.apache.cassandra.utils.Pair; -import static com.google.common.base.Charsets.UTF_8; - /** * This class generates a BigIntegerToken using MD5 hash. */ @@ -65,7 +63,7 @@ public class RandomPartitioner implements IPartitioner String token = null; try { - token = ByteBufferUtil.string(fromdisk, fromdisk.position(), splitPoint - fromdisk.position(), UTF_8); + token = ByteBufferUtil.string(fromdisk, fromdisk.position(), splitPoint - fromdisk.position()); } catch (CharacterCodingException e) { diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index c54ab773e0..0a01c1c522 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -52,8 +52,6 @@ import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.thrift.*; import org.apache.cassandra.utils.*; -import static com.google.common.base.Charsets.UTF_8; - public class StorageProxy implements StorageProxyMBean { private static final Logger logger = LoggerFactory.getLogger(StorageProxy.class); @@ -258,7 +256,7 @@ public class StorageProxy implements StorageProxyMBean { dos.write(previousHints); } - ByteBufferUtil.writeWithShortLength(ByteBuffer.wrap(target.getHostAddress().getBytes(UTF_8)), dos); + ByteBufferUtil.writeWithShortLength(ByteBufferUtil.bytes(target.getHostAddress()), dos); message.setHeader(RowMutation.HINT, bos.toByteArray()); } diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java index e0dd182c5a..f0acb0f3f4 100644 --- a/src/java/org/apache/cassandra/service/StorageService.java +++ b/src/java/org/apache/cassandra/service/StorageService.java @@ -2078,7 +2078,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe RawColumnDefinition rcd = new RawColumnDefinition(); rcd.index_name = cd.getIndexName(); rcd.index_type = cd.getIndexType(); - rcd.name = ByteBufferUtil.string(cd.name, Charsets.UTF_8); + rcd.name = ByteBufferUtil.string(cd.name); rcd.validator_class = cd.validator.getClass().getName(); rcf.column_metadata[j++] = rcd; } diff --git a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java index 35ef9666f1..8507114b56 100644 --- a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java +++ b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java @@ -23,12 +23,13 @@ import java.io.DataOutput; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.util.Arrays; +import static com.google.common.base.Charsets.UTF_8; + import org.apache.cassandra.io.util.FileDataInput; import org.apache.commons.lang.ArrayUtils; @@ -101,16 +102,41 @@ public class ByteBufferUtil return compareUnsigned(o1, ByteBuffer.wrap(o2)); } + /** + * Decode a String representation. + * This method assumes that the encoding charset is UTF_8. + * + * @param buffer a byte buffer holding the string representation + * @return the decoded string + */ public static String string(ByteBuffer buffer) throws CharacterCodingException { - return string(buffer, Charset.defaultCharset()); + return string(buffer, UTF_8); } + /** + * Decode a String representation. + * This method assumes that the encoding charset is UTF_8. + * + * @param buffer a byte buffer holding the string representation + * @param position the starting position in {@code buffer} to start decoding from + * @param length the number of bytes from {@code buffer} to use + * @return the decoded string + */ public static String string(ByteBuffer buffer, int position, int length) throws CharacterCodingException { - return string(buffer, position, length, Charset.defaultCharset()); + return string(buffer, position, length, UTF_8); } + /** + * Decode a String representation. + * + * @param buffer a byte buffer holding the string representation + * @param position the starting position in {@code buffer} to start decoding from + * @param length the number of bytes from {@code buffer} to use + * @param charset the String encoding charset + * @return the decoded string + */ public static String string(ByteBuffer buffer, int position, int length, Charset charset) throws CharacterCodingException { ByteBuffer copy = buffer.duplicate(); @@ -119,6 +145,13 @@ public class ByteBufferUtil return string(copy, charset); } + /** + * Decode a String representation. + * + * @param buffer a byte buffer holding the string representation + * @param charset the String encoding charset + * @return the decoded string + */ public static String string(ByteBuffer buffer, Charset charset) throws CharacterCodingException { return charset.newDecoder().decode(buffer.duplicate()).toString(); @@ -177,16 +210,27 @@ public class ByteBufferUtil return -1; } - public static ByteBuffer bytes(String s) - { - try - { - return ByteBuffer.wrap(s.getBytes("UTF-8")); - } - catch (UnsupportedEncodingException e) - { - throw new RuntimeException(e); - } + /** + * Encode a String in a ByteBuffer using UTF_8. + * + * @param s the string to encode + * @return the encoded string + */ + public static ByteBuffer bytes(String s) + { + return ByteBuffer.wrap(s.getBytes(UTF_8)); + } + + /** + * Encode a String in a ByteBuffer using the provided charset. + * + * @param s the string to encode + * @param charset the String encoding charset to use + * @return the encoded string + */ + public static ByteBuffer bytes(String s, Charset charset) + { + return ByteBuffer.wrap(s.getBytes(charset)); } /** diff --git a/test/distributed/org/apache/cassandra/MovementTest.java b/test/distributed/org/apache/cassandra/MovementTest.java index 5577e2be9b..0fa3c5e75b 100644 --- a/test/distributed/org/apache/cassandra/MovementTest.java +++ b/test/distributed/org/apache/cassandra/MovementTest.java @@ -50,13 +50,13 @@ public class MovementTest extends TestBase { final int N = 1000; Column col1 = new Column( - ByteBuffer.wrap("c1".getBytes()), - ByteBuffer.wrap("v1".getBytes()), + ByteBufferUtil.bytes("c1"), + ByteBufferUtil.bytes("v1"), 0 ); Column col2 = new Column( - ByteBuffer.wrap("c2".getBytes()), - ByteBuffer.wrap("v2".getBytes()), + ByteBufferUtil.bytes("c2"), + ByteBufferUtil.bytes("v2"), 0 ); @@ -66,7 +66,7 @@ public class MovementTest extends TestBase for (int i = 0; i < N; i++) { String rawKey = String.format("test.key.%d", i); - ByteBuffer key = ByteBuffer.wrap(rawKey.getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(rawKey); Mutation m1 = (new Mutation()).setColumn_or_supercolumn((new ColumnOrSuperColumn()).setColumn(col1)); Mutation m2 = (new Mutation()).setColumn_or_supercolumn((new ColumnOrSuperColumn()).setColumn(col2)); rows.put(key, Arrays.asList(m1.getColumn_or_supercolumn(), diff --git a/test/distributed/org/apache/cassandra/MutationTest.java b/test/distributed/org/apache/cassandra/MutationTest.java index f0cd79e3ee..26514251d5 100644 --- a/test/distributed/org/apache/cassandra/MutationTest.java +++ b/test/distributed/org/apache/cassandra/MutationTest.java @@ -189,8 +189,8 @@ public class MutationTest extends TestBase throws InvalidRequestException, UnavailableException, TimedOutException, TException { Column col = new Column( - ByteBuffer.wrap(name.getBytes()), - ByteBuffer.wrap(value.getBytes()), + ByteBufferUtil.bytes(name), + ByteBufferUtil.bytes(value), timestamp ); client.insert(key, new ColumnParent(cf), col, cl); @@ -337,8 +337,8 @@ public class MutationTest extends TestBase protected void assertColumnEqual(String name, String value, long timestamp, Column col) { - assertEquals(ByteBuffer.wrap(name.getBytes()), col.name); - assertEquals(ByteBuffer.wrap(value.getBytes()), col.value); + assertEquals(ByteBufferUtil.bytes(name), col.name); + assertEquals(ByteBufferUtil.bytes(value), col.value); assertEquals(timestamp, col.timestamp); } @@ -371,6 +371,6 @@ public class MutationTest extends TestBase protected ByteBuffer newKey() { - return ByteBuffer.wrap(String.format("test.key.%d", System.currentTimeMillis()).getBytes()); + return ByteBufferUtil.bytes(String.format("test.key.%d", System.currentTimeMillis())); } } diff --git a/test/unit/org/apache/cassandra/Util.java b/test/unit/org/apache/cassandra/Util.java index 006d5f802d..518c045d91 100644 --- a/test/unit/org/apache/cassandra/Util.java +++ b/test/unit/org/apache/cassandra/Util.java @@ -25,13 +25,8 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.List; -import java.util.Map; -import java.util.HashMap; import java.util.concurrent.ExecutionException; -import static org.junit.Assert.*; - -import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.filter.QueryFilter; @@ -39,26 +34,26 @@ import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.dht.*; import org.apache.cassandra.gms.ApplicationState; import org.apache.cassandra.gms.VersionedValue; -import org.apache.cassandra.locator.AbstractReplicationStrategy; import org.apache.cassandra.service.StorageService; +import org.apache.cassandra.utils.ByteBufferUtil; -import static com.google.common.base.Charsets.UTF_8; +import static org.junit.Assert.assertTrue; public class Util { public static DecoratedKey dk(String key) { - return StorageService.getPartitioner().decorateKey(ByteBuffer.wrap(key.getBytes(UTF_8))); + return StorageService.getPartitioner().decorateKey(ByteBufferUtil.bytes(key)); } public static Column column(String name, String value, long timestamp) { - return new Column(ByteBuffer.wrap(name.getBytes()), ByteBuffer.wrap(value.getBytes()), timestamp); + return new Column(ByteBufferUtil.bytes(name), ByteBufferUtil.bytes(value), timestamp); } public static Token token(String key) { - return StorageService.getPartitioner().getToken(ByteBuffer.wrap(key.getBytes())); + return StorageService.getPartitioner().getToken(ByteBufferUtil.bytes(key)); } public static Range range(String left, String right) @@ -68,7 +63,7 @@ public class Util public static Range range(IPartitioner p, String left, String right) { - return new Range(p.getToken(ByteBuffer.wrap(left.getBytes())), p.getToken(ByteBuffer.wrap(right.getBytes()))); + return new Range(p.getToken(ByteBufferUtil.bytes(left)), p.getToken(ByteBufferUtil.bytes(right))); } public static Bounds bounds(String left, String right) @@ -78,7 +73,7 @@ public class Util public static void addMutation(RowMutation rm, String columnFamilyName, String superColumnName, long columnName, String value, long timestamp) { - rm.add(new QueryPath(columnFamilyName, ByteBuffer.wrap(superColumnName.getBytes()), getBytes(columnName)), ByteBuffer.wrap(value.getBytes()), timestamp); + rm.add(new QueryPath(columnFamilyName, ByteBufferUtil.bytes(superColumnName), getBytes(columnName)), ByteBufferUtil.bytes(value), timestamp); } public static ByteBuffer getBytes(long v) diff --git a/test/unit/org/apache/cassandra/client/TestRingCache.java b/test/unit/org/apache/cassandra/client/TestRingCache.java index 1382c78c22..8479207592 100644 --- a/test/unit/org/apache/cassandra/client/TestRingCache.java +++ b/test/unit/org/apache/cassandra/client/TestRingCache.java @@ -91,7 +91,7 @@ public class TestRingCache for (int nRows = minRow; nRows < maxRow; nRows++) { - ByteBuffer row = ByteBuffer.wrap((rowPrefix + nRows).getBytes()); + ByteBuffer row = ByteBufferUtil.bytes((rowPrefix + nRows)); ColumnPath col = new ColumnPath("Standard1").setSuper_column((ByteBuffer)null).setColumn("col1".getBytes()); ColumnParent parent = new ColumnParent("Standard1").setSuper_column((ByteBuffer)null); diff --git a/test/unit/org/apache/cassandra/db/CleanupTest.java b/test/unit/org/apache/cassandra/db/CleanupTest.java index c7dfaec042..c962ed93d8 100644 --- a/test/unit/org/apache/cassandra/db/CleanupTest.java +++ b/test/unit/org/apache/cassandra/db/CleanupTest.java @@ -51,7 +51,7 @@ public class CleanupTest extends CleanupHelper public static final String TABLE1 = "Keyspace1"; public static final String CF1 = "Indexed1"; public static final String CF2 = "Standard1"; - public static final ByteBuffer COLUMN = ByteBuffer.wrap("birthdate".getBytes()); + public static final ByteBuffer COLUMN = ByteBufferUtil.bytes("birthdate"); public static final ByteBuffer VALUE = ByteBuffer.allocate(8); static { diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java index d519ad1918..983d2dba6e 100644 --- a/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java +++ b/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java @@ -80,7 +80,7 @@ public class ColumnFamilyTest extends SchemaLoader cf = ColumnFamily.serializer().deserialize(new DataInputStream(bufIn)); for (String cName : map.navigableKeySet()) { - ByteBuffer val = cf.getColumn(ByteBuffer.wrap(cName.getBytes())).value(); + ByteBuffer val = cf.getColumn(ByteBufferUtil.bytes(cName)).value(); assert new String(val.array(),val.position(),val.remaining()).equals(map.get(cName)); } assert cf.getColumnNames().size() == map.size(); diff --git a/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java b/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java index c290b87617..9aeefec5a3 100644 --- a/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java +++ b/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java @@ -57,7 +57,7 @@ public class CompactionsPurgeTest extends CleanupHelper rm = new RowMutation(TABLE1, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); cfs.forceBlockingFlush(); @@ -66,14 +66,14 @@ public class CompactionsPurgeTest extends CleanupHelper for (int i = 0; i < 10; i++) { rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), 1); + rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1); rm.apply(); } cfs.forceBlockingFlush(); // resurrect one column rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(5).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); rm.apply(); cfs.forceBlockingFlush(); @@ -82,7 +82,7 @@ public class CompactionsPurgeTest extends CleanupHelper cfs.invalidateCachedRow(key); ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); assertColumns(cf, "5"); - assert cf.getColumn(ByteBuffer.wrap(String.valueOf(5).getBytes())) != null; + assert cf.getColumn(ByteBufferUtil.bytes(String.valueOf(5))) != null; } @Test @@ -102,7 +102,7 @@ public class CompactionsPurgeTest extends CleanupHelper rm = new RowMutation(TABLE2, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); cfs.forceBlockingFlush(); @@ -111,7 +111,7 @@ public class CompactionsPurgeTest extends CleanupHelper for (int i = 0; i < 10; i++) { rm = new RowMutation(TABLE2, key.key); - rm.delete(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), 1); + rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1); rm.apply(); } cfs.forceBlockingFlush(); @@ -125,7 +125,7 @@ public class CompactionsPurgeTest extends CleanupHelper cfs.forceBlockingFlush(); Collection sstablesIncomplete = cfs.getSSTables(); rm = new RowMutation(TABLE2, key1.key); - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(5).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); rm.apply(); cfs.forceBlockingFlush(); CompactionManager.instance.doCompaction(cfs, sstablesIncomplete, Integer.MAX_VALUE); @@ -157,7 +157,7 @@ public class CompactionsPurgeTest extends CleanupHelper rm = new RowMutation(TABLE1, key.key); for (int i = 0; i < 5; i++) { - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); @@ -165,7 +165,7 @@ public class CompactionsPurgeTest extends CleanupHelper for (int i = 0; i < 5; i++) { rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), 1); + rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1); rm.apply(); } store.forceBlockingFlush(); @@ -196,7 +196,7 @@ public class CompactionsPurgeTest extends CleanupHelper rm = new RowMutation(tableName, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); @@ -217,7 +217,7 @@ public class CompactionsPurgeTest extends CleanupHelper rm = new RowMutation(tableName, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); diff --git a/test/unit/org/apache/cassandra/db/CompactionsTest.java b/test/unit/org/apache/cassandra/db/CompactionsTest.java index 2eb4df1a43..06f853679b 100644 --- a/test/unit/org/apache/cassandra/db/CompactionsTest.java +++ b/test/unit/org/apache/cassandra/db/CompactionsTest.java @@ -61,7 +61,7 @@ public class CompactionsTest extends CleanupHelper for (int i = 0; i < ROWS_PER_SSTABLE; i++) { DecoratedKey key = Util.dk(String.valueOf(i % 2)); RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap(String.valueOf(i / 2).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, j * ROWS_PER_SSTABLE + i); + rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i / 2))), ByteBufferUtil.EMPTY_BYTE_BUFFER, j * ROWS_PER_SSTABLE + i); rm.apply(); inserted.add(key); } diff --git a/test/unit/org/apache/cassandra/db/DefsTest.java b/test/unit/org/apache/cassandra/db/DefsTest.java index 578a39e76b..a9a2bb5cdc 100644 --- a/test/unit/org/apache/cassandra/db/DefsTest.java +++ b/test/unit/org/apache/cassandra/db/DefsTest.java @@ -295,7 +295,7 @@ public class DefsTest extends CleanupHelper // write some data, force a flush, then verify that files exist on disk. RowMutation rm = new RowMutation(ks.name, dk.key); for (int i = 0; i < 100; i++) - rm.add(new QueryPath(cfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("anyvalue"), 1L); + rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(cfm.tableName).getColumnFamilyStore(cfm.cfName); assert store != null; @@ -341,7 +341,7 @@ public class DefsTest extends CleanupHelper // write some data, force a flush, then verify that files exist on disk. RowMutation rm = new RowMutation(ks.name, dk.key); for (int i = 0; i < 100; i++) - rm.add(new QueryPath(oldCfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("anyvalue"), 1L); + rm.add(new QueryPath(oldCfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(oldCfm.tableName).getColumnFamilyStore(oldCfm.cfName); assert store != null; @@ -415,7 +415,7 @@ public class DefsTest extends CleanupHelper // write some data, force a flush, then verify that files exist on disk. RowMutation rm = new RowMutation(ks.name, dk.key); for (int i = 0; i < 100; i++) - rm.add(new QueryPath(cfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("anyvalue"), 1L); + rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(cfm.tableName).getColumnFamilyStore(cfm.cfName); assert store != null; @@ -465,7 +465,7 @@ public class DefsTest extends CleanupHelper // write some data that we hope to read back later. RowMutation rm = new RowMutation(oldKs.name, dk.key); for (int i = 0; i < 10; i++) - rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("value"), 1L); + rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("value"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(oldKs.name).getColumnFamilyStore(cfName); assert store != null; diff --git a/test/unit/org/apache/cassandra/db/NameSortTest.java b/test/unit/org/apache/cassandra/db/NameSortTest.java index 433dc98ebc..823754cbd0 100644 --- a/test/unit/org/apache/cassandra/db/NameSortTest.java +++ b/test/unit/org/apache/cassandra/db/NameSortTest.java @@ -64,15 +64,15 @@ public class NameSortTest extends CleanupHelper for (int i = 0; i < N; ++i) { - ByteBuffer key = ByteBuffer.wrap(Integer.toString(i).getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(Integer.toString(i)); RowMutation rm; // standard for (int j = 0; j < 8; ++j) { - ByteBuffer bytes = ByteBuffer.wrap(j % 2 == 0 ? "a".getBytes() : "b".getBytes()); + ByteBuffer bytes = j % 2 == 0 ? ByteBufferUtil.bytes("a") : ByteBufferUtil.bytes("b"); rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap(("Column-" + j).getBytes())), bytes, j); + rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(("Column-" + j))), bytes, j); rm.applyUnsafe(); } diff --git a/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java b/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java index 519e99d751..5563229943 100644 --- a/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java +++ b/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java @@ -33,6 +33,7 @@ import static org.apache.cassandra.Util.column; import org.apache.cassandra.CleanupHelper; import org.apache.cassandra.Util; import org.apache.cassandra.db.commitlog.CommitLog; +import org.apache.cassandra.utils.ByteBufferUtil; public class RecoveryManager2Test extends CleanupHelper { @@ -73,7 +74,7 @@ public class RecoveryManager2Test extends CleanupHelper private void insertRow(String cfname, String key) throws IOException { - RowMutation rm = new RowMutation("Keyspace1", ByteBuffer.wrap(key.getBytes())); + RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(key)); ColumnFamily cf = ColumnFamily.create("Keyspace1", cfname); cf.addColumn(column("col1", "val1", 1L)); rm.add(cf); diff --git a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java index fed0fbad97..1c27f514f9 100644 --- a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java +++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java @@ -89,11 +89,11 @@ public class RecoveryManagerTruncateTest extends CleanupHelper return null; } cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter( - Util.dk(keyName), new QueryPath(cfName), ByteBuffer.wrap(columnName.getBytes()))); + Util.dk(keyName), new QueryPath(cfName), ByteBufferUtil.bytes(columnName))); if (cf == null) { return null; } - return cf.getColumn(ByteBuffer.wrap(columnName.getBytes())); + return cf.getColumn(ByteBufferUtil.bytes(columnName)); } } diff --git a/test/unit/org/apache/cassandra/db/RowIterationTest.java b/test/unit/org/apache/cassandra/db/RowIterationTest.java index d78111bb5b..82246668b3 100644 --- a/test/unit/org/apache/cassandra/db/RowIterationTest.java +++ b/test/unit/org/apache/cassandra/db/RowIterationTest.java @@ -55,7 +55,7 @@ public class RowIterationTest extends CleanupHelper for (int i = 0; i < ROWS_PER_SSTABLE; i++) { DecoratedKey key = Util.dk(String.valueOf(i)); RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath("Super3", ByteBufferUtil.bytes("sc"), ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBuffer.wrap(new byte[ROWS_PER_SSTABLE * 10 - i * 2]), i); + rm.add(new QueryPath("Super3", ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes(String.valueOf(i))), ByteBuffer.wrap(new byte[ROWS_PER_SSTABLE * 10 - i * 2]), i); rm.apply(); inserted.add(key); } diff --git a/test/unit/org/apache/cassandra/db/SerializationsTest.java b/test/unit/org/apache/cassandra/db/SerializationsTest.java index 577fe2bf1c..68c7d9190e 100644 --- a/test/unit/org/apache/cassandra/db/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/db/SerializationsTest.java @@ -32,6 +32,8 @@ import org.apache.cassandra.net.Message; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.thrift.SlicePredicate; import org.apache.cassandra.thrift.SliceRange; +import org.apache.cassandra.utils.ByteBufferUtil; + import org.junit.Test; import java.io.DataInputStream; @@ -47,9 +49,9 @@ public class SerializationsTest extends AbstractSerializationsTester { private void testRangeSliceCommandWrite() throws IOException { - ByteBuffer startCol = ByteBuffer.wrap("Start".getBytes()); - ByteBuffer stopCol = ByteBuffer.wrap("Stop".getBytes()); - ByteBuffer emptyCol = ByteBuffer.wrap("".getBytes()); + ByteBuffer startCol = ByteBufferUtil.bytes("Start"); + ByteBuffer stopCol = ByteBufferUtil.bytes("Stop"); + ByteBuffer emptyCol = ByteBufferUtil.bytes(""); SlicePredicate namesPred = new SlicePredicate(); namesPred.column_names = Statics.NamedCols; SliceRange emptySliceRange = new SliceRange(emptyCol, emptyCol, false, 100); @@ -284,24 +286,24 @@ public class SerializationsTest extends AbstractSerializationsTester } private static ByteBuffer bb(String s) { - return ByteBuffer.wrap(s.getBytes()); + return ByteBufferUtil.bytes(s); } private static class Statics { private static final String KS = "Keyspace1"; - private static final ByteBuffer Key = ByteBuffer.wrap("Key01".getBytes()); + private static final ByteBuffer Key = ByteBufferUtil.bytes("Key01"); private static final List NamedCols = new ArrayList() {{ - add(ByteBuffer.wrap("AAA".getBytes())); - add(ByteBuffer.wrap("BBB".getBytes())); - add(ByteBuffer.wrap("CCC".getBytes())); + add(ByteBufferUtil.bytes("AAA")); + add(ByteBufferUtil.bytes("BBB")); + add(ByteBufferUtil.bytes("CCC")); }}; - private static final ByteBuffer SC = ByteBuffer.wrap("SCName".getBytes()); + private static final ByteBuffer SC = ByteBufferUtil.bytes("SCName"); private static final QueryPath StandardPath = new QueryPath("Standard1"); private static final QueryPath SuperPath = new QueryPath("Super1", SC); - private static final ByteBuffer Start = ByteBuffer.wrap("Start".getBytes()); - private static final ByteBuffer Stop = ByteBuffer.wrap("Stop".getBytes()); + private static final ByteBuffer Start = ByteBufferUtil.bytes("Start"); + private static final ByteBuffer Stop = ByteBufferUtil.bytes("Stop"); private static final ColumnFamily StandardCf = ColumnFamily.create(Statics.KS, "Standard1"); private static final ColumnFamily SuperCf = ColumnFamily.create(Statics.KS, "Super1"); diff --git a/test/unit/org/apache/cassandra/db/TimeSortTest.java b/test/unit/org/apache/cassandra/db/TimeSortTest.java index e6ee425a58..ab06755173 100644 --- a/test/unit/org/apache/cassandra/db/TimeSortTest.java +++ b/test/unit/org/apache/cassandra/db/TimeSortTest.java @@ -68,7 +68,7 @@ public class TimeSortTest extends CleanupHelper for (int i = 900; i < 1000; ++i) { - RowMutation rm = new RowMutation("Keyspace1", ByteBuffer.wrap(Integer.toString(i).getBytes())); + RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(Integer.toString(i))); for (int j = 0; j < 8; ++j) { rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2)), ByteBufferUtil.bytes("a"), j * 2); diff --git a/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java b/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java index dfd57d6aa0..d742c0fd51 100644 --- a/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java +++ b/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java @@ -150,7 +150,7 @@ public class LazilyCompactedRowTest extends CleanupHelper Table table = Table.open("Keyspace1"); ColumnFamilyStore cfs = table.getColumnFamilyStore("Standard1"); - ByteBuffer key =ByteBuffer.wrap( "k".getBytes() ); + ByteBuffer key = ByteBufferUtil.bytes("k"); RowMutation rm = new RowMutation("Keyspace1", key); rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("d")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); @@ -212,9 +212,9 @@ public class LazilyCompactedRowTest extends CleanupHelper final int ROWS_PER_SSTABLE = 10; for (int j = 0; j < (DatabaseDescriptor.getIndexInterval() * 3) / ROWS_PER_SSTABLE; j++) { for (int i = 0; i < ROWS_PER_SSTABLE; i++) { - ByteBuffer key = ByteBuffer.wrap(String.valueOf(i % 2).getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(i % 2)); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap(String.valueOf(i / 2).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, j * ROWS_PER_SSTABLE + i); + rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i / 2))), ByteBufferUtil.EMPTY_BYTE_BUFFER, j * ROWS_PER_SSTABLE + i); rm.apply(); } cfs.forceBlockingFlush(); diff --git a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java index 8593bd9802..01d547a3c7 100644 --- a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java @@ -28,6 +28,7 @@ import org.apache.cassandra.CleanupHelper; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.columniterator.SSTableNamesIterator; import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.utils.ByteBufferUtil; import org.junit.BeforeClass; import org.junit.Test; @@ -99,7 +100,7 @@ public class LegacySSTableTest extends CleanupHelper SSTableReader reader = SSTableReader.open(getDescriptor(version)); for (String keystring : TEST_DATA) { - ByteBuffer key = ByteBuffer.wrap(keystring.getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(keystring); // confirm that the bloom filter does not reject any keys/names DecoratedKey dk = reader.partitioner.decorateKey(key); SSTableNamesIterator iter = new SSTableNamesIterator(reader, dk, FBUtilities.singleton(key)); diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java index 6c1a86a9e1..45a50aaf96 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java @@ -49,7 +49,7 @@ public class SSTableReaderTest extends CleanupHelper { static Token t(int i) { - return StorageService.getPartitioner().getToken(ByteBuffer.wrap(String.valueOf(i).getBytes())); + return StorageService.getPartitioner().getToken(ByteBufferUtil.bytes(String.valueOf(i))); } @Test @@ -62,7 +62,7 @@ public class SSTableReaderTest extends CleanupHelper CompactionManager.instance.disableAutoCompaction(); for (int j = 0; j < 10; j++) { - ByteBuffer key = ByteBuffer.wrap(String.valueOf(j).getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); @@ -103,7 +103,7 @@ public class SSTableReaderTest extends CleanupHelper CompactionManager.instance.disableAutoCompaction(); for (int j = 0; j < 100; j += 2) { - ByteBuffer key = ByteBuffer.wrap(String.valueOf(j).getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); @@ -140,7 +140,7 @@ public class SSTableReaderTest extends CleanupHelper for (int j = 0; j < 100; j += 2) { - ByteBuffer key = ByteBuffer.wrap(String.valueOf(j).getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java index 8f9d72f1a3..25c9ad09ca 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java @@ -34,7 +34,7 @@ public class SSTableTest extends CleanupHelper @Test public void testSingleWrite() throws IOException { // write test data - ByteBuffer key = ByteBuffer.wrap(Integer.toString(1).getBytes()); + ByteBuffer key = ByteBufferUtil.bytes(Integer.toString(1)); ByteBuffer bytes = ByteBuffer.wrap(new byte[1024]); new Random().nextBytes(bytes.array()); @@ -64,7 +64,7 @@ public class SSTableTest extends CleanupHelper Map map = new HashMap(); for (int i = 100; i < 1000; ++i) { - map.put(ByteBuffer.wrap(Integer.toString(i).getBytes()), ByteBuffer.wrap(("Avinash Lakshman is a good man: " + i).getBytes())); + map.put(ByteBufferUtil.bytes(Integer.toString(i)), ByteBufferUtil.bytes(("Avinash Lakshman is a good man: " + i))); } // write diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java b/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java index cefdb54d76..aa63976343 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java @@ -29,6 +29,7 @@ import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.IColumn; import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.utils.ByteBufferUtil; public class SSTableUtils { @@ -122,7 +123,7 @@ public class SSTableUtils for (String key : keys) { ColumnFamily cf = ColumnFamily.create(ksname, cfname); - cf.addColumn(new Column(ByteBuffer.wrap(key.getBytes()), ByteBuffer.wrap(key.getBytes()), 0)); + cf.addColumn(new Column(ByteBufferUtil.bytes(key), ByteBufferUtil.bytes(key), 0)); map.put(key, cf); } return write(map); @@ -135,8 +136,7 @@ public class SSTableUtils { DataOutputBuffer buffer = new DataOutputBuffer(); ColumnFamily.serializer().serializeWithIndexes(entry.getValue(), buffer); - map.put(ByteBuffer.wrap(entry.getKey().getBytes()), - ByteBuffer.wrap(buffer.asByteArray())); + map.put(ByteBufferUtil.bytes(entry.getKey()), ByteBuffer.wrap(buffer.asByteArray())); } return writeRaw(map); } diff --git a/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java b/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java index 56d7089ac4..42466e9f65 100644 --- a/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java +++ b/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java @@ -36,6 +36,7 @@ import org.apache.cassandra.db.Table; import org.apache.cassandra.dht.*; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.service.StorageServiceAccessor; +import org.apache.cassandra.utils.ByteBufferUtil; import static org.junit.Assert.*; @@ -68,7 +69,7 @@ public class SimpleStrategyTest extends CleanupHelper List keyTokens = new ArrayList(); for (int i = 0; i < 5; i++) { endpointTokens.add(new StringToken(String.valueOf((char)('a' + i * 2)))); - keyTokens.add(partitioner.getToken(ByteBuffer.wrap(String.valueOf((char)('a' + i * 2 + 1)).getBytes()))); + keyTokens.add(partitioner.getToken(ByteBufferUtil.bytes(String.valueOf((char)('a' + i * 2 + 1))))); } verifyGetNaturalEndpoints(endpointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0])); } diff --git a/test/unit/org/apache/cassandra/service/EmbeddedCassandraServiceTest.java b/test/unit/org/apache/cassandra/service/EmbeddedCassandraServiceTest.java index efd2e11500..143efa70cb 100644 --- a/test/unit/org/apache/cassandra/service/EmbeddedCassandraServiceTest.java +++ b/test/unit/org/apache/cassandra/service/EmbeddedCassandraServiceTest.java @@ -20,6 +20,7 @@ package org.apache.cassandra.service; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.charset.CharacterCodingException; import com.google.common.base.Charsets; import org.junit.BeforeClass; @@ -69,8 +70,8 @@ public class EmbeddedCassandraServiceTest extends CleanupHelper } @Test - public void testEmbeddedCassandraService() throws AuthenticationException, AuthorizationException, - InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException + public void testEmbeddedCassandraService() + throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, CharacterCodingException { Cassandra.Client client = getClient(); client.set_keyspace("Keyspace1"); @@ -84,14 +85,14 @@ public class EmbeddedCassandraServiceTest extends CleanupHelper // insert client.insert(key_user_id, par, new Column(ByteBufferUtil.bytes("name"), - ByteBuffer.wrap( "Ran".getBytes(Charsets.UTF_8)), timestamp), ConsistencyLevel.ONE); + ByteBufferUtil.bytes("Ran"), timestamp), ConsistencyLevel.ONE); // read ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE); // assert assertNotNull("Got a null ColumnOrSuperColumn", got); - assertEquals("Ran", new String(got.getColumn().getValue(), Charsets.UTF_8)); + assertEquals("Ran", ByteBufferUtil.string(got.getColumn().value)); } /** diff --git a/test/unit/org/apache/cassandra/streaming/SerializationsTest.java b/test/unit/org/apache/cassandra/streaming/SerializationsTest.java index 04d2f24d7d..af268dc8b5 100644 --- a/test/unit/org/apache/cassandra/streaming/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/streaming/SerializationsTest.java @@ -31,6 +31,7 @@ import org.apache.cassandra.dht.Range; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTable; import org.apache.cassandra.net.Message; +import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.Pair; import org.junit.Test; @@ -144,7 +145,7 @@ public class SerializationsTest extends AbstractSerializationsTester { Collection ranges = new ArrayList(); for (int i = 0; i < 5; i++) - ranges.add(new Range(new BytesToken(ByteBuffer.wrap(Integer.toString(10*i).getBytes())), new BytesToken(ByteBuffer.wrap(Integer.toString(10*i+5).getBytes())))); + ranges.add(new Range(new BytesToken(ByteBufferUtil.bytes(Integer.toString(10*i))), new BytesToken(ByteBufferUtil.bytes(Integer.toString(10*i+5))))); StreamRequestMessage msg0 = new StreamRequestMessage(FBUtilities.getLocalAddress(), ranges, "Keyspace1", 123L); StreamRequestMessage msg1 = new StreamRequestMessage(FBUtilities.getLocalAddress(), makePendingFile(true, "aa", 100), 124L); StreamRequestMessage msg2 = new StreamRequestMessage(FBUtilities.getLocalAddress(), makePendingFile(false, "aa", 100), 124L); @@ -180,8 +181,8 @@ public class SerializationsTest extends AbstractSerializationsTester Table t = Table.open("Keyspace1"); for (int i = 0; i < 100; i++) { - RowMutation rm = new RowMutation(t.name, ByteBuffer.wrap(Long.toString(System.nanoTime()).getBytes())); - rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("cola".getBytes())), ByteBuffer.wrap("value".getBytes()), 0); + RowMutation rm = new RowMutation(t.name, ByteBufferUtil.bytes(Long.toString(System.nanoTime()))); + rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("cola")), ByteBufferUtil.bytes("value"), 0); try { rm.apply(); diff --git a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java index d4bb97f3f0..29e250fe49 100644 --- a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java +++ b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java @@ -68,7 +68,7 @@ public class StreamingTransferTest extends CleanupHelper for (int i = 1; i <= 3; i++) { String key = "key" + i; - RowMutation rm = new RowMutation("Keyspace1", ByteBuffer.wrap(key.getBytes())); + RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(key)); ColumnFamily cf = ColumnFamily.create(table.name, cfs.columnFamily); cf.addColumn(column(key, "v", 0)); cf.addColumn(new Column(ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes((long) i), 0)); @@ -143,8 +143,8 @@ public class StreamingTransferTest extends CleanupHelper ColumnFamilyStore cfstore = Table.open(tablename).getColumnFamilyStore(cfname); List rows = Util.getRangeSlice(cfstore); assertEquals(6, rows.size()); - assert rows.get(0).key.key.equals( ByteBufferUtil.bytes("test")); - assert rows.get(3).key.key.equals(ByteBuffer.wrap( "transfer1".getBytes() )); + assert rows.get(0).key.key.equals(ByteBufferUtil.bytes("test")); + assert rows.get(3).key.key.equals(ByteBufferUtil.bytes("transfer1")); assert rows.get(0).cf.getColumnsMap().size() == 1; assert rows.get(3).cf.getColumnsMap().size() == 1; diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java index 50671eeb49..453f31340a 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java @@ -54,7 +54,7 @@ public class SSTableExportTest extends SchemaLoader { public String asHex(String str) { - return bytesToHex(ByteBuffer.wrap(str.getBytes())); + return bytesToHex(ByteBufferUtil.bytes(str)); } @Test diff --git a/test/unit/org/apache/cassandra/utils/ByteBufferUtilTest.java b/test/unit/org/apache/cassandra/utils/ByteBufferUtilTest.java index f89dd587ca..1c384abe8b 100644 --- a/test/unit/org/apache/cassandra/utils/ByteBufferUtilTest.java +++ b/test/unit/org/apache/cassandra/utils/ByteBufferUtilTest.java @@ -218,7 +218,7 @@ public class ByteBufferUtilTest public void testDecode() throws IOException { ByteBuffer bytes = ByteBuffer.wrap(new byte[]{(byte)0xff, (byte)0xfe}); - ByteBufferUtil.string(bytes, Charsets.UTF_8); + ByteBufferUtil.string(bytes); } @Test diff --git a/test/unit/org/apache/cassandra/utils/KeyGenerator.java b/test/unit/org/apache/cassandra/utils/KeyGenerator.java index 3ca15a7452..519c5809c6 100644 --- a/test/unit/org/apache/cassandra/utils/KeyGenerator.java +++ b/test/unit/org/apache/cassandra/utils/KeyGenerator.java @@ -92,7 +92,7 @@ public class KeyGenerator { } public ByteBuffer next() { - return ByteBuffer.wrap(Integer.toString(i++).getBytes()); + return ByteBufferUtil.bytes(Integer.toString(i++)); } public void remove() { From 7a7dd17d0d00e226208eabb9c916c31287350a9b Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 23 Mar 2011 18:56:21 +0000 Subject: [PATCH 04/15] allow negative numbers in the cli patch by Pavel Yaskevich; reviewed by jbellis for CASSANDRA-2358 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084674 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + src/java/org/apache/cassandra/cli/Cli.g | 1 + test/unit/org/apache/cassandra/cli/CliTest.java | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index f3b4e6ef35..af3f295daa 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,7 @@ * fix potential infinite loop in ByteBufferUtil.inputStream (CASSANDRA-2365) * fix encoding bugs in HintedHandoffManager, SystemTable when default charset is not UTF8 (CASSANDRA-2367) + * allow negative numbers in the cli (CASSANDRA-2358) 0.7.4 diff --git a/src/java/org/apache/cassandra/cli/Cli.g b/src/java/org/apache/cassandra/cli/Cli.g index 9dcf12423f..d0b9c99f09 100644 --- a/src/java/org/apache/cassandra/cli/Cli.g +++ b/src/java/org/apache/cassandra/cli/Cli.g @@ -569,6 +569,7 @@ Alnum // syntactic Elements IntegerLiteral : Digit+ + | '-' Digit+ ; DoubleLiteral diff --git a/test/unit/org/apache/cassandra/cli/CliTest.java b/test/unit/org/apache/cassandra/cli/CliTest.java index d13396445d..25d7587664 100644 --- a/test/unit/org/apache/cassandra/cli/CliTest.java +++ b/test/unit/org/apache/cassandra/cli/CliTest.java @@ -39,7 +39,11 @@ public class CliTest extends CleanupHelper "use TestKeySpace;", "create column family CF1 with comparator=UTF8Type and column_metadata=[{ column_name:world, validation_class:IntegerType, index_type:0, index_name:IdxName }, { column_name:world2, validation_class:LongType, index_type:KEYS, index_name:LongIdxName}];", "set CF1[hello][world] = 123848374878933948398384;", + "set CF1[hello][-31337] = 'some string value';", + "get CF1[hello][-31337];", "get CF1[hello][world];", + "set CF1[hello][-31337] = -23876;", + "set CF1[hello][-31337] = long(-23876);", "set CF1[hello][world2] = 15;", "get CF1 where world2 = long(15);", "get cF1 where world2 = long(15);", @@ -79,6 +83,10 @@ public class CliTest extends CleanupHelper "del SCF1['hello'][1][9999];", "get SCF1['hello'][1][9999];", "set SCF1['hello'][1][9999] = Long(1234);", + "set SCF1['hello'][-1][-12] = Long(5678);", + "get SCF1['hello'][-1][-12];", + "set SCF1['hello'][-1][-12] = -340897;", + "set SCF1['hello'][-1][-12] = integer(-340897);", "del SCF1['hello'][9999];", "get SCF1['hello'][1][9999];", "truncate CF1;", From 7d7de37d91310b8c8bac679ebce0c3b9dacc036e Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 23 Mar 2011 21:46:58 +0000 Subject: [PATCH 05/15] Show units on 'show keyspaces' cli output. Patch by Pavek Yaskevich, reviewed by Jon Hermes for CASSANDRA-2345 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084765 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/cassandra/cli/CliClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index 4dadb21ed3..b2bc55f0fb 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -1319,9 +1319,9 @@ public class CliClient extends CliUserHelp } sessionState.out.printf(" Columns sorted by: %s%s%n", cf_def.comparator_type, cf_def.column_type.equals("Super") ? "/" + cf_def.subcomparator_type : ""); - sessionState.out.printf(" Row cache size / save period: %s/%s%n", cf_def.row_cache_size, cf_def.row_cache_save_period_in_seconds); - sessionState.out.printf(" Key cache size / save period: %s/%s%n", cf_def.key_cache_size, cf_def.key_cache_save_period_in_seconds); - sessionState.out.printf(" Memtable thresholds: %s/%s/%s%n", + sessionState.out.printf(" Row cache size / save period in seconds: %s/%s%n", cf_def.row_cache_size, cf_def.row_cache_save_period_in_seconds); + sessionState.out.printf(" Key cache size / save period in seconds: %s/%s%n", cf_def.key_cache_size, cf_def.key_cache_save_period_in_seconds); + sessionState.out.printf(" Memtable thresholds: %s/%s/%s (millions of ops/minutes/MB)%n", cf_def.memtable_operations_in_millions, cf_def.memtable_throughput_in_mb, cf_def.memtable_flush_after_mins); sessionState.out.printf(" GC grace seconds: %s%n", cf_def.gc_grace_seconds); sessionState.out.printf(" Compaction min/max thresholds: %s/%s%n", cf_def.min_compaction_threshold, cf_def.max_compaction_threshold); From c7f6f168fb3bd09a65c3c9beb5c7328b7d6ce190 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Thu, 24 Mar 2011 02:32:26 +0000 Subject: [PATCH 06/15] s/Session/Repair session/ git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084830 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/cassandra/service/AntiEntropyService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/org/apache/cassandra/service/AntiEntropyService.java b/src/java/org/apache/cassandra/service/AntiEntropyService.java index 11cddea5ff..9e4ba7bfe9 100644 --- a/src/java/org/apache/cassandra/service/AntiEntropyService.java +++ b/src/java/org/apache/cassandra/service/AntiEntropyService.java @@ -804,7 +804,7 @@ public class AntiEntropyService return; // all requests completed - logger.info("Session " + getName() + " completed successfully."); + logger.info("Repair session " + getName() + " completed successfully."); AntiEntropyService.this.sessions.remove(getName()); completed.signalAll(); } From 253b34fe967f4aefa3d4798f31caebafd14fbc90 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Thu, 24 Mar 2011 13:23:34 +0000 Subject: [PATCH 07/15] add explicit serialVersionUID to Token subclasses patch by slebresne; reviewed by jbellis for CASSANDRA-2361 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1084948 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/cassandra/dht/BigIntegerToken.java | 2 ++ src/java/org/apache/cassandra/dht/BytesToken.java | 2 ++ src/java/org/apache/cassandra/dht/LocalToken.java | 2 ++ src/java/org/apache/cassandra/dht/StringToken.java | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/java/org/apache/cassandra/dht/BigIntegerToken.java b/src/java/org/apache/cassandra/dht/BigIntegerToken.java index a2c34f81de..5a9c5b9b6b 100644 --- a/src/java/org/apache/cassandra/dht/BigIntegerToken.java +++ b/src/java/org/apache/cassandra/dht/BigIntegerToken.java @@ -22,6 +22,8 @@ import java.math.BigInteger; public class BigIntegerToken extends Token { + static final long serialVersionUID = -5833589141319293006L; + public BigIntegerToken(BigInteger token) { super(token); diff --git a/src/java/org/apache/cassandra/dht/BytesToken.java b/src/java/org/apache/cassandra/dht/BytesToken.java index da17965a1b..580c3f1ff3 100644 --- a/src/java/org/apache/cassandra/dht/BytesToken.java +++ b/src/java/org/apache/cassandra/dht/BytesToken.java @@ -26,6 +26,8 @@ import org.apache.cassandra.utils.FBUtilities; public class BytesToken extends Token { + static final long serialVersionUID = -2630749093733680626L; + public BytesToken(ByteBuffer token) { this(ByteBufferUtil.getArray(token)); diff --git a/src/java/org/apache/cassandra/dht/LocalToken.java b/src/java/org/apache/cassandra/dht/LocalToken.java index 737cc8b909..e5f5f98410 100644 --- a/src/java/org/apache/cassandra/dht/LocalToken.java +++ b/src/java/org/apache/cassandra/dht/LocalToken.java @@ -24,6 +24,8 @@ import org.apache.cassandra.db.marshal.AbstractType; public class LocalToken extends Token { + static final long serialVersionUID = 8437543776403014875L; + private final AbstractType comparator; public LocalToken(AbstractType comparator, ByteBuffer token) diff --git a/src/java/org/apache/cassandra/dht/StringToken.java b/src/java/org/apache/cassandra/dht/StringToken.java index 7865dc0252..da28d1e3a4 100644 --- a/src/java/org/apache/cassandra/dht/StringToken.java +++ b/src/java/org/apache/cassandra/dht/StringToken.java @@ -21,6 +21,8 @@ package org.apache.cassandra.dht; public class StringToken extends Token { + static final long serialVersionUID = 5464084395277974963L; + public StringToken(String token) { super(token); From e05fb25675bf20567b530ed862116d0607841ad1 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 24 Mar 2011 18:59:31 +0000 Subject: [PATCH 08/15] Log a message when a streaming action for an unkown session is received instead of NPE. Patch by brandonwilliams, reviewed by jbellis for CASSANDRA-2377 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1085074 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/cassandra/streaming/StreamReplyVerbHandler.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/java/org/apache/cassandra/streaming/StreamReplyVerbHandler.java b/src/java/org/apache/cassandra/streaming/StreamReplyVerbHandler.java index 52f45eb85a..4094ec8342 100644 --- a/src/java/org/apache/cassandra/streaming/StreamReplyVerbHandler.java +++ b/src/java/org/apache/cassandra/streaming/StreamReplyVerbHandler.java @@ -46,6 +46,11 @@ public class StreamReplyVerbHandler implements IVerbHandler StreamReply reply = StreamReply.serializer.deserialize(new DataInputStream(bufIn)); logger.debug("Received StreamReply {}", reply); StreamOutSession session = StreamOutSession.get(message.getFrom(), reply.sessionId); + if (session == null) + { + logger.debug("Received stream action " + reply.action + " for an unknown session from " + message.getFrom()); + return; + } switch (reply.action) { From 37d063ee97e9521d3fb84d1427f3ef4adc0939b9 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Fri, 25 Mar 2011 13:59:45 +0000 Subject: [PATCH 09/15] fsync statistics component on write patch by jbellis; reviewed by brandonwilliams for CASSANDRA-2382 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1085372 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../apache/cassandra/io/sstable/SSTableWriter.java | 5 ++++- .../apache/cassandra/utils/EstimatedHistogram.java | 12 ++++++------ .../apache/cassandra/io/CompactSerializerTest.java | 1 - 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index af3f295daa..f4be29becb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,6 +18,7 @@ * fix encoding bugs in HintedHandoffManager, SystemTable when default charset is not UTF8 (CASSANDRA-2367) * allow negative numbers in the cli (CASSANDRA-2358) + * fsync statistics component on write (CASSANDRA-2382) 0.7.4 diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java index 809a3f4353..dd362da243 100644 --- a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java @@ -198,7 +198,10 @@ public class SSTableWriter extends SSTable private static void writeStatistics(Descriptor desc, EstimatedHistogram rowSizes, EstimatedHistogram columnnCounts) throws IOException { - DataOutputStream out = new DataOutputStream(new FileOutputStream(desc.filenameFor(SSTable.COMPONENT_STATS))); + BufferedRandomAccessFile out = new BufferedRandomAccessFile(new File(desc.filenameFor(SSTable.COMPONENT_STATS)), + "rw", + BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE, + true); EstimatedHistogram.serializer.serialize(rowSizes, out); EstimatedHistogram.serializer.serialize(columnnCounts, out); out.close(); diff --git a/src/java/org/apache/cassandra/utils/EstimatedHistogram.java b/src/java/org/apache/cassandra/utils/EstimatedHistogram.java index 2374dd4dc9..ec6b285933 100644 --- a/src/java/org/apache/cassandra/utils/EstimatedHistogram.java +++ b/src/java/org/apache/cassandra/utils/EstimatedHistogram.java @@ -18,13 +18,13 @@ */ package org.apache.cassandra.utils; -import java.io.DataInputStream; -import java.io.DataOutputStream; +import java.io.DataInput; +import java.io.DataOutput; import java.io.IOException; import java.util.Arrays; import java.util.concurrent.atomic.AtomicLongArray; -import org.apache.cassandra.io.ICompactSerializer; +import org.apache.cassandra.io.ICompactSerializer2; public class EstimatedHistogram { @@ -188,9 +188,9 @@ public class EstimatedHistogram return buckets.get(buckets.length() - 1) > 0; } - public static class EstimatedHistogramSerializer implements ICompactSerializer + public static class EstimatedHistogramSerializer implements ICompactSerializer2 { - public void serialize(EstimatedHistogram eh, DataOutputStream dos) throws IOException + public void serialize(EstimatedHistogram eh, DataOutput dos) throws IOException { long[] offsets = eh.getBucketOffsets(); long[] buckets = eh.getBuckets(false); @@ -202,7 +202,7 @@ public class EstimatedHistogram } } - public EstimatedHistogram deserialize(DataInputStream dis) throws IOException + public EstimatedHistogram deserialize(DataInput dis) throws IOException { int size = dis.readInt(); long[] offsets = new long[size - 1]; diff --git a/test/unit/org/apache/cassandra/io/CompactSerializerTest.java b/test/unit/org/apache/cassandra/io/CompactSerializerTest.java index ace90d73c3..302b17b34e 100644 --- a/test/unit/org/apache/cassandra/io/CompactSerializerTest.java +++ b/test/unit/org/apache/cassandra/io/CompactSerializerTest.java @@ -68,7 +68,6 @@ public class CompactSerializerTest extends CleanupHelper expectedClassNames.add("FileStatusSerializer"); expectedClassNames.add("StreamRequestMessageSerializer"); expectedClassNames.add("BloomFilterSerializer"); - expectedClassNames.add("EstimatedHistogramSerializer"); expectedClassNames.add("LegacyBloomFilterSerializer"); discoveredClassNames = new ArrayList(); From a590dac59c8a8893e98360bd9bc04bd05b348b49 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Fri, 25 Mar 2011 19:47:00 +0000 Subject: [PATCH 10/15] more info on failed key/column name length assert git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1085538 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/cassandra/utils/ByteBufferUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java index 8507114b56..58a0ce61cd 100644 --- a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java +++ b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java @@ -292,7 +292,7 @@ public class ByteBufferUtil public static void writeWithShortLength(ByteBuffer buffer, DataOutput out) { int length = buffer.remaining(); - assert 0 <= length && length <= FBUtilities.MAX_UNSIGNED_SHORT; + assert 0 <= length && length <= FBUtilities.MAX_UNSIGNED_SHORT : length; try { out.writeByte((length >> 8) & 0xFF); From 469f947cf7322f0f5edae7331972a14a66040a49 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Sun, 27 Mar 2011 05:28:41 +0000 Subject: [PATCH 11/15] specify UTF8Type comparator to fix regression found by Jingguo Yao patch by jbellis for CASSANDRA-2390 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1085877 13f79535-47bb-0310-9956-ffa450edef68 --- conf/schema-sample.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/schema-sample.txt b/conf/schema-sample.txt index dacc3d47d9..83e109d718 100644 --- a/conf/schema-sample.txt +++ b/conf/schema-sample.txt @@ -53,7 +53,8 @@ create column family Super3 and comment = 'A column family with supercolumns, whose column names are Longs (8 bytes)'; create column family Indexed1 - with default_validation_class = LongType + with comparator = UTF8Type + and default_validation_class = LongType and column_metadata = [{ column_name : birthdate, validation_class : LongType, From 8e180e8764d2dffd6c71ca399b51c24dcee268d6 Mon Sep 17 00:00:00 2001 From: Sylvain Lebresne Date: Mon, 28 Mar 2011 16:14:39 +0000 Subject: [PATCH 12/15] Don't cast block offsets to int patch by jbellis; reviewed by slebresne for CASSANDRA-2376 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1086290 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../db/columniterator/IndexedSliceReader.java | 4 +-- .../columniterator/SSTableNamesIterator.java | 3 +-- .../hadoop/streaming/AvroOutputReader.java | 12 +++------ .../cassandra/io/sstable/IndexHelper.java | 8 +++--- .../apache/cassandra/io/sstable/SSTable.java | 2 +- .../apache/cassandra/io/util/FileUtils.java | 25 +++++++++++++++++++ .../cassandra/utils/ByteBufferUtil.java | 9 +++---- 8 files changed, 40 insertions(+), 25 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f4be29becb..0d3bc214d7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,8 @@ charset is not UTF8 (CASSANDRA-2367) * allow negative numbers in the cli (CASSANDRA-2358) * fsync statistics component on write (CASSANDRA-2382) + * fix incorrect truncation of long to int when reading columns via block + index (CASSANDRA-2376) 0.7.4 diff --git a/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java b/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java index 105703625e..b264c6957d 100644 --- a/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java +++ b/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java @@ -39,6 +39,7 @@ import org.apache.cassandra.io.sstable.IndexHelper; import org.apache.cassandra.io.util.FileDataInput; import org.apache.cassandra.io.util.FileMark; import org.apache.cassandra.io.sstable.SSTableReader; +import org.apache.cassandra.io.util.FileUtils; /** * This is a reader that finds the block for a starting column and returns @@ -172,8 +173,7 @@ class IndexedSliceReader extends AbstractIterator implements IColumnIte boolean outOfBounds = false; file.reset(mark); - long curOffset = file.skipBytes((int) curColPosition.offset); - assert curOffset == curColPosition.offset; + FileUtils.skipBytesFully(file, curColPosition.offset); while (file.bytesPastMark(mark) < curColPosition.offset + curColPosition.width && !outOfBounds) { IColumn column = emptyColumnFamily.getColumnSerializer().deserialize(file); diff --git a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java index 93e6a96ed0..6cbc64bae0 100644 --- a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java +++ b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java @@ -172,8 +172,7 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator implement for (IndexHelper.IndexInfo indexInfo : ranges) { file.reset(mark); - long curOffsert = file.skipBytes((int) indexInfo.offset); - assert curOffsert == indexInfo.offset; + FileUtils.skipBytesFully(file, indexInfo.offset); // TODO only completely deserialize columns we are interested in while (file.bytesPastMark(mark) < indexInfo.offset + indexInfo.width) { diff --git a/src/java/org/apache/cassandra/hadoop/streaming/AvroOutputReader.java b/src/java/org/apache/cassandra/hadoop/streaming/AvroOutputReader.java index 7fdbf47125..f7a7f3bf93 100644 --- a/src/java/org/apache/cassandra/hadoop/streaming/AvroOutputReader.java +++ b/src/java/org/apache/cassandra/hadoop/streaming/AvroOutputReader.java @@ -32,6 +32,7 @@ import org.apache.avro.io.DecoderFactory; import org.apache.avro.specific.SpecificDatumReader; import org.apache.cassandra.avro.Mutation; import org.apache.cassandra.avro.StreamingMutation; +import org.apache.cassandra.io.util.FileUtils; import org.apache.hadoop.streaming.PipeMapRed; import org.apache.hadoop.streaming.io.OutputReader; @@ -139,15 +140,8 @@ public class AvroOutputReader extends OutputReader> @Override public long skip(long n) throws IOException { - long skipped = 0; - while (n > 0) - { - // skip in batches up to max_int in size - int skip = (int)Math.min(Integer.MAX_VALUE, n); - skipped += in.skipBytes(skip); - n -= skip; - } - return skipped; + FileUtils.skipBytesFully(in, n); + return n; } } } diff --git a/src/java/org/apache/cassandra/io/sstable/IndexHelper.java b/src/java/org/apache/cassandra/io/sstable/IndexHelper.java index 74d1f7c119..202c7df056 100644 --- a/src/java/org/apache/cassandra/io/sstable/IndexHelper.java +++ b/src/java/org/apache/cassandra/io/sstable/IndexHelper.java @@ -28,6 +28,7 @@ import java.util.List; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.io.util.FileDataInput; import org.apache.cassandra.io.util.FileMark; +import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.utils.*; /** @@ -46,9 +47,7 @@ public class IndexHelper /* size of the bloom filter */ int size = in.readInt(); /* skip the serialized bloom filter */ - int skipped = in.skipBytes(size); - if (skipped != size) - throw new EOFException("attempted to skip " + size + " bytes but only skipped " + skipped); + FileUtils.skipBytesFully(in, size); } /** @@ -61,8 +60,7 @@ public class IndexHelper /* read only the column index list */ int columnIndexSize = file.readInt(); /* skip the column index data */ - if (file.skipBytes(columnIndexSize) != columnIndexSize) - throw new EOFException(); + FileUtils.skipBytesFully(file, columnIndexSize); } /** diff --git a/src/java/org/apache/cassandra/io/sstable/SSTable.java b/src/java/org/apache/cassandra/io/sstable/SSTable.java index 6b4d517622..4b56c28137 100644 --- a/src/java/org/apache/cassandra/io/sstable/SSTable.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTable.java @@ -227,7 +227,7 @@ public abstract class SSTable while (ifile.getFilePointer() < BYTES_CAP && keys < SAMPLES_CAP) { ByteBufferUtil.skipShortLength(ifile); - ifile.skipBytes(8); + FileUtils.skipBytesFully(ifile, 8); keys++; } assert keys > 0 && ifile.getFilePointer() > 0 && ifile.length() > 0; diff --git a/src/java/org/apache/cassandra/io/util/FileUtils.java b/src/java/org/apache/cassandra/io/util/FileUtils.java index 251d80ff2b..265768c5f5 100644 --- a/src/java/org/apache/cassandra/io/util/FileUtils.java +++ b/src/java/org/apache/cassandra/io/util/FileUtils.java @@ -210,4 +210,29 @@ public class FileUtils // The directory is now empty so now it can be smoked deleteWithConfirm(dir); } + + public static void skipBytesFully(DataInput in, int bytes) throws IOException + { + int n = 0; + while (n < bytes) + { + int skipped = in.skipBytes(bytes - n); + if (skipped == 0) + throw new EOFException("EOF after " + n + " bytes out of " + bytes); + n += skipped; + } + } + + public static void skipBytesFully(DataInput in, long bytes) throws IOException + { + long n = 0; + while (n < bytes) + { + int m = (int) Math.min(Integer.MAX_VALUE, bytes - n); + int skipped = in.skipBytes(m); + if (skipped == 0) + throw new EOFException("EOF after " + n + " bytes out of " + bytes); + n += skipped; + } + } } diff --git a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java index 58a0ce61cd..2c0ce47185 100644 --- a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java +++ b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java @@ -31,6 +31,8 @@ import java.util.Arrays; import static com.google.common.base.Charsets.UTF_8; import org.apache.cassandra.io.util.FileDataInput; +import org.apache.cassandra.io.util.FileUtils; + import org.apache.commons.lang.ArrayUtils; /** @@ -341,12 +343,7 @@ public class ByteBufferUtil public static ByteBuffer skipShortLength(DataInput in) throws IOException { int skip = readShortLength(in); - while (skip > 0) - { - int skipped = in.skipBytes(skip); - if (skipped == 0) throw new EOFException(); - skip -= skipped; - } + FileUtils.skipBytesFully(in, skip); return null; } From 979ce41ef44a0444188f73ab0ab4ce8253d1c3fe Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Mon, 28 Mar 2011 19:05:32 +0000 Subject: [PATCH 13/15] fix migration race vs flush patch by jbellis; reviewed by gdusbabek for CASSANDRA-2381 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1086343 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + NEWS.txt | 15 +++++++ .../cassandra/thrift/ConsistencyLevel.java | 27 +++++++++--- .../cassandra/db/ColumnFamilyStore.java | 15 ++++--- .../org/apache/cassandra/db/Memtable.java | 13 ++++-- .../cassandra/db/RowIteratorFactory.java | 4 +- src/java/org/apache/cassandra/db/Table.java | 16 +++---- .../db/migration/DropColumnFamily.java | 44 +++++++++---------- .../cassandra/db/migration/DropKeyspace.java | 36 ++++++++------- .../cassandra/db/migration/Migration.java | 18 -------- .../db/migration/UpdateColumnFamily.java | 8 ---- 11 files changed, 104 insertions(+), 94 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0d3bc214d7..3696214a69 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,8 @@ * fsync statistics component on write (CASSANDRA-2382) * fix incorrect truncation of long to int when reading columns via block index (CASSANDRA-2376) + * fix race condition that could leave orphaned data files when + dropping CF or KS (CASSANDRA-2381) 0.7.4 diff --git a/NEWS.txt b/NEWS.txt index f608075a44..a94a2126ed 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,3 +1,18 @@ +0.7.5 +===== + +Upgrading +--------- + - Nothing specific to 0.7.4, but see 0.7.3 Upgrading if upgrading + from earlier than 0.7.1. + +Changes +------- + - system_update_column_family no longer snapshots before applying + the schema change. (_update_keyspace never did. _drop_keyspace + and _drop_column_family continue to snapshot.) + + 0.7.4 ===== diff --git a/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java b/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java index 7a0fc55c87..ee09ae8b80 100644 --- a/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java +++ b/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java @@ -32,13 +32,26 @@ import java.util.HashMap; import org.apache.thrift.TEnum; /** - * The ConsistencyLevel is an enum that controls both read and write behavior based on the ReplicationFactor of the keyspace. - * The different consistency levels have different meanings, depending on if you're doing a write or read - * operation. Note that if W + R > ReplicationFactor, where W is the number of nodes to block for on write, and R - * the number to block for on reads, you will have strongly consistent behavior; that is, readers will always see the most - * recent write. Of these, the most interesting is to do QUORUM reads and writes, which gives you consistency while still - * allowing availability in the face of node failures up to half of . Of course if latency is more - * important than consistency then you can use lower values for either or both. + * The ConsistencyLevel is an enum that controls both read and write + * behavior based on the ReplicationFactor of the keyspace. The + * different consistency levels have different meanings, depending on + * if you're doing a write or read operation. + * + * If W + R > ReplicationFactor, where W is the number of nodes to + * block for on write, and R the number to block for on reads, you + * will have strongly consistent behavior; that is, readers will + * always see the most recent write. Of these, the most interesting is + * to do QUORUM reads and writes, which gives you consistency while + * still allowing availability in the face of node failures up to half + * of . Of course if latency is more important than + * consistency then you can use lower values for either or both. + * + * Some ConsistencyLevels (ONE, TWO, THREE) refer to a specific number + * of replicas rather than a logical concept that adjusts + * automatically with the replication factor. Of these, only ONE is + * commonly used; TWO and (even more rarely) THREE are only useful + * when you care more about guaranteeing a certain level of + * durability, than consistency. * * Write consistency levels make the following guarantees before reporting success to the client: * ANY Ensure that the write has been written once somewhere, including possibly being hinted in a non-target node. diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 43b0338500..047ef47238 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -25,6 +25,8 @@ import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Pattern; import javax.management.MBeanServer; import javax.management.ObjectName; @@ -136,6 +138,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean private volatile DefaultInteger rowCacheSaveInSeconds; private volatile DefaultInteger keyCacheSaveInSeconds; + /** Lock to allow migrations to block all flushing, so we can be sure not to write orphaned data files */ + public final Lock flushLock = new ReentrantLock(); + // Locally held row/key cache scheduled tasks private volatile ScheduledFuture saveRowCacheTask; private volatile ScheduledFuture saveKeyCacheTask; @@ -695,7 +700,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean * contexts (commitlog position) were read, even though the flush executor * is multithreaded. */ - Table.flusherLock.writeLock().lock(); + Table.switchLock.writeLock().lock(); try { if (oldMemtable.isFrozen()) @@ -759,7 +764,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean } finally { - Table.flusherLock.writeLock().unlock(); + Table.switchLock.writeLock().unlock(); } } @@ -1084,14 +1089,14 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean */ private Memtable getMemtableThreadSafe() { - Table.flusherLock.readLock().lock(); + Table.switchLock.readLock().lock(); try { return memtable; } finally { - Table.flusherLock.readLock().unlock(); + Table.switchLock.readLock().unlock(); } } @@ -1138,7 +1143,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean // TODO this actually isn't a good meature of pending tasks public int getPendingTasks() { - return Table.flusherLock.getQueueLength(); + return Table.switchLock.getQueueLength(); } public long getWriteCount() diff --git a/src/java/org/apache/cassandra/db/Memtable.java b/src/java/org/apache/cassandra/db/Memtable.java index c52e8de647..cdff33a987 100644 --- a/src/java/org/apache/cassandra/db/Memtable.java +++ b/src/java/org/apache/cassandra/db/Memtable.java @@ -37,7 +37,6 @@ import com.google.common.collect.PeekingIterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.cassandra.config.ConfigurationException; import org.apache.cassandra.db.columniterator.IColumnIterator; import org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator; import org.apache.cassandra.db.filter.AbstractColumnIterator; @@ -173,8 +172,16 @@ public class Memtable implements Comparable, IFlushable { public void runMayThrow() throws IOException { - cfs.addSSTable(writeSortedContents()); - cfs.getMemtablesPendingFlush().remove(Memtable.this); + cfs.flushLock.lock(); + try + { + cfs.addSSTable(writeSortedContents()); + cfs.getMemtablesPendingFlush().remove(Memtable.this); + } + finally + { + cfs.flushLock.unlock(); + } latch.countDown(); } }); diff --git a/src/java/org/apache/cassandra/db/RowIteratorFactory.java b/src/java/org/apache/cassandra/db/RowIteratorFactory.java index 3d31ff0e0e..8e2d1bc28d 100644 --- a/src/java/org/apache/cassandra/db/RowIteratorFactory.java +++ b/src/java/org/apache/cassandra/db/RowIteratorFactory.java @@ -169,14 +169,14 @@ public class RowIteratorFactory */ private static Iterator> memtableEntryIterator(Memtable memtable, DecoratedKey startWith) { - Table.flusherLock.readLock().lock(); + Table.switchLock.readLock().lock(); try { return memtable.getEntryIterator(startWith); } finally { - Table.flusherLock.readLock().unlock(); + Table.switchLock.readLock().unlock(); } } diff --git a/src/java/org/apache/cassandra/db/Table.java b/src/java/org/apache/cassandra/db/Table.java index 531ce84fad..8819ce2f18 100644 --- a/src/java/org/apache/cassandra/db/Table.java +++ b/src/java/org/apache/cassandra/db/Table.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; import com.google.common.base.Function; @@ -61,7 +60,7 @@ public class Table * accesses to CFS.memtable should acquire this for thread safety. * Table.maybeSwitchMemtable should aquire the writeLock; see that method for the full explanation. */ - static final ReentrantReadWriteLock flusherLock = new ReentrantReadWriteLock(); + static final ReentrantReadWriteLock switchLock = new ReentrantReadWriteLock(); // It is possible to call Table.open without a running daemon, so it makes sense to ensure // proper directories here as well as in CassandraDaemon. @@ -115,11 +114,6 @@ public class Table } return tableInstance; } - - public static Lock getFlushLock() - { - return flusherLock.writeLock(); - } public static Table clear(String table) throws IOException { @@ -343,7 +337,7 @@ public class Table logger.debug("applying mutation of row {}", ByteBufferUtil.bytesToHex(mutation.key())); // write the mutation to the commitlog and memtables - flusherLock.readLock().lock(); + switchLock.readLock().lock(); try { if (writeCommitLog) @@ -407,7 +401,7 @@ public class Table } finally { - flusherLock.readLock().unlock(); + switchLock.readLock().unlock(); } // flush memtables that got filled up outside the readlock (maybeSwitchMemtable acquires writeLock). @@ -562,7 +556,7 @@ public class Table DecoratedKey key = iter.next(); logger.debug("Indexing row {} ", key); List memtablesToFlush = Collections.emptyList(); - flusherLock.readLock().lock(); + switchLock.readLock().lock(); try { synchronized (indexLockFor(key.key)) @@ -574,7 +568,7 @@ public class Table } finally { - flusherLock.readLock().unlock(); + switchLock.readLock().unlock(); } // during index build, we do flush index memtables separately from master; otherwise we could OOM diff --git a/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java b/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java index 6ac1c7792d..e27d3d0ccb 100644 --- a/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java +++ b/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java @@ -9,6 +9,7 @@ import org.apache.cassandra.config.ConfigurationException; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.CompactionManager; import org.apache.cassandra.db.Table; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.UUIDGen; @@ -66,36 +67,31 @@ public class DropColumnFamily extends Migration return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()])); } - @Override - public void beforeApplyModels() - { - if (clientMode) - return; - ColumnFamilyStore cfs = Table.open(tableName).getColumnFamilyStore(cfName); - cfs.snapshot(Table.getTimestampedSnapshotName(null)); - } - - @Override public void applyModels() throws IOException { - acquireLocks(); - try + ColumnFamilyStore cfs = Table.open(tableName).getColumnFamilyStore(cfName); + + // reinitialize the table. + KSMetaData existing = DatabaseDescriptor.getTableDefinition(tableName); + CFMetaData cfm = existing.cfMetaData().get(cfName); + KSMetaData ksm = makeNewKeyspaceDefinition(existing); + CFMetaData.purge(cfm); + DatabaseDescriptor.setTableDefinition(ksm, newVersion); + + if (!clientMode) { - // reinitialize the table. - KSMetaData existing = DatabaseDescriptor.getTableDefinition(tableName); - CFMetaData cfm = existing.cfMetaData().get(cfName); - KSMetaData ksm = makeNewKeyspaceDefinition(existing); - CFMetaData.purge(cfm); - DatabaseDescriptor.setTableDefinition(ksm, newVersion); - - if (!clientMode) + CompactionManager.instance.getCompactionLock().lock(); + cfs.flushLock.lock(); + try { + cfs.snapshot(Table.getTimestampedSnapshotName(null)); Table.open(ksm.name).dropCf(cfm.cfId); } - } - finally - { - releaseLocks(); + finally + { + cfs.flushLock.unlock(); + CompactionManager.instance.getCompactionLock().unlock(); + } } } diff --git a/src/java/org/apache/cassandra/db/migration/DropKeyspace.java b/src/java/org/apache/cassandra/db/migration/DropKeyspace.java index 0e69a5aefa..1fefbdaf4d 100644 --- a/src/java/org/apache/cassandra/db/migration/DropKeyspace.java +++ b/src/java/org/apache/cassandra/db/migration/DropKeyspace.java @@ -24,6 +24,8 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.ConfigurationException; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.KSMetaData; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.CompactionManager; import org.apache.cassandra.db.HintedHandOffManager; import org.apache.cassandra.db.Table; import org.apache.cassandra.utils.FBUtilities; @@ -46,35 +48,37 @@ public class DropKeyspace extends Migration rm = makeDefinitionMutation(null, ksm, newVersion); } - @Override - public void beforeApplyModels() - { - if (!clientMode) - Table.open(name).snapshot(null); - } - - @Override public void applyModels() throws IOException { - acquireLocks(); + String snapshotName = Table.getTimestampedSnapshotName(null); + CompactionManager.instance.getCompactionLock().lock(); try { KSMetaData ksm = DatabaseDescriptor.getTableDefinition(name); - // remove the table from the static instances. - Table table = Table.clear(ksm.name); - if (table == null) - throw new IOException("Table is not active. " + ksm.name); - + // remove all cfs from the table instance. for (CFMetaData cfm : ksm.cfMetaData().values()) { + ColumnFamilyStore cfs = Table.open(ksm.name).getColumnFamilyStore(cfm.cfName); CFMetaData.purge(cfm); if (!clientMode) { - table.dropCf(cfm.cfId); + cfs.flushLock.lock(); + try + { + cfs.snapshot(snapshotName); + Table.open(ksm.name).dropCf(cfm.cfId); + } + finally + { + cfs.flushLock.unlock(); + } } } + // remove the table from the static instances. + Table table = Table.clear(ksm.name); + assert table != null; // reset defs. DatabaseDescriptor.clearTableDefinition(ksm, newVersion); @@ -86,7 +90,7 @@ public class DropKeyspace extends Migration } finally { - releaseLocks(); + CompactionManager.instance.getCompactionLock().unlock(); } } diff --git a/src/java/org/apache/cassandra/db/migration/Migration.java b/src/java/org/apache/cassandra/db/migration/Migration.java index fe3ff95811..ef55b8cb26 100644 --- a/src/java/org/apache/cassandra/db/migration/Migration.java +++ b/src/java/org/apache/cassandra/db/migration/Migration.java @@ -92,22 +92,6 @@ public abstract class Migration this.lastVersion = lastVersion; } - // block compactions and flushing. - protected final void acquireLocks() - { - CompactionManager.instance.getCompactionLock().lock(); - Table.getFlushLock().lock(); - } - - protected final void releaseLocks() - { - Table.getFlushLock().unlock(); - CompactionManager.instance.getCompactionLock().unlock(); - } - - /** override this to perform logic before writing the migration or applying it. defaults to nothing. */ - public void beforeApplyModels() {} - /** apply changes */ public final void apply() throws IOException, ConfigurationException { @@ -119,8 +103,6 @@ public abstract class Migration if (!clientMode) rm.apply(); - beforeApplyModels(); - // write migration. if (!clientMode) { diff --git a/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java b/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java index 472cf8b787..80bb1e1075 100644 --- a/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java +++ b/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java @@ -65,14 +65,6 @@ public class UpdateColumnFamily extends Migration newKsMeta.cfMetaData().get(cf_def.name.toString()).apply(cf_def); rm = Migration.makeDefinitionMutation(newKsMeta, null, newVersion); } - - public void beforeApplyModels() - { - if (clientMode) - return; - ColumnFamilyStore cfs = Table.open(metadata.tableName).getColumnFamilyStore(metadata.cfName); - cfs.snapshot(Table.getTimestampedSnapshotName(null)); - } void applyModels() throws IOException { From 92da3e2d60a37999110648528fc7cb7659dd66e6 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Mon, 28 Mar 2011 19:15:18 +0000 Subject: [PATCH 14/15] add actual dropped check to Memtable.flush for CASSANDRA-2381 patch by jbellis git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1086350 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/cassandra/db/ColumnFamilyStore.java | 12 ++++++++---- src/java/org/apache/cassandra/db/Memtable.java | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 047ef47238..629ad4e36e 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -709,10 +709,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean return null; } - boolean isDropped = isIndex() - ? DatabaseDescriptor.getCFMetaData(table.name, getParentColumnfamily()) == null - : DatabaseDescriptor.getCFMetaData(metadata.cfId) == null; - if (isDropped) + if (isDropped()) { logger.debug("column family was dropped; no point in flushing"); return null; @@ -768,6 +765,13 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean } } + public boolean isDropped() + { + return isIndex() + ? DatabaseDescriptor.getCFMetaData(table.name, getParentColumnfamily()) == null + : DatabaseDescriptor.getCFMetaData(metadata.cfId) == null; + } + void switchBinaryMemtable(DecoratedKey key, ByteBuffer buffer) { binaryMemtable.set(new BinaryMemtable(this)); diff --git a/src/java/org/apache/cassandra/db/Memtable.java b/src/java/org/apache/cassandra/db/Memtable.java index cdff33a987..3c39bb24fd 100644 --- a/src/java/org/apache/cassandra/db/Memtable.java +++ b/src/java/org/apache/cassandra/db/Memtable.java @@ -175,8 +175,11 @@ public class Memtable implements Comparable, IFlushable cfs.flushLock.lock(); try { - cfs.addSSTable(writeSortedContents()); - cfs.getMemtablesPendingFlush().remove(Memtable.this); + if (!cfs.isDropped()) + { + cfs.addSSTable(writeSortedContents()); + cfs.getMemtablesPendingFlush().remove(Memtable.this); + } } finally { From 323ee4606cf4bd20cc98d2a2e7986386e9a83822 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Mon, 28 Mar 2011 19:17:19 +0000 Subject: [PATCH 15/15] r/m unnecessary isDropped check from maybeSwitchMemtable (the one in Memtable.writeSortedContents it the important one) patch by jbellis for CASSANDRA-2381 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1086351 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/cassandra/db/ColumnFamilyStore.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 629ad4e36e..f1f1956cce 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -709,12 +709,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean return null; } - if (isDropped()) - { - logger.debug("column family was dropped; no point in flushing"); - return null; - } - assert memtable == oldMemtable; memtable.freeze(); final CommitLogSegment.CommitLogContext ctx = writeCommitLog ? CommitLog.instance.getContext() : null;