Example usage for org.apache.cassandra.io.sstable.format SSTableReader getMaxTimestamp

List of usage examples for org.apache.cassandra.io.sstable.format SSTableReader getMaxTimestamp

Introduction

In this page you can find the example usage for org.apache.cassandra.io.sstable.format SSTableReader getMaxTimestamp.

Prototype

public long getMaxTimestamp() 

Source Link

Usage

From source file:com.jeffjirsa.cassandra.db.compaction.TimeWindowCompactionStrategy.java

License:Apache License

/**
 * Group files with similar max timestamp into buckets.
 *
 * @param files pairs consisting of a file and its min timestamp
 * @param sstableWindowUnit//  w ww  .jav a 2 s.  c om
 * @param sstableWindowSize
 * @param timestampResolution
 * @return A pair, where the left element is the bucket representation (map of timestamp to sstablereader), and the right is the highest timestamp seen
 */
@VisibleForTesting
static Pair<HashMultimap<Long, SSTableReader>, Long> getBuckets(Iterable<SSTableReader> files,
        TimeUnit sstableWindowUnit, int sstableWindowSize, TimeUnit timestampResolution) {
    HashMultimap<Long, SSTableReader> buckets = HashMultimap.create();

    long maxTimestamp = 0;
    // Create hash map to represent buckets
    // For each sstable, add sstable to the time bucket
    // Where the bucket is the file's max timestamp rounded to the nearest window bucket
    for (SSTableReader f : files) {
        long tStamp = f.getMaxTimestamp();
        if (timestampResolution.equals(TimeUnit.MICROSECONDS))
            tStamp = tStamp / 1000L;
        else if (timestampResolution.equals(TimeUnit.NANOSECONDS))
            tStamp = tStamp / 1000000L;
        else if (timestampResolution.equals(TimeUnit.SECONDS))
            tStamp = tStamp * 1000L;
        else
            assert TimeWindowCompactionStrategyOptions.validTimestampTimeUnits.contains(timestampResolution);

        Pair<Long, Long> bounds = getWindowBoundsInMillis(sstableWindowUnit, sstableWindowSize, tStamp);
        buckets.put(bounds.left, f);
        if (bounds.left > maxTimestamp)
            maxTimestamp = bounds.left;
    }

    logger.debug("buckets {}, max timestamp", buckets, maxTimestamp);
    return Pair.<HashMultimap<Long, SSTableReader>, Long>create(buckets, maxTimestamp);
}