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());
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations