use of org.apache.cassandra.cql3.statements.schema.IndexTarget in project cassandra by apache.
the class RangeTombstoneTest method testOverwritesToDeletedColumns.
@Test
public void testOverwritesToDeletedColumns() throws Exception {
Keyspace table = Keyspace.open(KSNAME);
ColumnFamilyStore cfs = table.getColumnFamilyStore(CFNAME);
ByteBuffer key = ByteBufferUtil.bytes("k6");
ByteBuffer indexedColumnName = ByteBufferUtil.bytes("val");
cfs.truncateBlocking();
cfs.disableAutoCompaction();
ColumnMetadata cd = cfs.metadata().getColumn(indexedColumnName).copy();
IndexMetadata indexDef = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(cd.name, IndexTarget.Type.VALUES)), "test_index", IndexMetadata.Kind.CUSTOM, ImmutableMap.of(IndexTarget.CUSTOM_INDEX_OPTION_NAME, StubIndex.class.getName()));
TableMetadata current = cfs.metadata();
if (!current.indexes.get("test_index").isPresent()) {
TableMetadata updated = current.unbuild().indexes(current.indexes.with(indexDef)).build();
MigrationManager.announceTableUpdate(updated, true);
}
Future<?> rebuild = cfs.indexManager.addIndex(indexDef, false);
// If rebuild there is, wait for the rebuild to finish so it doesn't race with the following insertions
if (rebuild != null)
rebuild.get();
StubIndex index = (StubIndex) cfs.indexManager.getIndexByName("test_index");
index.reset();
UpdateBuilder.create(cfs.metadata(), key).withTimestamp(0).newRow(1).add("val", 1).applyUnsafe();
// add a RT which hides the column we just inserted
new RowUpdateBuilder(cfs.metadata(), 1, key).addRangeTombstone(0, 1).build().applyUnsafe();
// now re-insert that column
UpdateBuilder.create(cfs.metadata(), key).withTimestamp(2).newRow(1).add("val", 1).applyUnsafe();
cfs.forceBlockingFlush();
// We should have 1 insert and 1 update to the indexed "1" column
// CASSANDRA-6640 changed index update to just update, not insert then delete
assertEquals(1, index.rowsInserted.size());
assertEquals(1, index.rowsUpdated.size());
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget in project cassandra by apache.
the class DirectoriesTest method testSecondaryIndexDirectories.
@Test
public void testSecondaryIndexDirectories() {
TableMetadata.Builder builder = TableMetadata.builder(KS, "cf").addPartitionKeyColumn("thekey", UTF8Type.instance).addClusteringColumn("col", UTF8Type.instance);
ColumnIdentifier col = ColumnIdentifier.getInterned("col", true);
IndexMetadata indexDef = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(col, IndexTarget.Type.VALUES)), "idx", IndexMetadata.Kind.KEYS, Collections.emptyMap());
builder.indexes(Indexes.of(indexDef));
TableMetadata PARENT_CFM = builder.build();
TableMetadata INDEX_CFM = CassandraIndex.indexCfsMetadata(PARENT_CFM, indexDef);
Directories parentDirectories = new Directories(PARENT_CFM, toDataDirectories(tempDataDir));
Directories indexDirectories = new Directories(INDEX_CFM, toDataDirectories(tempDataDir));
// secondary index has its own directory
for (File dir : indexDirectories.getCFDirectories()) {
assertEquals(cfDir(INDEX_CFM), dir);
}
Descriptor parentDesc = new Descriptor(parentDirectories.getDirectoryForNewSSTables(), KS, PARENT_CFM.name, 0, SSTableFormat.Type.BIG);
Descriptor indexDesc = new Descriptor(indexDirectories.getDirectoryForNewSSTables(), KS, INDEX_CFM.name, 0, SSTableFormat.Type.BIG);
// snapshot dir should be created under its parent's
File parentSnapshotDirectory = Directories.getSnapshotDirectory(parentDesc, "test");
File indexSnapshotDirectory = Directories.getSnapshotDirectory(indexDesc, "test");
assertEquals(parentSnapshotDirectory, indexSnapshotDirectory.parent());
// check if snapshot directory exists
parentSnapshotDirectory.tryCreateDirectories();
assertTrue(parentDirectories.snapshotExists("test"));
assertTrue(indexDirectories.snapshotExists("test"));
// check true snapshot size
Descriptor parentSnapshot = new Descriptor(parentSnapshotDirectory, KS, PARENT_CFM.name, 0, SSTableFormat.Type.BIG);
createFile(parentSnapshot.filenameFor(Component.DATA), 30);
Descriptor indexSnapshot = new Descriptor(indexSnapshotDirectory, KS, INDEX_CFM.name, 0, SSTableFormat.Type.BIG);
createFile(indexSnapshot.filenameFor(Component.DATA), 40);
assertEquals(30, parentDirectories.trueSnapshotsSize());
assertEquals(40, indexDirectories.trueSnapshotsSize());
// check snapshot details
Map<String, TableSnapshot> parentSnapshotDetail = parentDirectories.listSnapshots();
assertTrue(parentSnapshotDetail.containsKey("test"));
assertEquals(30L, parentSnapshotDetail.get("test").computeTrueSizeBytes());
Map<String, TableSnapshot> indexSnapshotDetail = indexDirectories.listSnapshots();
assertTrue(indexSnapshotDetail.containsKey("test"));
assertEquals(40L, indexSnapshotDetail.get("test").computeTrueSizeBytes());
// check backup directory
File parentBackupDirectory = Directories.getBackupsDirectory(parentDesc);
File indexBackupDirectory = Directories.getBackupsDirectory(indexDesc);
assertEquals(parentBackupDirectory, indexBackupDirectory.parent());
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget in project cassandra by apache.
the class SchemaCQLHelperTest method testCfmIndexJson.
@Test
public void testCfmIndexJson() {
String keyspace = "cql_test_keyspace_3";
String table = "test_table_3";
TableMetadata.Builder builder = TableMetadata.builder(keyspace, table).addPartitionKeyColumn("pk1", IntegerType.instance).addClusteringColumn("cl1", IntegerType.instance).addRegularColumn("reg1", AsciiType.instance);
ColumnIdentifier reg1 = ColumnIdentifier.getInterned("reg1", true);
builder.indexes(Indexes.of(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(reg1, IndexTarget.Type.VALUES)), "indexName", IndexMetadata.Kind.COMPOSITES, Collections.emptyMap()), IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(reg1, IndexTarget.Type.KEYS)), "indexName2", IndexMetadata.Kind.COMPOSITES, Collections.emptyMap()), IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(reg1, IndexTarget.Type.KEYS_AND_VALUES)), "indexName3", IndexMetadata.Kind.COMPOSITES, Collections.emptyMap()), IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(reg1, IndexTarget.Type.KEYS_AND_VALUES)), "indexName4", IndexMetadata.Kind.CUSTOM, Collections.singletonMap(IndexTarget.CUSTOM_INDEX_OPTION_NAME, SASIIndex.class.getName())), IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(reg1, IndexTarget.Type.KEYS_AND_VALUES)), "indexName5", IndexMetadata.Kind.CUSTOM, ImmutableMap.of(IndexTarget.CUSTOM_INDEX_OPTION_NAME, SASIIndex.class.getName(), "is_literal", "false"))));
SchemaLoader.createKeyspace(keyspace, KeyspaceParams.simple(1), builder);
ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(table);
assertEquals(ImmutableList.of("CREATE INDEX \"indexName\" ON cql_test_keyspace_3.test_table_3 (values(reg1));", "CREATE INDEX \"indexName2\" ON cql_test_keyspace_3.test_table_3 (keys(reg1));", "CREATE INDEX \"indexName3\" ON cql_test_keyspace_3.test_table_3 (entries(reg1));", "CREATE CUSTOM INDEX \"indexName4\" ON cql_test_keyspace_3.test_table_3 (entries(reg1)) USING 'org.apache.cassandra.index.sasi.SASIIndex';", "CREATE CUSTOM INDEX \"indexName5\" ON cql_test_keyspace_3.test_table_3 (entries(reg1)) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'is_literal': 'false'};"), SchemaCQLHelper.getIndexesAsCQL(cfs.metadata(), false).collect(Collectors.toList()));
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget in project cassandra by apache.
the class AbstractPendingAntiCompactionTest method setup.
@Before
public void setup() {
ks = "ks_" + System.currentTimeMillis();
cfm = CreateTableStatement.parse(String.format("CREATE TABLE %s.%s (k INT PRIMARY KEY, v INT)", ks, tbl), ks).build();
Indexes.Builder indexes = Indexes.builder();
indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("v", true), IndexTarget.Type.VALUES)), tbl2 + "_idx", IndexMetadata.Kind.COMPOSITES, Collections.emptyMap()));
TableMetadata cfm2 = CreateTableStatement.parse(String.format("CREATE TABLE %s.%s (k INT PRIMARY KEY, v INT)", ks, tbl2), ks).indexes(indexes.build()).build();
SchemaLoader.createKeyspace(ks, KeyspaceParams.simple(1), cfm, cfm2);
cfs = Schema.instance.getColumnFamilyStoreInstance(cfm.id);
cfs2 = Schema.instance.getColumnFamilyStoreInstance(cfm2.id);
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget in project cassandra by apache.
the class SchemaLoader method compositeIndexCFMD.
public static TableMetadata.Builder compositeIndexCFMD(String ksName, String cfName, boolean withRegularIndex, boolean withStaticIndex) throws ConfigurationException {
// the withIndex flag exists to allow tests index creation
// on existing columns
TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addRegularColumn("birthdate", LongType.instance).addRegularColumn("notbirthdate", LongType.instance).addStaticColumn("static", LongType.instance).compression(getCompressionParameters());
Indexes.Builder indexes = Indexes.builder();
if (withRegularIndex) {
indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("birthdate", true), IndexTarget.Type.VALUES)), cfName + "_birthdate_key_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
}
if (withStaticIndex) {
indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("static", true), IndexTarget.Type.VALUES)), cfName + "_static_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
}
return builder.indexes(indexes.build());
}
Aggregations