cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject cassandra git commit: Add a virtual table to expose all running sstable tasks [Forced Update!]
Date Tue, 05 Jun 2018 14:23:59 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 899f7c419 -> 2a2ee0063 (forced update)


Add a virtual table to expose all running sstable tasks

patch by Chris Lohfink; reviewed by Aleksey Yeschenko for
CASSANDRA-14457


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2a2ee006
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2a2ee006
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2a2ee006

Branch: refs/heads/trunk
Commit: 2a2ee006302a086ff054eac52161209a3118bb7c
Parents: 0f79427
Author: Chris Lohfink <clohfink@apple.com>
Authored: Sat May 19 01:27:28 2018 -0500
Committer: Aleksey Yeshchenko <aleksey@apple.com>
Committed: Tue Jun 5 15:22:34 2018 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/db/compaction/CompactionInfo.java | 51 +++++++++------
 .../db/compaction/CompactionManager.java        | 13 +++-
 .../cassandra/db/virtual/SSTableTasksTable.java | 69 ++++++++++++++++++++
 .../db/virtual/SystemViewsKeyspace.java         |  2 +-
 .../tools/nodetool/CompactionStats.java         | 14 ++--
 6 files changed, 121 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2a2ee006/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 86842d0..351ae37 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0
+ * Add a virtual table to expose all running sstable tasks (CASSANDRA-14457)
  * Let nodetool import take a list of directories (CASSANDRA-14442)
  * Avoid unneeded memory allocations / cpu for disabled log levels (CASSANDRA-14488)
  * Implement virtual keyspace interface (CASSANDRA-7622)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2a2ee006/src/java/org/apache/cassandra/db/compaction/CompactionInfo.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionInfo.java b/src/java/org/apache/cassandra/db/compaction/CompactionInfo.java
index ccdfeb4..99df259 100644
--- a/src/java/org/apache/cassandra/db/compaction/CompactionInfo.java
+++ b/src/java/org/apache/cassandra/db/compaction/CompactionInfo.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.db.compaction;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.UUID;
 
 import org.apache.cassandra.schema.TableMetadata;
@@ -28,6 +29,16 @@ import org.apache.cassandra.schema.TableMetadata;
 public final class CompactionInfo implements Serializable
 {
     private static final long serialVersionUID = 3695381572726744816L;
+
+    public static final String ID = "id";
+    public static final String KEYSPACE = "keyspace";
+    public static final String COLUMNFAMILY = "columnfamily";
+    public static final String COMPLETED = "completed";
+    public static final String TOTAL = "total";
+    public static final String TASK_TYPE = "taskType";
+    public static final String UNIT = "unit";
+    public static final String COMPACTION_ID = "compactionId";
+
     private final TableMetadata metadata;
     private final OperationType tasktype;
     private final long completed;
@@ -84,19 +95,14 @@ public final class CompactionInfo implements Serializable
         return new CompactionInfo(metadata, tasktype, complete, total, unit, compactionId);
     }
 
-    public UUID getId()
-    {
-        return metadata != null ? metadata.id.asUUID() : null;
-    }
-
-    public String getKeyspace()
+    public Optional<String> getKeyspace()
     {
-        return metadata != null ? metadata.keyspace : null;
+        return Optional.ofNullable(metadata != null ? metadata.keyspace : null);
     }
 
-    public String getColumnFamily()
+    public Optional<String> getTable()
     {
-        return metadata != null ? metadata.name : null;
+        return Optional.ofNullable(metadata != null ? metadata.name : null);
     }
 
     public TableMetadata getTableMetadata()
@@ -119,19 +125,24 @@ public final class CompactionInfo implements Serializable
         return tasktype;
     }
 
-    public UUID compactionId()
+    public UUID getTaskId()
     {
         return compactionId;
     }
 
