Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6785C1828A for ; Tue, 15 Dec 2015 20:31:39 +0000 (UTC) Received: (qmail 15562 invoked by uid 500); 15 Dec 2015 20:31:39 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 15526 invoked by uid 500); 15 Dec 2015 20:31:39 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 15513 invoked by uid 99); 15 Dec 2015 20:31:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Dec 2015 20:31:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1A13EE0AF0; Tue, 15 Dec 2015 20:31:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yukim@apache.org To: commits@cassandra.apache.org Message-Id: <3cc34ac73f244823939a5fa25795ea3d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cassandra git commit: Sort compactionhistory output by timestamp Date: Tue, 15 Dec 2015 20:31:38 +0000 (UTC) Repository: cassandra Updated Branches: refs/heads/trunk 7139f959d -> 07c6a36cc Sort compactionhistory output by timestamp patch by Michael Edge; reviewed by yukim for CASSANDRA-10464 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/07c6a36c Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/07c6a36c Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/07c6a36c Branch: refs/heads/trunk Commit: 07c6a36cc3c9661348688256dff69ef1b795f30a Parents: 7139f95 Author: michael Authored: Tue Nov 17 14:22:21 2015 +0800 Committer: Yuki Morishita Committed: Tue Dec 15 14:29:40 2015 -0600 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../tools/nodetool/CompactionHistory.java | 74 ++++++++++++++++++-- 2 files changed, 70 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/07c6a36c/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 4149d91..991d42a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.2 + * Sort compactionhistory output by timestamp (CASSANDRA-10464) * More efficient BTree removal (CASSANDRA-9991) * Make tablehistograms accept the same syntax as tablestats (CASSANDRA-10149) * Group pending compactions based on table (CASSANDRA-10718) http://git-wip-us.apache.org/repos/asf/cassandra/blob/07c6a36c/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 index cbb054a..1348d05 100644 --- a/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java +++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java @@ -17,17 +17,22 @@ */ package org.apache.cassandra.tools.nodetool; -import static com.google.common.collect.Iterables.toArray; -import io.airlift.command.Command; - +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; - import javax.management.openmbean.TabularData; +import io.airlift.command.Command; + import org.apache.cassandra.tools.NodeProbe; import org.apache.cassandra.tools.NodeTool.NodeToolCmd; +import static com.google.common.collect.Iterables.toArray; + @Command(name = "compactionhistory", description = "Print history of compaction") public class CompactionHistory extends NodeToolCmd { @@ -48,10 +53,69 @@ public class CompactionHistory extends NodeToolCmd System.out.printf(format, toArray(indexNames, Object.class)); Set values = tabularData.keySet(); + List chr = new ArrayList<>(); for (Object eachValue : values) { List value = (List) eachValue; - System.out.printf(format, toArray(value, Object.class)); + CompactionHistoryRow chc = new CompactionHistoryRow((String)value.get(0), + (String)value.get(1), + (String)value.get(2), + (Long)value.get(3), + (Long)value.get(4), + (Long)value.get(5), + (String)value.get(6)); + chr.add(chc); } + Collections.sort(chr); + for (CompactionHistoryRow eachChc : chr) + { + System.out.printf(format, eachChc.getAllAsArray()); + } + } +} + +/** + * Allows the Compaction History output to be ordered by 'compactedAt' - that is the + * time at which compaction finished. + */ +class CompactionHistoryRow implements Comparable +{ + private final String id; + private final String ksName; + private final String cfName; + private final long compactedAt; + private final long bytesIn; + private final long bytesOut; + private final String rowMerged; + + CompactionHistoryRow(String id, String ksName, String cfName, long compactedAt, long bytesIn, long bytesOut, String rowMerged) + { + this.id = id; + this.ksName = ksName; + this.cfName = cfName; + this.compactedAt = compactedAt; + this.bytesIn = bytesIn; + this.bytesOut = bytesOut; + this.rowMerged = rowMerged; + } + + public int compareTo(CompactionHistoryRow chc) + { + return Long.signum(chc.compactedAt - this.compactedAt); + } + + public Object[] getAllAsArray() + { + Object[] obj = new Object[7]; + obj[0] = this.id; + obj[1] = this.ksName; + obj[2] = this.cfName; + Instant instant = Instant.ofEpochMilli(this.compactedAt); + LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); + obj[3] = ldt.toString(); + obj[4] = this.bytesIn; + obj[5] = this.bytesOut; + obj[6] = this.rowMerged; + return obj; } } \ No newline at end of file