Search in sources :

Example 1 with CompactionMetadata

use of org.apache.cassandra.io.sstable.metadata.CompactionMetadata in project cassandra by apache.

the class SSTableMetadataViewer method printSStableMetadata.

private void printSStableMetadata(String fname, boolean scan) throws IOException {
    Descriptor descriptor = Descriptor.fromFilename(fname);
    Map<MetadataType, MetadataComponent> metadata = descriptor.getMetadataSerializer().deserialize(descriptor, EnumSet.allOf(MetadataType.class));
    ValidationMetadata validation = (ValidationMetadata) metadata.get(MetadataType.VALIDATION);
    StatsMetadata stats = (StatsMetadata) metadata.get(MetadataType.STATS);
    CompactionMetadata compaction = (CompactionMetadata) metadata.get(MetadataType.COMPACTION);
    CompressionMetadata compression = null;
    File compressionFile = new File(descriptor.filenameFor(Component.COMPRESSION_INFO));
    if (compressionFile.exists())
        compression = CompressionMetadata.create(fname);
    SerializationHeader.Component header = (SerializationHeader.Component) metadata.get(MetadataType.HEADER);
    field("SSTable", descriptor);
    if (scan && descriptor.version.getVersion().compareTo("ma") >= 0) {
        printScannedOverview(descriptor, stats);
    }
    if (validation != null) {
        field("Partitioner", validation.partitioner);
        field("Bloom Filter FP chance", validation.bloomFilterFPChance);
    }
    if (stats != null) {
        field("Minimum timestamp", stats.minTimestamp, toDateString(stats.minTimestamp, tsUnit));
        field("Maximum timestamp", stats.maxTimestamp, toDateString(stats.maxTimestamp, tsUnit));
        field("SSTable min local deletion time", stats.minLocalDeletionTime, deletion(stats.minLocalDeletionTime));
        field("SSTable max local deletion time", stats.maxLocalDeletionTime, deletion(stats.maxLocalDeletionTime));
        field("Compressor", compression != null ? compression.compressor().getClass().getName() : "-");
        if (compression != null)
            field("Compression ratio", stats.compressionRatio);
        field("TTL min", stats.minTTL, toDurationString(stats.minTTL, TimeUnit.SECONDS));
        field("TTL max", stats.maxTTL, toDurationString(stats.maxTTL, TimeUnit.SECONDS));
        if (validation != null && header != null)
            printMinMaxToken(descriptor, FBUtilities.newPartitioner(descriptor), header.getKeyType());
        if (header != null && header.getClusteringTypes().size() == stats.minClusteringValues.size()) {
            List<AbstractType<?>> clusteringTypes = header.getClusteringTypes();
            List<ByteBuffer> minClusteringValues = stats.minClusteringValues;
            List<ByteBuffer> maxClusteringValues = stats.maxClusteringValues;
            String[] minValues = new String[clusteringTypes.size()];
            String[] maxValues = new String[clusteringTypes.size()];
            for (int i = 0; i < clusteringTypes.size(); i++) {
                minValues[i] = clusteringTypes.get(i).getString(minClusteringValues.get(i));
                maxValues[i] = clusteringTypes.get(i).getString(maxClusteringValues.get(i));
            }
            field("minClusteringValues", Arrays.toString(minValues));
            field("maxClusteringValues", Arrays.toString(maxValues));
        }
        field("Estimated droppable tombstones", stats.getEstimatedDroppableTombstoneRatio((int) (currentTimeMillis() / 1000) - this.gc));
        field("SSTable Level", stats.sstableLevel);
        field("Repaired at", stats.repairedAt, toDateString(stats.repairedAt, TimeUnit.MILLISECONDS));
        field("Pending repair", stats.pendingRepair);
        field("Replay positions covered", stats.commitLogIntervals);
        field("totalColumnsSet", stats.totalColumnsSet);
        field("totalRows", stats.totalRows);
        field("Estimated tombstone drop times", "");
        TermHistogram estDropped = new TermHistogram(stats.estimatedTombstoneDropTime, "Drop Time", offset -> String.format("%d %s", offset, Util.wrapQuiet(toDateString(offset, TimeUnit.SECONDS), color)), String::valueOf);
        estDropped.printHistogram(out, color, unicode);
        field("Partition Size", "");
        TermHistogram rowSize = new TermHistogram(stats.estimatedPartitionSize, "Size (bytes)", offset -> String.format("%d %s", offset, Util.wrapQuiet(toByteString(offset), color)), String::valueOf);
        rowSize.printHistogram(out, color, unicode);
        field("Column Count", "");
        TermHistogram cellCount = new TermHistogram(stats.estimatedCellPerPartitionCount, "Columns", String::valueOf, String::valueOf);
        cellCount.printHistogram(out, color, unicode);
    }
    if (compaction != null) {
        field("Estimated cardinality", compaction.cardinalityEstimator.cardinality());
    }
    if (header != null) {
        EncodingStats encodingStats = header.getEncodingStats();
        AbstractType<?> keyType = header.getKeyType();
        List<AbstractType<?>> clusteringTypes = header.getClusteringTypes();
        Map<ByteBuffer, AbstractType<?>> staticColumns = header.getStaticColumns();
        Map<String, String> statics = staticColumns.entrySet().stream().collect(Collectors.toMap(e -> UTF8Type.instance.getString(e.getKey()), e -> e.getValue().toString()));
        Map<ByteBuffer, AbstractType<?>> regularColumns = header.getRegularColumns();
        Map<String, String> regulars = regularColumns.entrySet().stream().collect(Collectors.toMap(e -> UTF8Type.instance.getString(e.getKey()), e -> e.getValue().toString()));
        field("EncodingStats minTTL", encodingStats.minTTL, toDurationString(encodingStats.minTTL, TimeUnit.SECONDS));
        field("EncodingStats minLocalDeletionTime", encodingStats.minLocalDeletionTime, toDateString(encodingStats.minLocalDeletionTime, TimeUnit.SECONDS));
        field("EncodingStats minTimestamp", encodingStats.minTimestamp, toDateString(encodingStats.minTimestamp, tsUnit));
        field("KeyType", keyType.toString());
        field("ClusteringTypes", clusteringTypes.toString());
        field("StaticColumns", FBUtilities.toString(statics));
        field("RegularColumns", FBUtilities.toString(regulars));
        field("IsTransient", stats.isTransient);
    }
}
Also used : Arrays(java.util.Arrays) CompressionMetadata(org.apache.cassandra.io.compress.CompressionMetadata) File(org.apache.cassandra.io.util.File) RESET(org.apache.cassandra.tools.Util.RESET) AbstractType(org.apache.cassandra.db.marshal.AbstractType) WHITE(org.apache.cassandra.tools.Util.WHITE) ByteBuffer(java.nio.ByteBuffer) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Pair(org.apache.cassandra.utils.Pair) Map(java.util.Map) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) EnumSet(java.util.EnumSet) CYAN(org.apache.cassandra.tools.Util.CYAN) PrintWriter(java.io.PrintWriter) FBUtilities(org.apache.cassandra.utils.FBUtilities) MetadataType(org.apache.cassandra.io.sstable.metadata.MetadataType) BLUE(org.apache.cassandra.tools.Util.BLUE) Collectors(java.util.stream.Collectors) List(java.util.List) ValidationMetadata(org.apache.cassandra.io.sstable.metadata.ValidationMetadata) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef) ParseException(org.apache.commons.cli.ParseException) TableMetadata(org.apache.cassandra.schema.TableMetadata) CompactionMetadata(org.apache.cassandra.io.sstable.metadata.CompactionMetadata) StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) DataInputStream(java.io.DataInputStream) Unfiltered(org.apache.cassandra.db.rows.Unfiltered) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) Options(org.apache.commons.cli.Options) DurationFormatUtils.formatDurationWords(org.apache.commons.lang3.time.DurationFormatUtils.formatDurationWords) HelpFormatter(org.apache.commons.cli.HelpFormatter) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) Row(org.apache.cassandra.db.rows.Row) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Component(org.apache.cassandra.io.sstable.Component) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent) Descriptor(org.apache.cassandra.io.sstable.Descriptor) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) SerializationHeader(org.apache.cassandra.db.SerializationHeader) Option(org.apache.commons.cli.Option) PrintStream(java.io.PrintStream) Files(java.nio.file.Files) CommandLineParser(org.apache.commons.cli.CommandLineParser) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) IOException(java.io.IOException) MinMaxPriorityQueue(com.google.common.collect.MinMaxPriorityQueue) TimeUnit(java.util.concurrent.TimeUnit) IPartitioner(org.apache.cassandra.dht.IPartitioner) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) TermHistogram(org.apache.cassandra.tools.Util.TermHistogram) Comparator(java.util.Comparator) IndexSummary(org.apache.cassandra.io.sstable.IndexSummary) CompactionMetadata(org.apache.cassandra.io.sstable.metadata.CompactionMetadata) TermHistogram(org.apache.cassandra.tools.Util.TermHistogram) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) Component(org.apache.cassandra.io.sstable.Component) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent) StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) CompressionMetadata(org.apache.cassandra.io.compress.CompressionMetadata) MetadataType(org.apache.cassandra.io.sstable.metadata.MetadataType) ValidationMetadata(org.apache.cassandra.io.sstable.metadata.ValidationMetadata) ByteBuffer(java.nio.ByteBuffer) SerializationHeader(org.apache.cassandra.db.SerializationHeader) AbstractType(org.apache.cassandra.db.marshal.AbstractType) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Descriptor(org.apache.cassandra.io.sstable.Descriptor) File(org.apache.cassandra.io.util.File)

Aggregations

MinMaxPriorityQueue (com.google.common.collect.MinMaxPriorityQueue)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 SerializationHeader (org.apache.cassandra.db.SerializationHeader)1 AbstractType (org.apache.cassandra.db.marshal.AbstractType)1 UTF8Type (org.apache.cassandra.db.marshal.UTF8Type)1 EncodingStats (org.apache.cassandra.db.rows.EncodingStats)1