use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.
the class PendingAntiCompactionTest method callbackNullTxn.
/**
* If an AcquireResult has a null txn, there were no sstables to acquire references
* for, so no anti compaction should have been submitted.
*/
@Test
public void callbackNullTxn() throws Exception {
cfs.disableAutoCompaction();
makeSSTables(2);
PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, FULL_RANGE, UUIDGen.getTimeUUID());
PendingAntiCompaction.AcquireResult result = acquisitionCallable.call();
Assert.assertNotNull(result);
ColumnFamilyStore cfs2 = Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getTableMetadata("system", "peers").id);
PendingAntiCompaction.AcquireResult fakeResult = new PendingAntiCompaction.AcquireResult(cfs2, null, null);
InstrumentedAcquisitionCallback cb = new InstrumentedAcquisitionCallback(UUIDGen.getTimeUUID(), FULL_RANGE);
Assert.assertTrue(cb.submittedCompactions.isEmpty());
cb.apply(Lists.newArrayList(result, fakeResult));
Assert.assertEquals(1, cb.submittedCompactions.size());
Assert.assertTrue(cb.submittedCompactions.contains(cfm.id));
Assert.assertFalse(cb.submittedCompactions.contains(cfs2.metadata.id));
}
use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.
the class MigrationManagerTest method addNewTable.
@Test
public void addNewTable() throws ConfigurationException {
final String ksName = KEYSPACE1;
final String tableName = "anewtable";
KeyspaceMetadata original = Schema.instance.getKeyspaceMetadata(ksName);
TableMetadata cfm = addTestTable(original.name, tableName, "A New Table");
assertFalse(Schema.instance.getKeyspaceMetadata(ksName).tables.get(cfm.name).isPresent());
MigrationManager.announceNewTable(cfm);
assertTrue(Schema.instance.getKeyspaceMetadata(ksName).tables.get(cfm.name).isPresent());
assertEquals(cfm, Schema.instance.getKeyspaceMetadata(ksName).tables.get(cfm.name).get());
// now read and write to it.
QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (key, col, val) VALUES (?, ?, ?)", ksName, tableName), "key0", "col0", "val0");
// flush to exercise more than just hitting the memtable
ColumnFamilyStore cfs = Keyspace.open(ksName).getColumnFamilyStore(tableName);
assertNotNull(cfs);
cfs.forceBlockingFlush();
// and make sure we get out what we put in
UntypedResultSet rows = QueryProcessor.executeInternal(String.format("SELECT * FROM %s.%s", ksName, tableName));
assertRows(rows, row("key0", "col0", "val0"));
}
use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.
the class MigrationManagerTest method testDropIndex.
/*
@Test
public void testUpdateColumnFamilyNoIndexes() throws ConfigurationException
{
// create a keyspace with a cf to update.
CFMetaData cf = addTestTable("UpdatedCfKs", "Standard1added", "A new cf that will be updated");
KSMetaData ksm = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(1), cf);
MigrationManager.announceNewKeyspace(ksm);
assertNotNull(Schema.instance.getKSMetaData(cf.ksName));
assertEquals(Schema.instance.getKSMetaData(cf.ksName), ksm);
assertNotNull(Schema.instance.getTableMetadataRef(cf.ksName, cf.cfName));
// updating certain fields should fail.
CFMetaData newCfm = cf.copy();
newCfm.defaultValidator(BytesType.instance);
newCfm.minCompactionThreshold(5);
newCfm.maxCompactionThreshold(31);
// test valid operations.
newCfm.comment("Modified comment");
MigrationManager.announceTableUpdate(newCfm); // doesn't get set back here.
newCfm.readRepairChance(0.23);
MigrationManager.announceTableUpdate(newCfm);
newCfm.gcGraceSeconds(12);
MigrationManager.announceTableUpdate(newCfm);
newCfm.defaultValidator(UTF8Type.instance);
MigrationManager.announceTableUpdate(newCfm);
newCfm.minCompactionThreshold(3);
MigrationManager.announceTableUpdate(newCfm);
newCfm.maxCompactionThreshold(33);
MigrationManager.announceTableUpdate(newCfm);
// can't test changing the reconciler because there is only one impl.
// check the cumulative affect.
assertEquals(Schema.instance.getTableMetadataRef(cf.ksName, cf.cfName).getComment(), newCfm.getComment());
assertEquals(Schema.instance.getTableMetadataRef(cf.ksName, cf.cfName).getReadRepairChance(), newCfm.getReadRepairChance(), 0.0001);
assertEquals(Schema.instance.getTableMetadataRef(cf.ksName, cf.cfName).getGcGraceSeconds(), newCfm.getGcGraceSeconds());
assertEquals(UTF8Type.instance, Schema.instance.getTableMetadataRef(cf.ksName, cf.cfName).getDefaultValidator());
// Change tableId
newCfm = new CFMetaData(cf.ksName, cf.cfName, cf.cfType, cf.comparator);
CFMetaData.copyOpts(newCfm, cf);
try
{
cf.apply(newCfm);
throw new AssertionError("Should have blown up when you used a different id.");
}
catch (ConfigurationException expected) {}
// Change cfName
newCfm = new CFMetaData(cf.ksName, cf.cfName + "_renamed", cf.cfType, cf.comparator);
CFMetaData.copyOpts(newCfm, cf);
try
{
cf.apply(newCfm);
throw new AssertionError("Should have blown up when you used a different name.");
}
catch (ConfigurationException expected) {}
// Change ksName
newCfm = new CFMetaData(cf.ksName + "_renamed", cf.cfName, cf.cfType, cf.comparator);
CFMetaData.copyOpts(newCfm, cf);
try
{
cf.apply(newCfm);
throw new AssertionError("Should have blown up when you used a different keyspace.");
}
catch (ConfigurationException expected) {}
// Change cf type
newCfm = new CFMetaData(cf.ksName, cf.cfName, ColumnFamilyType.Super, cf.comparator);
CFMetaData.copyOpts(newCfm, cf);
try
{
cf.apply(newCfm);
throw new AssertionError("Should have blwon up when you used a different cf type.");
}
catch (ConfigurationException expected) {}
// Change comparator
newCfm = new CFMetaData(cf.ksName, cf.cfName, cf.cfType, new SimpleDenseCellNameType(TimeUUIDType.instance));
CFMetaData.copyOpts(newCfm, cf);
try
{
cf.apply(newCfm);
throw new AssertionError("Should have blown up when you used a different comparator.");
}
catch (ConfigurationException expected) {}
}
*/
@Test
public void testDropIndex() throws ConfigurationException {
// persist keyspace definition in the system keyspace
SchemaKeyspace.makeCreateKeyspaceMutation(Schema.instance.getKeyspaceMetadata(KEYSPACE6), FBUtilities.timestampMicros()).build().applyUnsafe();
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE6).getColumnFamilyStore(TABLE1i);
String indexName = TABLE1i + "_birthdate_key_index";
// insert some data. save the sstable descriptor so we can make sure it's marked for delete after the drop
QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (key, c1, birthdate, notbirthdate) VALUES (?, ?, ?, ?)", KEYSPACE6, TABLE1i), "key0", "col0", 1L, 1L);
cfs.forceBlockingFlush();
ColumnFamilyStore indexCfs = cfs.indexManager.getIndexByName(indexName).getBackingTable().orElseThrow(throwAssert("Cannot access index cfs"));
Descriptor desc = indexCfs.getLiveSSTables().iterator().next().descriptor;
// drop the index
TableMetadata meta = cfs.metadata();
IndexMetadata existing = meta.indexes.get(indexName).orElseThrow(throwAssert("Index not found"));
MigrationManager.announceTableUpdate(meta.unbuild().indexes(meta.indexes.without(existing.name)).build());
// check
assertTrue(cfs.indexManager.listIndexes().isEmpty());
LifecycleTransaction.waitForDeletions();
assertFalse(new File(desc.filenameFor(Component.DATA)).exists());
}
use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.
the class MigrationManagerTest method dropCf.
@Test
public void dropCf() throws ConfigurationException {
// sanity
final KeyspaceMetadata ks = Schema.instance.getKeyspaceMetadata(KEYSPACE1);
assertNotNull(ks);
final TableMetadata cfm = ks.tables.getNullable(TABLE1);
assertNotNull(cfm);
// write some data, force a flush, then verify that files exist on disk.
for (int i = 0; i < 100; i++) QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (key, name, val) VALUES (?, ?, ?)", KEYSPACE1, TABLE1), "dropCf", "col" + i, "anyvalue");
ColumnFamilyStore store = Keyspace.open(cfm.keyspace).getColumnFamilyStore(cfm.name);
assertNotNull(store);
store.forceBlockingFlush();
assertTrue(store.getDirectories().sstableLister(Directories.OnTxnErr.THROW).list().size() > 0);
MigrationManager.announceTableDrop(ks.name, cfm.name);
assertFalse(Schema.instance.getKeyspaceMetadata(ks.name).tables.get(cfm.name).isPresent());
// any write should fail.
boolean success = true;
try {
QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (key, name, val) VALUES (?, ?, ?)", KEYSPACE1, TABLE1), "dropCf", "col0", "anyvalue");
} catch (Throwable th) {
success = false;
}
assertFalse("This mutation should have failed since the CF no longer exists.", success);
// verify that the files are gone.
Supplier<Object> lambda = () -> {
for (File file : store.getDirectories().sstableLister(Directories.OnTxnErr.THROW).listFiles()) {
if (file.getPath().endsWith("Data.db") && !new File(file.getPath().replace("Data.db", "Compacted")).exists())
return false;
}
return true;
};
Util.spinAssertEquals(true, lambda, 30);
}
use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.
the class ValidatorTest method simpleValidationTest.
/**
* Test for CASSANDRA-5263
* 1. Create N rows
* 2. Run validation compaction
* 3. Expect merkle tree with size 2^(log2(n))
*/
public void simpleValidationTest(int n) throws Exception {
Keyspace ks = Keyspace.open(keyspace);
ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnFamily);
cfs.clearUnsafe();
// disable compaction while flushing
cfs.disableAutoCompaction();
//ttl=3s
CompactionsTest.populate(keyspace, columnFamily, 0, n, 0);
cfs.forceBlockingFlush();
assertEquals(1, cfs.getLiveSSTables().size());
// wait enough to force single compaction
TimeUnit.SECONDS.sleep(5);
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
UUID repairSessionId = UUIDGen.getTimeUUID();
final RepairJobDesc desc = new RepairJobDesc(repairSessionId, UUIDGen.getTimeUUID(), cfs.keyspace.getName(), cfs.getTableName(), Collections.singletonList(new Range<>(sstable.first.getToken(), sstable.last.getToken())));
ActiveRepairService.instance.registerParentRepairSession(repairSessionId, FBUtilities.getBroadcastAddress(), Collections.singletonList(cfs), desc.ranges, false, ActiveRepairService.UNREPAIRED_SSTABLE, false);
final CompletableFuture<MessageOut> outgoingMessageSink = registerOutgoingMessageSink();
Validator validator = new Validator(desc, FBUtilities.getBroadcastAddress(), 0, true, false);
CompactionManager.instance.submitValidation(cfs, validator);
MessageOut message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
assertEquals(MessagingService.Verb.REPAIR_MESSAGE, message.verb);
RepairMessage m = (RepairMessage) message.payload;
assertEquals(RepairMessage.Type.VALIDATION_COMPLETE, m.messageType);
assertEquals(desc, m.desc);
assertTrue(((ValidationComplete) m).success());
MerkleTrees trees = ((ValidationComplete) m).trees;
Iterator<Map.Entry<Range<Token>, MerkleTree>> iterator = trees.iterator();
while (iterator.hasNext()) {
assertEquals(Math.pow(2, Math.ceil(Math.log(n) / Math.log(2))), iterator.next().getValue().size(), 0.0);
}
assertEquals(trees.rowCount(), n);
}
Aggregations