Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added configurable connection pool support for mssql #38818

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins;

import com.appsmith.external.configurations.connectionpool.ConnectionPoolConfig;
import com.appsmith.external.constants.DataType;
import com.appsmith.external.datatypes.AppsmithType;
import com.appsmith.external.dtos.ExecuteActionDTO;
Expand Down Expand Up @@ -114,6 +115,12 @@ public static class MssqlPluginExecutor implements PluginExecutor<HikariDataSour

private static final int PREPARED_STATEMENT_INDEX = 0;

private final ConnectionPoolConfig connectionPoolConfig;

public MssqlPluginExecutor(ConnectionPoolConfig connectionPoolConfig) {
this.connectionPoolConfig = connectionPoolConfig;
}

/**
* Instead of using the default executeParametrized provided by pluginExecutor, this implementation affords an opportunity
* to use PreparedStatement (if configured) which requires the variable substitution, etc. to happen in a particular format
Expand Down Expand Up @@ -356,9 +363,13 @@ private Set<String> populateHintMessages(List<String> columnNames) {
@Override
public Mono<HikariDataSource> datasourceCreate(DatasourceConfiguration datasourceConfiguration) {
log.debug(Thread.currentThread().getName() + ": datasourceCreate() called for MSSQL plugin.");
return Mono.fromCallable(() -> {
log.debug(Thread.currentThread().getName() + ": Connecting to SQL Server db");
return createConnectionPool(datasourceConfiguration);
return connectionPoolConfig
.getMaxConnectionPoolSize()
.flatMap(maxPoolSize -> {
return Mono.fromCallable(() -> {
log.debug(Thread.currentThread().getName() + ": Connecting to SQL Server db");
return createConnectionPool(datasourceConfiguration, maxPoolSize);
});
})
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -561,8 +572,8 @@ public static long getPort(Endpoint endpoint) {
* @param datasourceConfiguration
* @return connection pool
*/
private static HikariDataSource createConnectionPool(DatasourceConfiguration datasourceConfiguration)
throws AppsmithPluginException {
private static HikariDataSource createConnectionPool(
DatasourceConfiguration datasourceConfiguration, Integer maxPoolSize) throws AppsmithPluginException {

DBAuth authentication = null;
StringBuilder urlBuilder = null;
Expand All @@ -572,7 +583,11 @@ private static HikariDataSource createConnectionPool(DatasourceConfiguration dat
hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName(JDBC_DRIVER);
hikariConfig.setMinimumIdle(MINIMUM_POOL_SIZE);
hikariConfig.setMaximumPoolSize(MAXIMUM_POOL_SIZE);

// Use maxPoolSize from config if available, otherwise use default
int maximumPoolSize = maxPoolSize != null ? maxPoolSize : MAXIMUM_POOL_SIZE;
hikariConfig.setMaximumPoolSize(maximumPoolSize);

// Configuring leak detection threshold for 60 seconds. Any connection which hasn't been released in 60 seconds
// should get tracked (may be falsely for long running queries) as leaked connection
hikariConfig.setLeakDetectionThreshold(LEAK_DETECTION_TIME_MS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins;

import com.appsmith.external.configurations.connectionpool.ConnectionPoolConfig;
import com.appsmith.external.models.DBAuth;
import com.appsmith.external.models.DatasourceConfiguration;
import com.appsmith.external.models.Endpoint;
Expand All @@ -8,6 +9,7 @@
import com.zaxxer.hikari.HikariDataSource;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.DockerImageName;
import reactor.core.publisher.Mono;

import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -18,7 +20,15 @@

public class MssqlTestDBContainerManager {

static MssqlPlugin.MssqlPluginExecutor mssqlPluginExecutor = new MssqlPlugin.MssqlPluginExecutor();
private static class MockConnectionPoolConfig implements ConnectionPoolConfig {
@Override
public Mono<Integer> getMaxConnectionPoolSize() {
return Mono.just(5);
}
}

static MssqlPlugin.MssqlPluginExecutor mssqlPluginExecutor =
new MssqlPlugin.MssqlPluginExecutor(new MockConnectionPoolConfig());

public static MssqlDatasourceUtils mssqlDatasourceUtils = new MssqlDatasourceUtils();

Expand Down
Loading