From 6112cd19ed86f7b5606d6f0d9c5aa3534db8fb5a Mon Sep 17 00:00:00 2001 From: Artur Oganezov Date: Fri, 8 Nov 2024 14:32:51 -0600 Subject: [PATCH 1/4] Allow preparedStatementThreshold to be 0 to disable the cache. --- ballerina/client.bal | 4 +++- .../java/io/ballerina/stdlib/postgresql/utils/Utils.java | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ballerina/client.bal b/ballerina/client.bal index dab326a6..0ec7e7ee 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -149,9 +149,11 @@ type ClientConfiguration record {| # + cachedMetadataFieldSize - The maximum size (in megabytes) of fields to be cached per connection. # A value of 0 disables the cache # + preparedStatementThreshold - The number of `PreparedStatement` executions required before switching -# over to use server-side prepared statements +# over to use server-side prepared statements. A value of 0 disables the cache. # + preparedStatementCacheQueries - The number of queries that are cached in each connection +# A value of 0 for preparedStatementThreshold disables the cache. # + preparedStatementCacheSize - The maximum size (in mebibytes) of the prepared queries +# A value of 0 for preparedStatementThreshold disables the cache. # + cancelSignalTimeout - Time (in seconds) by which the cancel command is sent out of band over its own connection # so that the cancel message itself can get stuck. The default value is 10 seconds # + keepAliveTcpProbe - Enable or disable the TCP keep-alive probe diff --git a/native/src/main/java/io/ballerina/stdlib/postgresql/utils/Utils.java b/native/src/main/java/io/ballerina/stdlib/postgresql/utils/Utils.java index 74628234..fd3ec6d3 100644 --- a/native/src/main/java/io/ballerina/stdlib/postgresql/utils/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/postgresql/utils/Utils.java @@ -66,14 +66,14 @@ public static BMap generateOptionsMap(BMap postgresqlOptions) { if (postgresqlOptions.containsKey(Constants.Options.PREPARE_THRESHOLD)) { long preparedStatementThreshold = getIntegerValue(postgresqlOptions. getIntValue(Constants.Options.PREPARE_THRESHOLD)); - if (preparedStatementThreshold > 0) { + if (preparedStatementThreshold >= 0) { options.put(Constants.DatabaseProps.PREPARE_THRESHOLD, preparedStatementThreshold); } } if (postgresqlOptions.containsKey(Constants.Options.PREPARED_STATEMENT_CACHE_QUERIES)) { long preparedStatementCacheQueries = getIntegerValue(postgresqlOptions .getIntValue(Constants.Options.PREPARED_STATEMENT_CACHE_QUERIES)); - if (preparedStatementCacheQueries > 0) { + if (preparedStatementCacheQueries >= 0) { options.put(Constants.DatabaseProps.PREPARED_STATEMENT_CACHE_QUERIES, preparedStatementCacheQueries); } @@ -81,7 +81,7 @@ public static BMap generateOptionsMap(BMap postgresqlOptions) { if (postgresqlOptions.containsKey(Constants.Options.PREPARED_STATEMENT_CACHE_QUERIES)) { long preparedStatementCacheSize = getIntegerValue(postgresqlOptions .getIntValue(Constants.Options.PREPARED_STATEMENT_CACHE_SIZE_MIB)); - if (preparedStatementCacheSize > 0) { + if (preparedStatementCacheSize >= 0) { options.put(Constants.DatabaseProps.PREPARED_STATEMENT_CACHE_SIZE_MIB, preparedStatementCacheSize); } } From b766fae84f51b3f90ac39feb50b35c6f5d71bede Mon Sep 17 00:00:00 2001 From: Artur Oganezov Date: Fri, 8 Nov 2024 14:37:14 -0600 Subject: [PATCH 2/4] update change log --- changelog.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 0c1c36b8..2073efd9 100644 --- a/changelog.md +++ b/changelog.md @@ -7,8 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - -### Changed +- [Allow prepareThreshold, preparedStatementCacheQueries and preparedStatementCacheSizeMiB to pass 0 values](https://github.com/ballerina-platform/ballerina-standard-library/issues/7345) ## [1.10.0] - 2023-06-30 From e7c408472f38dc9716ab670b03ebb9abdaf988d0 Mon Sep 17 00:00:00 2001 From: Artur Oganezov Date: Fri, 8 Nov 2024 14:38:08 -0600 Subject: [PATCH 3/4] Update spec --- docs/spec/spec.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 776d522a..f87e0b73 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -78,9 +78,11 @@ public isolated function init(string host = "localhost", string? username = "pos # + cachedMetadataFieldSize - The maximum size (in megabytes) of fields to be cached per connection. # A value of 0 disables the cache # + preparedStatementThreshold - The number of `PreparedStatement` executions required before switching - # over to use server-side prepared statements + # over to use server-side prepared statements. A value of 0 disables the cache. # + preparedStatementCacheQueries - The number of queries that are cached in each connection + # A value of 0 for preparedStatementThreshold disables the cache. # + preparedStatementCacheSize - The maximum size (in mebibytes) of the prepared queries + # A value of 0 for preparedStatementThreshold disables the cache. # + cancelSignalTimeout - Time (in seconds) by which the cancel command is sent out of band over its own connection # so that the cancel message itself can get stuck. The default value is 10 seconds # + keepAliveTcpProbe - Enable or disable the TCP keep-alive probe From d154e67cb0be529234545e8e49bf48fb6386dc47 Mon Sep 17 00:00:00 2001 From: Artur Oganezov Date: Fri, 8 Nov 2024 14:49:31 -0600 Subject: [PATCH 4/4] update tests to account for different scenarios --- ballerina/tests/connection-init-test.bal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ballerina/tests/connection-init-test.bal b/ballerina/tests/connection-init-test.bal index 07bf6e9f..d7a64621 100644 --- a/ballerina/tests/connection-init-test.bal +++ b/ballerina/tests/connection-init-test.bal @@ -120,9 +120,9 @@ function testWithOptions2() returns error? { rowFetchSize: 0, cachedMetadataFieldsCount: 0, cachedMetadataFieldSize: 0, - preparedStatementThreshold: 0, - preparedStatementCacheQueries: 0, - preparedStatementCacheSize: 0, + preparedStatementThreshold: -1, + preparedStatementCacheQueries: -1, + preparedStatementCacheSize: -1, cancelSignalTimeout: 0, keepAliveTcpProbe: false }; @@ -240,7 +240,7 @@ function testWithConnectionParams3() returns error? { rowFetchSize: 20, cachedMetadataFieldsCount: 65536, cachedMetadataFieldSize: 5, - preparedStatementThreshold: 5, + preparedStatementThreshold: 0, preparedStatementCacheQueries: 256, preparedStatementCacheSize: 5, cancelSignalTimeout: 10,