Skip to content

Commit e1fe69b

Browse files
Merge pull request #675 from cloudsufi/transaction-isolation-level-develop
Add TRANSACTION_ISOLATION_LEVEL config in cloudsql-postgres and cloudsql-mysql plugins for develop
2 parents 76fe714 + cf3e095 commit e1fe69b

13 files changed

Lines changed: 113 additions & 2 deletions

File tree

cloudsql-mysql-plugin/docs/CloudSQLMySQL-batchsink.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Can be found in the instance overview page.
4242

4343
**Password:** Password to use to connect to the specified database.
4444

45-
**Transaction Isolation Level:** Transaction isolation level for queries run by this sink.
45+
**Transaction Isolation Level:** Transaction isolation level for queries run by this sink.
4646

4747
**Connection Timeout:** The timeout value (in seconds) used for socket connect operations. If connecting to the server
4848
takes longer than this value, the connection is broken. A value of 0 means that it is disabled.

cloudsql-mysql-plugin/docs/CloudSQLMySQL-batchsource.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ For example, 'SELECT MIN(id),MAX(id) FROM table'. Not required if numSplits is s
5252

5353
**Password:** Password to use to connect to the specified database.
5454

55+
**Transaction Isolation Level:** The transaction isolation level of the database connection.
56+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
57+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
58+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
59+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
60+
61+
For more details on the Transaction Isolation Levels supported in CloudSQL MySQL, refer to the [CloudSQL MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html)
62+
5563
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
5664
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.
5765

cloudsql-mysql-plugin/docs/CloudSQLMySQL-connector.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ authentication. Optional for databases that do not require authentication.
2727

2828
**Password:** Password to use to connect to the specified database.
2929

30+
**Transaction Isolation Level:** The transaction isolation level of the database connection.
31+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
32+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
33+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
34+
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.
35+
36+
For more details on the Transaction Isolation Levels supported in CloudSQL MySQL, refer to the [CloudSQL MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html)
37+
3038
**Connection Arguments:** A list of arbitrary string tag/value pairs as connection arguments. These arguments
3139
will be passed to the JDBC driver, as connection arguments, for JDBC drivers that may need additional configurations.
3240
This is a semicolon-separated list of key-value pairs, where each pair is separated by a equals '=' and specifies

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLSource.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ public static class CloudSQLMySQLSourceConfig extends AbstractDBSpecificSourceCo
156156
@Description("The existing connection to use.")
157157
private CloudSQLMySQLConnectorConfig connection;
158158

159+
@Name(TRANSACTION_ISOLATION_LEVEL)
160+
@Description("Transaction isolation level for queries run by this source.")
161+
@Nullable
162+
private String transactionIsolationLevel;
163+
164+
private static final String DEFAULT_TRANSACTION_ISOLATION_LEVEL = "TRANSACTION_REPEATABLE_READ";
165+
159166
@Override
160167
protected Map<String, String> getDBSpecificArguments() {
161168
if (getFetchSize() == null || getFetchSize() <= 0) {
@@ -168,6 +175,11 @@ protected Map<String, String> getDBSpecificArguments() {
168175
return arguments;
169176
}
170177

178+
@Override
179+
public String getTransactionIsolationLevel() {
180+
return transactionIsolationLevel != null ? transactionIsolationLevel : DEFAULT_TRANSACTION_ISOLATION_LEVEL;
181+
}
182+
171183
@Override
172184
public void validate(FailureCollector collector) {
173185
ConfigUtil.validateConnection(this, useConnection, connection, collector);

cloudsql-mysql-plugin/widgets/CloudSQLMySQL-batchsource.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@
8484
"label": "Password",
8585
"name": "password"
8686
},
87+
{
88+
"widget-type": "select",
89+
"label": "Transaction Isolation Level",
90+
"name": "transactionIsolationLevel",
91+
"widget-attributes": {
92+
"default": "TRANSACTION_REPEATABLE_READ",
93+
"values": [
94+
"TRANSACTION_REPEATABLE_READ",
95+
"TRANSACTION_READ_UNCOMMITTED",
96+
"TRANSACTION_READ_COMMITTED",
97+
"TRANSACTION_SERIALIZABLE"
98+
]
99+
}
100+
},
87101
{
88102
"widget-type": "keyvalue",
89103
"label": "Connection Arguments",

cloudsql-mysql-plugin/widgets/CloudSQLMySQL-connector.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@
5454
"widget-attributes": {
5555
"default": "3306"
5656
}
57+
},
58+
{
59+
"widget-type": "select",
60+
"label": "Transaction Isolation Level",
61+
"name": "transactionIsolationLevel",
62+
"widget-attributes": {
63+
"default": "TRANSACTION_REPEATABLE_READ",
64+
"values": [
65+
"TRANSACTION_REPEATABLE_READ",
66+
"TRANSACTION_READ_UNCOMMITTED",
67+
"TRANSACTION_READ_COMMITTED",
68+
"TRANSACTION_SERIALIZABLE"
69+
]
70+
}
5771
}
5872
]
5973
},

