Merge branch 'cassandra-3.11' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6b4c8a97 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6b4c8a97 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6b4c8a97 Branch: refs/heads/trunk Commit: 6b4c8a9733f6eef276d602b440ae2f1906c1f264 Parents: 289f6b1 2a24acf Author: Jason Brown <[email protected]> Authored: Fri Sep 29 05:24:27 2017 -0700 Committer: Jason Brown <[email protected]> Committed: Fri Sep 29 05:26:51 2017 -0700 ---------------------------------------------------------------------- CHANGES.txt | 1 + src/java/org/apache/cassandra/cql3/Lists.java | 75 +++++++-- .../org/apache/cassandra/cql3/ListsTest.java | 166 +++++++++++++++++++ 3 files changed, 225 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/6b4c8a97/CHANGES.txt ---------------------------------------------------------------------- diff --cc CHANGES.txt index a9108aa,6c3a1d0..f2f23bd --- a/CHANGES.txt +++ b/CHANGES.txt @@@ -153,7 -13,8 +153,8 @@@ * Duplicate the buffer before passing it to analyser in SASI operation (CASSANDRA-13512) * Properly evict pstmts from prepared statements cache (CASSANDRA-13641) Merged from 3.0: + * AssertionError prepending to a list (CASSANDRA-13149) - * Fix support for SuperColumn tables (CASSANDRA-12373) + * Handle limit correctly on tables with strict liveness (CASSANDRA-13883) * Remove non-rpc-ready nodes from counter leader candidates (CASSANDRA-13043) * Improve short read protection performance (CASSANDRA-13794) * Fix sstable reader to support range-tombstone-marker for multi-slices (CASSANDRA-13787) http://git-wip-us.apache.org/repos/asf/cassandra/blob/6b4c8a97/src/java/org/apache/cassandra/cql3/Lists.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/cql3/Lists.java index 48fe54f,6a2a5a5..4a68df9 --- a/src/java/org/apache/cassandra/cql3/Lists.java +++ b/src/java/org/apache/cassandra/cql3/Lists.java @@@ -22,13 -22,12 +22,14 @@@ import static org.apache.cassandra.cql3 import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; +import org.apache.cassandra.schema.ColumnMetadata; + import com.google.common.annotations.VisibleForTesting; - -import org.apache.cassandra.config.ColumnDefinition; import org.apache.cassandra.cql3.functions.Function; import org.apache.cassandra.db.*; import org.apache.cassandra.db.rows.*; http://git-wip-us.apache.org/repos/asf/cassandra/blob/6b4c8a97/test/unit/org/apache/cassandra/cql3/ListsTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/cql3/ListsTest.java index 0000000,07623a2..63c496c mode 000000,100644..100644 --- a/test/unit/org/apache/cassandra/cql3/ListsTest.java +++ b/test/unit/org/apache/cassandra/cql3/ListsTest.java @@@ -1,0 -1,166 +1,166 @@@ + /* + * 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.cql3; + + import java.nio.ByteBuffer; + import java.util.ArrayList; + import java.util.Collections; + import java.util.List; + import java.util.UUID; + + import com.google.common.collect.Iterators; + import org.junit.Assert; + import org.junit.Test; + -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.ColumnDefinition; + import org.apache.cassandra.cql3.Lists.PrecisionTime; + import org.apache.cassandra.db.Clustering; + import org.apache.cassandra.db.DecoratedKey; + import org.apache.cassandra.db.rows.Cell; + import org.apache.cassandra.db.rows.Row; + import org.apache.cassandra.dht.Murmur3Partitioner; ++import org.apache.cassandra.schema.ColumnMetadata; ++import org.apache.cassandra.schema.TableMetadata; + import org.apache.cassandra.utils.ByteBufferUtil; + import org.apache.cassandra.utils.UUIDGen; + + public class ListsTest extends CQLTester + { + private static final long DEFAULT_MILLIS = 424242424242L; + private static final int DEFAULT_NANOS = PrecisionTime.MAX_NANOS; + + @Test + public void testPrecisionTime_getNext_simple() + { + PrecisionTime.set(DEFAULT_MILLIS, DEFAULT_NANOS); + + long millis = DEFAULT_MILLIS - 100; + int count = 1; + PrecisionTime next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(millis, next.millis); + Assert.assertEquals(DEFAULT_NANOS - count, next.nanos); + + next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(millis, next.millis); + Assert.assertEquals(DEFAULT_NANOS - (count * 2), next.nanos); + } + + @Test + public void testPrecisionTime_getNext_Mulitple() + { + PrecisionTime.set(DEFAULT_MILLIS, DEFAULT_NANOS); + + long millis = DEFAULT_MILLIS - 100; + int count = DEFAULT_NANOS / 2; + PrecisionTime next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(millis, next.millis); + Assert.assertEquals(DEFAULT_NANOS - count, next.nanos); + } + + @Test + public void testPrecisionTime_getNext_RollOverNanos() + { + final int remainingNanos = 0; + PrecisionTime.set(DEFAULT_MILLIS, remainingNanos); + + long millis = DEFAULT_MILLIS; + int count = 1; + PrecisionTime next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(millis - 1, next.millis); + Assert.assertEquals(DEFAULT_NANOS - count, next.nanos); + + next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(millis - 1, next.millis); + Assert.assertEquals(DEFAULT_NANOS - (count * 2), next.nanos); + } + + @Test + public void testPrecisionTime_getNext_BorkedClock() + { + final int remainingNanos = 1; + PrecisionTime.set(DEFAULT_MILLIS, remainingNanos); + + long millis = DEFAULT_MILLIS + 100; + int count = 1; + PrecisionTime next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(DEFAULT_MILLIS, next.millis); + Assert.assertEquals(remainingNanos - count, next.nanos); + + // this should roll the clock + next = PrecisionTime.getNext(millis, count); + Assert.assertEquals(DEFAULT_MILLIS - 1, next.millis); + Assert.assertEquals(DEFAULT_NANOS - count, next.nanos); + } + + @Test + public void testPrepender_SmallList() + { + List<ByteBuffer> terms = new ArrayList<>(); + terms.add(ByteBufferUtil.bytes(1)); + terms.add(ByteBufferUtil.bytes(2)); + terms.add(ByteBufferUtil.bytes(3)); + terms.add(ByteBufferUtil.bytes(4)); + terms.add(ByteBufferUtil.bytes(5)); + testPrepender_execute(terms); + } + + @Test + public void testPrepender_HugeList() + { + List<ByteBuffer> terms = new ArrayList<>(); + // create a large enough array, then remove some off the end, just to make it an odd size + for (int i = 0; i < PrecisionTime.MAX_NANOS * 4 - 287; i++) + terms.add(ByteBufferUtil.bytes(i)); + testPrepender_execute(terms); + } + + private void testPrepender_execute(List<ByteBuffer> terms) + { + createTable("CREATE TABLE %s (k int PRIMARY KEY, l list<text>)"); - CFMetaData metaData = currentTableMetadata(); ++ TableMetadata metaData = currentTableMetadata(); + - ColumnDefinition columnDefinition = metaData.getColumnDefinition(ByteBufferUtil.bytes("l")); ++ ColumnMetadata columnMetadata = metaData.getColumn(ByteBufferUtil.bytes("l")); + Term term = new Lists.Value(terms); - Lists.Prepender prepender = new Lists.Prepender(columnDefinition, term); ++ Lists.Prepender prepender = new Lists.Prepender(columnMetadata, term); + + ByteBuffer keyBuf = ByteBufferUtil.bytes("key"); + DecoratedKey key = Murmur3Partitioner.instance.decorateKey(keyBuf); + UpdateParameters parameters = new UpdateParameters(metaData, null, null, System.currentTimeMillis(), 1000, Collections.emptyMap()); + Clustering clustering = Clustering.make(ByteBufferUtil.bytes(1)); + parameters.newRow(clustering); + prepender.execute(key, parameters); + + Row row = parameters.buildRow(); + Assert.assertEquals(terms.size(), Iterators.size(row.cells().iterator())); + + int idx = 0; + UUID last = null; + for (Cell cell : row.cells()) + { + UUID uuid = UUIDGen.getUUID(cell.path().get(0)); + + if (last != null) + Assert.assertTrue(last.compareTo(uuid) < 0); + last = uuid; + + Assert.assertEquals(String.format("different values found: expected: '%d', found '%d'", ByteBufferUtil.toInt(terms.get(idx)), ByteBufferUtil.toInt(cell.value())), + terms.get(idx), cell.value()); + idx++; + } + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
