use of org.apache.cassandra.db.rows.EncodingStats in project cassandra by apache.
the class SSTableMetadataViewer method main.
/**
* @param args a list of sstables whose metadata we're interested in
*/
public static void main(String[] args) throws IOException {
PrintStream out = System.out;
Option optGcgs = new Option(null, GCGS_KEY, true, "The " + GCGS_KEY + " to use when calculating droppable tombstones");
Options options = new Options();
options.addOption(optGcgs);
CommandLine cmd = null;
CommandLineParser parser = new PosixParser();
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
printHelp(options, out);
}
if (cmd.getArgs().length == 0) {
printHelp(options, out);
}
int gcgs = Integer.parseInt(cmd.getOptionValue(GCGS_KEY, "0"));
Util.initDatabaseDescriptor();
for (String fname : cmd.getArgs()) {
if (new File(fname).exists()) {
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);
out.printf("SSTable: %s%n", descriptor);
if (validation != null) {
out.printf("Partitioner: %s%n", validation.partitioner);
out.printf("Bloom Filter FP chance: %f%n", validation.bloomFilterFPChance);
}
if (stats != null) {
out.printf("Minimum timestamp: %s%n", stats.minTimestamp);
out.printf("Maximum timestamp: %s%n", stats.maxTimestamp);
out.printf("SSTable min local deletion time: %s%n", stats.minLocalDeletionTime);
out.printf("SSTable max local deletion time: %s%n", stats.maxLocalDeletionTime);
out.printf("Compressor: %s%n", compression != null ? compression.compressor().getClass().getName() : "-");
if (compression != null)
out.printf("Compression ratio: %s%n", stats.compressionRatio);
out.printf("TTL min: %s%n", stats.minTTL);
out.printf("TTL max: %s%n", stats.maxTTL);
if (validation != null && header != null)
printMinMaxToken(descriptor, FBUtilities.newPartitioner(descriptor), header.getKeyType(), out);
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));
}
out.printf("minClustringValues: %s%n", Arrays.toString(minValues));
out.printf("maxClustringValues: %s%n", Arrays.toString(maxValues));
}
out.printf("Estimated droppable tombstones: %s%n", stats.getEstimatedDroppableTombstoneRatio((int) (System.currentTimeMillis() / 1000) - gcgs));
out.printf("SSTable Level: %d%n", stats.sstableLevel);
out.printf("Repaired at: %d%n", stats.repairedAt);
out.printf("Pending repair: %s%n", stats.pendingRepair);
out.printf("Replay positions covered: %s%n", stats.commitLogIntervals);
out.printf("totalColumnsSet: %s%n", stats.totalColumnsSet);
out.printf("totalRows: %s%n", stats.totalRows);
out.println("Estimated tombstone drop times:");
for (Map.Entry<Number, long[]> entry : stats.estimatedTombstoneDropTime.getAsMap().entrySet()) {
out.printf("%-10s:%10s%n", entry.getKey().intValue(), entry.getValue()[0]);
}
printHistograms(stats, out);
}
if (compaction != null) {
out.printf("Estimated cardinality: %s%n", 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()));
out.printf("EncodingStats minTTL: %s%n", encodingStats.minTTL);
out.printf("EncodingStats minLocalDeletionTime: %s%n", encodingStats.minLocalDeletionTime);
out.printf("EncodingStats minTimestamp: %s%n", encodingStats.minTimestamp);
out.printf("KeyType: %s%n", keyType.toString());
out.printf("ClusteringTypes: %s%n", clusteringTypes.toString());
out.printf("StaticColumns: {%s}%n", FBUtilities.toString(statics));
out.printf("RegularColumns: {%s}%n", FBUtilities.toString(regulars));
}
} else {
out.println("No such file: " + fname);
}
}
}
use of org.apache.cassandra.db.rows.EncodingStats in project cassandra by apache.
the class PartitionTest method testColumnStatsRecordsRowDeletesCorrectly.
@Test
public void testColumnStatsRecordsRowDeletesCorrectly() {
long timestamp = System.currentTimeMillis();
int localDeletionTime = (int) (timestamp / 1000);
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_TENCOL);
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 5, "key1").clustering("c").add("val", "val1");
for (int i = 0; i < 10; i++) builder.add("val" + i, "val" + i);
builder.build().applyUnsafe();
RowUpdateBuilder.deleteRowAt(cfs.metadata(), 10L, localDeletionTime, "key1", "c").applyUnsafe();
ImmutableBTreePartition partition = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, "key1").build());
EncodingStats stats = partition.stats();
assertEquals(localDeletionTime, stats.minLocalDeletionTime);
}
Aggregations