Repository: cassandra
Updated Branches:
  refs/heads/trunk 9c142f915 -> 45c3b461e


Add a virtual table to expose caches

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


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

Branch: refs/heads/trunk
Commit: 45c3b461ec28abdb24353c7317dfa7544c415f11
Parents: 9c142f9
Author: Chris Lohfink <clohf...@apple.com>
Authored: Mon Jun 25 12:08:40 2018 -0500
Committer: Aleksey Yeshchenko <alek...@apple.com>
Committed: Fri Aug 3 16:25:47 2018 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/db/virtual/CachesTable.java       | 77 ++++++++++++++++++++
 .../db/virtual/SystemViewsKeyspace.java         |  2 +-
 3 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/45c3b461/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e310589..3b35608 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0
+ * Add a virtual table to expose caches (CASSANDRA-14538)
  * Fix toDate function for timestamp arguments (CASSANDRA-14502)
  * Revert running dtests by default in circleci (CASSANDRA-14614)
  * Stream entire SSTables when possible (CASSANDRA-14556)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/45c3b461/src/java/org/apache/cassandra/db/virtual/CachesTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/virtual/CachesTable.java 
b/src/java/org/apache/cassandra/db/virtual/CachesTable.java
new file mode 100644
index 0000000..e5f80f7
--- /dev/null
+++ b/src/java/org/apache/cassandra/db/virtual/CachesTable.java
@@ -0,0 +1,77 @@
+/*
+ * 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.marshal.*;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.metrics.CacheMetrics;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.service.CacheService;
+
+final class CachesTable extends AbstractVirtualTable
+{
+    private static final String NAME = "name";
+    private static final String CAPACITY_BYTES = "capacity_bytes";
+    private static final String SIZE_BYTES = "size_bytes";
+    private static final String ENTRY_COUNT = "entry_count";
+    private static final String REQUEST_COUNT = "request_count";
+    private static final String HIT_COUNT = "hit_count";
+    private static final String HIT_RATIO = "hit_ratio";
+    private static final String RECENT_REQUEST_RATE_PER_SECOND = 
"recent_request_rate_per_second";
+    private static final String RECENT_HIT_RATE_PER_SECOND = 
"recent_hit_rate_per_second";
+
+    CachesTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, "caches")
+                           .comment("system caches")
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new 
LocalPartitioner(UTF8Type.instance))
+                           .addPartitionKeyColumn(NAME, UTF8Type.instance)
+                           .addRegularColumn(CAPACITY_BYTES, LongType.instance)
+                           .addRegularColumn(SIZE_BYTES, LongType.instance)
+                           .addRegularColumn(ENTRY_COUNT, Int32Type.instance)
+                           .addRegularColumn(REQUEST_COUNT, LongType.instance)
+                           .addRegularColumn(HIT_COUNT, LongType.instance)
+                           .addRegularColumn(HIT_RATIO, DoubleType.instance)
+                           .addRegularColumn(RECENT_REQUEST_RATE_PER_SECOND, 
LongType.instance)
+                           .addRegularColumn(RECENT_HIT_RATE_PER_SECOND, 
LongType.instance)
+                           .build());
+    }
+
+    private void addRow(SimpleDataSet result, String name, CacheMetrics 
metrics)
+    {
+        result.row(name)
+              .column(CAPACITY_BYTES, metrics.capacity.getValue())
+              .column(SIZE_BYTES, metrics.size.getValue())
+              .column(ENTRY_COUNT, metrics.entries.getValue())
+              .column(REQUEST_COUNT, metrics.requests.getCount())
+              .column(HIT_COUNT, metrics.hits.getCount())
+              .column(HIT_RATIO, metrics.hitRate.getValue())
+              .column(RECENT_REQUEST_RATE_PER_SECOND, (long) 
metrics.requests.getFifteenMinuteRate())
+              .column(RECENT_HIT_RATE_PER_SECOND, (long) 
metrics.hits.getFifteenMinuteRate());
+    }
+
+    public DataSet data()
+    {
+        SimpleDataSet result = new SimpleDataSet(metadata());
+        addRow(result, "counters", 
CacheService.instance.counterCache.getMetrics());
+        addRow(result, "keys", CacheService.instance.keyCache.getMetrics());
+        addRow(result, "rows", CacheService.instance.rowCache.getMetrics());
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/45c3b461/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 53c01a4..e803d3d 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(new SSTableTasksTable(NAME), new 
ClientsTable(NAME)));
+        super(NAME, ImmutableList.of(new SSTableTasksTable(NAME), new 
ClientsTable(NAME), new CachesTable(NAME)));
     }
 }


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

Reply via email to