Example usage for org.apache.cassandra.io.sstable Descriptor baseFilename

List of usage examples for org.apache.cassandra.io.sstable Descriptor baseFilename

Introduction

In this page you can find the example usage for org.apache.cassandra.io.sstable Descriptor baseFilename.

Prototype

public String baseFilename() 

Source Link

Usage

From source file:com.spotify.cassandra.opstools.CountTombstones.java

License:Apache License

private static void run(Descriptor desc, CommandLine cmd, PrintStream out) throws IOException {
    // Since we don't have a schema, make one up!
    CFMetaData cfm = new CFMetaData(desc.ksname, desc.cfname, ColumnFamilyType.Standard, UTF8Type.instance,
            UTF8Type.instance);/*w w w. jav a 2  s . co  m*/

    SSTableReader reader = SSTableReader.open(desc, cfm);
    SSTableScanner scanner = reader.getScanner();

    long totalTombstones = 0, totalColumns = 0;
    if (cmd.hasOption("l")) {
        out.printf(desc.baseFilename() + "\n");
        out.printf("rowkey #tombstones (#columns)\n");
    }
    while (scanner.hasNext()) {
        SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();

        int tombstonesCount = 0, columnsCount = 0;
        while (row.hasNext()) {
            OnDiskAtom column = row.next();
            long now = System.currentTimeMillis();
            if (column instanceof Column && ((Column) column).isMarkedForDelete(now)) {
                tombstonesCount++;
            }
            columnsCount++;
        }
        totalTombstones += tombstonesCount;
        totalColumns += columnsCount;

        if (tombstonesCount > 0) {
            String key;
            try {
                key = UTF8Type.instance.getString(row.getKey().key);
            } catch (RuntimeException e) {
                key = BytesType.instance.getString(row.getKey().key);
            }
            out.printf("%s %d (%d)%n", key, tombstonesCount, columnsCount);
        }

    }

    if (cmd.hasOption("l")) {
        out.printf("#total_tombstones (#total_columns)\n");
    }
    out.printf("%d (%d)%n", totalTombstones, totalColumns);

    scanner.close();
}

From source file:com.spotify.cassandra.opstools.SSTableTimestampViewer.java

License:Apache License

/**
 * @param args a list of sstables whose metadata we're interested in
 *//*from  w w w.  j  a  v a  2 s  . c  o m*/
public static void main(String[] args) throws IOException {
    PrintStream out = System.out;
    if (args.length == 0) {
        out.println("Usage: spcassandra-sstable-timestamp <sstable filenames>");
        System.exit(1);
    }

    List<TimeMetadata> metadata = Lists.newArrayListWithExpectedSize(args.length);
    for (String fname : args) {
        Descriptor descriptor = Descriptor.fromFilename(fname);
        SSTableMetadata md = SSTableMetadata.serializer.deserialize(descriptor).left;
        metadata.add(new TimeMetadata(descriptor.toString(), md.minTimestamp, md.maxTimestamp,
                new java.io.File(descriptor.baseFilename() + "-Data.db").length()));
    }

    Collections.sort(metadata, new Comparator<TimeMetadata>() {
        public int compare(TimeMetadata o1, TimeMetadata o2) {
            return Long.compare(o1.minTimestamp, o2.minTimestamp);
        }
    });

    long[] timespanHistogram = new long[metadata.size() + 1];
    SortedSet<TimeMetadata> currentOverlaps = new TreeSet<>(new Comparator<TimeMetadata>() {
        public int compare(TimeMetadata o1, TimeMetadata o2) {
            return Long.compare(o1.maxTimestamp, o2.maxTimestamp);
        }
    });

    List<Interval<Long, Integer>> intervals = Lists.newArrayList();

    long currentTime = 0;
    boolean wasMax = false;
    for (TimeMetadata md : metadata) {
        while (currentOverlaps.size() > 0 && currentOverlaps.first().maxTimestamp < md.minTimestamp) {
            intervals.add(new Interval<>(currentTime, !wasMax, currentOverlaps.first().maxTimestamp, true,
                    currentOverlaps.size()));
            timespanHistogram[currentOverlaps.size()] += currentOverlaps.first().maxTimestamp - currentTime;
            currentTime = currentOverlaps.first().maxTimestamp;
            wasMax = true;
            currentOverlaps.remove(currentOverlaps.first());
        }
        if (currentTime != 0) {
            intervals.add(new Interval<>(currentTime, !wasMax, md.minTimestamp, false, currentOverlaps.size()));
            timespanHistogram[currentOverlaps.size()] += md.minTimestamp - currentTime;
        }
        currentTime = md.minTimestamp;
        wasMax = false;
        currentOverlaps.add(md);
    }
    while (currentOverlaps.size() > 0) {
        intervals.add(new Interval<>(currentTime, !wasMax, currentOverlaps.first().maxTimestamp, true,
                currentOverlaps.size()));
        timespanHistogram[currentOverlaps.size()] += currentOverlaps.first().maxTimestamp - currentTime;
        currentTime = currentOverlaps.first().maxTimestamp;
        wasMax = true;
        currentOverlaps.remove(currentOverlaps.first());
    }

    for (TimeMetadata md : metadata)
        out.println(md);

    for (Interval<Long, Integer> interval : intervals)
        out.println(interval);
    out.println();

    for (int i = 0; i < timespanHistogram.length; i++)
        out.printf("Total time covered by %s sstables: %s (%.2f%%)%n", i, timespanHistogram[i],
                (double) timespanHistogram[i] / (currentTime - metadata.get(0).minTimestamp) * 100);
}