Java Code Examples for org.apache.cassandra.io.sstable.SSTableReader#bytesOnDisk()

The following examples show how to use org.apache.cassandra.io.sstable.SSTableReader#bytesOnDisk() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SizeTieredCompactionStrategy.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private long avgSize(List<SSTableReader> sstables)
{
    long n = 0;
    for (SSTableReader sstable : sstables)
        n += sstable.bytesOnDisk();
    return n / sstables.size();
}
 
Example 2
Source File: DataTracker.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void addNewSSTablesSize(Iterable<SSTableReader> newSSTables)
{
    for (SSTableReader sstable : newSSTables)
    {
        if (logger.isDebugEnabled())
            logger.debug(String.format("adding %s to list of files tracked for %s.%s",
                        sstable.descriptor, cfstore.keyspace.getName(), cfstore.name));
        long size = sstable.bytesOnDisk();
        StorageMetrics.load.inc(size);
        cfstore.metric.liveDiskSpaceUsed.inc(size);
        cfstore.metric.totalDiskSpaceUsed.inc(size);
        sstable.setTrackedBy(this);
    }
}
 
Example 3
Source File: DataTracker.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void removeOldSSTablesSize(Iterable<SSTableReader> oldSSTables)
{
    for (SSTableReader sstable : oldSSTables)
    {
        if (logger.isDebugEnabled())
            logger.debug(String.format("removing %s from list of files tracked for %s.%s",
                        sstable.descriptor, cfstore.keyspace.getName(), cfstore.name));
        long size = sstable.bytesOnDisk();
        StorageMetrics.load.dec(size);
        cfstore.metric.liveDiskSpaceUsed.dec(size);
    }
}
 
Example 4
Source File: ColumnFamilyMetricTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSizeMetric()
{
    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard1");
    store.disableAutoCompaction();

    store.truncateBlocking();

    assertEquals(0, store.metric.liveDiskSpaceUsed.count());
    assertEquals(0, store.metric.totalDiskSpaceUsed.count());

    for (int j = 0; j < 10; j++)
    {
        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
        Mutation rm = new Mutation("Keyspace1", key);
        rm.add("Standard1", cellname("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
        rm.apply();
    }
    store.forceBlockingFlush();
    Collection<SSTableReader> sstables = store.getSSTables();
    long size = 0;
    for (SSTableReader reader : sstables)
    {
        size += reader.bytesOnDisk();
    }

    // size metrics should show the sum of all SSTable sizes
    assertEquals(size, store.metric.liveDiskSpaceUsed.count());
    assertEquals(size, store.metric.totalDiskSpaceUsed.count());

    store.truncateBlocking();

    // after truncate, size metrics should be down to 0
    assertEquals(0, store.metric.liveDiskSpaceUsed.count());
    assertEquals(0, store.metric.totalDiskSpaceUsed.count());

    store.enableAutoCompaction();
}