From bdb192c56a08f01349ed13d166b8aac4b724530a Mon Sep 17 00:00:00 2001 From: Oleg Loginov Date: Wed, 28 Jul 2021 22:56:41 +0300 Subject: [PATCH] [#9826][test] Fix for timeout error in org.yb.cql.TestBigNumShards#testDropTableTimeout. Summary: The test `org.yb.cql.TestBigNumShards#testDropTableTimeout` sets `NumShardsPerTServer `==32. For 1 table + 5 indexes it created 192 tablets. For the many number of tablets Jenkins can occasionally fail with timeout. The big number of tablets was a way to reproduce some cases when the DROP TABLE happens when the CREATE TABLE/INDEX is not finished. See for details: - GH: https://github.com/yugabyte/yugabyte-db/issues/3032 - Diff: https://phabricator.dev.yugabyte.com/D7670 - Commit: https://github.com/yugabyte/yugabyte-db/commit/a70ab64b07f4fcaf658805c71e595ec5a7f781de Current fix keeps the test for big number of shards, but the number of tables (and indexes) reduced to 2. Slow CREATE TABLE test-case is re-implemented via `TEST_simulate_slow_table_create_secs`: `org.yb.cql.TestMasterLatency#testSlowCreateDropIndex `. Test Plan: ybd --java-test org.yb.cql.TestBigNumShards#testCreateDropTable --tp 1 -n 10 ybd --java-test org.yb.cql.TestMasterLatency#testSlowCreateDropTable --tp 1 -n 10 ybd --java-test org.yb.cql.TestMasterLatency#testSlowCreateDropIndex --tp 1 -n 10 ybd --java-test org.yb.cql.TestSlowCreateTable#testCreateTableTimeout --tp 1 -n 10 Reviewers: timur, amitanand Reviewed By: amitanand Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D12427 --- .../java/org/yb/cql/TestBigNumShards.java | 10 +-- .../java/org/yb/cql/TestMasterLatency.java | 26 ++++++-- .../java/org/yb/cql/TestSlowCreateTable.java | 62 +++++++++++++++++++ 3 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 java/yb-cql/src/test/java/org/yb/cql/TestSlowCreateTable.java diff --git a/java/yb-cql/src/test/java/org/yb/cql/TestBigNumShards.java b/java/yb-cql/src/test/java/org/yb/cql/TestBigNumShards.java index 532c591ec70f..0100b88d0573 100644 --- a/java/yb-cql/src/test/java/org/yb/cql/TestBigNumShards.java +++ b/java/yb-cql/src/test/java/org/yb/cql/TestBigNumShards.java @@ -29,7 +29,7 @@ protected int getNumShardsPerTServer() { } @Test - public void testDropTableTimeout() throws Exception { + public void testCreateDropTable() throws Exception { LOG.info("Start test: " + getCurrentTestMethodName()); // Create test table. @@ -37,16 +37,10 @@ public void testDropTableTimeout() throws Exception { "c1 int, c2 int, c3 int, c4 int, c5 int) " + "with transactions = {'enabled' : true};"); - // Create test indexes. + // Create test index. session.execute("create index i1 on test_drop (c1);"); - session.execute("create index i2 on test_drop (c2);"); - session.execute("create index i3 on test_drop (c3);"); - session.execute("create index i4 on test_drop (c4);"); - session.execute("create index i5 on test_drop (c5);"); // Drop test table. session.execute("drop table test_drop;"); - - LOG.info("End test: " + getCurrentTestMethodName()); } } diff --git a/java/yb-cql/src/test/java/org/yb/cql/TestMasterLatency.java b/java/yb-cql/src/test/java/org/yb/cql/TestMasterLatency.java index 5d97ca2b9ceb..ca2f7a8f7b83 100644 --- a/java/yb-cql/src/test/java/org/yb/cql/TestMasterLatency.java +++ b/java/yb-cql/src/test/java/org/yb/cql/TestMasterLatency.java @@ -18,9 +18,9 @@ import org.slf4j.LoggerFactory; import org.yb.minicluster.MiniYBClusterBuilder; -import org.yb.YBTestRunner; +import org.yb.util.YBTestRunnerNonTsanOnly; -@RunWith(value=YBTestRunner.class) +@RunWith(value=YBTestRunnerNonTsanOnly.class) public class TestMasterLatency extends BaseCQLTest { private static final Logger LOG = LoggerFactory.getLogger(TestMasterLatency.class); @@ -35,7 +35,7 @@ protected void customizeMiniClusterBuilder(MiniYBClusterBuilder builder) { } @Test - public void testCreateDropTableTimeout() throws Exception { + public void testSlowCreateDropTable() throws Exception { LOG.info("Start test: " + getCurrentTestMethodName()); // Create test table. @@ -43,7 +43,25 @@ public void testCreateDropTableTimeout() throws Exception { "with transactions = {'enabled' : true};"); // Drop test table. session.execute("drop table test_table;"); + } - LOG.info("End test: " + getCurrentTestMethodName()); + @Test + public void testSlowCreateDropIndex() throws Exception { + LOG.info("Start test: " + getCurrentTestMethodName()); + + // Create test table. + session.execute("create table test_drop (h1 int primary key, " + + "c1 int, c2 int, c3 int, c4 int, c5 int) " + + "with transactions = {'enabled' : true};"); + + // Create test indexes. + session.execute("create index i1 on test_drop (c1);"); + session.execute("create index i2 on test_drop (c2);"); + session.execute("create index i3 on test_drop (c3);"); + session.execute("create index i4 on test_drop (c4);"); + session.execute("create index i5 on test_drop (c5);"); + + // Drop test table. + session.execute("drop table test_drop;"); } } diff --git a/java/yb-cql/src/test/java/org/yb/cql/TestSlowCreateTable.java b/java/yb-cql/src/test/java/org/yb/cql/TestSlowCreateTable.java new file mode 100644 index 000000000000..3904fd3d45da --- /dev/null +++ b/java/yb-cql/src/test/java/org/yb/cql/TestSlowCreateTable.java @@ -0,0 +1,62 @@ +// Copyright (c) YugaByte, Inc. +// +// Licensed 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.yb.cql; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.yb.minicluster.MiniYBClusterBuilder; +import org.yb.util.YBTestRunnerNonTsanOnly; + +import static org.yb.AssertionWrappers.assertTrue; +import static org.yb.AssertionWrappers.fail; + +@RunWith(value=YBTestRunnerNonTsanOnly.class) +public class TestSlowCreateTable extends BaseCQLTest { + private static final Logger LOG = LoggerFactory.getLogger(TestSlowCreateTable.class); + + @Override + protected void customizeMiniClusterBuilder(MiniYBClusterBuilder builder) { + super.customizeMiniClusterBuilder(builder); + // Set latency in yb::master::CatalogManager::CreateTable(). + builder.addMasterFlag("TEST_simulate_slow_table_create_secs", "20"); + // Set default CREATE/DROP TABLE operation timeout. + builder.addCommonTServerFlag("yb_client_admin_operation_timeout_sec", "10"); + } + + @Test + public void testCreateTableTimeout() throws Exception { + LOG.info("Start test: " + getCurrentTestMethodName()); + + // Create test table. + try { + session.execute("create table test_table (h1 int primary key, c1 int) " + + "with transactions = {'enabled' : true};"); + fail("Create Table did not fail due to timeout as expected"); + } catch (com.datastax.driver.core.exceptions.ServerError ex) { + LOG.info("Expected exception:", ex); + String errorMsg = ex.getCause().getMessage(); + if (!errorMsg.contains("Timed out waiting for Table Creation") && + !errorMsg.contains("CreateTable timed out after deadline expired.")) { + fail("Unexpected error message '" + errorMsg + "'"); + } + } + + Thread.sleep(15 * 1000); // Let CREATE TABLE finish. + + // Drop test table. + session.execute("drop table test_table;"); + } +}