Search in sources :

Example 16 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.

the class CrcCheckChanceTest method testChangingCrcCheckChance.

public void testChangingCrcCheckChance(boolean newFormat) throws Throwable {
    //Start with crc_check_chance of 99%
    if (newFormat)
        createTable("CREATE TABLE %s (p text, c text, v text, s text static, PRIMARY KEY (p, c)) WITH compression = {'sstable_compression': 'LZ4Compressor'} AND crc_check_chance = 0.99;");
    else
        createTable("CREATE TABLE %s (p text, c text, v text, s text static, PRIMARY KEY (p, c)) WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance' : 0.99}");
    execute("CREATE INDEX foo ON %s(v)");
    execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
    execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
    execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
    ColumnFamilyStore cfs = Keyspace.open(CQLTester.KEYSPACE).getColumnFamilyStore(currentTable());
    ColumnFamilyStore indexCfs = cfs.indexManager.getAllIndexColumnFamilyStores().iterator().next();
    cfs.forceBlockingFlush();
    Assert.assertEquals(0.99, cfs.getCrcCheckChance());
    Assert.assertEquals(0.99, cfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    Assert.assertEquals(0.99, indexCfs.getCrcCheckChance());
    Assert.assertEquals(0.99, indexCfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    //Test for stack overflow
    if (newFormat)
        alterTable("ALTER TABLE %s WITH crc_check_chance = 0.99");
    else
        alterTable("ALTER TABLE %s WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance': 0.99}");
    assertRows(execute("SELECT * FROM %s WHERE p=?", "p1"), row("p1", "k1", "sv1", "v1"), row("p1", "k2", "sv1", "v2"));
    assertRows(execute("SELECT * FROM %s WHERE v=?", "v1"), row("p1", "k1", "sv1", "v1"));
    //Write a few SSTables then Compact
    execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
    execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
    execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
    cfs.forceBlockingFlush();
    execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
    execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
    execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
    cfs.forceBlockingFlush();
    execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
    execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
    execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
    cfs.forceBlockingFlush();
    cfs.forceMajorCompaction();
    //Now let's change via JMX
    cfs.setCrcCheckChance(0.01);
    Assert.assertEquals(0.01, cfs.getCrcCheckChance());
    Assert.assertEquals(0.01, cfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    Assert.assertEquals(0.01, indexCfs.getCrcCheckChance());
    Assert.assertEquals(0.01, indexCfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    assertRows(execute("SELECT * FROM %s WHERE p=?", "p1"), row("p1", "k1", "sv1", "v1"), row("p1", "k2", "sv1", "v2"));
    assertRows(execute("SELECT * FROM %s WHERE v=?", "v1"), row("p1", "k1", "sv1", "v1"));
    //Alter again via schema
    if (newFormat)
        alterTable("ALTER TABLE %s WITH crc_check_chance = 0.5");
    else
        alterTable("ALTER TABLE %s WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance': 0.5}");
    //We should be able to get the new value by accessing directly the schema metadata
    Assert.assertEquals(0.5, cfs.metadata().params.crcCheckChance);
    //but previous JMX-set value will persist until next restart
    Assert.assertEquals(0.01, cfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    Assert.assertEquals(0.01, indexCfs.getCrcCheckChance());
    Assert.assertEquals(0.01, indexCfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    //Verify the call used by JMX still works
    cfs.setCrcCheckChance(0.03);
    Assert.assertEquals(0.03, cfs.getCrcCheckChance());
    Assert.assertEquals(0.03, cfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    Assert.assertEquals(0.03, indexCfs.getCrcCheckChance());
    Assert.assertEquals(0.03, indexCfs.getLiveSSTables().iterator().next().getCrcCheckChance());
    // Also check that any open readers also use the updated value
    // note: only compressed files currently perform crc checks, so only the dfile reader is relevant here
    SSTableReader baseSSTable = cfs.getLiveSSTables().iterator().next();
    SSTableReader idxSSTable = indexCfs.getLiveSSTables().iterator().next();
    try (RandomAccessReader baseDataReader = baseSSTable.openDataReader();
        RandomAccessReader idxDataReader = idxSSTable.openDataReader()) {
        Assert.assertEquals(0.03, baseDataReader.getCrcCheckChance());
        Assert.assertEquals(0.03, idxDataReader.getCrcCheckChance());
        cfs.setCrcCheckChance(0.31);
        Assert.assertEquals(0.31, baseDataReader.getCrcCheckChance());
        Assert.assertEquals(0.31, idxDataReader.getCrcCheckChance());
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 17 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.

the class SSTableMetadataTrackingTest method testTrackMetadata_rangeTombstone.

@Test
public void testTrackMetadata_rangeTombstone() throws Throwable {
    createTable("CREATE TABLE %s (a int, b int, c text, PRIMARY KEY (a, b)) WITH gc_grace_seconds = 10000");
    ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(currentTable());
    execute("DELETE FROM %s USING TIMESTAMP 9999 WHERE a = 1 and b = 1");
    cfs.forceBlockingFlush();
    assertEquals(1, cfs.getLiveSSTables().size());
    StatsMetadata metadata = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(9999, metadata.minTimestamp);
    assertEquals(9999, metadata.maxTimestamp);
    assertEquals(System.currentTimeMillis() / 1000, metadata.maxLocalDeletionTime, 5);
    cfs.forceMajorCompaction();
    StatsMetadata metadata2 = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(metadata.maxLocalDeletionTime, metadata2.maxLocalDeletionTime);
    assertEquals(metadata.minTimestamp, metadata2.minTimestamp);
    assertEquals(metadata.maxTimestamp, metadata2.maxTimestamp);
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 18 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.

the class SSTableMetadataTrackingTest method testTrackMetadata_rowMarker.

@Test
public void testTrackMetadata_rowMarker() throws Throwable {
    createTable("CREATE TABLE %s (a int, PRIMARY KEY (a))");
    ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(currentTable());
    execute("INSERT INTO %s (a) VALUES (1) USING TIMESTAMP 9999");
    cfs.forceBlockingFlush();
    assertEquals(1, cfs.getLiveSSTables().size());
    StatsMetadata metadata = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(9999, metadata.minTimestamp);
    assertEquals(9999, metadata.maxTimestamp);
    assertEquals(Integer.MAX_VALUE, metadata.maxLocalDeletionTime);
    cfs.forceMajorCompaction();
    StatsMetadata metadata2 = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(metadata.maxLocalDeletionTime, metadata2.maxLocalDeletionTime);
    assertEquals(metadata.minTimestamp, metadata2.minTimestamp);
    assertEquals(metadata.maxTimestamp, metadata2.maxTimestamp);
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 19 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.

the class SSTableMetadataTrackingTest method baseCheck.

@Test
public void baseCheck() throws Throwable {
    createTable("CREATE TABLE %s (a int, b int, c text, PRIMARY KEY (a, b))");
    ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(currentTable());
    execute("INSERT INTO %s (a,b,c) VALUES (1,1,'1') using timestamp 9999");
    cfs.forceBlockingFlush();
    StatsMetadata metadata = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(9999, metadata.minTimestamp);
    assertEquals(Integer.MAX_VALUE, metadata.maxLocalDeletionTime);
    cfs.forceMajorCompaction();
    metadata = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(9999, metadata.minTimestamp);
    assertEquals(Integer.MAX_VALUE, metadata.maxLocalDeletionTime);
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 20 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.

the class SSTableMetadataTrackingTest method testTrackMetadata_rowTombstone.

@Test
public void testTrackMetadata_rowTombstone() throws Throwable {
    createTable("CREATE TABLE %s (a int, b int, c text, PRIMARY KEY (a, b))");
    ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(currentTable());
    execute("DELETE FROM %s USING TIMESTAMP 9999 WHERE a = 1");
    cfs.forceBlockingFlush();
    assertEquals(1, cfs.getLiveSSTables().size());
    StatsMetadata metadata = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(9999, metadata.minTimestamp);
    assertEquals(9999, metadata.maxTimestamp);
    assertEquals(System.currentTimeMillis() / 1000, metadata.maxLocalDeletionTime, 5);
    cfs.forceMajorCompaction();
    StatsMetadata metadata2 = cfs.getLiveSSTables().iterator().next().getSSTableMetadata();
    assertEquals(metadata.maxLocalDeletionTime, metadata2.maxLocalDeletionTime);
    assertEquals(metadata.minTimestamp, metadata2.minTimestamp);
    assertEquals(metadata.maxTimestamp, metadata2.maxTimestamp);
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Aggregations

ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)175 Test (org.junit.Test)110 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)90 Keyspace (org.apache.cassandra.db.Keyspace)64 File (java.io.File)30 Directories (org.apache.cassandra.db.Directories)25 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)24 DecoratedKey (org.apache.cassandra.db.DecoratedKey)22 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)20 AbstractTransactionalTest (org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)20 RandomAccessFile (java.io.RandomAccessFile)19 CompactionController (org.apache.cassandra.db.compaction.CompactionController)14 ArrayList (java.util.ArrayList)13 ByteBuffer (java.nio.ByteBuffer)12 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)12 Range (org.apache.cassandra.dht.Range)11 Table (org.apache.cassandra.db.Table)9 Token (org.apache.cassandra.dht.Token)9 Descriptor (org.apache.cassandra.io.sstable.Descriptor)9 StatsMetadata (org.apache.cassandra.io.sstable.metadata.StatsMetadata)9