cloudsql-postgresql-plugin/docs/CloudSQLPostgreSQL-batchsink.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Can be found in the instance overview page.
4242

4343
**Password:** Password to use to connect to the specified database.
4444

45-
**Transaction Isolation Level:** Transaction isolation level for queries run by this sink.
45+
**Transaction Isolation Level:** Transaction isolation level for queries run by this sink.
4646

4747
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
4848
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.

cloudsql-postgresql-plugin/docs/CloudSQLPostgreSQL-batchsource.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ For example, 'SELECT MIN(id),MAX(id) FROM table'. Not required if numSplits is s
5252

5353
**Password:** Password to use to connect to the specified database.
5454

55+
**Transaction Isolation Level:** The transaction isolation level of the database connection.
56+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
57+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
58+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
59+
- Note: PostgreSQL does not implement `TRANSACTION_READ_UNCOMMITTED` as a distinct isolation level. Instead, this mode behaves identically to`TRANSACTION_READ_COMMITTED`, which is why it is not exposed as a separate option.
60+
61+
For more details on the Transaction Isolation Levels supported in CloudSQL PostgreSQL, refer to the [CloudSQL PostgreSQL documentation](https://www.postgresql.org/docs/current/transaction-iso.html)
62+
5563
**Connection Arguments:** A list of arbitrary string key/value pairs as connection arguments. These arguments
5664
will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.
5765

cloudsql-postgresql-plugin/docs/CloudSQLPostgreSQL-connector.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ authentication. Optional for databases that do not require authentication.
2727

2828
**Password:** Password to use to connect to the specified database.
2929

30+
**Transaction Isolation Level:** The transaction isolation level of the database connection.
31+
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
32+
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
33+
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
34+
- Note: PostgreSQL does not implement `TRANSACTION_READ_UNCOMMITTED` as a distinct isolation level. Instead, this mode behaves identically to`TRANSACTION_READ_COMMITTED`, which is why it is not exposed as a separate option.
35+
36+
For more details on the Transaction Isolation Levels supported in CloudSQL PostgreSQL, refer to the [CloudSQL PostgreSQL documentation](https://www.postgresql.org/docs/current/transaction-iso.html)
37+
3038
**Connection Arguments:** A list of arbitrary string tag/value pairs as connection arguments. These arguments
3139
will be passed to the JDBC driver, as connection arguments, for JDBC drivers that may need additional configurations.
3240
This is a semicolon-separated list of key-value pairs, where each pair is separated by a equals '=' and specifies

cloudsql-postgresql-plugin/src/main/java/io/cdap/plugin/cloudsql/postgres/CloudSQLPostgreSQLSource.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ public static class CloudSQLPostgreSQLSourceConfig extends AbstractDBSpecificSou
157157
@Description("The existing connection to use.")
158158
private CloudSQLPostgreSQLConnectorConfig connection;
159159

160+
@Name(TRANSACTION_ISOLATION_LEVEL)
161+
@Description("Transaction isolation level for queries run by this source.")
162+
@Nullable
163+
private String transactionIsolationLevel;
164+
165+
private static final String DEFAULT_TRANSACTION_ISOLATION_LEVEL = "TRANSACTION_READ_COMMITTED";
166+
160167
@Override
161168
protected Map<String, String> getDBSpecificArguments() {
162169
return Collections.emptyMap();
@@ -173,6 +180,11 @@ protected CloudSQLPostgreSQLConnectorConfig getConnection() {
173180
return connection;
174181
}
175182

183+
@Override
184+
public String getTransactionIsolationLevel() {
185+
return transactionIsolationLevel != null ? transactionIsolationLevel : DEFAULT_TRANSACTION_ISOLATION_LEVEL;
186+
}
187+
176188
@Override
177189
public void validate(FailureCollector collector) {
178190
ConfigUtil.validateConnection(this, useConnection, connection, collector);

0 commit comments

Comments
 (0)