Skip to content

Commit 4d7980e

Browse files
authored
feat(cloud sql): add lazy refresh property for postgres, sql server and mysql (#10022)
1 parent d9f01f1 commit 4d7980e

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

cloud-sql/mysql/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public static DataSource createConnectionPool() {
7373
config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE");
7474
// [START cloud_sql_mysql_servlet_connect_unix]
7575

76+
// cloudSqlRefreshStrategy set to "lazy" is used to perform a
77+
// refresh when needed, rather than on a scheduled interval.
78+
// This is recommended for serverless environments to
79+
// avoid background refreshes from throttling CPU.
80+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy");
81+
7682
// ... Specify additional connection properties here.
7783
// [START_EXCLUDE]
7884
configureConnectionPool(config);

cloud-sql/mysql/servlet/src/main/java/com/example/cloudsql/ConnectorIamAuthnConnectionPoolFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public static DataSource createConnectionPool() {
6060
// The Java Connector will handle SSL so it is unneccesary to enable it at the driver level.
6161
config.addDataSourceProperty("sslmode", "disable");
6262

63+
// cloudSqlRefreshStrategy set to "lazy" is used to perform a
64+
// refresh when needed, rather than on a scheduled interval.
65+
// This is recommended for serverless environments to
66+
// avoid background refreshes from throttling CPU.
67+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy");
68+
6369

6470
// ... Specify additional connection properties here.
6571
// [START_EXCLUDE]

cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public static DataSource createConnectionPool() {
7272
config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE");
7373
// [START cloud_sql_postgres_servlet_connect_unix]
7474

75+
// cloudSqlRefreshStrategy set to "lazy" is used to perform a
76+
// refresh when needed, rather than on a scheduled interval.
77+
// This is recommended for serverless environments to
78+
// avoid background refreshes from throttling CPU.
79+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy");
7580

7681
// ... Specify additional connection properties here.
7782
// [START_EXCLUDE]

cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorIamAuthnConnectionPoolFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public static DataSource createConnectionPool() {
6161
// The Java Connector will handle SSL so it is unneccesary to enable it at the driver level.
6262
config.addDataSourceProperty("sslmode", "disable");
6363

64+
// cloudSqlRefreshStrategy set to "lazy" is used to perform a
65+
// refresh when needed, rather than on a scheduled interval.
66+
// This is recommended for serverless environments to
67+
// avoid background refreshes from throttling CPU.
68+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy");
6469

6570
// ... Specify additional connection properties here.
6671
// [START_EXCLUDE]

cloud-sql/sqlserver/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public static DataSource createConnectionPool() {
6161
// at the driver level.
6262
config.addDataSourceProperty("encrypt", "false");
6363

64+
// cloudSqlRefreshStrategy set to "lazy" is used to perform a
65+
// refresh when needed, rather than on a scheduled interval.
66+
// This is recommended for serverless environments to
67+
// avoid background refreshes from throttling CPU.
68+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy");
69+
6470
// ... Specify additional connection properties here.
6571
// [START_EXCLUDE]
6672
configureConnectionPool(config);

0 commit comments

Comments
 (0)