Skip to content

Commit

Permalink
[#26116] YSQL, QueryDiagnostics: Fix TestYbQueryDiagnostics.testInter…
Browse files Browse the repository at this point in the history
…mediateFlushing

Summary:
TestYbQueryDiagnostics.testIntermediateFlushing has been failing in TSAN builds starting from #22612. This is a regression based on the stability history.
Jira: DB-15443

Test Plan: yb_build.sh --java-test 'org.yb.pgsql.TestYbQueryDiagnostics#testIntermediateFlushing'

Reviewers: asaha

Reviewed By: asaha

Subscribers: svc_phabricator

Differential Revision: https://phorge.dev.yugabyte.com/D42073
  • Loading branch information
IshanChhangani committed Mar 1, 2025
1 parent c4cd5c0 commit 79dc5da
Showing 1 changed file with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,25 +338,30 @@ private void waitForBundleCompletion(String queryId, Statement statement,
int diagnosticsInterval) throws Exception {
Thread.sleep(diagnosticsInterval * 1000 + BG_WORKER_INTERVAL_MS);

long start_time = System.currentTimeMillis();
while (true)
{
System.out.println("Waiting in forever loop");
long startTime = System.currentTimeMillis();

ResultSet resultSet = statement.executeQuery(
"SELECT * FROM yb_query_diagnostics_status where query_id = " +
queryId);

if (resultSet.next() && !resultSet.getString("status").equals("In Progress"))
break;

if (System.currentTimeMillis() - start_time > 60000) // 1 minute
fail("Bundle did not complete within the expected time");

Thread.sleep(BG_WORKER_INTERVAL_MS);
try {
TestUtils.waitFor(() -> {
ResultSet resultSet = statement.executeQuery(
"SELECT * FROM yb_query_diagnostics_status where query_id = " +
queryId);

if (resultSet.next() && !resultSet.getString("status").equals("In Progress"))
return true;

return false;
},
60000L, BG_WORKER_INTERVAL_MS);
} catch (Exception e) {
throw new AssertionError(
"Bundle did not complete within the expected time");
}
}

private void waitForBundleCompletion(String queryId, Statement statement) throws Exception {
waitForBundleCompletion(queryId, statement, 0);
}

/*
* Counts the number of table sections in the schema details.
*/
Expand Down Expand Up @@ -1397,12 +1402,12 @@ public void testIntermediateFlushing() throws Exception {
* we consider only half the length.
*/
int varLen = minLen / 2;
String largeVariable = new String(new char[ varLen ]).replace('\0', 'a');
String largeVariable = new String(new char[varLen]).replace('\0', 'a');

/* To ensure that the buffer overflows we do twice as many iterations */
int noOfIterations = (maxLen / varLen) + 1;

int diagnosticsInterval = noOfIterations * (BG_WORKER_INTERVAL_MS / 1000);
int diagnosticsInterval = 2 * noOfIterations * (BG_WORKER_INTERVAL_MS / 1000);
QueryDiagnosticsParams params = new QueryDiagnosticsParams(
diagnosticsInterval,
100 /* explainSampleRate */,
Expand All @@ -1420,19 +1425,7 @@ public void testIntermediateFlushing() throws Exception {
Thread.sleep(BG_WORKER_INTERVAL_MS);
}

long start_time = System.currentTimeMillis();
while (true)
{
ResultSet resultSet = statement.executeQuery(
"SELECT * FROM yb_query_diagnostics_status");
if (resultSet.next() && resultSet.getString("status").equals("Success"))
break;

if (System.currentTimeMillis() - start_time > 60000) // 1 minute
fail("Bundle did not complete within the expected time");

Thread.sleep(BG_WORKER_INTERVAL_MS);
}
waitForBundleCompletion(queryId, statement);

/* Bundle has expired */
Path bindVariablesPath = bundleDataPath.resolve("constants_and_bind_variables.csv");
Expand All @@ -1444,6 +1437,9 @@ public void testIntermediateFlushing() throws Exception {
String bindVariablesContent = new String(Files.readAllBytes(bindVariablesPath));
String explainPlanContent = new String(Files.readAllBytes(explainPlanPath));

LOG.info("Explain plan content: \n" + explainPlanContent);
LOG.info("Bind variables content: \n" + bindVariablesContent);

int bindVariablesLength = bindVariablesContent.length();
int explainPlanLength = explainPlanContent.length();

Expand Down

0 comments on commit 79dc5da

Please sign in to comment.