You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2021/09/02 09:12:48 UTC

[cassandra] branch cassandra-3.11 updated: Nodetool setcachecapacity behaves oddly when cache disabled

This is an automated email from the ASF dual-hosted git repository.

bereng pushed a commit to branch cassandra-3.11
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-3.11 by this push:
     new 957c626  Nodetool setcachecapacity behaves oddly when cache disabled
957c626 is described below

commit 957c6264ef97909a043a70b96cf896b1feb0f204
Author: Bereng <be...@gmail.com>
AuthorDate: Thu Aug 19 11:21:58 2021 +0200

    Nodetool setcachecapacity behaves oddly when cache disabled
    
    patch by Michal Szczepanski, Berenguer Blasi; reviewed by Benjamin Lerer, Berenguer Blasi for CASSANDRA-#####
    
    Co-authored-by: Michal Szczepanski
    Co-authored-by: Berenguer Blasi <be...@gmail.com>
---
 .../apache/cassandra/cache/NopCacheProvider.java   |  5 +++
 .../cassandra/distributed/test/NodeToolTest.java   | 10 +++++
 .../cassandra/cache/NopCacheProviderTest.java      | 46 ++++++++++++++++++++++
 3 files changed, 61 insertions(+)

diff --git a/src/java/org/apache/cassandra/cache/NopCacheProvider.java b/src/java/org/apache/cassandra/cache/NopCacheProvider.java
index 20f837a..9b8a3dc 100644
--- a/src/java/org/apache/cassandra/cache/NopCacheProvider.java
+++ b/src/java/org/apache/cassandra/cache/NopCacheProvider.java
@@ -36,6 +36,11 @@ public class NopCacheProvider implements CacheProvider<RowCacheKey, IRowCacheEnt
 
         public void setCapacity(long capacity)
         {
+            if (capacity != 0)
+            {
+                throw new UnsupportedOperationException("Setting capacity of " + NopCache.class.getSimpleName()
+                                                        + " is not permitted as this cache is disabled. Check your yaml settings if you want to enable it.");
+            }
         }
 
         public void put(RowCacheKey key, IRowCacheEntry value)
diff --git a/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java b/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java
index d8b9ce7..aaa7dc3 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/NodeToolTest.java
@@ -50,4 +50,14 @@ public class NodeToolTest extends TestBaseImpl
             assertEquals("Non-empty error output", "", ringResult.getStderr());
         }
     }
+
+    @Test
+    public void testSetCacheCapacityWhenDisabled() throws Throwable
+    {
+        try (ICluster cluster = init(builder().withNodes(1).withConfig(c->c.set("row_cache_size_in_mb", "0")).start()))
+        {
+            NodeToolResult ringResult = cluster.get(1).nodetoolResult("setcachecapacity", "1", "1", "1");
+            ringResult.asserts().stderrContains("is not permitted as this cache is disabled");
+        }
+    }
 }
diff --git a/test/unit/org/apache/cassandra/cache/NopCacheProviderTest.java b/test/unit/org/apache/cassandra/cache/NopCacheProviderTest.java
new file mode 100644
index 0000000..8807883
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cache/NopCacheProviderTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.cache;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class NopCacheProviderTest
+{
+    private ICache<RowCacheKey, IRowCacheEntry> cache;
+
+    @Before
+    public void createCache()
+    {
+        NopCacheProvider cacheProvider = new NopCacheProvider();
+        cache = cacheProvider.create();
+    }
+
+    @Test
+    public void settingCapacityToZeroIsIgnored()
+    {
+        cache.setCapacity(0L);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void failsOnSettingCapacityOtherThanZero()
+    {
+        cache.setCapacity(1);
+    }
+}

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