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/33f94dec Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/33f94dec Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/33f94dec Branch: refs/heads/trunk Commit: 33f94dec093d70f1276fc86a5051ee04b1fa058e Parents: cf4a057 7ff4a65 Author: Jeff Jirsa <[email protected]> Authored: Wed Jul 26 16:57:57 2017 -0700 Committer: Jeff Jirsa <[email protected]> Committed: Wed Jul 26 16:59:20 2017 -0700 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/hints/ChecksummedDataInput.java | 2 +- .../org/apache/cassandra/hints/HintsReader.java | 2 +- .../apache/cassandra/hints/HintsReaderTest.java | 174 +++++++++++++++++++ 4 files changed, 177 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/33f94dec/CHANGES.txt ---------------------------------------------------------------------- diff --cc CHANGES.txt index 7189cb4,dd8f88b..2500043 --- a/CHANGES.txt +++ b/CHANGES.txt @@@ -107,7 -4,9 +107,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: -3.0.15 * Fixed ambiguous output of nodetool tablestats command (CASSANDRA-13722) + * Fix Digest mismatch Exception if hints file has UnknownColumnFamily (CASSANDRA-13696) * Purge tombstones created by expired cells (CASSANDRA-13643) * Make concat work with iterators that have different subsets of columns (CASSANDRA-13482) * Set test.runners based on cores and memory size (CASSANDRA-13078) http://git-wip-us.apache.org/repos/asf/cassandra/blob/33f94dec/src/java/org/apache/cassandra/hints/HintsReader.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/33f94dec/test/unit/org/apache/cassandra/hints/HintsReaderTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/hints/HintsReaderTest.java index 0000000,70cf6e7..d95bd56 mode 000000,100644..100644 --- a/test/unit/org/apache/cassandra/hints/HintsReaderTest.java +++ b/test/unit/org/apache/cassandra/hints/HintsReaderTest.java @@@ -1,0 -1,172 +1,174 @@@ + /* + * 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.hints; + + import java.io.File; + import java.io.IOException; + import java.nio.ByteBuffer; + import java.nio.file.Files; + import java.util.Iterator; + import java.util.UUID; + import java.util.concurrent.TimeUnit; + + import com.google.common.collect.Iterables; + import org.junit.BeforeClass; + import org.junit.Test; + + import org.apache.cassandra.SchemaLoader; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.Schema; + import org.apache.cassandra.db.Mutation; + import org.apache.cassandra.db.RowUpdateBuilder; + import org.apache.cassandra.db.rows.Cell; + import org.apache.cassandra.db.rows.Row; + import org.apache.cassandra.io.util.FileUtils; + import org.apache.cassandra.schema.KeyspaceParams; ++import org.apache.cassandra.schema.MigrationManager; ++import org.apache.cassandra.schema.Schema; ++import org.apache.cassandra.schema.TableMetadata; + + import static junit.framework.Assert.assertEquals; + import static junit.framework.Assert.assertNotNull; + import static org.apache.cassandra.Util.dk; + import static org.apache.cassandra.utils.ByteBufferUtil.bytes; + + public class HintsReaderTest + { + private static final String CF_STANDARD1 = "Standard1"; + private static final String CF_STANDARD2 = "Standard2"; + + private static HintsDescriptor descriptor; + + private static File directory; + + @BeforeClass + public static void defineSchema() throws Exception + { + SchemaLoader.prepareServer(); + + descriptor = new HintsDescriptor(UUID.randomUUID(), System.currentTimeMillis()); + } + + private static Mutation createMutation(int index, long timestamp, String ks, String tb) + { - CFMetaData table = Schema.instance.getCFMetaData(ks, tb); ++ TableMetadata table = Schema.instance.getTableMetadata(ks, tb); + return new RowUpdateBuilder(table, timestamp, bytes(index)) + .clustering(bytes(index)) + .add("val", bytes(index)) + .build(); + } + + private void generateHints(int num, String ks) throws IOException + { + try (HintsWriter writer = HintsWriter.create(directory, descriptor)) + { + ByteBuffer buffer = ByteBuffer.allocateDirect(256 * 1024); + try (HintsWriter.Session session = writer.newSession(buffer)) + { + for (int i = 0; i < num; i++) + { + long timestamp = descriptor.timestamp + i; + Mutation m = createMutation(i, TimeUnit.MILLISECONDS.toMicros(timestamp), ks, CF_STANDARD1); + session.append(Hint.create(m, timestamp)); + m = createMutation(i, TimeUnit.MILLISECONDS.toMicros(timestamp), ks, CF_STANDARD2); + session.append(Hint.create(m, timestamp)); + } + } + FileUtils.clean(buffer); + } + } + + private void readHints(int num, int numTable) throws IOException + { + long baseTimestamp = descriptor.timestamp; + int index = 0; + + try (HintsReader reader = HintsReader.open(new File(directory, descriptor.fileName()))) + { + for (HintsReader.Page page : reader) + { + Iterator<Hint> hints = page.hintsIterator(); + while (hints.hasNext()) + { + int i = index / numTable; + Hint hint = hints.next(); + + long timestamp = baseTimestamp + i; + Mutation mutation = hint.mutation; + + assertEquals(timestamp, hint.creationTime); + assertEquals(dk(bytes(i)), mutation.key()); + + Row row = mutation.getPartitionUpdates().iterator().next().iterator().next(); + assertEquals(1, Iterables.size(row.cells())); + assertEquals(bytes(i), row.clustering().get(0)); + Cell cell = row.cells().iterator().next(); + assertNotNull(cell); + assertEquals(bytes(i), cell.value()); + assertEquals(timestamp * 1000, cell.timestamp()); + + index++; + } + } + } + + assertEquals(index, num); + } + + @Test + public void testNormalRead() throws IOException + { + String ks = "testNormalRead"; + SchemaLoader.createKeyspace(ks, + KeyspaceParams.simple(1), + SchemaLoader.standardCFMD(ks, CF_STANDARD1), + SchemaLoader.standardCFMD(ks, CF_STANDARD2)); + int numTable = 2; + directory = Files.createTempDirectory(null).toFile(); + try + { + generateHints(3, ks); + readHints(3 * numTable, numTable); + } + finally + { + directory.delete(); + } + } + + @Test + public void testDroppedTableRead() throws IOException + { + String ks = "testDroppedTableRead"; + SchemaLoader.createKeyspace(ks, + KeyspaceParams.simple(1), + SchemaLoader.standardCFMD(ks, CF_STANDARD1), + SchemaLoader.standardCFMD(ks, CF_STANDARD2)); ++ + directory = Files.createTempDirectory(null).toFile(); + try + { + generateHints(3, ks); - Schema.instance.dropTable(ks, CF_STANDARD1); ++ MigrationManager.announceTableDrop(ks, CF_STANDARD1, true); + readHints(3, 1); + } + finally + { + directory.delete(); + } + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