+    public Unit getUnit()
+    {
+        return unit;
+    }
+
     public String toString()
     {
         StringBuilder buff = new StringBuilder();
         buff.append(getTaskType());
         if (metadata != null)
         {
-            buff.append('@').append(getId()).append('(');
-            buff.append(getKeyspace()).append(", ").append(getColumnFamily()).append(", ");
+            buff.append('@').append(metadata.id).append('(');
+            buff.append(metadata.keyspace).append(", ").append(metadata.name).append(", ");
         }
         else
         {
@@ -144,14 +155,14 @@ public final class CompactionInfo implements Serializable
     public Map<String, String> asMap()
     {
         Map<String, String> ret = new HashMap<String, String>();
-        ret.put("id", getId() == null ? "" : getId().toString());
-        ret.put("keyspace", getKeyspace());
-        ret.put("columnfamily", getColumnFamily());
-        ret.put("completed", Long.toString(completed));
-        ret.put("total", Long.toString(total));
-        ret.put("taskType", tasktype.toString());
-        ret.put("unit", unit.toString());
-        ret.put("compactionId", compactionId == null ? "" : compactionId.toString());
+        ret.put(ID, metadata != null ? metadata.id.toString() : "");
+        ret.put(KEYSPACE, getKeyspace().orElse(null));
+        ret.put(COLUMNFAMILY, getTable().orElse(null));
+        ret.put(COMPLETED, Long.toString(completed));
+        ret.put(TOTAL, Long.toString(total));
+        ret.put(TASK_TYPE, tasktype.toString());
+        ret.put(UNIT, unit.toString());
+        ret.put(COMPACTION_ID, compactionId == null ? "" : compactionId.toString());
         return ret;
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2a2ee006/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
index 05891d2..8a8aaec 100644
--- a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
+++ b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
@@ -1773,7 +1773,7 @@ public class CompactionManager implements CompactionManagerMBean
     {
         for (Holder holder : CompactionMetrics.getCompactions())
         {
-            UUID holderId = holder.getCompactionInfo().compactionId();
+            UUID holderId = holder.getCompactionInfo().getTaskId();
             if (holderId != null && holderId.equals(UUID.fromString(compactionId)))
                 holder.stop();
         }
@@ -1951,4 +1951,15 @@ public class CompactionManager implements CompactionManagerMBean
                 break;
         }
     }
+
+    public List<CompactionInfo> getSStableTasks()
+    {
+        return CompactionMetrics.getCompactions()
+                                .stream()
+                                .map(CompactionInfo.Holder::getCompactionInfo)
+                                .filter(task -> task.getTaskType() != OperationType.COUNTER_CACHE_SAVE
+                                             && task.getTaskType() != OperationType.KEY_CACHE_SAVE
+                                             && task.getTaskType() != OperationType.ROW_CACHE_SAVE)
+                                .collect(Collectors.toList());
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2a2ee006/src/java/org/apache/cassandra/db/virtual/SSTableTasksTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/virtual/SSTableTasksTable.java b/src/java/org/apache/cassandra/db/virtual/SSTableTasksTable.java
new file mode 100644
index 0000000..e98e3a6
--- /dev/null
+++ b/src/java/org/apache/cassandra/db/virtual/SSTableTasksTable.java
@@ -0,0 +1,69 @@
+/*
+ * 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.db.virtual;
+
+import org.apache.cassandra.db.compaction.CompactionInfo;
+import org.apache.cassandra.db.compaction.CompactionManager;
+import org.apache.cassandra.db.marshal.LongType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.db.marshal.UUIDType;
+import org.apache.cassandra.schema.TableMetadata;
+
+final class SSTableTasksTable extends AbstractVirtualTable
+{
+    private final static String KEYSPACE_NAME = "keyspace_name";
+    private final static String TABLE_NAME = "table_name";
+    private final static String TASK_ID = "task_id";
+    private final static String KIND = "kind";
+    private final static String PROGRESS = "progress";
+    private final static String TOTAL = "total";
+    private final static String UNIT = "unit";
+
+    SSTableTasksTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, "sstable_tasks")
+                           .comment("current sstable tasks")
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .addPartitionKeyColumn(KEYSPACE_NAME, UTF8Type.instance)
+                           .addClusteringColumn(TABLE_NAME, UTF8Type.instance)
+                           .addClusteringColumn(TASK_ID, UUIDType.instance)
+                           .addRegularColumn(KIND, UTF8Type.instance)
+                           .addRegularColumn(PROGRESS, LongType.instance)
+                           .addRegularColumn(TOTAL, LongType.instance)
+                           .addRegularColumn(UNIT, UTF8Type.instance)
+                           .build());
+    }
+
+    public DataSet data()
+    {
+        SimpleDataSet result = new SimpleDataSet(metadata());
+
+        for (CompactionInfo task : CompactionManager.instance.getSStableTasks())
+        {
+            result.row(task.getKeyspace().orElse("*"),
+                       task.getTable().orElse("*"),
+                       task.getTaskId())
+                  .column(KIND, task.getTaskType().toString().toLowerCase())
+                  .column(PROGRESS, task.getCompleted())
+                  .column(TOTAL, task.getTotal())
+                  .column(UNIT, task.getUnit().toString().toLowerCase());
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2a2ee006/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java b/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
index 8d6f59b..5d33a63 100644
--- a/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
+++ b/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
@@ -27,6 +27,6 @@ public final class SystemViewsKeyspace extends VirtualKeyspace
 
     private SystemViewsKeyspace()
     {
-        super(NAME, ImmutableList.of());
+        super(NAME, ImmutableList.of(new SSTableTasksTable(NAME)));
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2a2ee006/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
index 574220e..497fe24 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java
@@ -82,17 +82,17 @@ public class CompactionStats extends NodeToolCmd
             table.add("id", "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 unit = c.get("unit");
+                long total = Long.parseLong(c.get(CompactionInfo.TOTAL));
+                long completed = Long.parseLong(c.get(CompactionInfo.COMPLETED));
+                String taskType = c.get(CompactionInfo.TASK_TYPE);
+                String keyspace = c.get(CompactionInfo.KEYSPACE);
+                String columnFamily = c.get(CompactionInfo.COLUMNFAMILY);
+                String unit = c.get(CompactionInfo.UNIT);
                 boolean toFileSize = humanReadable && Unit.isFileSize(unit);
                 String completedStr = toFileSize ? FileUtils.stringifyFileSize(completed)
: Long.toString(completed);
                 String totalStr = toFileSize ? FileUtils.stringifyFileSize(total) : Long.toString(total);
                 String percentComplete = total == 0 ? "n/a" : new DecimalFormat("0.00").format((double)
completed / total * 100) + "%";
-                String id = c.get("compactionId");
+                String id = c.get(CompactionInfo.COMPACTION_ID);
                 table.add(id, taskType, keyspace, columnFamily, completedStr, totalStr, unit,
percentComplete);
                 if (taskType.equals(OperationType.COMPACTION.toString()))
                     remainingBytes += total - completed;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message