Skip to content

Commit

Permalink
Merge pull request #735 from MohamedSabthar/master
Browse files Browse the repository at this point in the history
Fix strand hanging when strand count exceeds BALLERINA_SQL_MAX_POOL_SIZE
  • Loading branch information
MohamedSabthar authored Oct 9, 2024
2 parents 1c6399b + e11222c commit 99a0d7a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
8 changes: 4 additions & 4 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "sql"
version = "1.14.1"
version = "1.14.2"
authors = ["Ballerina"]
keywords = ["database", "client", "network", "SQL", "RDBMS"]
repository = "https://github.com/ballerina-platform/module-ballerina-sql"
Expand All @@ -15,11 +15,11 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "sql-native"
version = "1.14.1"
path = "../native/build/libs/sql-native-1.14.1.jar"
version = "1.14.2"
path = "../native/build/libs/sql-native-1.14.2-SNAPSHOT.jar"

[[platform.java17.dependency]]
path = "../test-utils/build/libs/sql-test-utils-1.14.1.jar"
path = "../test-utils/build/libs/sql-test-utils-1.14.2-SNAPSHOT.jar"
scope = "testOnly"

[[platform.java17.dependency]]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "sql-compiler-plugin"
class = "io.ballerina.stdlib.sql.compiler.SQLCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/sql-compiler-plugin-1.14.1.jar"
path = "../compiler-plugin/build/libs/sql-compiler-plugin-1.14.2-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -302,7 +302,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "sql"
version = "1.14.1"
version = "1.14.2"
dependencies = [
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
Expand Down
29 changes: 29 additions & 0 deletions ballerina/tests/query-row-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,35 @@ function queryRowEmptyTest2() returns error? {
test:assertEquals(result, expectedAlbum);
}

@test:Config {
groups: ["query", "query-row"]
}
function loadTestQueryRow() returns error? {
MockClient dbClient = check getMockClient(queryRowDb);
int strandCount = 60;
future<Album3|error>[] futures = [];
foreach int i in 0 ... strandCount {
future<Album3|error> 'future = start queryAlbum3(dbClient);
futures.push('future);
}
Album3 expectedAlbum = {
id: "2",
name: "Lemonade",
artist: (),
price: 20.0
};
foreach int i in 0 ... strandCount {
Album3 album = check wait futures.pop();
test:assertEquals(album, expectedAlbum);
}
check dbClient.close();
}

isolated function queryAlbum3(MockClient dbClient) returns Album3|error {
Album3 result = check dbClient->queryRow(`SELECT * FROM Album WHERE id_test = 2`);
return result;
}

isolated function validateDataTableRecordResult(record {}? returnData) {
decimal decimalVal = 23.45;
if returnData is () {
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- [Fix strand hanging when strand count exceeds BALLERINA_SQL_MAX_POOL_SIZE](https://github.com/ballerina-platform/ballerina-library/issues/7244)

## [1.14.1] - 2024-08-29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package io.ballerina.stdlib.sql.datasource;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand All @@ -41,7 +41,7 @@ private SQLWorkerThreadPool() {

// This is similar to cachedThreadPool util from Executors.newCachedThreadPool(..); but with upper cap on threads
public static final ExecutorService SQL_EXECUTOR_SERVICE = new ThreadPoolExecutor(0, MAX_POOL_SIZE,
60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new SQLThreadFactory());
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new SQLThreadFactory());

static class SQLThreadFactory implements ThreadFactory {
@Override
Expand Down

0 comments on commit 99a0d7a

Please sign in to comment.