You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2021/11/17 23:14:08 UTC

[GitHub] [cassandra] dcapwell commented on a change in pull request #1329: CASSANDRA-17159 Log queries that fail on timeout or unavailable errors up to once per minute by default

dcapwell commented on a change in pull request #1329:
URL: https://github.com/apache/cassandra/pull/1329#discussion_r751714924



##########
File path: test/distributed/org/apache/cassandra/distributed/test/FailureLoggingTest.java
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.distributed.test;
+
+import java.io.IOException;
+import java.util.List;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.db.SinglePartitionReadCommand;
+import org.apache.cassandra.db.partitions.PartitionIterator;
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.LogResult;
+import org.apache.cassandra.exceptions.UnavailableException;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.service.reads.range.RangeCommandIterator;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class FailureLoggingTest extends TestBaseImpl
+{
+    private static Cluster cluster;
+    
+    @BeforeClass
+    public static void setUpCluster() throws IOException
+    {
+        System.setProperty("cassandra.request_failure_log_interval_seconds", "0");
+        cluster = init(Cluster.build(1).withInstanceInitializer(BBRequestFailures::install).start());
+        cluster.schemaChange("create table "+KEYSPACE+".tbl (id int primary key, i int)");
+    }
+
+    @AfterClass
+    public static void tearDownCluster()
+    {
+        cluster.close();

Review comment:
       ```
   if (cluster != null)
     cluster.close()
   ```
   
   if the cluster fails to start up, the close exception becomes what gets shown; making it harder to debug

##########
File path: test/distributed/org/apache/cassandra/distributed/test/FailureLoggingTest.java
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.distributed.test;
+
+import java.io.IOException;
+import java.util.List;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.db.SinglePartitionReadCommand;
+import org.apache.cassandra.db.partitions.PartitionIterator;
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.LogResult;
+import org.apache.cassandra.exceptions.UnavailableException;
+import org.apache.cassandra.service.StorageProxy;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.service.reads.range.RangeCommandIterator;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class FailureLoggingTest extends TestBaseImpl
+{
+    private static Cluster cluster;
+    
+    @BeforeClass
+    public static void setUpCluster() throws IOException
+    {
+        System.setProperty("cassandra.request_failure_log_interval_seconds", "0");
+        cluster = init(Cluster.build(1).withInstanceInitializer(BBRequestFailures::install).start());
+        cluster.schemaChange("create table "+KEYSPACE+".tbl (id int primary key, i int)");
+    }
+
+    @AfterClass
+    public static void tearDownCluster()
+    {
+        cluster.close();
+    }
+    
+    @Before
+    public void resetBootstrappingState()
+    {
+        cluster.get(1).callOnInstance(() -> BBRequestFailures.bootstrapping = false);
+        
+    }
+    
+    @Test
+    public void testRequestBootstrapFail() throws Throwable
+    {
+        cluster.get(1).callOnInstance(() -> BBRequestFailures.bootstrapping = true);
+        long mark = cluster.get(1).logs().mark();
+
+        try
+        {
+            cluster.coordinator(1).execute("select * from " + KEYSPACE + ".tbl where id = 55", ConsistencyLevel.ALL);
+            fail("Query should fail");
+        }
+        catch (RuntimeException e)
+        {
+            LogResult<List<String>> result = cluster.get(1).logs().grep(mark, "while executing SELECT");
+            assertEquals(1, result.getResult().size());
+            assertTrue(result.getResult().get(0).contains("Cannot read from a bootstrapping node"));
+        }
+    }
+
+    @Test
+    public void testRangeRequestFail() throws Throwable
+    {
+        long mark = cluster.get(1).logs().mark();
+
+        try
+        {
+            cluster.coordinator(1).execute("select * from " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
+            fail("Query should fail");
+        }
+        catch (RuntimeException e)
+        {
+            LogResult<List<String>> result = cluster.get(1).logs().grep(mark, "while executing SELECT");
+            assertEquals(1, result.getResult().size());
+            assertTrue(result.getResult().get(0).contains("Cannot achieve consistency level"));
+        }
+    }
+
+    @Test
+    public void testReadRequestFail() throws Throwable
+    {
+        long mark = cluster.get(1).logs().mark();
+
+        try
+        {
+            cluster.coordinator(1).execute("select * from " + KEYSPACE + ".tbl where id = 55", ConsistencyLevel.ALL);
+            fail("Query should fail");
+        }
+        catch (RuntimeException e)
+        {
+            LogResult<List<String>> result = cluster.get(1).logs().grep(mark, "while executing SELECT");
+            assertEquals(1, result.getResult().size());
+            assertTrue(result.getResult().get(0).contains("Cannot achieve consistency level"));
+        }
+    }

Review comment:
       given we are dealing with no-spam logger, this test assert matches in `testRangeRequestFail` and `testReadRequestFail`; so possible the second test is reading the logs from the first test

##########
File path: src/java/org/apache/cassandra/service/StorageProxy.java
##########
@@ -162,6 +164,9 @@
     private static final Logger logger = LoggerFactory.getLogger(StorageProxy.class);
 
     public static final String UNREACHABLE = "UNREACHABLE";
+    
+    public static final String REQUEST_FAIL_MESSAGE = "\"{}\" while executing {}";
+    private static final int FAILURE_LOGGING_INTERVAL_SECONDS = Integer.getInteger("cassandra.request_failure_log_interval_seconds", 60);

Review comment:
       can we use `CassandraRelevantProperties`?

##########
File path: src/java/org/apache/cassandra/service/StorageProxy.java
##########
@@ -2455,6 +2466,17 @@ protected void runMayThrow() throws Exception
         abstract protected void runMayThrow() throws Exception;
     }
 
+    public static void logRequestException(Exception exception, Collection<? extends ReadCommand> commands)
+    {
+        NoSpamLogger.log(logger, NoSpamLogger.Level.INFO, FAILURE_LOGGING_INTERVAL_SECONDS, TimeUnit.SECONDS,
+                         REQUEST_FAIL_MESSAGE,
+                         () -> new Object[]
+                               {
+                                   exception.getMessage(),
+                                   commands.stream().map(ReadCommand::toCQLString).collect(Collectors.joining("; "))

Review comment:
       nit; `";\n"`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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