Skip to content

Commit

Permalink
[#23770] [#23797] [#23837] YSQL: Fix most non-regress tests when run …
Browse files Browse the repository at this point in the history
…with Connection Manager

Summary:
Some additional tests can be fixed when running with Connection Manager, using different methods. The list of the tests being fixed, along with method/reasoning of fix are stated below:

[DISABLED TESTS]
TestAlterTableWithConcurrentTxn.testTransactionConflictErrorCode - Disabled due to flakiness that needs further understanding.
TestPgAuthorization.testRevokeLoginMidSession - Disabled until better understanding of the problem.
TestPgAuthorization.testConnectionLimitDecreasedMidSession -  Disabled until better understanding of the problem.
PgYbHashCodeScanProjection.testScans - For this specific test, we would need to still remove connection manager debug + query logs in order to reduce flakiness, disabling test until we can make log levels configurable via common server flags.
PgYbStat.testYbTerminatedQueriesMultipleCauses -  Test is flaky with modifications via round robin killing of backends as the assertion check may pass or fail when checking if connection is still alive after having killed backend processes. Disabling test for now.

[TESTS WITHOUT WARMUP]
TestPgExplainAnalyze.testSeqScan - While running in any warmup mode, catalog read requests decrease, but not to the expected value of 0. Allow test to run in single connection mode until further analysis.
TestPgExplainAnalyze.testInsertValues - While running in any warmup mode, catalog read requests decrease, but not to the expected value of 0. Allow test to run in single connection mode until further analysis.
TestToastFunction.testSimple - Memory allocation is significantly higher with a pool of warmed up connections, allow the test to run with a single connection to allow metrics assertions to pass.

[TESTS WITH ROUND ROBIN ALLOCATION OF WARMED UP CONNECTIONS]
TestPgCostModelSeekNextEstimation.testSeekNextEstimationIndexScan - Modified to have round robin behaviour in an earlier diff, allow setUp to happen after having restarted the cluster in round robin mode.
TestPgCostModelSeekNextEstimation.testSeekNextEstimationBitmapScan - Modified to have round robin behaviour in an earlier diff, allow setUp to happen after having restarted the cluster in round robin mode.
Jira: DB-12674, DB-12699, DB-12741

Test Plan: Jenkins: enable connection manager, all tests

Reviewers: skumar, mkumar

Reviewed By: skumar

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D37826
  • Loading branch information
Rahul Barigidad committed Sep 16, 2024
1 parent 55b4187 commit f97d7d5
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 21 deletions.
10 changes: 10 additions & 0 deletions java/yb-pgsql/src/test/java/org/yb/pgsql/BasePgSQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ public class BasePgSQLTest extends BaseMiniClusterTest {
"variables at the beginning of transaction boundaries, causing erroneous results in " +
"the test, leading to failure.";

protected static final String INCORRECT_CONN_STATE_BEHAVIOR =
"Skipping this test with Connection Manager enabled. The connections may not be in the " +
"expected state due to the way physical connections are attached and detached from " +
"logical connections, where certain setting changes should only exist in new connections.";

protected static final String CONFIGURABLE_DEBUG_LOGS_NEEDED =
"(DB-12742) Skipping this test with Connection Manager enabled. The test requires the " +
"ability to configure debug logs for connection manager to be at the same levels as " +
"tserver log levels.";

// Warmup modes for Connection Manager during test runs.
protected static enum ConnectionManagerWarmupMode {
NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,10 @@ public void testDmlTransactionWithAlterOnDifferentResource() throws Exception {

@Test
public void testTransactionConflictErrorCode() throws Exception {
// (DB-12741) Disabling the test due to a flaky failure point when run with
// connection manager, needs further investigation.
assumeFalse(BasePgSQLTest.INCORRECT_CONN_STATE_BEHAVIOR, isTestRunningWithConnectionManager());

try (Connection conn1 = getConnectionBuilder().connect();
Statement stmt1 = conn1.createStatement();
Connection conn2 = getConnectionBuilder().connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,9 @@ public void testCreateSchemaAuthorization() throws Exception {

@Test
public void testRevokeLoginMidSession() throws Exception {
// (DB-12741) Skip this test if running with connection manager.
assumeFalse(BasePgSQLTest.INCORRECT_CONN_STATE_BEHAVIOR, isTestRunningWithConnectionManager());

try (Connection connection1 = getConnectionBuilder().withTServer(0).connect();
Statement statement1 = connection1.createStatement()) {

Expand Down Expand Up @@ -2847,6 +2850,9 @@ public void testRevokeAttributesMidSession() throws Exception {

@Test
public void testConnectionLimitDecreasedMidSession() throws Exception {
// (DB-12741) Skip this test if running with connection manager.
assumeFalse(BasePgSQLTest.INCORRECT_CONN_STATE_BEHAVIOR, isTestRunningWithConnectionManager());

try (Connection connection1 = getConnectionBuilder().withTServer(0).connect();
Statement statement1 = connection1.createStatement()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,13 @@ protected Map<String, String> getTServerFlags() {
// in Nov/2023.
@Test
public void testSeekNextEstimationIndexScan() throws Exception {
// (DB-12674) Allow tests to run in round-robin allocation mode when
// using a pool of warmed up connections to allow for deterministic results.
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.ROUND_ROBIN);
boolean isConnMgr = isTestRunningWithConnectionManager();
if (isConnMgr) {
setUp();
}
try (Statement stmt = this.connection2.createStatement()) {
// Warmup the cache when Connection Manager is enabled.
// Additionally warmup all backends in round-robin mode.
Expand Down Expand Up @@ -432,8 +437,14 @@ public void testSeekNextEstimationIndexScan() throws Exception {
@Test
public void testSeekNextEstimationBitmapScan() throws Exception {
assumeTrue("BitmapScan has much fewer nexts in fastdebug (#22052)", TestUtils.isReleaseBuild());

// (DB-12674) Allow tests to run in round-robin allocation mode when
// using a pool of warmed up connections to allow for deterministic results.
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.ROUND_ROBIN);
boolean isConnMgr = isTestRunningWithConnectionManager();
if (isConnMgr) {
setUp();
}
try (Statement stmt = this.connection2.createStatement()) {
stmt.execute("SET work_mem TO '1GB'"); /* avoid getting close to work_mem */
// Warmup the cache when Connection Manager is enabled.
Expand Down
18 changes: 16 additions & 2 deletions java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgExplainAnalyze.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ public void testExplainNoTiming(String query, Checker checker) throws Exception

@Test
public void testSeqScan() throws Exception {
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.ROUND_ROBIN);
// (DB-12699) Catalog read requests decrease in any warmup mode when
// connection manager is enabled, but not to the expected value of 0.
// Allow the test to run without warmed up connections for now.
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.NONE);
if (isTestRunningWithConnectionManager()) {
setUp();
}

try (Statement stmt = connection.createStatement()) {
Checker checker = makeTopLevelBuilder()
.storageReadRequests(Checkers.equal(5))
Expand Down Expand Up @@ -342,7 +349,14 @@ public void testEmptyNestedLoop() throws Exception {

@Test
public void testInsertValues() throws Exception {
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.ROUND_ROBIN);
// (DB-12699) Catalog read requests decrease in any warmup mode when
// connection manager is enabled, but not to the expected value of 0.
// Allow the test to run without warmed up connections for now.
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.NONE);
if (isTestRunningWithConnectionManager()) {
setUp();
}

try (Statement stmt = connection.createStatement()) {
// reduce the batch size to avoid 0 wait time
stmt.execute("SET ysql_session_max_batch_size = 4");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.yb.AssertionWrappers.assertEquals;
import static org.yb.AssertionWrappers.assertFalse;
import static org.yb.AssertionWrappers.assertTrue;
import static org.junit.Assume.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -200,7 +201,18 @@ private void testOneCase(

@Test
public void testScans() throws Exception {
// (DB-12741) This test works with connection manager provided that its
// debug and query logs are disabled, which allows the logInterceptor to
// capture the needed information for this test to pass. Skip the test for
// the time being when connection manager is enabled.
assumeFalse(BasePgSQLTest.CONFIGURABLE_DEBUG_LOGS_NEEDED, isTestRunningWithConnectionManager());

setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.ROUND_ROBIN);
// Set up the necessary aspects of the test after restarting the cluster.
if (isConnMgrWarmupRoundRobinMode()) {
logInterceptor.detach();
setUp();
}
try (Statement stmt = connection.createStatement()) {
// Note: In case of using yb_hash_code function all its argument columns are fetched.
// They are required for row recheck.
Expand Down
24 changes: 7 additions & 17 deletions java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgYbStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.yb.pgsql;

import static org.yb.AssertionWrappers.*;
import static org.junit.Assume.*;

import java.sql.Connection;
import java.sql.ResultSet;
Expand Down Expand Up @@ -62,15 +63,7 @@ private void executeQueryAndExpectTempFileLimitExceeded(final String query,
private void executeQueryAndSendSignal(final String query,
final Connection inputConnection, final String signal) throws Exception {
try (Statement statement = inputConnection.createStatement()) {

int[] pids = new int[CONN_MGR_WARMUP_BACKEND_COUNT];
if (isConnMgrWarmupRoundRobinMode()) {
for (int i = 0; i < CONN_MGR_WARMUP_BACKEND_COUNT; i++){
pids[i] = getPid(inputConnection);
}
} else {
pids[0] = getPid(inputConnection);
}
final int pid = getPid(inputConnection);

final CountDownLatch startSignal = new CountDownLatch(1);
final List<ThrowingRunnable> cmds = new ArrayList<>();
Expand All @@ -91,13 +84,7 @@ private void executeQueryAndSendSignal(final String query,
startSignal.countDown();
startSignal.await();
Thread.sleep(100); // Allow the query execution a headstart before killing
if (isConnMgrWarmupRoundRobinMode()) {
for (int i = 0; i < CONN_MGR_WARMUP_BACKEND_COUNT; i++) {
ProcessUtil.signalProcess(pids[i], signal);
}
} else {
ProcessUtil.signalProcess(pids[0], signal);
}
ProcessUtil.signalProcess(pid, signal);
});
MiscUtil.runInParallel(cmds, startSignal, 60);
} catch (Throwable exception) {
Expand Down Expand Up @@ -160,7 +147,10 @@ private boolean waitUntilConditionSatisfiedOrTimeout(String query,

@Test
public void testYbTerminatedQueriesMultipleCauses() throws Exception {
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.ROUND_ROBIN);
// (DB-12741) Test is flaky with connection manager irrespective of warmup
// mode. Disable the test for now when running with connection manager.
assumeFalse(BasePgSQLTest.INCORRECT_CONN_STATE_BEHAVIOR, isTestRunningWithConnectionManager());

// We need to restart the cluster to wipe the state currently contained in yb_terminated_queries
// that can potentially be leftover from another test in this class. This would let us start
// with a clean slate.
Expand Down
10 changes: 9 additions & 1 deletion java/yb-pgsql/src/test/java/org/yb/pgsql/TestToastFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ public class TestToastFunction extends TestToastFunctionBase {
private static final Logger LOG = LoggerFactory.getLogger(TestToastFunction.class);

@Test
public void testSimple() throws SQLException {
public void testSimple() throws Exception {
// (DB-12699) In any warmup mode, the memory usage is much higher than in
// the case of no warmup mode. Allow the test to run exclusively in no
// warmup mode for now.
setConnMgrWarmupModeAndRestartCluster(ConnectionManagerWarmupMode.NONE);
if (isTestRunningWithConnectionManager()) {
createTables();
}

setEnableToastFlag(true);
CacheMemoryContextTracker cxt = simpleTest();
cxt.assertMemoryUsageLessThan(300 * KB);
Expand Down
4 changes: 3 additions & 1 deletion src/odyssey/sources/server_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ static inline od_server_t *yb_od_server_pool_idle_last(od_server_pool_t *pool)
{
od_list_t *target = &pool->idle;
od_server_t *server = NULL;
od_list_t *i, *n;
int len = pool->count_idle;
if (len == 0)
return NULL;
server = od_container_of(target->prev, od_server_t, link);
od_list_foreach(target, i)
server = od_container_of(i, od_server_t, link);

return server;
}
Expand Down

0 comments on commit f97d7d5

Please sign in to comment.