http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/partition/PartitionUpdateTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/partition/PartitionUpdateTest.java b/test/unit/org/apache/cassandra/db/partition/PartitionUpdateTest.java index bfa9796..fdd34f1 100644 --- a/test/unit/org/apache/cassandra/db/partition/PartitionUpdateTest.java +++ b/test/unit/org/apache/cassandra/db/partition/PartitionUpdateTest.java @@ -18,7 +18,7 @@ package org.apache.cassandra.db.partition; import org.apache.cassandra.UpdateBuilder; -import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.db.RowUpdateBuilder; import org.apache.cassandra.db.partitions.PartitionUpdate; @@ -33,7 +33,7 @@ public class PartitionUpdateTest extends CQLTester public void testOperationCount() { createTable("CREATE TABLE %s (key text, clustering int, a int, s int static, PRIMARY KEY(key, clustering))"); - CFMetaData cfm = currentTableMetadata(); + TableMetadata cfm = currentTableMetadata(); UpdateBuilder builder = UpdateBuilder.create(cfm, "key0"); Assert.assertEquals(0, builder.build().operationCount()); @@ -52,7 +52,7 @@ public class PartitionUpdateTest extends CQLTester public void testOperationCountWithCompactTable() { createTable("CREATE TABLE %s (key text PRIMARY KEY, a int) WITH COMPACT STORAGE"); - CFMetaData cfm = currentTableMetadata(); + TableMetadata cfm = currentTableMetadata(); PartitionUpdate update = new RowUpdateBuilder(cfm, FBUtilities.timestampMicros(), "key0").add("a", 1) .buildUpdate();
http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/rows/RowAndDeletionMergeIteratorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/rows/RowAndDeletionMergeIteratorTest.java b/test/unit/org/apache/cassandra/db/rows/RowAndDeletionMergeIteratorTest.java index e4c04fb..fb35ead 100644 --- a/test/unit/org/apache/cassandra/db/rows/RowAndDeletionMergeIteratorTest.java +++ b/test/unit/org/apache/cassandra/db/rows/RowAndDeletionMergeIteratorTest.java @@ -29,18 +29,18 @@ import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.db.ClusteringPrefix; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.ColumnFilter; import org.apache.cassandra.db.marshal.AbstractType; -import org.apache.cassandra.config.ColumnDefinition; import org.apache.cassandra.cql3.ColumnIdentifier; import org.apache.cassandra.db.partitions.PartitionUpdate; import org.apache.cassandra.db.marshal.Int32Type; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; -import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.db.marshal.AsciiType; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.schema.KeyspaceParams; @@ -55,23 +55,22 @@ public class RowAndDeletionMergeIteratorTest private int nowInSeconds; private DecoratedKey dk; private ColumnFamilyStore cfs; - private CFMetaData cfm; - private ColumnDefinition defA; + private TableMetadata cfm; + private ColumnMetadata defA; @BeforeClass public static void defineSchema() throws ConfigurationException { DatabaseDescriptor.daemonInitialization(); - CFMetaData cfMetadata = CFMetaData.Builder.create(KEYSPACE1, CF_STANDARD1) - .addPartitionKey("key", AsciiType.instance) - .addClusteringColumn("col1", Int32Type.instance) - .addRegularColumn("a", Int32Type.instance) - .build(); - SchemaLoader.prepareServer(); - SchemaLoader.createKeyspace(KEYSPACE1, - KeyspaceParams.simple(1), - cfMetadata); + TableMetadata.Builder builder = + TableMetadata.builder(KEYSPACE1, CF_STANDARD1) + .addPartitionKeyColumn("key", AsciiType.instance) + .addClusteringColumn("col1", Int32Type.instance) + .addRegularColumn("a", Int32Type.instance); + + SchemaLoader.prepareServer(); + SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), builder); } @Before @@ -80,8 +79,8 @@ public class RowAndDeletionMergeIteratorTest nowInSeconds = FBUtilities.nowInSeconds(); dk = Util.dk("key0"); cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1); - cfm = cfs.metadata; - defA = cfm.getColumnDefinition(new ColumnIdentifier("a", true)); + cfm = cfs.metadata(); + defA = cfm.getColumn(new ColumnIdentifier("a", true)); } @Test @@ -367,7 +366,7 @@ public class RowAndDeletionMergeIteratorTest private Iterator<Row> createRowIterator() { - PartitionUpdate update = new PartitionUpdate(cfm, dk, cfm.partitionColumns(), 1); + PartitionUpdate update = new PartitionUpdate(cfm, dk, cfm.regularAndStaticColumns(), 1); for (int i = 0; i < 5; i++) addRow(update, i, i); @@ -401,9 +400,9 @@ public class RowAndDeletionMergeIteratorTest update.add(BTreeRow.singleCellRow(update.metadata().comparator.make(col1), makeCell(defA, a, 0))); } - private Cell makeCell(ColumnDefinition columnDefinition, int value, long timestamp) + private Cell makeCell(ColumnMetadata columnMetadata, int value, long timestamp) { - return BufferCell.live(columnDefinition, timestamp, ((AbstractType)columnDefinition.cellValueType()).decompose(value)); + return BufferCell.live(columnMetadata, timestamp, ((AbstractType) columnMetadata.cellValueType()).decompose(value)); } private static RangeTombstone atLeast(int start, long tstamp, int delTime) http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/rows/RowBuilder.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/rows/RowBuilder.java b/test/unit/org/apache/cassandra/db/rows/RowBuilder.java index b1223f1..5eed774 100644 --- a/test/unit/org/apache/cassandra/db/rows/RowBuilder.java +++ b/test/unit/org/apache/cassandra/db/rows/RowBuilder.java @@ -21,7 +21,7 @@ package org.apache.cassandra.db.rows; import java.util.LinkedList; import java.util.List; -import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.schema.ColumnMetadata; import org.apache.cassandra.db.Clustering; import org.apache.cassandra.db.DeletionTime; import org.apache.cassandra.db.LivenessInfo; @@ -37,7 +37,7 @@ public class RowBuilder implements Row.Builder public Clustering clustering = null; public LivenessInfo livenessInfo = null; public Row.Deletion deletionTime = null; - public List<Pair<ColumnDefinition, DeletionTime>> complexDeletions = new LinkedList<>(); + public List<Pair<ColumnMetadata, DeletionTime>> complexDeletions = new LinkedList<>(); public void addCell(Cell cell) { @@ -72,7 +72,7 @@ public class RowBuilder implements Row.Builder deletionTime = deletion; } - public void addComplexDeletion(ColumnDefinition column, DeletionTime complexDeletion) + public void addComplexDeletion(ColumnMetadata column, DeletionTime complexDeletion) { complexDeletions.add(Pair.create(column, complexDeletion)); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/rows/RowsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/rows/RowsTest.java b/test/unit/org/apache/cassandra/db/rows/RowsTest.java index 5629f3f..3f59003 100644 --- a/test/unit/org/apache/cassandra/db/rows/RowsTest.java +++ b/test/unit/org/apache/cassandra/db/rows/RowsTest.java @@ -33,8 +33,8 @@ import com.google.common.collect.Sets; import org.junit.Assert; import org.junit.Test; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.ColumnIdentifier; import org.apache.cassandra.db.Clustering; @@ -50,23 +50,24 @@ public class RowsTest { private static final String KEYSPACE = "rows_test"; private static final String KCVM_TABLE = "kcvm"; - private static final CFMetaData kcvm; - private static final ColumnDefinition v; - private static final ColumnDefinition m; + private static final TableMetadata kcvm; + private static final ColumnMetadata v; + private static final ColumnMetadata m; private static final Clustering c1; static { DatabaseDescriptor.daemonInitialization(); - kcvm = CFMetaData.Builder.create(KEYSPACE, KCVM_TABLE) - .addPartitionKey("k", IntegerType.instance) - .addClusteringColumn("c", IntegerType.instance) - .addRegularColumn("v", IntegerType.instance) - .addRegularColumn("m", MapType.getInstance(IntegerType.instance, IntegerType.instance, true)) - .build(); - - v = kcvm.getColumnDefinition(new ColumnIdentifier("v", false)); - m = kcvm.getColumnDefinition(new ColumnIdentifier("m", false)); + kcvm = + TableMetadata.builder(KEYSPACE, KCVM_TABLE) + .addPartitionKeyColumn("k", IntegerType.instance) + .addClusteringColumn("c", IntegerType.instance) + .addRegularColumn("v", IntegerType.instance) + .addRegularColumn("m", MapType.getInstance(IntegerType.instance, IntegerType.instance, true)) + .build(); + + v = kcvm.getColumn(new ColumnIdentifier("v", false)); + m = kcvm.getColumn(new ColumnIdentifier("m", false)); c1 = kcvm.comparator.make(BigInteger.valueOf(1)); } @@ -158,8 +159,8 @@ public class RowsTest updates++; } - Map<ColumnDefinition, List<MergedPair<DeletionTime>>> complexDeletions = new HashMap<>(); - public void onComplexDeletion(int i, Clustering clustering, ColumnDefinition column, DeletionTime merged, DeletionTime original) + Map<ColumnMetadata, List<MergedPair<DeletionTime>>> complexDeletions = new HashMap<>(); + public void onComplexDeletion(int i, Clustering clustering, ColumnMetadata column, DeletionTime merged, DeletionTime original) { updateClustering(clustering); if (!complexDeletions.containsKey(column)) complexDeletions.put(column, new LinkedList<>()); @@ -550,14 +551,14 @@ public class RowsTest } // Creates a dummy cell for a (regular) column for the provided name and without a cellPath. - private static Cell liveCell(ColumnDefinition name) + private static Cell liveCell(ColumnMetadata name) { return liveCell(name, -1); } // Creates a dummy cell for a (regular) column for the provided name. // If path >= 0, the cell will have a CellPath containing path as an Int32Type. - private static Cell liveCell(ColumnDefinition name, int path) + private static Cell liveCell(ColumnMetadata name, int path) { CellPath cp = path < 0 ? null : CellPath.create(ByteBufferUtil.bytes(path)); return new BufferCell(name, 0L, Cell.NO_TTL, Cell.NO_DELETION_TIME, ByteBuffer.allocate(1), cp); @@ -593,20 +594,21 @@ public class RowsTest // Creates a table with // - 3 Simple columns: a, c and e // - 2 Complex columns: b and d - CFMetaData metadata = CFMetaData.Builder.create("dummy_ks", "dummy_tbl") - .addPartitionKey("k", BytesType.instance) - .addRegularColumn("a", BytesType.instance) - .addRegularColumn("b", MapType.getInstance(Int32Type.instance, BytesType.instance, true)) - .addRegularColumn("c", BytesType.instance) - .addRegularColumn("d", MapType.getInstance(Int32Type.instance, BytesType.instance, true)) - .addRegularColumn("e", BytesType.instance) - .build(); - - ColumnDefinition a = metadata.getColumnDefinition(new ColumnIdentifier("a", false)); - ColumnDefinition b = metadata.getColumnDefinition(new ColumnIdentifier("b", false)); - ColumnDefinition c = metadata.getColumnDefinition(new ColumnIdentifier("c", false)); - ColumnDefinition d = metadata.getColumnDefinition(new ColumnIdentifier("d", false)); - ColumnDefinition e = metadata.getColumnDefinition(new ColumnIdentifier("e", false)); + TableMetadata metadata = + TableMetadata.builder("dummy_ks", "dummy_tbl") + .addPartitionKeyColumn("k", BytesType.instance) + .addRegularColumn("a", BytesType.instance) + .addRegularColumn("b", MapType.getInstance(Int32Type.instance, BytesType.instance, true)) + .addRegularColumn("c", BytesType.instance) + .addRegularColumn("d", MapType.getInstance(Int32Type.instance, BytesType.instance, true)) + .addRegularColumn("e", BytesType.instance) + .build(); + + ColumnMetadata a = metadata.getColumn(new ColumnIdentifier("a", false)); + ColumnMetadata b = metadata.getColumn(new ColumnIdentifier("b", false)); + ColumnMetadata c = metadata.getColumn(new ColumnIdentifier("c", false)); + ColumnMetadata d = metadata.getColumn(new ColumnIdentifier("d", false)); + ColumnMetadata e = metadata.getColumn(new ColumnIdentifier("e", false)); Row row; http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/rows/UnfilteredRowIteratorsMergeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/rows/UnfilteredRowIteratorsMergeTest.java b/test/unit/org/apache/cassandra/db/rows/UnfilteredRowIteratorsMergeTest.java index 4578ad1..8c99057 100644 --- a/test/unit/org/apache/cassandra/db/rows/UnfilteredRowIteratorsMergeTest.java +++ b/test/unit/org/apache/cassandra/db/rows/UnfilteredRowIteratorsMergeTest.java @@ -31,7 +31,7 @@ import org.junit.Assert; import org.junit.Test; import org.apache.cassandra.Util; -import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.marshal.AsciiType; @@ -47,11 +47,13 @@ public class UnfilteredRowIteratorsMergeTest } static DecoratedKey partitionKey = Util.dk("key"); static DeletionTime partitionLevelDeletion = DeletionTime.LIVE; - static CFMetaData metadata = CFMetaData.Builder.create("UnfilteredRowIteratorsMergeTest", "Test"). - addPartitionKey("key", AsciiType.instance). - addClusteringColumn("clustering", Int32Type.instance). - addRegularColumn("data", Int32Type.instance). - build(); + static TableMetadata metadata = + TableMetadata.builder("UnfilteredRowIteratorsMergeTest", "Test") + .addPartitionKeyColumn("key", AsciiType.instance) + .addClusteringColumn("clustering", Int32Type.instance) + .addRegularColumn("data", Int32Type.instance) + .build(); + static Comparator<Clusterable> comparator = new ClusteringComparator(Int32Type.instance); static int nowInSec = FBUtilities.nowInSeconds(); @@ -424,7 +426,7 @@ public class UnfilteredRowIteratorsMergeTest super(UnfilteredRowIteratorsMergeTest.metadata, UnfilteredRowIteratorsMergeTest.partitionKey, UnfilteredRowIteratorsMergeTest.partitionLevelDeletion, - UnfilteredRowIteratorsMergeTest.metadata.partitionColumns(), + UnfilteredRowIteratorsMergeTest.metadata.regularAndStaticColumns(), null, reversed, EncodingStats.NO_STATS); http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/rows/UnfilteredRowsGenerator.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/rows/UnfilteredRowsGenerator.java b/test/unit/org/apache/cassandra/db/rows/UnfilteredRowsGenerator.java index 7cdccdb..1f8793a 100644 --- a/test/unit/org/apache/cassandra/db/rows/UnfilteredRowsGenerator.java +++ b/test/unit/org/apache/cassandra/db/rows/UnfilteredRowsGenerator.java @@ -25,10 +25,10 @@ import java.util.regex.Pattern; import org.junit.Assert; -import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.db.*; import org.apache.cassandra.db.marshal.Int32Type; import org.apache.cassandra.db.rows.Unfiltered.Kind; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.utils.btree.BTree; public class UnfilteredRowsGenerator @@ -289,12 +289,12 @@ public class UnfilteredRowsGenerator new DeletionTime(delTime, delTime)); } - public static UnfilteredRowIterator source(Iterable<Unfiltered> content, CFMetaData metadata, DecoratedKey partitionKey) + public static UnfilteredRowIterator source(Iterable<Unfiltered> content, TableMetadata metadata, DecoratedKey partitionKey) { return source(content, metadata, partitionKey, DeletionTime.LIVE); } - public static UnfilteredRowIterator source(Iterable<Unfiltered> content, CFMetaData metadata, DecoratedKey partitionKey, DeletionTime delTime) + public static UnfilteredRowIterator source(Iterable<Unfiltered> content, TableMetadata metadata, DecoratedKey partitionKey, DeletionTime delTime) { return new Source(content.iterator(), metadata, partitionKey, delTime, false); } @@ -303,12 +303,12 @@ public class UnfilteredRowsGenerator { Iterator<Unfiltered> content; - protected Source(Iterator<Unfiltered> content, CFMetaData metadata, DecoratedKey partitionKey, DeletionTime partitionLevelDeletion, boolean reversed) + protected Source(Iterator<Unfiltered> content, TableMetadata metadata, DecoratedKey partitionKey, DeletionTime partitionLevelDeletion, boolean reversed) { super(metadata, partitionKey, partitionLevelDeletion, - metadata.partitionColumns(), + metadata.regularAndStaticColumns(), Rows.EMPTY_STATIC_ROW, reversed, EncodingStats.NO_STATS); http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/db/view/ViewUtilsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/view/ViewUtilsTest.java b/test/unit/org/apache/cassandra/db/view/ViewUtilsTest.java index 89bb44a..658b87a 100644 --- a/test/unit/org/apache/cassandra/db/view/ViewUtilsTest.java +++ b/test/unit/org/apache/cassandra/db/view/ViewUtilsTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import junit.framework.Assert; import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken; import org.apache.cassandra.exceptions.ConfigurationException; @@ -74,7 +74,7 @@ public class ViewUtilsTest Keyspace.clear("Keyspace1"); KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap)); - Schema.instance.setKeyspaceMetadata(meta); + Schema.instance.load(meta); Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1", new StringToken("CA"), @@ -107,7 +107,7 @@ public class ViewUtilsTest Keyspace.clear("Keyspace1"); KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap)); - Schema.instance.setKeyspaceMetadata(meta); + Schema.instance.load(meta); Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1", new StringToken("CA"), @@ -139,7 +139,7 @@ public class ViewUtilsTest Keyspace.clear("Keyspace1"); KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap)); - Schema.instance.setKeyspaceMetadata(meta); + Schema.instance.load(meta); Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1", new StringToken("AB"), http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/dht/BootStrapperTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/dht/BootStrapperTest.java b/test/unit/org/apache/cassandra/dht/BootStrapperTest.java index ba0352d..9481201 100644 --- a/test/unit/org/apache/cassandra/dht/BootStrapperTest.java +++ b/test/unit/org/apache/cassandra/dht/BootStrapperTest.java @@ -41,7 +41,7 @@ import org.junit.runner.RunWith; import org.apache.cassandra.OrderedJUnit4ClassRunner; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.dht.tokenallocator.TokenAllocation; import org.apache.cassandra.exceptions.ConfigurationException; http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/dht/KeyCollisionTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/dht/KeyCollisionTest.java b/test/unit/org/apache/cassandra/dht/KeyCollisionTest.java index c0ff9ca..5b5365d 100644 --- a/test/unit/org/apache/cassandra/dht/KeyCollisionTest.java +++ b/test/unit/org/apache/cassandra/dht/KeyCollisionTest.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.db.RowUpdateBuilder; @@ -95,7 +95,7 @@ public class KeyCollisionTest private void insert(String key) { - RowUpdateBuilder builder = new RowUpdateBuilder(Schema.instance.getCFMetaData(KEYSPACE1, CF), FBUtilities.timestampMicros(), key); + RowUpdateBuilder builder = new RowUpdateBuilder(Schema.instance.getTableMetadata(KEYSPACE1, CF), FBUtilities.timestampMicros(), key); builder.clustering("c").add("val", "asdf").build().applyUnsafe(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/dht/LengthPartitioner.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/dht/LengthPartitioner.java b/test/unit/org/apache/cassandra/dht/LengthPartitioner.java index 97f2dcc..bd6f3d4 100644 --- a/test/unit/org/apache/cassandra/dht/LengthPartitioner.java +++ b/test/unit/org/apache/cassandra/dht/LengthPartitioner.java @@ -22,8 +22,8 @@ import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.ThreadLocalRandom; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.schema.TableMetadata; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.BufferDecoratedKey; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.marshal.AbstractType; @@ -143,12 +143,12 @@ public class LengthPartitioner implements IPartitioner for (String ks : Schema.instance.getKeyspaces()) { - for (CFMetaData cfmd : Schema.instance.getTablesAndViews(ks)) + for (TableMetadata cfmd : Schema.instance.getTablesAndViews(ks)) { for (Range<Token> r : sortedRanges) { // Looping over every KS:CF:Range, get the splits size and add it to the count - allTokens.put(r.right, allTokens.get(r.right) + StorageService.instance.getSplits(ks, cfmd.cfName, r, 1).size()); + allTokens.put(r.right, allTokens.get(r.right) + StorageService.instance.getSplits(ks, cfmd.name, r, 1).size()); } } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/hints/AlteredHints.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/AlteredHints.java b/test/unit/org/apache/cassandra/hints/AlteredHints.java index 7efe08f..6cc507b 100644 --- a/test/unit/org/apache/cassandra/hints/AlteredHints.java +++ b/test/unit/org/apache/cassandra/hints/AlteredHints.java @@ -32,8 +32,9 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.apache.cassandra.SchemaLoader; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.schema.TableMetadata; +import org.apache.cassandra.schema.TableMetadataRef; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.Mutation; import org.apache.cassandra.db.RowUpdateBuilder; import org.apache.cassandra.schema.KeyspaceParams; @@ -51,7 +52,7 @@ public abstract class AlteredHints private static Mutation createMutation(int index, long timestamp) { - CFMetaData table = Schema.instance.getCFMetaData(KEYSPACE, TABLE); + TableMetadata table = Schema.instance.getTableMetadata(KEYSPACE, TABLE); return new RowUpdateBuilder(table, timestamp, bytes(index)) .clustering(bytes(index)) .add("val", bytes(index)) http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/hints/HintMessageTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintMessageTest.java b/test/unit/org/apache/cassandra/hints/HintMessageTest.java index 7ffaa54..bb015a8 100644 --- a/test/unit/org/apache/cassandra/hints/HintMessageTest.java +++ b/test/unit/org/apache/cassandra/hints/HintMessageTest.java @@ -23,8 +23,8 @@ import java.util.UUID; 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.schema.TableMetadata; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.Mutation; import org.apache.cassandra.db.RowUpdateBuilder; import org.apache.cassandra.io.util.DataInputBuffer; @@ -53,7 +53,7 @@ public class HintMessageTest UUID hostId = UUID.randomUUID(); long now = FBUtilities.timestampMicros(); - CFMetaData table = Schema.instance.getCFMetaData(KEYSPACE, TABLE); + TableMetadata table = Schema.instance.getTableMetadata(KEYSPACE, TABLE); Mutation mutation = new RowUpdateBuilder(table, now, bytes("key")) .clustering("column") http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/hints/HintTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintTest.java b/test/unit/org/apache/cassandra/hints/HintTest.java index e4a33fd..23189e1 100644 --- a/test/unit/org/apache/cassandra/hints/HintTest.java +++ b/test/unit/org/apache/cassandra/hints/HintTest.java @@ -43,8 +43,12 @@ import org.apache.cassandra.locator.TokenMetadata; import org.apache.cassandra.metrics.StorageMetrics; import org.apache.cassandra.net.MessageIn; import org.apache.cassandra.net.MessagingService; +import org.apache.cassandra.schema.ColumnMetadata; import org.apache.cassandra.schema.KeyspaceParams; +import org.apache.cassandra.schema.Schema; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.schema.TableParams; +import org.apache.cassandra.schema.MigrationManager; import org.apache.cassandra.service.StorageProxy; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; @@ -54,7 +58,6 @@ import static junit.framework.Assert.*; import static org.apache.cassandra.Util.dk; import static org.apache.cassandra.hints.HintsTestUtil.assertHintsEqual; import static org.apache.cassandra.hints.HintsTestUtil.assertPartitionsEqual; -import static org.apache.cassandra.utils.ByteBufferUtil.bytes; public class HintTest { @@ -83,8 +86,8 @@ public class HintTest tokenMeta.updateHostId(UUID.randomUUID(), local); tokenMeta.updateNormalTokens(BootStrapper.getRandomTokens(tokenMeta, 1), local); - for (CFMetaData table : Schema.instance.getTablesAndViews(KEYSPACE)) - table.gcGraceSeconds(TableParams.DEFAULT_GC_GRACE_SECONDS); + for (TableMetadata table : Schema.instance.getTablesAndViews(KEYSPACE)) + MigrationManager.announceTableUpdate(table.unbuild().gcGraceSeconds(TableParams.DEFAULT_GC_GRACE_SECONDS).build(), true); } @Test @@ -125,7 +128,7 @@ public class HintTest // assert that we can read the inserted partitions for (PartitionUpdate partition : mutation.getPartitionUpdates()) - assertPartitionsEqual(partition, readPartition(key, partition.metadata().cfName, partition.columns())); + assertPartitionsEqual(partition, readPartition(key, partition.metadata().name, partition.columns())); } @Test @@ -150,9 +153,9 @@ public class HintTest assertNoPartitions(key, TABLE1); // TABLE0 and TABLE2 updates should have been applied successfully - PartitionUpdate upd0 = mutation.getPartitionUpdate(Schema.instance.getId(KEYSPACE, TABLE0)); + PartitionUpdate upd0 = mutation.getPartitionUpdate(Schema.instance.getTableMetadata(KEYSPACE, TABLE0)); assertPartitionsEqual(upd0, readPartition(key, TABLE0, upd0.columns())); - PartitionUpdate upd2 = mutation.getPartitionUpdate(Schema.instance.getId(KEYSPACE, TABLE2)); + PartitionUpdate upd2 = mutation.getPartitionUpdate(Schema.instance.getTableMetadata(KEYSPACE, TABLE2)); assertPartitionsEqual(upd2, readPartition(key, TABLE2, upd2.columns())); } @@ -161,7 +164,6 @@ public class HintTest { long now = FBUtilities.timestampMicros(); String key = "testApplyWithRegularExpiration"; - Mutation mutation = createMutation(key, now); // sanity check that there is no data inside yet assertNoPartitions(key, TABLE0); @@ -169,8 +171,15 @@ public class HintTest assertNoPartitions(key, TABLE2); // lower the GC GS on TABLE0 to 0 BEFORE the hint is created - Schema.instance.getCFMetaData(KEYSPACE, TABLE0).gcGraceSeconds(0); + TableMetadata updated = + Schema.instance + .getTableMetadata(KEYSPACE, TABLE0) + .unbuild() + .gcGraceSeconds(0) + .build(); + MigrationManager.announceTableUpdate(updated, true); + Mutation mutation = createMutation(key, now); Hint.create(mutation, now / 1000).apply(); // all updates should have been skipped and not applied, as expired @@ -184,8 +193,6 @@ public class HintTest { long now = FBUtilities.timestampMicros(); String key = "testApplyWithGCGSReducedLater"; - Mutation mutation = createMutation(key, now); - Hint hint = Hint.create(mutation, now / 1000); // sanity check that there is no data inside yet assertNoPartitions(key, TABLE0); @@ -193,8 +200,16 @@ public class HintTest assertNoPartitions(key, TABLE2); // lower the GC GS on TABLE0 AFTER the hint is already created - Schema.instance.getCFMetaData(KEYSPACE, TABLE0).gcGraceSeconds(0); + TableMetadata updated = + Schema.instance + .getTableMetadata(KEYSPACE, TABLE0) + .unbuild() + .gcGraceSeconds(0) + .build(); + MigrationManager.announceTableUpdate(updated, true); + Mutation mutation = createMutation(key, now); + Hint hint = Hint.create(mutation, now / 1000); hint.apply(); // all updates should have been skipped and not applied, as expired @@ -298,17 +313,17 @@ public class HintTest { Mutation.SimpleBuilder builder = Mutation.simpleBuilder(KEYSPACE, dk(key)); - builder.update(Schema.instance.getCFMetaData(KEYSPACE, TABLE0)) + builder.update(Schema.instance.getTableMetadata(KEYSPACE, TABLE0)) .timestamp(now) .row("column0") .add("val", "value0"); - builder.update(Schema.instance.getCFMetaData(KEYSPACE, TABLE1)) + builder.update(Schema.instance.getTableMetadata(KEYSPACE, TABLE1)) .timestamp(now + 1) .row("column1") .add("val", "value1"); - builder.update(Schema.instance.getCFMetaData(KEYSPACE, TABLE2)) + builder.update(Schema.instance.getTableMetadata(KEYSPACE, TABLE2)) .timestamp(now + 2) .row("column2") .add("val", "value2"); @@ -318,14 +333,14 @@ public class HintTest private static ColumnFamilyStore cfs(String table) { - return Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getCFMetaData(KEYSPACE, table).cfId); + return Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getTableMetadata(KEYSPACE, table).id); } - private static FilteredPartition readPartition(String key, String table, PartitionColumns columns) + private static FilteredPartition readPartition(String key, String table, RegularAndStaticColumns columns) { String[] columnNames = new String[columns.size()]; int i = 0; - for (ColumnDefinition column : columns) + for (ColumnMetadata column : columns) columnNames[i++] = column.name.toString(); return Util.getOnlyPartition(Util.cmd(cfs(table), key).columns(columnNames).build()); http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/hints/HintsBufferTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintsBufferTest.java b/test/unit/org/apache/cassandra/hints/HintsBufferTest.java index 08f7ec0..a4cb651 100644 --- a/test/unit/org/apache/cassandra/hints/HintsBufferTest.java +++ b/test/unit/org/apache/cassandra/hints/HintsBufferTest.java @@ -29,8 +29,6 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.concurrent.NamedThreadFactory; -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; @@ -39,6 +37,8 @@ import org.apache.cassandra.io.util.DataInputBuffer; import org.apache.cassandra.io.util.DataInputPlus; import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.schema.KeyspaceParams; +import org.apache.cassandra.schema.Schema; +import org.apache.cassandra.schema.TableMetadata; import static junit.framework.Assert.*; @@ -197,7 +197,7 @@ public class HintsBufferTest private static Mutation createMutation(int index, long timestamp) { - CFMetaData table = Schema.instance.getCFMetaData(KEYSPACE, TABLE); + TableMetadata table = Schema.instance.getTableMetadata(KEYSPACE, TABLE); return new RowUpdateBuilder(table, timestamp, bytes(index)) .clustering(bytes(index)) .add("val", bytes(index)) http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/hints/HintsServiceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintsServiceTest.java b/test/unit/org/apache/cassandra/hints/HintsServiceTest.java index 077a9d1..2da8993 100644 --- a/test/unit/org/apache/cassandra/hints/HintsServiceTest.java +++ b/test/unit/org/apache/cassandra/hints/HintsServiceTest.java @@ -34,8 +34,8 @@ import org.junit.Test; import com.datastax.driver.core.utils.MoreFutures; import org.apache.cassandra.SchemaLoader; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.schema.TableMetadata; +import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.partitions.PartitionUpdate; import org.apache.cassandra.gms.IFailureDetectionEventListener; @@ -78,7 +78,7 @@ public class HintsServiceTest } @Before - public void reinstanciateService() throws ExecutionException, InterruptedException + public void reinstanciateService() throws Throwable { MessagingService.instance().clearMessageSinks(); @@ -89,7 +89,9 @@ public class HintsServiceTest } failureDetector.isAlive = true; + HintsService.instance = new HintsService(failureDetector); + HintsService.instance.startDispatch(); } @@ -202,8 +204,8 @@ public class HintsServiceTest { long now = System.currentTimeMillis(); DecoratedKey dkey = dk(String.valueOf(i)); - CFMetaData cfMetaData = Schema.instance.getCFMetaData(KEYSPACE, TABLE); - PartitionUpdate.SimpleBuilder builder = PartitionUpdate.simpleBuilder(cfMetaData, dkey).timestamp(now); + TableMetadata metadata = Schema.instance.getTableMetadata(KEYSPACE, TABLE); + PartitionUpdate.SimpleBuilder builder = PartitionUpdate.simpleBuilder(metadata, dkey).timestamp(now); builder.row("column0").add("val", "value0"); Hint hint = Hint.create(builder.buildAsMutation(), now); HintsService.instance.write(hostId, hint); http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/hints/HintsTestUtil.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintsTestUtil.java b/test/unit/org/apache/cassandra/hints/HintsTestUtil.java index 89b532f..c1c6192 100644 --- a/test/unit/org/apache/cassandra/hints/HintsTestUtil.java +++ b/test/unit/org/apache/cassandra/hints/HintsTestUtil.java @@ -17,11 +17,8 @@ */ package org.apache.cassandra.hints; -import java.util.UUID; - import com.google.common.collect.Iterators; -import org.apache.cassandra.db.Mutation; import org.apache.cassandra.db.partitions.AbstractBTreePartition; import org.apache.cassandra.db.partitions.PartitionUpdate; @@ -30,15 +27,6 @@ import static junit.framework.Assert.assertTrue; final class HintsTestUtil { - static void assertMutationsEqual(Mutation expected, Mutation actual) - { - assertEquals(expected.key(), actual.key()); - assertEquals(expected.getPartitionUpdates().size(), actual.getPartitionUpdates().size()); - - for (UUID id : expected.getColumnFamilyIds()) - assertPartitionsEqual(expected.getPartitionUpdate(id), actual.getPartitionUpdate(id)); - } - static void assertPartitionsEqual(AbstractBTreePartition expected, AbstractBTreePartition actual) { assertEquals(expected.partitionKey(), actual.partitionKey()); @@ -51,9 +39,9 @@ final class HintsTestUtil { assertEquals(expected.mutation.getKeyspaceName(), actual.mutation.getKeyspaceName()); assertEquals(expected.mutation.key(), actual.mutation.key()); - assertEquals(expected.mutation.getColumnFamilyIds(), actual.mutation.getColumnFamilyIds()); + assertEquals(expected.mutation.getTableIds(), actual.mutation.getTableIds()); for (PartitionUpdate partitionUpdate : expected.mutation.getPartitionUpdates()) - assertPartitionsEqual(partitionUpdate, actual.mutation.getPartitionUpdate(partitionUpdate.metadata().cfId)); + assertPartitionsEqual(partitionUpdate, actual.mutation.getPartitionUpdate(partitionUpdate.metadata())); assertEquals(expected.creationTime, actual.creationTime); assertEquals(expected.gcgs, actual.gcgs); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/index/CustomIndexTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/index/CustomIndexTest.java b/test/unit/org/apache/cassandra/index/CustomIndexTest.java index a095ef4..b6b401d 100644 --- a/test/unit/org/apache/cassandra/index/CustomIndexTest.java +++ b/test/unit/org/apache/cassandra/index/CustomIndexTest.java @@ -27,12 +27,11 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.junit.Test; import com.datastax.driver.core.exceptions.QueryValidationException; import org.apache.cassandra.Util; -import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.cql3.ColumnIdentifier; import org.apache.cassandra.cql3.restrictions.IndexRestrictions; @@ -54,7 +53,6 @@ import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.concurrent.OpOrder; -import static org.apache.cassandra.Util.throwAssert; import static org.apache.cassandra.cql3.statements.IndexTarget.CUSTOM_INDEX_OPTION_NAME; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -233,21 +231,21 @@ public class CustomIndexTest extends CQLTester createTable("CREATE TABLE %s(k int, c int, v1 int, v2 int, PRIMARY KEY(k,c))"); createIndex(String.format("CREATE CUSTOM INDEX ON %%s(v1, v2) USING '%s'", StubIndex.class.getName())); - assertEquals(1, getCurrentColumnFamilyStore().metadata.getIndexes().size()); + assertEquals(1, getCurrentColumnFamilyStore().metadata().indexes.size()); assertIndexCreated(currentTable() + "_idx", "v1", "v2"); createIndex(String.format("CREATE CUSTOM INDEX ON %%s(c, v1, v2) USING '%s'", StubIndex.class.getName())); - assertEquals(2, getCurrentColumnFamilyStore().metadata.getIndexes().size()); + assertEquals(2, getCurrentColumnFamilyStore().metadata().indexes.size()); assertIndexCreated(currentTable() + "_idx_1", "c", "v1", "v2"); createIndex(String.format("CREATE CUSTOM INDEX ON %%s(c, v2) USING '%s'", StubIndex.class.getName())); - assertEquals(3, getCurrentColumnFamilyStore().metadata.getIndexes().size()); + assertEquals(3, getCurrentColumnFamilyStore().metadata().indexes.size()); assertIndexCreated(currentTable() + "_idx_2", "c", "v2"); // duplicate the previous index with some additional options and check the name is generated as expected createIndex(String.format("CREATE CUSTOM INDEX ON %%s(c, v2) USING '%s' WITH OPTIONS = {'foo':'bar'}", StubIndex.class.getName())); - assertEquals(4, getCurrentColumnFamilyStore().metadata.getIndexes().size()); + assertEquals(4, getCurrentColumnFamilyStore().metadata().indexes.size()); Map<String, String> options = new HashMap<>(); options.put("foo", "bar"); assertIndexCreated(currentTable() + "_idx_3", options, "c", "v2"); @@ -279,7 +277,19 @@ public class CustomIndexTest extends CQLTester testCreateIndex("idx_5", "c2", "v1"); testCreateIndex("idx_6", "v1", "v2"); testCreateIndex("idx_7", "pk2", "c2", "v2"); - testCreateIndex("idx_8", "pk1", "c1", "v1", "mval", "sval", "lval"); + + createIndex(String.format("CREATE CUSTOM INDEX idx_8 ON %%s(" + + " pk1, c1, v1, values(mval), values(sval), values(lval)" + + ") USING '%s'", + StubIndex.class.getName())); + assertIndexCreated("idx_8", + new HashMap<>(), + ImmutableList.of(indexTarget("pk1", IndexTarget.Type.SIMPLE), + indexTarget("c1", IndexTarget.Type.SIMPLE), + indexTarget("v1", IndexTarget.Type.SIMPLE), + indexTarget("mval", IndexTarget.Type.VALUES), + indexTarget("sval", IndexTarget.Type.VALUES), + indexTarget("lval", IndexTarget.Type.VALUES))); createIndex(String.format("CREATE CUSTOM INDEX inc_frozen ON %%s(" + " pk2, c2, v2, full(fmap), full(fset), full(flist)" + @@ -287,9 +297,9 @@ public class CustomIndexTest extends CQLTester StubIndex.class.getName())); assertIndexCreated("inc_frozen", new HashMap<>(), - ImmutableList.of(indexTarget("pk2", IndexTarget.Type.VALUES), - indexTarget("c2", IndexTarget.Type.VALUES), - indexTarget("v2", IndexTarget.Type.VALUES), + ImmutableList.of(indexTarget("pk2", IndexTarget.Type.SIMPLE), + indexTarget("c2", IndexTarget.Type.SIMPLE), + indexTarget("v2", IndexTarget.Type.SIMPLE), indexTarget("fmap", IndexTarget.Type.FULL), indexTarget("fset", IndexTarget.Type.FULL), indexTarget("flist", IndexTarget.Type.FULL))); @@ -300,12 +310,12 @@ public class CustomIndexTest extends CQLTester StubIndex.class.getName())); assertIndexCreated("all_teh_things", new HashMap<>(), - ImmutableList.of(indexTarget("pk1", IndexTarget.Type.VALUES), - indexTarget("pk2", IndexTarget.Type.VALUES), - indexTarget("c1", IndexTarget.Type.VALUES), - indexTarget("c2", IndexTarget.Type.VALUES), - indexTarget("v1", IndexTarget.Type.VALUES), - indexTarget("v2", IndexTarget.Type.VALUES), + ImmutableList.of(indexTarget("pk1", IndexTarget.Type.SIMPLE), + indexTarget("pk2", IndexTarget.Type.SIMPLE), + indexTarget("c1", IndexTarget.Type.SIMPLE), + indexTarget("c2", IndexTarget.Type.SIMPLE), + indexTarget("v1", IndexTarget.Type.SIMPLE), + indexTarget("v2", IndexTarget.Type.SIMPLE), indexTarget("mval", IndexTarget.Type.KEYS), indexTarget("lval", IndexTarget.Type.VALUES), indexTarget("sval", IndexTarget.Type.VALUES), @@ -320,16 +330,6 @@ public class CustomIndexTest extends CQLTester String myType = KEYSPACE + '.' + createType("CREATE TYPE %s (a int, b int)"); createTable("CREATE TABLE %s (k int PRIMARY KEY, v1 int, v2 frozen<" + myType + ">)"); testCreateIndex("udt_idx", "v1", "v2"); - Indexes indexes = getCurrentColumnFamilyStore().metadata.getIndexes(); - IndexMetadata expected = IndexMetadata.fromIndexTargets(getCurrentColumnFamilyStore().metadata, - ImmutableList.of(indexTarget("v1", IndexTarget.Type.VALUES), - indexTarget("v2", IndexTarget.Type.VALUES)), - "udt_idx", - IndexMetadata.Kind.CUSTOM, - ImmutableMap.of(CUSTOM_INDEX_OPTION_NAME, - StubIndex.class.getName())); - IndexMetadata actual = indexes.get("udt_idx").orElseThrow(throwAssert("Index udt_idx not found")); - assertEquals(expected, actual); } @Test @@ -355,13 +355,13 @@ public class CustomIndexTest extends CQLTester execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", row); - assertInvalidMessage(String.format(IndexRestrictions.INDEX_NOT_FOUND, indexName, keyspace(), currentTable()), + assertInvalidMessage(String.format(IndexRestrictions.INDEX_NOT_FOUND, indexName, currentTableMetadata().toString()), String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName)); createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'", indexName, StubIndex.class.getName())); assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), - String.format(IndexRestrictions.INDEX_NOT_FOUND, "no_such_index", keyspace(), currentTable()), + String.format(IndexRestrictions.INDEX_NOT_FOUND, "no_such_index", currentTableMetadata().toString()), QueryValidationException.class, "SELECT * FROM %s WHERE expr(no_such_index, 'foo bar baz ')"); @@ -536,7 +536,7 @@ public class CustomIndexTest extends CQLTester @Test public void reloadIndexMetadataOnBaseCfsReload() throws Throwable { - // verify that whenever the base table CFMetadata is reloaded, a reload of the index + // verify that whenever the base table TableMetadata is reloaded, a reload of the index // metadata is performed createTable("CREATE TABLE %s (k int, v1 int, PRIMARY KEY(k))"); createIndex(String.format("CREATE CUSTOM INDEX reload_counter ON %%s() USING '%s'", @@ -616,13 +616,13 @@ public class CustomIndexTest extends CQLTester } @Test - public void validateOptionsWithCFMetaData() throws Throwable + public void validateOptionsWithTableMetadata() throws Throwable { createTable("CREATE TABLE %s(k int, c int, v1 int, v2 int, PRIMARY KEY(k,c))"); createIndex(String.format("CREATE CUSTOM INDEX ON %%s(c, v2) USING '%s' WITH OPTIONS = {'foo':'bar'}", IndexWithOverloadedValidateOptions.class.getName())); - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; - assertEquals(cfm, IndexWithOverloadedValidateOptions.cfm); + TableMetadata table = getCurrentColumnFamilyStore().metadata(); + assertEquals(table, IndexWithOverloadedValidateOptions.table); assertNotNull(IndexWithOverloadedValidateOptions.options); assertEquals("bar", IndexWithOverloadedValidateOptions.options.get("foo")); } @@ -823,8 +823,7 @@ public class CustomIndexTest extends CQLTester private void assertIndexCreated(String name, Map<String, String> options, String... targetColumnNames) { List<IndexTarget> targets = Arrays.stream(targetColumnNames) - .map(s -> new IndexTarget(ColumnIdentifier.getInterned(s, true), - IndexTarget.Type.VALUES)) + .map(s -> new IndexTarget(ColumnIdentifier.getInterned(s, true), IndexTarget.Type.SIMPLE)) .collect(Collectors.toList()); assertIndexCreated(name, options, targets); } @@ -834,14 +833,13 @@ public class CustomIndexTest extends CQLTester // all tests here use StubIndex as the custom index class, // so add that to the map of options options.put(CUSTOM_INDEX_OPTION_NAME, StubIndex.class.getName()); - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; - IndexMetadata expected = IndexMetadata.fromIndexTargets(cfm, targets, name, IndexMetadata.Kind.CUSTOM, options); - Indexes indexes = getCurrentColumnFamilyStore().metadata.getIndexes(); + IndexMetadata expected = IndexMetadata.fromIndexTargets(targets, name, IndexMetadata.Kind.CUSTOM, options); + Indexes indexes = getCurrentColumnFamilyStore().metadata().indexes; for (IndexMetadata actual : indexes) if (actual.equals(expected)) return; - fail(String.format("Index %s not found in CFMetaData", expected)); + fail(String.format("Index %s not found", expected)); } private static IndexTarget indexTarget(String name, IndexTarget.Type type) @@ -998,7 +996,7 @@ public class CustomIndexTest extends CQLTester public static final class IndexWithOverloadedValidateOptions extends StubIndex { - public static CFMetaData cfm; + public static TableMetadata table; public static Map<String, String> options; public IndexWithOverloadedValidateOptions(ColumnFamilyStore baseCfs, IndexMetadata metadata) @@ -1006,10 +1004,10 @@ public class CustomIndexTest extends CQLTester super(baseCfs, metadata); } - public static Map<String, String> validateOptions(Map<String, String> options, CFMetaData cfm) + public static Map<String, String> validateOptions(Map<String, String> options, TableMetadata table) { IndexWithOverloadedValidateOptions.options = options; - IndexWithOverloadedValidateOptions.cfm = cfm; + IndexWithOverloadedValidateOptions.table = table; return new HashMap<>(); } } @@ -1047,7 +1045,7 @@ public class CustomIndexTest extends CQLTester // various OpOrder.Groups, which it can obtain from this index. public Indexer indexerFor(final DecoratedKey key, - PartitionColumns columns, + RegularAndStaticColumns columns, int nowInSec, OpOrder.Group opGroup, IndexTransaction.Type transactionType) http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/index/StubIndex.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/index/StubIndex.java b/test/unit/org/apache/cassandra/index/StubIndex.java index c80f0d9..00c47d1 100644 --- a/test/unit/org/apache/cassandra/index/StubIndex.java +++ b/test/unit/org/apache/cassandra/index/StubIndex.java @@ -23,7 +23,7 @@ import java.util.concurrent.Callable; import java.util.function.BiFunction; import org.apache.cassandra.Util; -import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.schema.ColumnMetadata; import org.apache.cassandra.cql3.Operator; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.RowFilter; @@ -77,12 +77,12 @@ public class StubIndex implements Index return false; } - public boolean dependsOn(ColumnDefinition column) + public boolean dependsOn(ColumnMetadata column) { return false; } - public boolean supportsExpression(ColumnDefinition column, Operator operator) + public boolean supportsExpression(ColumnMetadata column, Operator operator) { return operator == Operator.EQ; } @@ -98,7 +98,7 @@ public class StubIndex implements Index } public Indexer indexerFor(final DecoratedKey key, - PartitionColumns columns, + RegularAndStaticColumns columns, int nowInSec, OpOrder.Group opGroup, IndexTransaction.Type transactionType) @@ -161,7 +161,7 @@ public class StubIndex implements Index return Optional.empty(); } - public Collection<ColumnDefinition> getIndexedColumns() + public Collection<ColumnMetadata> getIndexedColumns() { return Collections.emptySet(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java b/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java index 5c7d840..9bedb68 100644 --- a/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java +++ b/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java @@ -26,9 +26,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.*; import org.junit.Test; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.ColumnDefinition; -import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.cql3.restrictions.StatementRestrictions; @@ -40,6 +37,9 @@ import org.apache.cassandra.db.rows.Row; import org.apache.cassandra.db.rows.Unfiltered; import org.apache.cassandra.db.rows.UnfilteredRowIterator; import org.apache.cassandra.exceptions.InvalidRequestException; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.SchemaConstants; +import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; @@ -488,20 +488,20 @@ public class CassandraIndexTest extends CQLTester } // this is slightly annoying, but we cannot read rows from the methods in Util as - // ReadCommand#executeInternal uses metadata retrieved via the cfId, which the index + // ReadCommand#executeInternal uses metadata retrieved via the tableId, which the index // CFS inherits from the base CFS. This has the 'wrong' partitioner (the index table // uses LocalPartition, the base table a real one, so we cannot read from the index // table with executeInternal private void assertIndexRowTtl(ColumnFamilyStore indexCfs, int indexedValue, int ttl) throws Throwable { DecoratedKey indexKey = indexCfs.decorateKey(ByteBufferUtil.bytes(indexedValue)); - ClusteringIndexFilter filter = new ClusteringIndexSliceFilter(Slices.with(indexCfs.metadata.comparator, + ClusteringIndexFilter filter = new ClusteringIndexSliceFilter(Slices.with(indexCfs.metadata().comparator, Slice.ALL), false); - SinglePartitionReadCommand command = SinglePartitionReadCommand.create(indexCfs.metadata, + SinglePartitionReadCommand command = SinglePartitionReadCommand.create(indexCfs.metadata(), FBUtilities.nowInSeconds(), indexKey, - ColumnFilter.all(indexCfs.metadata), + ColumnFilter.all(indexCfs.metadata()), filter); try (ReadExecutionController executionController = command.executionController(); UnfilteredRowIterator iter = command.queryMemtableAndDisk(indexCfs, executionController)) @@ -603,7 +603,7 @@ public class CassandraIndexTest extends CQLTester if (updateExpression != null) assertNotNull(postUpdateQueryExpression); - // first, create the table as we need the CFMetaData to build the other cql statements + // first, create the table as we need the Tablemetadata to build the other cql statements createTable(tableDefinition); // now setup the cql statements the test will run through. Some are dependent on @@ -704,7 +704,7 @@ public class CassandraIndexTest extends CQLTester private void assertPrimaryKeyColumnsOnly(UntypedResultSet resultSet, Object[] row) { assertFalse(resultSet.isEmpty()); - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; + TableMetadata cfm = getCurrentColumnFamilyStore().metadata(); int columnCount = cfm.partitionKeyColumns().size(); if (cfm.isCompound()) columnCount += cfm.clusteringColumns().size(); @@ -714,14 +714,12 @@ public class CassandraIndexTest extends CQLTester private String getInsertCql() { - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; + TableMetadata metadata = getCurrentColumnFamilyStore().metadata(); String columns = Joiner.on(", ") - .join(Iterators.transform(cfm.allColumnsInSelectOrder(), + .join(Iterators.transform(metadata.allColumnsInSelectOrder(), (column) -> column.name.toString())); - String markers = Joiner.on(", ").join(Iterators.transform(cfm.allColumnsInSelectOrder(), - (column) -> { - return "?"; - })); + String markers = Joiner.on(", ").join(Iterators.transform(metadata.allColumnsInSelectOrder(), + (column) -> "?")); return String.format("INSERT INTO %%s (%s) VALUES (%s)", columns, markers); } @@ -740,15 +738,15 @@ public class CassandraIndexTest extends CQLTester private String getDeletePartitionCql() { - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; + TableMetadata cfm = getCurrentColumnFamilyStore().metadata(); return StreamSupport.stream(cfm.partitionKeyColumns().spliterator(), false) .map(column -> column.name.toString() + "=?") .collect(Collectors.joining(" AND ", "DELETE FROM %s WHERE ", "")); } - private Stream<ColumnDefinition> getPrimaryKeyColumns() + private Stream<ColumnMetadata> getPrimaryKeyColumns() { - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; + TableMetadata cfm = getCurrentColumnFamilyStore().metadata(); if (cfm.isCompactTable()) return cfm.partitionKeyColumns().stream(); else @@ -757,7 +755,7 @@ public class CassandraIndexTest extends CQLTester private Object[] getPrimaryKeyValues(Object[] row) { - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; + TableMetadata cfm = getCurrentColumnFamilyStore().metadata(); if (cfm.isCompactTable()) return getPartitionKeyValues(row); @@ -766,7 +764,7 @@ public class CassandraIndexTest extends CQLTester private Object[] getPartitionKeyValues(Object[] row) { - CFMetaData cfm = getCurrentColumnFamilyStore().metadata; + TableMetadata cfm = getCurrentColumnFamilyStore().metadata(); return copyValuesFromRow(row, cfm.partitionKeyColumns().size()); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/af3fe39d/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java b/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java index 1173801..1f1d8b9 100644 --- a/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java +++ b/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java @@ -32,8 +32,10 @@ import org.apache.cassandra.index.TargetParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.Schema; +import org.apache.cassandra.schema.TableMetadata; +import org.apache.cassandra.schema.TableMetadataRef; import org.apache.cassandra.cql3.Operator; import org.apache.cassandra.cql3.statements.IndexTarget; import org.apache.cassandra.db.*; @@ -73,7 +75,7 @@ public class CustomCassandraIndex implements Index public final ColumnFamilyStore baseCfs; protected IndexMetadata metadata; protected ColumnFamilyStore indexCfs; - protected ColumnDefinition indexedColumn; + protected ColumnMetadata indexedColumn; protected CassandraIndexFunctions functions; public CustomCassandraIndex(ColumnFamilyStore baseCfs, IndexMetadata indexDef) @@ -88,19 +90,19 @@ public class CustomCassandraIndex implements Index * @param operator * @return */ - protected boolean supportsOperator(ColumnDefinition indexedColumn, Operator operator) + protected boolean supportsOperator(ColumnMetadata indexedColumn, Operator operator) { return operator.equals(Operator.EQ); } - public ColumnDefinition getIndexedColumn() + public ColumnMetadata getIndexedColumn() { return indexedColumn; } public ClusteringComparator getIndexComparator() { - return indexCfs.metadata.comparator; + return indexCfs.metadata().comparator; } public ColumnFamilyStore getIndexCfs() @@ -150,7 +152,6 @@ public class CustomCassandraIndex implements Index { setMetadata(indexDef); return () -> { - indexCfs.metadata.reloadIndexMetadataProperties(baseCfs.metadata); indexCfs.reload(); return null; }; @@ -159,12 +160,12 @@ public class CustomCassandraIndex implements Index private void setMetadata(IndexMetadata indexDef) { metadata = indexDef; - Pair<ColumnDefinition, IndexTarget.Type> target = TargetParser.parse(baseCfs.metadata, indexDef); + Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(baseCfs.metadata(), indexDef); functions = getFunctions(indexDef, target); - CFMetaData cfm = indexCfsMetadata(baseCfs.metadata, indexDef); + TableMetadata cfm = indexCfsMetadata(baseCfs.metadata(), indexDef); indexCfs = ColumnFamilyStore.createColumnFamilyStore(baseCfs.keyspace, - cfm.cfName, - cfm, + cfm.name, + TableMetadataRef.forOfflineTools(cfm), baseCfs.getTracker().loadsstables); indexedColumn = target.left; } @@ -182,12 +183,12 @@ public class CustomCassandraIndex implements Index return true; } - public boolean dependsOn(ColumnDefinition column) + public boolean dependsOn(ColumnMetadata column) { return column.equals(indexedColumn); } - public boolean supportsExpression(ColumnDefinition column, Operator operator) + public boolean supportsExpression(ColumnMetadata column, Operator operator) { return indexedColumn.name.equals(column.name) && supportsOperator(indexedColumn, operator); @@ -285,7 +286,7 @@ public class CustomCassandraIndex implements Index } public Indexer indexerFor(final DecoratedKey key, - final PartitionColumns columns, + final RegularAndStaticColumns columns, final int nowInSec, final OpOrder.Group opGroup, final IndexTransaction.Type transactionType) @@ -553,8 +554,8 @@ public class CustomCassandraIndex implements Index "Cannot index value of size %d for index %s on %s.%s(%s) (maximum allowed size=%d)", value.remaining(), metadata.name, - baseCfs.metadata.ksName, - baseCfs.metadata.cfName, + baseCfs.metadata.keyspace, + baseCfs.metadata.name, indexedColumn.name.toString(), FBUtilities.MAX_UNSIGNED_SHORT)); } @@ -586,7 +587,7 @@ public class CustomCassandraIndex implements Index private PartitionUpdate partitionUpdate(DecoratedKey valueKey, Row row) { - return PartitionUpdate.singleRowUpdate(indexCfs.metadata, valueKey, row); + return PartitionUpdate.singleRowUpdate(indexCfs.metadata(), valueKey, row); } private void invalidate() @@ -629,8 +630,8 @@ public class CustomCassandraIndex implements Index if (sstables.isEmpty()) { logger.info("No SSTable data for {}.{} to build index {} from, marking empty index as built", - baseCfs.metadata.ksName, - baseCfs.metadata.cfName, + baseCfs.metadata.keyspace, + baseCfs.metadata.name, metadata.name); baseCfs.indexManager.markIndexBuilt(metadata.name); return;