Skip to content

Conversation

@Akanksha-kedia
Copy link
Contributor

@Akanksha-kedia Akanksha-kedia commented Jul 8, 2025

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.

@cla-bot cla-bot bot added the cla-signed label Jul 8, 2025
@Akanksha-kedia
Copy link
Contributor Author

@ebyhr

@Akanksha-kedia
Copy link
Contributor Author

Akanksha-kedia commented Jul 9, 2025 via email

@Akanksha-kedia Akanksha-kedia force-pushed the feature/new_pr branch 2 times, most recently from d8bbdb2 to c1469cc Compare July 9, 2025 02:23
@ebyhr
Copy link
Member

ebyhr commented Jul 9, 2025

I ll have to remove that

Why do we need to remove webapp/pnpm-lock.yaml?

@Akanksha-kedia
Copy link
Contributor Author

Akanksha-kedia commented Jul 9, 2025 via email

@Akanksha-kedia
Copy link
Contributor Author

@ebyhr please review

@Akanksha-kedia
Copy link
Contributor Author

@ebyhr have resolved please review.

@Akanksha-kedia
Copy link
Contributor Author

  • Database Configuration Changes:

    • In gateway-ha/config.yaml: Changed database connection parameters to use environment variables with defaults, making the configuration more flexible for different environments.
  • Timestamp Handling Improvements:

    • In ExactMatchSourceSelectorsDao.java: Added a TimestampColumnMapper class to properly handle timestamp formatting.
    • In HaResourceGroupsManager.java: Added automatic timestamp generation for updateTime when it's null or empty.
  • Test Framework Modernization:

    • In TestingJdbcConnectionManager.java: Replaced H2 in-memory database with PostgreSQL using TestContainers.
    • In TestSpecificDbResourceGroupsManager.java: Removed file-based setup and switched to TestContainers.
    • In TestResourceGroupsManager.java: Updated test assertions to use newer Java methods (e.g., getFirst() instead of get(0)), and improved resource group ID lookup.

@Akanksha-kedia
Copy link
Contributor Author

@mosabua please review.

@Akanksha-kedia
Copy link
Contributor Author

@mosabua

@Akanksha-kedia
Copy link
Contributor Author

Please review and help to merge
@ebyhr @mosabua

@Akanksha-kedia
Copy link
Contributor Author

Screenshot 2025-08-08 at 11 18 58 AM https://nexus-iq.visa.com/assets/index.html#/vulnerabilities/CVE-2021-42392

@Akanksha-kedia
Copy link
Contributor Author

@mosabua @electrum @ebyhr please review

@Akanksha-kedia
Copy link
Contributor Author

@mosabua
Copy link
Member

mosabua commented Sep 18, 2025

We cut a new release now .. will hopefully be able to test soon .. can you rebase in the meantime

@Akanksha-kedia
Copy link
Contributor Author

Akanksha-kedia commented Sep 20, 2025 via email

@Akanksha-kedia
Copy link
Contributor Author

@mosabua please review

@mosabua
Copy link
Member

mosabua commented Oct 11, 2025

With #780 merged now .. can you rebase and adjust and make sure CI passes?

@Akanksha-kedia
Copy link
Contributor Author

Akanksha-kedia commented Oct 12, 2025 via email

@Akanksha-kedia
Copy link
Contributor Author

please review @mosabua

@mosabua
Copy link
Member

mosabua commented Jan 10, 2026

Can you rebase and resolve conflicts here @Akanksha-kedia ? It would be good to get this in

@Akanksha-kedia
Copy link
Contributor Author

@mosabua please review i have rebased and resolved conflicts

@Akanksha-kedia Akanksha-kedia force-pushed the feature/new_pr branch 2 times, most recently from 1ab7c9d to 4d6bf67 Compare January 13, 2026 15:00
@ebyhr
Copy link
Member

ebyhr commented Jan 15, 2026

@Akanksha-kedia Could you fix CI failure?

@Akanksha-kedia
Copy link
Contributor Author

Akanksha-kedia commented Jan 15, 2026 via email

Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I agree with the idea and PR. We definitely need to make sure all tests pass before merging.

