You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by yu...@apache.org on 2015/12/15 21:31:38 UTC

cassandra git commit: Sort compactionhistory output by timestamp

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 <mi...@localhost.localdomain>
Authored: Tue Nov 17 14:22:21 2015 +0800
Committer: Yuki Morishita <yu...@apache.org>
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<CompactionHistoryRow> 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<CompactionHistoryRow>
+{
+    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