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 2014/10/30 00:20:06 UTC
[3/6] git commit: Fix totalDiskSpaceUsed calculation
Fix totalDiskSpaceUsed calculation
patch by yukim; reviewed by krummas for CASSANDRA-8205
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/62386f13
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/62386f13
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/62386f13
Branch: refs/heads/trunk
Commit: 62386f13e5d822e54fa556bc4ca017769d21ebf7
Parents: f13ce55
Author: Yuki Morishita <yu...@apache.org>
Authored: Wed Oct 29 17:55:43 2014 -0500
Committer: Yuki Morishita <yu...@apache.org>
Committed: Wed Oct 29 17:57:31 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../io/sstable/SSTableDeletingTask.java | 4 +-
.../cassandra/db/ColumnFamilyMetricTest.java | 73 ++++++++++++++++++++
3 files changed, 76 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/62386f13/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9051b34..4387d81 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,7 @@
rpc_max_threads setting of 'unlimited' (CASSANDRA-8116)
* Allow concurrent writing of the same table in the same JVM using
CQLSSTableWriter (CASSANDRA-7463)
+ * Fix totalDiskSpaceUsed calculation (CASSANDRA-8205)
2.0.11:
http://git-wip-us.apache.org/repos/asf/cassandra/blob/62386f13/src/java/org/apache/cassandra/io/sstable/SSTableDeletingTask.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableDeletingTask.java b/src/java/org/apache/cassandra/io/sstable/SSTableDeletingTask.java
index fb7f036..ec20fe5 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableDeletingTask.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableDeletingTask.java
@@ -46,14 +46,12 @@ public class SSTableDeletingTask implements Runnable
private final Descriptor desc;
private final Set<Component> components;
private DataTracker tracker;
- private final long size;
public SSTableDeletingTask(SSTableReader referent)
{
this.referent = referent;
this.desc = referent.descriptor;
this.components = referent.components;
- this.size = referent.bytesOnDisk();
}
public void setTracker(DataTracker tracker)
@@ -68,6 +66,8 @@ public class SSTableDeletingTask implements Runnable
public void run()
{
+ long size = referent.bytesOnDisk();
+
if (tracker != null)
tracker.notifyDeleting(referent);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/62386f13/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
new file mode 100644
index 0000000..da58ea4
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.io.sstable.SSTableReader;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import static org.junit.Assert.assertEquals;
+
+public class ColumnFamilyMetricTest extends SchemaLoader
+{
+ @Test
+ public void testSizeMetric()
+ {
+ Keyspace keyspace = Keyspace.open("Keyspace1");
+ ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard1");
+ store.disableAutoCompaction();
+
+ store.truncateBlocking();
+
+ assertEquals(0, store.metric.liveDiskSpaceUsed.count());
+ assertEquals(0, store.metric.totalDiskSpaceUsed.count());
+
+ for (int j = 0; j < 10; j++)
+ {
+ ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
+ RowMutation rm = new RowMutation("Keyspace1", key);
+ rm.add("Standard1", ByteBufferUtil.bytes("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
+ rm.apply();
+ }
+ store.forceBlockingFlush();
+ Collection<SSTableReader> sstables = store.getSSTables();
+ long size = 0;
+ for (SSTableReader reader : sstables)
+ {
+ size += reader.bytesOnDisk();
+ }
+
+ // size metrics should show the sum of all SSTable sizes
+ assertEquals(size, store.metric.liveDiskSpaceUsed.count());
+ assertEquals(size, store.metric.totalDiskSpaceUsed.count());
+
+ store.truncateBlocking();
+
+ // after truncate, size metrics should be down to 0
+ assertEquals(0, store.metric.liveDiskSpaceUsed.count());
+ assertEquals(0, store.metric.totalDiskSpaceUsed.count());
+
+ store.enableAutoCompaction();
+ }
+
+}