One aspect to keep in mind also is that we will hopefully delete all the resource groups table stuff and the related code from Trino Gateway since it really is outside of the scope of the project as has been discussed in our team syncs before

Jdbi jdbi = HaGatewayProviderModule.createJdbi(db);
JdbcConnectionManager connectionManager = new JdbcConnectionManager(jdbi, db);
super.resourceGroupManager = new HaResourceGroupsManager(connectionManager);
PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:14-alpine")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why such an old version of PostgreSQL? In either case .. it should be same as in other tests and usage within the codebase

@mosabua
Copy link
Member

mosabua commented Jan 22, 2026

Ping @Akanksha-kedia

@Akanksha-kedia
Copy link
Contributor Author

Akanksha-kedia commented Jan 22, 2026 via email

@Akanksha-kedia
Copy link
Contributor Author

Overall I agree with the idea and PR. We definitely need to make sure all tests pass before merging.

One aspect to keep in mind also is that we will hopefully delete all the resource groups table stuff and the related code from Trino Gateway since it really is outside of the scope of the project as has been discussed in our team syncs before

by when or anyhelp needed from my end

@Akanksha-kedia Akanksha-kedia force-pushed the feature/new_pr branch 2 times, most recently from 3c528b2 to 25982c4 Compare January 23, 2026 11:17
return timestamp != null ? timestamp.toLocalDateTime().format(FORMATTER) : null;
}
catch (SQLException e) {
return LocalDateTime.now(ZoneId.systemDefault()).format(FORMATTER);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a code comment why we need this fallback logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this issue happen? Is it covered by tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my analysis, the tests do exercise the timestamp mapper (through testReadExactMatchSourceSelectors()), but they don't specifically test the fallback scenario where getTimestamp() throws a SQLException. The fallback is a defensive measure for edge cases with certain database drivers.

assertThat(resourceGroups.get(0).getMaxQueued()).isEqualTo(200);
assertThat(resourceGroups.get(0).getJmxExport()).isTrue();
assertThat(resourceGroups.get(0).getSoftMemoryLimit()).isEqualTo("80%");
assertThat(resourceGroups.getFirst().getResourceGroupId()).isEqualTo(1L);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to H2->PostgreSQL change. Please separate a commit.

{
List<ResourceGroupsDetail> resourceGroups = resourceGroupManager.readAllResourceGroups(null);
long adminResourceGroupId = resourceGroups.stream()
.filter(rg -> "admin".equals(rg.getName()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.findFirst()
.orElse(null);

if (testGroup == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test non-deterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test code in TestResourceGroupsManager.java at line 237-240 is non-deterministic because it uses .stream().filter().findFirst() on a List without guaranteed ordering:

ResourceGroupsDetail testGroup = existingGroups.stream()
    .filter(rg -> "selector-test-group".equals(rg.getName()))
    .findFirst()
    .orElse(null);

Root Cause:

  1. Database ordering is not guaranteed: The readAllResourceGroups(null) method returns a List from a database query, but without an explicit ORDER BY clause, the database can return rows in any order.

  2. Test execution order dependency: The test uses @TestMethodOrder(OrderAnnotation.class) and @Order annotations, but previous tests create multiple resource groups. The order in which these groups are returned from the database is unpredictable.

  3. Stream.findFirst() behavior: When filtering a stream, findFirst() returns the first element that matches the filter predicate. If multiple elements could match (or if the list order changes), the result becomes non-deterministic.

The Problem:

If there are multiple resource groups in the database when this test runs, and the database returns them in different orders on different executions, the test behavior becomes unpredictable. Even though the filter looks for a specific name ("selector-test-group"), the order in which the database returns all groups can vary, affecting test execution timing and state.

Solution:

The code should either:

  1. Use a deterministic query with explicit ordering in readAllResourceGroups()
  2. Not rely on list ordering when searching for specific items
  3. Clean up test data more reliably between test methods

The pattern appears in multiple places in the test file (lines 90-94, 237-240, 268-271, 305-310), making the entire test suite potentially flaky.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this change relate to the H2 → PostgreSQL migration?

assumeTrue("true".equals(System.getenv("GITHUB_ACTIONS"))
|| "x86_64".equalsIgnoreCase(System.getProperty("os.arch"))
|| "true".equals(System.getenv("TG_RUN_ORACLE_TESTS")));
return new OracleContainer("gvenzl/oracle-xe:18.4.0-slim");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you downgrade the version? Please revert this change.

@Akanksha-kedia
Copy link
Contributor Author

please review @mosabua

@Akanksha-kedia Akanksha-kedia force-pushed the feature/new_pr branch 4 times, most recently from c155698 to 891a4ba Compare January 23, 2026 11:54
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing H2 with PostgreSQL is totally fine. However, some test changes don't make sense to me.

assertThat(resourceGroups.get(0).getHardConcurrencyLimit()).isEqualTo(20);
assertThat(resourceGroups.get(0).getMaxQueued()).isEqualTo(200);
assertThat(resourceGroups.get(0).getJmxExport()).isTrue();
assertThat(resourceGroups.get(0).getJmxExport()).isEqualTo(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert.

// Find the admin resource group and verify its properties
ResourceGroupsDetail adminGroup = resourceGroups.stream()
.filter(rg -> "admin".equals(rg.getName()))
.findFirst()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid findFirst as much as possible. Consider using collect(toOptional()) instead.

ExactSelectorsDetail exactSelectorDetail)
{
// If updateTime is null or empty, set current timestamp
if (exactSelectorDetail.getUpdateTime() == null || exactSelectorDetail.getUpdateTime().trim().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUpdateTime() contains @Nonnull annotation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change DateTimeFormatter formatter to a constant.

extends TestResourceGroupsManager
{
private String specificDb;
private String specificDb = "test_db_specific";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it static final and uppercase the constant name.

Comment on lines 60 to 62
catch (Exception e) {
throw new RuntimeException("Failed to setup test database: " + specificDb, e);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove a redundant catch block.

Comment on lines 49 to 51
String jdbcUrl = postgres.getJdbcUrl();
String username = postgres.getUsername();
String password = postgres.getPassword();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline.

Comment on lines 34 to 36
String jdbcUrl = postgres.getJdbcUrl();
String username = postgres.getUsername();
String password = postgres.getPassword();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline.

import java.io.File;
import java.nio.file.Path;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid a deprecated class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder.

postgres.getJdbcUrl(),
postgres.getUsername(),
postgres.getPassword(),
"org.postgresql.Driver",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgreSQLContainer offers getDriverClassName method.

@Akanksha-kedia
Copy link
Contributor Author

@ebyhr please review all and let me know wat more chnages i need to do

@ebyhr
Copy link
Member

ebyhr commented Jan 27, 2026

Please fix build failures:

Error:  src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java:[26,15] (imports) UnusedImports: Unused import - com.google.common.collect.MoreObjects.firstNonNull.
Error:  src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java:[32,15] (imports) UnusedImports: Unused import - java.util.stream.Collectors.collectingAndThen.
Error:  src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java:[33,15] (imports) UnusedImports: Unused import - java.util.stream.Collectors.toList.

@Akanksha-kedia Akanksha-kedia force-pushed the feature/new_pr branch 3 times, most recently from 31386a1 to 146e761 Compare January 27, 2026 09:45
@Akanksha-kedia
Copy link
Contributor Author

Please fix build failures:

Error:  src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java:[26,15] (imports) UnusedImports: Unused import - com.google.common.collect.MoreObjects.firstNonNull.
Error:  src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java:[32,15] (imports) UnusedImports: Unused import - java.util.stream.Collectors.collectingAndThen.
Error:  src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java:[33,15] (imports) UnusedImports: Unused import - java.util.stream.Collectors.toList.

done @ebyhr do review its a long pending pr thanks in advance.

@Akanksha-kedia
Copy link
Contributor Author

@mosabua please help to review and merge or else again we have spend time in rebasing and all


public static JdbcConnectionManager createTestingJdbcConnectionManager()
{
PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:14-alpine")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use TestcontainersUtils.createPostgreSqlContainer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants