http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/Assassinate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/Assassinate.java b/src/java/org/apache/cassandra/tools/nodetool/Assassinate.java new file mode 100644 index 0000000..56fec44 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/Assassinate.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static org.apache.commons.lang3.StringUtils.EMPTY; +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.net.UnknownHostException; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "assassinate", description = "Forcefully remove a dead node without re-replicating any data. Use as a last resort if you cannot removenode") +public class Assassinate extends NodeToolCmd +{ + @Arguments(title = "ip address", usage = "<ip_address>", description = "IP address of the endpoint to assassinate", required = true) + private String endpoint = EMPTY; + + @Override + public void execute(NodeProbe probe) + { + try + { + probe.assassinateEndpoint(endpoint); + } + catch (UnknownHostException e) + { + throw new RuntimeException(e); + } + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java b/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java new file mode 100644 index 0000000..bb47e10 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/BootstrapResume.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import java.io.IOError; +import java.io.IOException; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "resume", description = "Resume bootstrap streaming") +public class BootstrapResume extends NodeToolCmd +{ + @Override + protected void execute(NodeProbe probe) + { + try + { + probe.resumeBootstrap(System.out); + } + catch (IOException e) + { + throw new IOError(e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/CfHistograms.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/CfHistograms.java b/src/java/org/apache/cassandra/tools/nodetool/CfHistograms.java new file mode 100644 index 0000000..a9e43fd --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/CfHistograms.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static com.google.common.base.Preconditions.checkArgument; +import static java.lang.String.format; +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.metrics.CassandraMetricsRegistry; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; +import org.apache.cassandra.utils.EstimatedHistogram; +import org.apache.commons.lang3.ArrayUtils; + +@Command(name = "cfhistograms", description = "Print statistic histograms for a given column family") +public class CfHistograms extends NodeToolCmd +{ + @Arguments(usage = "<keyspace> <table>", description = "The keyspace and table name") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + checkArgument(args.size() == 2, "cfhistograms requires ks and cf args"); + + String keyspace = args.get(0); + String cfname = args.get(1); + + // calculate percentile of row size and column count + long[] estimatedRowSize = (long[]) probe.getColumnFamilyMetric(keyspace, cfname, "EstimatedRowSizeHistogram"); + long[] estimatedColumnCount = (long[]) probe.getColumnFamilyMetric(keyspace, cfname, "EstimatedColumnCountHistogram"); + + // build arrays to store percentile values + double[] estimatedRowSizePercentiles = new double[7]; + double[] estimatedColumnCountPercentiles = new double[7]; + double[] offsetPercentiles = new double[]{0.5, 0.75, 0.95, 0.98, 0.99}; + + if (ArrayUtils.isEmpty(estimatedRowSize) || ArrayUtils.isEmpty(estimatedColumnCount)) + { + System.err.println("No SSTables exists, unable to calculate 'Partition Size' and 'Cell Count' percentiles"); + + for (int i = 0; i < 7; i++) + { + estimatedRowSizePercentiles[i] = Double.NaN; + estimatedColumnCountPercentiles[i] = Double.NaN; + } + } + else + { + long[] rowSizeBucketOffsets = new EstimatedHistogram(estimatedRowSize.length).getBucketOffsets(); + long[] columnCountBucketOffsets = new EstimatedHistogram(estimatedColumnCount.length).getBucketOffsets(); + EstimatedHistogram rowSizeHist = new EstimatedHistogram(rowSizeBucketOffsets, estimatedRowSize); + EstimatedHistogram columnCountHist = new EstimatedHistogram(columnCountBucketOffsets, estimatedColumnCount); + + if (rowSizeHist.isOverflowed()) + { + System.err.println(String.format("Row sizes are larger than %s, unable to calculate percentiles", rowSizeBucketOffsets[rowSizeBucketOffsets.length - 1])); + for (int i = 0; i < offsetPercentiles.length; i++) + estimatedRowSizePercentiles[i] = Double.NaN; + } + else + { + for (int i = 0; i < offsetPercentiles.length; i++) + estimatedRowSizePercentiles[i] = rowSizeHist.percentile(offsetPercentiles[i]); + } + + if (columnCountHist.isOverflowed()) + { + System.err.println(String.format("Column counts are larger than %s, unable to calculate percentiles", columnCountBucketOffsets[columnCountBucketOffsets.length - 1])); + for (int i = 0; i < estimatedColumnCountPercentiles.length; i++) + estimatedColumnCountPercentiles[i] = Double.NaN; + } + else + { + for (int i = 0; i < offsetPercentiles.length; i++) + estimatedColumnCountPercentiles[i] = columnCountHist.percentile(offsetPercentiles[i]); + } + + // min value + estimatedRowSizePercentiles[5] = rowSizeHist.min(); + estimatedColumnCountPercentiles[5] = columnCountHist.min(); + // max value + estimatedRowSizePercentiles[6] = rowSizeHist.max(); + estimatedColumnCountPercentiles[6] = columnCountHist.max(); + } + + String[] percentiles = new String[]{"50%", "75%", "95%", "98%", "99%", "Min", "Max"}; + double[] readLatency = probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspace, cfname, "ReadLatency")); + double[] writeLatency = probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspace, cfname, "WriteLatency")); + double[] sstablesPerRead = probe.metricPercentilesAsArray((CassandraMetricsRegistry.JmxHistogramMBean) probe.getColumnFamilyMetric(keyspace, cfname, "SSTablesPerReadHistogram")); + + System.out.println(format("%s/%s histograms", keyspace, cfname)); + System.out.println(format("%-10s%10s%18s%18s%18s%18s", + "Percentile", "SSTables", "Write Latency", "Read Latency", "Partition Size", "Cell Count")); + System.out.println(format("%-10s%10s%18s%18s%18s%18s", + "", "", "(micros)", "(micros)", "(bytes)", "")); + + for (int i = 0; i < percentiles.length; i++) + { + System.out.println(format("%-10s%10.2f%18.2f%18.2f%18.0f%18.0f", + percentiles[i], + sstablesPerRead[i], + writeLatency[i], + readLatency[i], + estimatedRowSizePercentiles[i], + estimatedColumnCountPercentiles[i])); + } + System.out.println(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/CfStats.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/CfStats.java b/src/java/org/apache/cassandra/tools/nodetool/CfStats.java new file mode 100644 index 0000000..2f4d17f --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/CfStats.java @@ -0,0 +1,312 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; +import io.airlift.command.Option; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.management.InstanceNotFoundException; + +import org.apache.cassandra.db.ColumnFamilyStoreMBean; +import org.apache.cassandra.io.util.FileUtils; +import org.apache.cassandra.metrics.CassandraMetricsRegistry; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "cfstats", description = "Print statistics on tables") +public class CfStats extends NodeToolCmd +{ + @Arguments(usage = "[<keyspace.table>...]", description = "List of tables (or keyspace) names") + private List<String> cfnames = new ArrayList<>(); + + @Option(name = "-i", description = "Ignore the list of tables and display the remaining cfs") + private boolean ignore = false; + + @Option(title = "human_readable", + name = {"-H", "--human-readable"}, + description = "Display bytes in human readable form, i.e. KB, MB, GB, TB") + private boolean humanReadable = false; + + @Override + public void execute(NodeProbe probe) + { + CfStats.OptionFilter filter = new OptionFilter(ignore, cfnames); + Map<String, List<ColumnFamilyStoreMBean>> cfstoreMap = new HashMap<>(); + + // get a list of column family stores + Iterator<Map.Entry<String, ColumnFamilyStoreMBean>> cfamilies = probe.getColumnFamilyStoreMBeanProxies(); + + while (cfamilies.hasNext()) + { + Map.Entry<String, ColumnFamilyStoreMBean> entry = cfamilies.next(); + String keyspaceName = entry.getKey(); + ColumnFamilyStoreMBean cfsProxy = entry.getValue(); + + if (!cfstoreMap.containsKey(keyspaceName) && filter.isColumnFamilyIncluded(entry.getKey(), cfsProxy.getColumnFamilyName())) + { + List<ColumnFamilyStoreMBean> columnFamilies = new ArrayList<>(); + columnFamilies.add(cfsProxy); + cfstoreMap.put(keyspaceName, columnFamilies); + } else if (filter.isColumnFamilyIncluded(entry.getKey(), cfsProxy.getColumnFamilyName())) + { + cfstoreMap.get(keyspaceName).add(cfsProxy); + } + } + + // make sure all specified kss and cfs exist + filter.verifyKeyspaces(probe.getKeyspaces()); + filter.verifyColumnFamilies(); + + // print out the table statistics + for (Map.Entry<String, List<ColumnFamilyStoreMBean>> entry : cfstoreMap.entrySet()) + { + String keyspaceName = entry.getKey(); + List<ColumnFamilyStoreMBean> columnFamilies = entry.getValue(); + long keyspaceReadCount = 0; + long keyspaceWriteCount = 0; + int keyspacePendingFlushes = 0; + double keyspaceTotalReadTime = 0.0f; + double keyspaceTotalWriteTime = 0.0f; + + System.out.println("Keyspace: " + keyspaceName); + for (ColumnFamilyStoreMBean cfstore : columnFamilies) + { + String cfName = cfstore.getColumnFamilyName(); + long writeCount = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getCount(); + long readCount = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getCount(); + + if (readCount > 0) + { + keyspaceReadCount += readCount; + keyspaceTotalReadTime += (long) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadTotalLatency"); + } + if (writeCount > 0) + { + keyspaceWriteCount += writeCount; + keyspaceTotalWriteTime += (long) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteTotalLatency"); + } + keyspacePendingFlushes += (long) probe.getColumnFamilyMetric(keyspaceName, cfName, "PendingFlushes"); + } + + double keyspaceReadLatency = keyspaceReadCount > 0 + ? keyspaceTotalReadTime / keyspaceReadCount / 1000 + : Double.NaN; + double keyspaceWriteLatency = keyspaceWriteCount > 0 + ? keyspaceTotalWriteTime / keyspaceWriteCount / 1000 + : Double.NaN; + + System.out.println("\tRead Count: " + keyspaceReadCount); + System.out.println("\tRead Latency: " + String.format("%s", keyspaceReadLatency) + " ms."); + System.out.println("\tWrite Count: " + keyspaceWriteCount); + System.out.println("\tWrite Latency: " + String.format("%s", keyspaceWriteLatency) + " ms."); + System.out.println("\tPending Flushes: " + keyspacePendingFlushes); + + // print out column family statistics for this keyspace + for (ColumnFamilyStoreMBean cfstore : columnFamilies) + { + String cfName = cfstore.getColumnFamilyName(); + if (cfName.contains(".")) + System.out.println("\t\tTable (index): " + cfName); + else + System.out.println("\t\tTable: " + cfName); + + System.out.println("\t\tSSTable count: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "LiveSSTableCount")); + + int[] leveledSStables = cfstore.getSSTableCountPerLevel(); + if (leveledSStables != null) + { + System.out.print("\t\tSSTables in each level: ["); + for (int level = 0; level < leveledSStables.length; level++) + { + int count = leveledSStables[level]; + System.out.print(count); + long maxCount = 4L; // for L0 + if (level > 0) + maxCount = (long) Math.pow(10, level); + // show max threshold for level when exceeded + if (count > maxCount) + System.out.print("/" + maxCount); + + if (level < leveledSStables.length - 1) + System.out.print(", "); + else + System.out.println("]"); + } + } + + Long memtableOffHeapSize = null; + Long bloomFilterOffHeapSize = null; + Long indexSummaryOffHeapSize = null; + Long compressionMetadataOffHeapSize = null; + + Long offHeapSize = null; + + try + { + memtableOffHeapSize = (Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MemtableOffHeapSize"); + bloomFilterOffHeapSize = (Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "BloomFilterOffHeapMemoryUsed"); + indexSummaryOffHeapSize = (Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "IndexSummaryOffHeapMemoryUsed"); + compressionMetadataOffHeapSize = (Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "CompressionMetadataOffHeapMemoryUsed"); + + offHeapSize = memtableOffHeapSize + bloomFilterOffHeapSize + indexSummaryOffHeapSize + compressionMetadataOffHeapSize; + } + catch (RuntimeException e) + { + // offheap-metrics introduced in 2.1.3 - older versions do not have the appropriate mbeans + if (!(e.getCause() instanceof InstanceNotFoundException)) + throw e; + } + + System.out.println("\t\tSpace used (live): " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "LiveDiskSpaceUsed"), humanReadable)); + System.out.println("\t\tSpace used (total): " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "TotalDiskSpaceUsed"), humanReadable)); + System.out.println("\t\tSpace used by snapshots (total): " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "SnapshotsSize"), humanReadable)); + if (offHeapSize != null) + System.out.println("\t\tOff heap memory used (total): " + format(offHeapSize, humanReadable)); + System.out.println("\t\tSSTable Compression Ratio: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "CompressionRatio")); + long numberOfKeys = 0; + for (long keys : (long[]) probe.getColumnFamilyMetric(keyspaceName, cfName, "EstimatedColumnCountHistogram")) + numberOfKeys += keys; + System.out.println("\t\tNumber of keys (estimate): " + numberOfKeys); + System.out.println("\t\tMemtable cell count: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "MemtableColumnsCount")); + System.out.println("\t\tMemtable data size: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MemtableLiveDataSize"), humanReadable)); + if (memtableOffHeapSize != null) + System.out.println("\t\tMemtable off heap memory used: " + format(memtableOffHeapSize, humanReadable)); + System.out.println("\t\tMemtable switch count: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "MemtableSwitchCount")); + System.out.println("\t\tLocal read count: " + ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getCount()); + double localReadLatency = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "ReadLatency")).getMean() / 1000; + double localRLatency = localReadLatency > 0 ? localReadLatency : Double.NaN; + System.out.printf("\t\tLocal read latency: %01.3f ms%n", localRLatency); + System.out.println("\t\tLocal write count: " + ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getCount()); + double localWriteLatency = ((CassandraMetricsRegistry.JmxTimerMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "WriteLatency")).getMean() / 1000; + double localWLatency = localWriteLatency > 0 ? localWriteLatency : Double.NaN; + System.out.printf("\t\tLocal write latency: %01.3f ms%n", localWLatency); + System.out.println("\t\tPending flushes: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "PendingFlushes")); + System.out.println("\t\tBloom filter false positives: " + probe.getColumnFamilyMetric(keyspaceName, cfName, "BloomFilterFalsePositives")); + System.out.printf("\t\tBloom filter false ratio: %s%n", String.format("%01.5f", probe.getColumnFamilyMetric(keyspaceName, cfName, "RecentBloomFilterFalseRatio"))); + System.out.println("\t\tBloom filter space used: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "BloomFilterDiskSpaceUsed"), humanReadable)); + if (bloomFilterOffHeapSize != null) + System.out.println("\t\tBloom filter off heap memory used: " + format(bloomFilterOffHeapSize, humanReadable)); + if (indexSummaryOffHeapSize != null) + System.out.println("\t\tIndex summary off heap memory used: " + format(indexSummaryOffHeapSize, humanReadable)); + if (compressionMetadataOffHeapSize != null) + System.out.println("\t\tCompression metadata off heap memory used: " + format(compressionMetadataOffHeapSize, humanReadable)); + + System.out.println("\t\tCompacted partition minimum bytes: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MinRowSize"), humanReadable)); + System.out.println("\t\tCompacted partition maximum bytes: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MaxRowSize"), humanReadable)); + System.out.println("\t\tCompacted partition mean bytes: " + format((Long) probe.getColumnFamilyMetric(keyspaceName, cfName, "MeanRowSize"), humanReadable)); + CassandraMetricsRegistry.JmxHistogramMBean histogram = (CassandraMetricsRegistry.JmxHistogramMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "LiveScannedHistogram"); + System.out.println("\t\tAverage live cells per slice (last five minutes): " + histogram.getMean()); + System.out.println("\t\tMaximum live cells per slice (last five minutes): " + histogram.getMax()); + histogram = (CassandraMetricsRegistry.JmxHistogramMBean) probe.getColumnFamilyMetric(keyspaceName, cfName, "TombstoneScannedHistogram"); + System.out.println("\t\tAverage tombstones per slice (last five minutes): " + histogram.getMean()); + System.out.println("\t\tMaximum tombstones per slice (last five minutes): " + histogram.getMax()); + + System.out.println(""); + } + System.out.println("----------------"); + } + } + + private String format(long bytes, boolean humanReadable) { + return humanReadable ? FileUtils.stringifyFileSize(bytes) : Long.toString(bytes); + } + + /** + * Used for filtering keyspaces and columnfamilies to be displayed using the cfstats command. + */ + private static class OptionFilter + { + private Map<String, List<String>> filter = new HashMap<>(); + private Map<String, List<String>> verifier = new HashMap<>(); + private List<String> filterList = new ArrayList<>(); + private boolean ignoreMode; + + public OptionFilter(boolean ignoreMode, List<String> filterList) + { + this.filterList.addAll(filterList); + this.ignoreMode = ignoreMode; + + for (String s : filterList) + { + String[] keyValues = s.split("\\.", 2); + + // build the map that stores the ks' and cfs to use + if (!filter.containsKey(keyValues[0])) + { + filter.put(keyValues[0], new ArrayList<String>()); + verifier.put(keyValues[0], new ArrayList<String>()); + + if (keyValues.length == 2) + { + filter.get(keyValues[0]).add(keyValues[1]); + verifier.get(keyValues[0]).add(keyValues[1]); + } + } else + { + if (keyValues.length == 2) + { + filter.get(keyValues[0]).add(keyValues[1]); + verifier.get(keyValues[0]).add(keyValues[1]); + } + } + } + } + + public boolean isColumnFamilyIncluded(String keyspace, String columnFamily) + { + // supplying empty params list is treated as wanting to display all kss & cfs + if (filterList.isEmpty()) + return !ignoreMode; + + List<String> cfs = filter.get(keyspace); + + // no such keyspace is in the map + if (cfs == null) + return ignoreMode; + // only a keyspace with no cfs was supplied + // so ignore or include (based on the flag) every column family in specified keyspace + else if (cfs.size() == 0) + return !ignoreMode; + + // keyspace exists, and it contains specific cfs + verifier.get(keyspace).remove(columnFamily); + return ignoreMode ^ cfs.contains(columnFamily); + } + + public void verifyKeyspaces(List<String> keyspaces) + { + for (String ks : verifier.keySet()) + if (!keyspaces.contains(ks)) + throw new IllegalArgumentException("Unknown keyspace: " + ks); + } + + public void verifyColumnFamilies() + { + for (String ks : filter.keySet()) + if (verifier.get(ks).size() > 0) + throw new IllegalArgumentException("Unknown tables: " + verifier.get(ks) + " in keyspace: " + ks); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java b/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java new file mode 100644 index 0000000..aa415b3 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/Cleanup.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.db.SystemKeyspace; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "cleanup", description = "Triggers the immediate cleanup of keys no longer belonging to a node. By default, clean all keyspaces") +public class Cleanup extends NodeToolCmd +{ + @Arguments(usage = "[<keyspace> <tables>...]", description = "The keyspace followed by one or many tables") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + List<String> keyspaces = parseOptionalKeyspace(args, probe); + String[] cfnames = parseOptionalColumnFamilies(args); + + for (String keyspace : keyspaces) + { + if (SystemKeyspace.NAME.equals(keyspace)) + continue; + + try + { + probe.forceKeyspaceCleanup(System.out, keyspace, cfnames); + } catch (Exception e) + { + throw new RuntimeException("Error occurred during cleanup", e); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java b/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java new file mode 100644 index 0000000..7167bd9 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static com.google.common.collect.Iterables.toArray; +import static org.apache.commons.lang3.StringUtils.EMPTY; +import static org.apache.commons.lang3.StringUtils.join; +import io.airlift.command.Arguments; +import io.airlift.command.Command; +import io.airlift.command.Option; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "clearsnapshot", description = "Remove the snapshot with the given name from the given keyspaces. If no snapshotName is specified we will remove all snapshots") +public class ClearSnapshot extends NodeToolCmd +{ + @Arguments(usage = "[<keyspaces>...] ", description = "Remove snapshots from the given keyspaces") + private List<String> keyspaces = new ArrayList<>(); + + @Option(title = "snapshot_name", name = "-t", description = "Remove the snapshot with a given name") + private String snapshotName = EMPTY; + + @Override + public void execute(NodeProbe probe) + { + StringBuilder sb = new StringBuilder(); + + sb.append("Requested clearing snapshot(s) for "); + + if (keyspaces.isEmpty()) + sb.append("[all keyspaces]"); + else + sb.append("[").append(join(keyspaces, ", ")).append("]"); + + if (!snapshotName.isEmpty()) + sb.append(" with snapshot name [").append(snapshotName).append("]"); + + System.out.println(sb.toString()); + + try + { + probe.clearSnapshot(snapshotName, toArray(keyspaces, String.class)); + } catch (IOException e) + { + throw new RuntimeException("Error during clearing snapshots", e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/Compact.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/Compact.java b/src/java/org/apache/cassandra/tools/nodetool/Compact.java new file mode 100644 index 0000000..4d04ae7 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/Compact.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; +import io.airlift.command.Option; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "compact", description = "Force a (major) compaction on one or more tables") +public class Compact extends NodeToolCmd +{ + @Arguments(usage = "[<keyspace> <tables>...]", description = "The keyspace followed by one or many tables") + private List<String> args = new ArrayList<>(); + + @Option(title = "split_output", name = {"-s", "--split-output"}, description = "Use -s to not create a single big file") + private boolean splitOutput = false; + + @Override + public void execute(NodeProbe probe) + { + List<String> keyspaces = parseOptionalKeyspace(args, probe); + String[] cfnames = parseOptionalColumnFamilies(args); + + for (String keyspace : keyspaces) + { + try + { + probe.forceKeyspaceCompaction(splitOutput, keyspace, cfnames); + } catch (Exception e) + { + throw new RuntimeException("Error occurred during compaction", e); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java new file mode 100644 index 0000000..cbb054a --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static com.google.common.collect.Iterables.toArray; +import io.airlift.command.Command; + +import java.util.List; +import java.util.Set; + +import javax.management.openmbean.TabularData; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "compactionhistory", description = "Print history of compaction") +public class CompactionHistory extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + System.out.println("Compaction History: "); + + TabularData tabularData = probe.getCompactionHistory(); + if (tabularData.isEmpty()) + { + System.out.printf("There is no compaction history"); + return; + } + + String format = "%-41s%-19s%-29s%-26s%-15s%-15s%s%n"; + List<String> indexNames = tabularData.getTabularType().getIndexNames(); + System.out.printf(format, toArray(indexNames, Object.class)); + + Set<?> values = tabularData.keySet(); + for (Object eachValue : values) + { + List<?> value = (List<?>) eachValue; + System.out.printf(format, toArray(value, Object.class)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java b/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java new file mode 100644 index 0000000..154ef49 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static java.lang.String.format; +import io.airlift.command.Command; +import io.airlift.command.Option; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.cassandra.db.compaction.CompactionManagerMBean; +import org.apache.cassandra.db.compaction.OperationType; +import org.apache.cassandra.io.util.FileUtils; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "compactionstats", description = "Print statistics on compactions") +public class CompactionStats extends NodeToolCmd +{ + @Option(title = "human_readable", + name = {"-H", "--human-readable"}, + description = "Display bytes in human readable form, i.e. KB, MB, GB, TB") + private boolean humanReadable = false; + + @Override + public void execute(NodeProbe probe) + { + CompactionManagerMBean cm = probe.getCompactionManagerProxy(); + System.out.println("pending tasks: " + probe.getCompactionMetric("PendingTasks")); + long remainingBytes = 0; + List<Map<String, String>> compactions = cm.getCompactions(); + if (!compactions.isEmpty()) + { + int compactionThroughput = probe.getCompactionThroughput(); + List<String[]> lines = new ArrayList<>(); + int[] columnSizes = new int[] { 0, 0, 0, 0, 0, 0, 0 }; + + addLine(lines, columnSizes, "compaction type", "keyspace", "table", "completed", "total", "unit", "progress"); + for (Map<String, String> c : compactions) + { + long total = Long.parseLong(c.get("total")); + long completed = Long.parseLong(c.get("completed")); + String taskType = c.get("taskType"); + String keyspace = c.get("keyspace"); + String columnFamily = c.get("columnfamily"); + String completedStr = humanReadable ? FileUtils.stringifyFileSize(completed) : Long.toString(completed); + String totalStr = humanReadable ? FileUtils.stringifyFileSize(total) : Long.toString(total); + String unit = c.get("unit"); + String percentComplete = total == 0 ? "n/a" : new DecimalFormat("0.00").format((double) completed / total * 100) + "%"; + addLine(lines, columnSizes, taskType, keyspace, columnFamily, completedStr, totalStr, unit, percentComplete); + if (taskType.equals(OperationType.COMPACTION.toString())) + remainingBytes += total - completed; + } + + StringBuilder buffer = new StringBuilder(); + for (int columnSize : columnSizes) { + buffer.append("%"); + buffer.append(columnSize + 3); + buffer.append("s"); + } + buffer.append("%n"); + String format = buffer.toString(); + + for (String[] line : lines) + { + System.out.printf(format, line[0], line[1], line[2], line[3], line[4], line[5], line[6]); + } + + String remainingTime = "n/a"; + if (compactionThroughput != 0) + { + long remainingTimeInSecs = remainingBytes / (1024L * 1024L * compactionThroughput); + remainingTime = format("%dh%02dm%02ds", remainingTimeInSecs / 3600, (remainingTimeInSecs % 3600) / 60, (remainingTimeInSecs % 60)); + } + System.out.printf("%25s%10s%n", "Active compaction remaining time : ", remainingTime); + } + } + + private void addLine(List<String[]> lines, int[] columnSizes, String... columns) { + lines.add(columns); + for (int i = 0; i < columns.length; i++) { + columnSizes[i] = Math.max(columnSizes[i], columns[i].length()); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/Decommission.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/Decommission.java b/src/java/org/apache/cassandra/tools/nodetool/Decommission.java new file mode 100644 index 0000000..a3feb67 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/Decommission.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "decommission", description = "Decommission the *node I am connecting to*") +public class Decommission extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + try + { + probe.decommission(); + } catch (InterruptedException e) + { + throw new RuntimeException("Error decommissioning node", e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java b/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java new file mode 100644 index 0000000..81dee20 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DescribeCluster.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static java.lang.String.format; +import io.airlift.command.Command; + +import java.util.List; +import java.util.Map; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "describecluster", description = "Print the name, snitch, partitioner and schema version of a cluster") +public class DescribeCluster extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + // display cluster name, snitch and partitioner + System.out.println("Cluster Information:"); + System.out.println("\tName: " + probe.getClusterName()); + System.out.println("\tSnitch: " + probe.getEndpointSnitchInfoProxy().getSnitchName()); + System.out.println("\tPartitioner: " + probe.getPartitioner()); + + // display schema version for each node + System.out.println("\tSchema versions:"); + Map<String, List<String>> schemaVersions = probe.getSpProxy().getSchemaVersions(); + for (String version : schemaVersions.keySet()) + { + System.out.println(format("\t\t%s: %s%n", version, schemaVersions.get(version))); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java b/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java new file mode 100644 index 0000000..a120ffe --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DescribeRing.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static org.apache.commons.lang3.StringUtils.EMPTY; +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.io.IOException; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "describering", description = "Shows the token ranges info of a given keyspace") +public class DescribeRing extends NodeToolCmd +{ + @Arguments(description = "The keyspace name", required = true) + String keyspace = EMPTY; + + @Override + public void execute(NodeProbe probe) + { + System.out.println("Schema Version:" + probe.getSchemaVersion()); + System.out.println("TokenRange: "); + try + { + for (String tokenRangeString : probe.describeRing(keyspace)) + { + System.out.println("\t" + tokenRangeString); + } + } catch (IOException e) + { + throw new RuntimeException(e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DisableAutoCompaction.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DisableAutoCompaction.java b/src/java/org/apache/cassandra/tools/nodetool/DisableAutoCompaction.java new file mode 100644 index 0000000..2f5832d --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DisableAutoCompaction.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "disableautocompaction", description = "Disable autocompaction for the given keyspace and table") +public class DisableAutoCompaction extends NodeToolCmd +{ + @Arguments(usage = "[<keyspace> <tables>...]", description = "The keyspace followed by one or many tables") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + List<String> keyspaces = parseOptionalKeyspace(args, probe); + String[] cfnames = parseOptionalColumnFamilies(args); + + for (String keyspace : keyspaces) + { + try + { + probe.disableAutoCompaction(keyspace, cfnames); + } catch (IOException e) + { + throw new RuntimeException("Error occurred during disabling auto-compaction", e); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DisableBackup.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DisableBackup.java b/src/java/org/apache/cassandra/tools/nodetool/DisableBackup.java new file mode 100644 index 0000000..74e7f50 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DisableBackup.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "disablebackup", description = "Disable incremental backup") +public class DisableBackup extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.setIncrementalBackupsEnabled(false); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DisableBinary.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DisableBinary.java b/src/java/org/apache/cassandra/tools/nodetool/DisableBinary.java new file mode 100644 index 0000000..dee319b --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DisableBinary.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "disablebinary", description = "Disable native transport (binary protocol)") +public class DisableBinary extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.stopNativeTransport(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DisableGossip.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DisableGossip.java b/src/java/org/apache/cassandra/tools/nodetool/DisableGossip.java new file mode 100644 index 0000000..32448c9 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DisableGossip.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "disablegossip", description = "Disable gossip (effectively marking the node down)") +public class DisableGossip extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.stopGossiping(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DisableHandoff.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DisableHandoff.java b/src/java/org/apache/cassandra/tools/nodetool/DisableHandoff.java new file mode 100644 index 0000000..11cd754 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DisableHandoff.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "disablehandoff", description = "Disable storing hinted handoffs") +public class DisableHandoff extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.disableHintedHandoff(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/DisableThrift.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/DisableThrift.java b/src/java/org/apache/cassandra/tools/nodetool/DisableThrift.java new file mode 100644 index 0000000..148b195 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/DisableThrift.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "disablethrift", description = "Disable thrift server") +public class DisableThrift extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.stopThriftServer(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/Drain.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/Drain.java b/src/java/org/apache/cassandra/tools/nodetool/Drain.java new file mode 100644 index 0000000..5562e6d --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/Drain.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "drain", description = "Drain the node (stop accepting writes and flush all tables)") +public class Drain extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + try + { + probe.drain(); + } catch (IOException | InterruptedException | ExecutionException e) + { + throw new RuntimeException("Error occurred during flushing", e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/EnableAutoCompaction.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/EnableAutoCompaction.java b/src/java/org/apache/cassandra/tools/nodetool/EnableAutoCompaction.java new file mode 100644 index 0000000..e846187 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/EnableAutoCompaction.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "enableautocompaction", description = "Enable autocompaction for the given keyspace and table") +public class EnableAutoCompaction extends NodeToolCmd +{ + @Arguments(usage = "[<keyspace> <tables>...]", description = "The keyspace followed by one or many tables") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + List<String> keyspaces = parseOptionalKeyspace(args, probe); + String[] cfnames = parseOptionalColumnFamilies(args); + + for (String keyspace : keyspaces) + { + try + { + probe.enableAutoCompaction(keyspace, cfnames); + } catch (IOException e) + { + throw new RuntimeException("Error occurred during enabling auto-compaction", e); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/EnableBackup.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/EnableBackup.java b/src/java/org/apache/cassandra/tools/nodetool/EnableBackup.java new file mode 100644 index 0000000..4847fa5 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/EnableBackup.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "enablebackup", description = "Enable incremental backup") +public class EnableBackup extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.setIncrementalBackupsEnabled(true); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/EnableBinary.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/EnableBinary.java b/src/java/org/apache/cassandra/tools/nodetool/EnableBinary.java new file mode 100644 index 0000000..f1d5d9c --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/EnableBinary.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "enablebinary", description = "Reenable native transport (binary protocol)") +public class EnableBinary extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.startNativeTransport(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/EnableGossip.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/EnableGossip.java b/src/java/org/apache/cassandra/tools/nodetool/EnableGossip.java new file mode 100644 index 0000000..16a9f4b --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/EnableGossip.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "enablegossip", description = "Reenable gossip") +public class EnableGossip extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.startGossiping(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/EnableHandoff.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/EnableHandoff.java b/src/java/org/apache/cassandra/tools/nodetool/EnableHandoff.java new file mode 100644 index 0000000..d18d77a --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/EnableHandoff.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static com.google.common.base.Preconditions.checkArgument; +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "enablehandoff", description = "Reenable the future hints storing on the current node") +public class EnableHandoff extends NodeToolCmd +{ + @Arguments(usage = "<dc-name>,<dc-name>", description = "Enable hinted handoff only for these DCs") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + checkArgument(args.size() <= 1, "enablehandoff does not accept two args"); + if(args.size() == 1) + probe.enableHintedHandoff(args.get(0)); + else + probe.enableHintedHandoff(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/EnableThrift.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/EnableThrift.java b/src/java/org/apache/cassandra/tools/nodetool/EnableThrift.java new file mode 100644 index 0000000..780b36d --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/EnableThrift.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "enablethrift", description = "Reenable thrift server") +public class EnableThrift extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + probe.startThriftServer(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/Flush.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/Flush.java b/src/java/org/apache/cassandra/tools/nodetool/Flush.java new file mode 100644 index 0000000..e9038f7 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/Flush.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "flush", description = "Flush one or more tables") +public class Flush extends NodeToolCmd +{ + @Arguments(usage = "[<keyspace> <tables>...]", description = "The keyspace followed by one or many tables") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + List<String> keyspaces = parseOptionalKeyspace(args, probe); + String[] cfnames = parseOptionalColumnFamilies(args); + + for (String keyspace : keyspaces) + { + try + { + probe.forceKeyspaceFlush(keyspace, cfnames); + } catch (Exception e) + { + throw new RuntimeException("Error occurred during flushing", e); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/GcStats.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/GcStats.java b/src/java/org/apache/cassandra/tools/nodetool/GcStats.java new file mode 100644 index 0000000..dd38fe7 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/GcStats.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +import io.airlift.command.Command; + +@Command(name = "gcstats", description = "Print GC Statistics") +public class GcStats extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + double[] stats = probe.getAndResetGCStats(); + double mean = stats[2] / stats[5]; + double stdev = Math.sqrt((stats[3] / stats[5]) - (mean * mean)); + System.out.printf("%20s%20s%20s%20s%20s%20s%25s%n", "Interval (ms)", "Max GC Elapsed (ms)", "Total GC Elapsed (ms)", "Stdev GC Elapsed (ms)", "GC Reclaimed (MB)", "Collections", "Direct Memory Bytes"); + System.out.printf("%20.0f%20.0f%20.0f%20.0f%20.0f%20.0f%25d%n", stats[0], stats[1], stats[2], stdev, stats[4], stats[5], (long)stats[6]); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java new file mode 100644 index 0000000..6c629de --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThreshold.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static com.google.common.base.Preconditions.checkArgument; +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.db.ColumnFamilyStoreMBean; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "getcompactionthreshold", description = "Print min and max compaction thresholds for a given table") +public class GetCompactionThreshold extends NodeToolCmd +{ + @Arguments(usage = "<keyspace> <table>", description = "The keyspace with a table") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + checkArgument(args.size() == 2, "getcompactionthreshold requires ks and cf args"); + String ks = args.get(0); + String cf = args.get(1); + + ColumnFamilyStoreMBean cfsProxy = probe.getCfsProxy(ks, cf); + System.out.println("Current compaction thresholds for " + ks + "/" + cf + ": \n" + + " min = " + cfsProxy.getMinimumCompactionThreshold() + ", " + + " max = " + cfsProxy.getMaximumCompactionThreshold()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java new file mode 100644 index 0000000..c3af184 --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/GetCompactionThroughput.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import io.airlift.command.Command; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "getcompactionthroughput", description = "Print the MB/s throughput cap for compaction in the system") +public class GetCompactionThroughput extends NodeToolCmd +{ + @Override + public void execute(NodeProbe probe) + { + System.out.println("Current compaction throughput: " + probe.getCompactionThroughput() + " MB/s"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/c5a81900/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java b/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java new file mode 100644 index 0000000..7b08a9a --- /dev/null +++ b/src/java/org/apache/cassandra/tools/nodetool/GetEndpoints.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.tools.nodetool; + +import static com.google.common.base.Preconditions.checkArgument; +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool.NodeToolCmd; + +@Command(name = "getendpoints", description = "Print the end points that owns the key") +public class GetEndpoints extends NodeToolCmd +{ + @Arguments(usage = "<keyspace> <table> <key>", description = "The keyspace, the table, and the key for which we need to find the endpoint") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + checkArgument(args.size() == 3, "getendpoints requires ks, cf and key args"); + String ks = args.get(0); + String cf = args.get(1); + String key = args.get(2); + + List<InetAddress> endpoints = probe.getEndpoints(ks, cf, key); + for (InetAddress endpoint : endpoints) + { + System.out.println(endpoint.getHostAddress()); + } + } +} \ No newline at end of file
