From d37084b119bc49380cb2123161d24f20b6f298c8 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 2 Nov 2011 15:54:13 +0000 Subject: [PATCH 1/3] switch from PrintGCTimeStamps (time-elapsed-since-jvm-start, which is almost useless) to PrintGCDateStamps (wall clock time in ISO 8601) git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-1.0@1196653 13f79535-47bb-0310-9956-ffa450edef68 --- conf/cassandra-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/cassandra-env.sh b/conf/cassandra-env.sh index 1c3c0edda8..5e595c2cf4 100644 --- a/conf/cassandra-env.sh +++ b/conf/cassandra-env.sh @@ -164,7 +164,7 @@ JVM_OPTS="$JVM_OPTS -XX:+UseCMSInitiatingOccupancyOnly" # GC logging options -- uncomment to enable # JVM_OPTS="$JVM_OPTS -XX:+PrintGCDetails" -# JVM_OPTS="$JVM_OPTS -XX:+PrintGCTimeStamps" +# JVM_OPTS="$JVM_OPTS -XX:+PrintGCDateStamps" # JVM_OPTS="$JVM_OPTS -XX:+PrintHeapAtGC" # JVM_OPTS="$JVM_OPTS -XX:+PrintTenuringDistribution" # JVM_OPTS="$JVM_OPTS -XX:+PrintGCApplicationStoppedTime" From b2dcd3e5a5600be55c558eb5e20833ecec8264d1 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Thu, 3 Nov 2011 04:52:01 +0000 Subject: [PATCH 2/3] fix DecimalType bytebuffer marshalling patch by Rick Shaw; reviewed by jbellis for CASSANDRA-3421 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-1.0@1196941 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + .../cassandra/cql/jdbc/JdbcDecimal.java | 8 +- .../cassandra/db/marshal/DecimalType.java | 9 ++ .../cassandra/db/marshal/DecimalTypeTest.java | 101 ++++++++++++++++++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 test/unit/org/apache/cassandra/db/marshal/DecimalTypeTest.java diff --git a/CHANGES.txt b/CHANGES.txt index e897761e29..d39c6ff778 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,8 @@ Merged from 0.8: * acquire compactionlock during truncate (CASSANDRA-3399) * fix bug that caused first column in per row indexes to be ignored (CASSANDRA-3441) + * fix DecimalType bytebuffer marshalling (CASSANDRA-3421) + 1.0.1 * acquire references during index build to prevent delete problems diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java index 8879a6bac2..f97634ed8c 100644 --- a/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java +++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java @@ -86,12 +86,14 @@ public class JdbcDecimal extends AbstractJdbcType public BigDecimal compose(ByteBuffer bytes) { if (bytes == null) return null; - + + // do not consume the contents of the ByteBuffer + bytes = bytes.duplicate(); int scale = bytes.getInt(); byte[] bibytes = new byte[bytes.remaining()]; - bytes.get(bibytes, 0, bytes.remaining()); + bytes.get(bibytes); + BigInteger bi = new BigInteger(bibytes); - return new BigDecimal(bi,scale); } } diff --git a/src/java/org/apache/cassandra/db/marshal/DecimalType.java b/src/java/org/apache/cassandra/db/marshal/DecimalType.java index 56381d900c..e98e228050 100644 --- a/src/java/org/apache/cassandra/db/marshal/DecimalType.java +++ b/src/java/org/apache/cassandra/db/marshal/DecimalType.java @@ -35,6 +35,15 @@ public class DecimalType extends AbstractType public int compare(ByteBuffer bb0, ByteBuffer bb1) { + if (bb0.remaining() == 0) + { + return bb1.remaining() == 0 ? 0 : -1; + } + if (bb1.remaining() == 0) + { + return 1; + } + return compose(bb0).compareTo(compose(bb1)); } diff --git a/test/unit/org/apache/cassandra/db/marshal/DecimalTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/DecimalTypeTest.java new file mode 100644 index 0000000000..db410833a1 --- /dev/null +++ b/test/unit/org/apache/cassandra/db/marshal/DecimalTypeTest.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cassandra.db.marshal; + +import static org.junit.Assert.*; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.util.Arrays; + +import org.apache.cassandra.db.marshal.DecimalType; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.junit.Test; + +public class DecimalTypeTest +{ + private static final String LOW = "12.34"; + private static final String HIGH = "34.5678"; + + private static BigDecimal zero = new BigDecimal("0.0"); + private static BigDecimal minus = new BigDecimal("-1.000001"); + private static BigDecimal low = new BigDecimal(LOW); + private static BigDecimal high = new BigDecimal(HIGH); + + @Test + public void test1Decompose_compose() + { + ByteBuffer bb = DecimalType.instance.decompose(low); + + String string = DecimalType.instance.compose(bb).toPlainString(); + + // check that the decomposed buffer when re-composed is equal to the initial string. + assertEquals(LOW, string); + + // check that a null argument yields an empty byte buffer + bb = DecimalType.instance.decompose(null); + assertEquals(bb, ByteBufferUtil.EMPTY_BYTE_BUFFER); + } + + @Test + public void test2Compare() + { + ByteBuffer lowBB = DecimalType.instance.decompose(low); + ByteBuffer low2BB = DecimalType.instance.decompose(low); + ByteBuffer highBB = DecimalType.instance.decompose(high); + assertEquals(-1, DecimalType.instance.compare(lowBB, highBB)); + + lowBB = DecimalType.instance.decompose(low); + highBB = DecimalType.instance.decompose(high); + assertEquals(1, DecimalType.instance.compare(highBB, lowBB)); + + lowBB = DecimalType.instance.decompose(low); + assertEquals(0, DecimalType.instance.compare(low2BB, lowBB)); + + lowBB = DecimalType.instance.decompose(low); + assertEquals(-1, DecimalType.instance.compare(ByteBufferUtil.EMPTY_BYTE_BUFFER, lowBB)); + + lowBB = DecimalType.instance.decompose(low); + assertEquals(1, DecimalType.instance.compare(lowBB,ByteBufferUtil.EMPTY_BYTE_BUFFER)); + + assertEquals(0, DecimalType.instance.compare(ByteBufferUtil.EMPTY_BYTE_BUFFER,ByteBufferUtil.EMPTY_BYTE_BUFFER)); + } + + @Test + public void test3Sort() + { + ByteBuffer zeroBB = DecimalType.instance.decompose(zero); + ByteBuffer minusBB = DecimalType.instance.decompose(minus); + ByteBuffer lowBB = DecimalType.instance.decompose(low); + ByteBuffer highBB = DecimalType.instance.decompose(high); + + ByteBuffer[] array = {highBB,minusBB,lowBB,lowBB,zeroBB,minusBB}; + + // Sort the array of ByteBuffer using a DecimalType comparator + Arrays.sort(array, DecimalType.instance); + + // Check that the array is in order + for (int i = 1; i < array.length; i++) + { + BigDecimal i0 = DecimalType.instance.compose(array[i - 1]); + BigDecimal i1 = DecimalType.instance.compose(array[i]); + assertTrue("#" + i, i0.compareTo(i1) <= 0); + } + } +} From 2224f8185a26a5f1ace942652bf3df8dbb8ba8c5 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Thu, 3 Nov 2011 06:21:24 +0000 Subject: [PATCH 3/3] merge #3415 from 0.8 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-1.0@1196958 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 6 ++++-- src/java/org/apache/cassandra/cli/CliClient.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d39c6ff778..1b2981a4b7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,10 +5,12 @@ * Cache for CompressionMetadata objects (CASSANDRA-3427) * synchronize BiMap of bootstrapping tokens (CASSANDRA-3417) * Avoid large array allocation for compressed chunk offsets (CASSANDRA-3432) + * fix DecimalType bytebuffer marshalling (CASSANDRA-3421) + * fix bug that caused first column in per row indexes to be ignored + (CASSANDRA-3441) Merged from 0.8: * acquire compactionlock during truncate (CASSANDRA-3399) - * fix bug that caused first column in per row indexes to be ignored (CASSANDRA-3441) - * fix DecimalType bytebuffer marshalling (CASSANDRA-3421) + * fix displaying cfdef entries for super columnfamilies (CASSANDRA-3415) 1.0.1 diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index 35f618be87..4049caae3c 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -1740,9 +1740,9 @@ public class CliClient { sb.append(NEWLINE + TAB + TAB + "{"); - final AbstractType comparator = getFormatType((cfDef.column_type == "Super") - ? cfDef.subcomparator_type - : cfDef.comparator_type); + final AbstractType comparator = getFormatType(cfDef.column_type.equals("Super") + ? cfDef.subcomparator_type + : cfDef.comparator_type); sb.append("column_name : '" + CliUtils.escapeSQLString(comparator.getString(colDef.name)) + "'," + NEWLINE); String validationClass = normaliseType(colDef.validation_class, "org.apache.cassandra.db.marshal"); sb.append(TAB + TAB + "validation_class : " + CliUtils.escapeSQLString(validationClass));