Example usage for org.apache.cassandra.db.compaction TimeWindowCompactionStrategyOptions validTimestampTimeUnits

List of usage examples for org.apache.cassandra.db.compaction TimeWindowCompactionStrategyOptions validTimestampTimeUnits

Introduction

In this page you can find the example usage for org.apache.cassandra.db.compaction TimeWindowCompactionStrategyOptions validTimestampTimeUnits.

Prototype

ImmutableList validTimestampTimeUnits

To view the source code for org.apache.cassandra.db.compaction TimeWindowCompactionStrategyOptions validTimestampTimeUnits.

Click 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//from  www.  jav a2 s  .co  m
 * @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);
}