Skip to content

[PLUGIN-1779] Add TRANSACTION_ISOLATION_LEVEL config in MySQL, PostgreSQL & SQL Server plugins #583

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

Merged
merged 1 commit into from
Apr 24, 2025
Merged
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
Expand Up @@ -45,6 +45,7 @@ public abstract class ConnectionConfig extends PluginConfig implements DatabaseC
public static final String CONNECTION_ARGUMENTS = "connectionArguments";
public static final String JDBC_PLUGIN_NAME = "jdbcPluginName";
public static final String JDBC_PLUGIN_TYPE = "jdbc";
public static final String TRANSACTION_ISOLATION_LEVEL = "transactionIsolationLevel";

@Name(JDBC_PLUGIN_NAME)
@Description("Name of the JDBC driver to use. This is the value of the 'jdbcPluginName' key defined in the JSON " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import io.cdap.cdap.api.annotation.Macro;
import io.cdap.cdap.api.annotation.Name;
import io.cdap.plugin.db.ConnectionConfig;
import io.cdap.plugin.db.TransactionIsolationLevel;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;

Expand All @@ -42,6 +43,12 @@ public abstract class AbstractDBSpecificConnectorConfig extends AbstractDBConnec
@Nullable
protected Integer port;

@Name(ConnectionConfig.TRANSACTION_ISOLATION_LEVEL)
@Description("The transaction isolation level for the database session.")
@Macro
@Nullable
protected String transactionIsolationLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this class also used by SQLServer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. Should we hide the property from SQLServer Plugins for now? OR
add this property to the respective connector configuration classes of PostgreSQL and MySQL plugins and remove from parent connector config?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not implement it in SQLServer as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here


public String getHost() {
return host;
}
Expand All @@ -55,4 +62,21 @@ public int getPort() {
public boolean canConnect() {
return super.canConnect() && !containsMacro(ConnectionConfig.HOST) && !containsMacro(ConnectionConfig.PORT);
}

@Override
public Map<String, String> getAdditionalArguments() {
Map<String, String> additonalArguments = new HashMap<>();
if (getTransactionIsolationLevel() != null) {
additonalArguments.put(TransactionIsolationLevel.CONF_KEY, getTransactionIsolationLevel());
}
return additonalArguments;
}

public String getTransactionIsolationLevel() {
if (transactionIsolationLevel == null) {
return null;
}
return TransactionIsolationLevel.Level.valueOf(transactionIsolationLevel).name();
}
}

8 changes: 8 additions & 0 deletions mssql-plugin/docs/SQL Server-connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ authentication. Optional for databases that do not require authentication.

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

**Transaction Isolation Level** The transaction isolation level of the database connection
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.

For more details on the Transaction Isolation Levels supported in SQL Server, refer to the [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver16)

**Authentication Type:** Indicates which authentication method will be used for the connection. Use 'SQL Login'. to
connect to a SQL Server using username and password properties. Use 'Active Directory Password' to connect to an Azure
SQL Database/Data Warehouse using an Azure AD principal name and password.
Expand Down
8 changes: 8 additions & 0 deletions mssql-plugin/docs/SqlServer-batchsink.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ an Azure SQL Database/Data Warehouse using an Azure AD principal name and passwo

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

**Transaction Isolation Level** The transaction isolation level of the database connection
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.

For more details on the Transaction Isolation Levels supported in SQL Server, refer to the [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver16)

**Instance Name:** SQL Server instance name to connect to. When it is not specified, a
connection is made to the default instance. For the case where both the instanceName and port are specified,
see the notes for port. If you specify a Virtual Network Name in the Server connection property, you cannot
Expand Down
8 changes: 8 additions & 0 deletions mssql-plugin/docs/SqlServer-batchsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ an Azure SQL Database/Data Warehouse using an Azure AD principal name and passwo

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

**Transaction Isolation Level** The transaction isolation level of the database connection
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.

For more details on the Transaction Isolation Levels supported in SQL Server, refer to the [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver16)

**Instance Name:** SQL Server instance name to connect to. When it is not specified, a
connection is made to the default instance. For the case where both the instanceName and port are specified,
see the notes for port. If you specify a Virtual Network Name in the Server connection property, you cannot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public Map<String, String> getDBSpecificArguments() {
packetSize, queryTimeout);
}

@Override
public String getTransactionIsolationLevel() {
return connection.getTransactionIsolationLevel();
}

@Override
public String getConnectionString() {
return String.format(SqlServerConstants.SQL_SERVER_CONNECTION_STRING_FORMAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public List<String> getInitQueries() {
return Collections.emptyList();
}

@Override
public String getTransactionIsolationLevel() {
return connection.getTransactionIsolationLevel();
}

@Override
public void validate(FailureCollector collector) {
ConfigUtil.validateConnection(this, useConnection, connection, collector);
Expand Down
14 changes: 14 additions & 0 deletions mssql-plugin/widgets/SQL Server-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@
"widget-type": "password",
"label": "Password",
"name": "password"
},
{
"widget-type": "select",
"label": "Transaction Isolation Level",
"name": "transactionIsolationLevel",
"widget-attributes": {
"values": [
"TRANSACTION_READ_UNCOMMITTED",
"TRANSACTION_READ_COMMITTED",
"TRANSACTION_REPEATABLE_READ",
"TRANSACTION_SERIALIZABLE"
],
"default": "TRANSACTION_SERIALIZABLE"
}
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions mssql-plugin/widgets/SqlServer-batchsink.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@
"label": "Password",
"name": "password"
},
{
"widget-type": "select",
"label": "Transaction Isolation Level",
"name": "transactionIsolationLevel",
"widget-attributes": {
"values": [
"TRANSACTION_READ_UNCOMMITTED",
"TRANSACTION_READ_COMMITTED",
"TRANSACTION_REPEATABLE_READ",
"TRANSACTION_SERIALIZABLE"
],
"default": "TRANSACTION_SERIALIZABLE"
}
},
{
"widget-type": "keyvalue",
"label": "Connection Arguments",
Expand Down Expand Up @@ -280,6 +294,10 @@
{
"type": "property",
"name": "connectionArguments"
},
{
"type": "property",
"name": "transactionIsolationLevel"
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions mssql-plugin/widgets/SqlServer-batchsource.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@
"label": "Password",
"name": "password"
},
{
"widget-type": "select",
"label": "Transaction Isolation Level",
"name": "transactionIsolationLevel",
"widget-attributes": {
"values": [
"TRANSACTION_READ_UNCOMMITTED",
"TRANSACTION_READ_COMMITTED",
"TRANSACTION_REPEATABLE_READ",
"TRANSACTION_SERIALIZABLE"
],
"default": "TRANSACTION_SERIALIZABLE"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to read commited as the default value as mentioned in the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 38bd277

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritwiksahani @itsankit-google Should we keep the default type as Serializable, which is currently used for all plugins, or should we change it to match the default isolation level supported by the database?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Serializable used for all plugins? I don't think so, correct me if I am wrong but we don't set transaction isolation level for other plugins currently. In that case it would be using the default isolation level of the DB.

We should maintain backward compatibility in terms of behaviour and have the defauilt isolation level match the DB one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, we were setting TRANSACTION_SERIALIZABLE for all plugins except Oracle, ref:

Copy link

@ritwiksahani ritwiksahani Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, agreed then in that case we should keep SERIALIZABLE as default and not change the behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the default value to TRANSACTION_SERIALIZABLE 0881eb7

}
},
{
"widget-type": "keyvalue",
"label": "Connection Arguments",
Expand Down Expand Up @@ -316,6 +330,10 @@
{
"type": "property",
"name": "connectionArguments"
},
{
"type": "property",
"name": "transactionIsolationLevel"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions mysql-plugin/docs/MySQL-connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ authentication. Optional for databases that do not require authentication.

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

**Transaction Isolation Level** The transaction isolation level of the databse connection
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.

For more details on the Transaction Isolation Levels supported in MySQL, refer to the [MySQL documentation](https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html)

**Connection Arguments:** A list of arbitrary string tag/value pairs as connection arguments. These arguments
will be passed to the JDBC driver, as connection arguments, for JDBC drivers that may need additional configurations.
This is a semicolon-separated list of key-value pairs, where each pair is separated by a equals '=' and specifies
Expand Down
8 changes: 8 additions & 0 deletions mysql-plugin/docs/Mysql-batchsink.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ You also can use the macro function ${conn(connection-name)}.

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

**Transaction Isolation Level** The transaction isolation level of the databse connection
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.

For more details on the Transaction Isolation Levels supported in MySQL, refer to the [MySQL documentation](https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html)

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

Expand Down
8 changes: 8 additions & 0 deletions mysql-plugin/docs/Mysql-batchsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ For example, 'SELECT MIN(id),MAX(id) FROM table'. Not required if numSplits is s

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

**Transaction Isolation Level** The transaction isolation level of the database connection
- TRANSACTION_READ_COMMITTED: No dirty reads. Non-repeatable reads and phantom reads are possible.
- TRANSACTION_SERIALIZABLE: No dirty reads. Non-repeatable and phantom reads are prevented.
- TRANSACTION_REPEATABLE_READ: No dirty reads. Prevents non-repeatable reads, but phantom reads are still possible.
- TRANSACTION_READ_UNCOMMITTED: Allows dirty reads (reading uncommitted changes from other transactions). Non-repeatable reads and phantom reads are possible.

For more details on the Transaction Isolation Levels supported in MySQL, refer to the [MySQL documentation](https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public Map<String, String> getDBSpecificArguments() {
trustCertificateKeyStorePassword, false);
}

@Override
public String getTransactionIsolationLevel() {
return connection.getTransactionIsolationLevel();
}

@Override
public MysqlConnectorConfig getConnection() {
return connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public MysqlConnectorConfig getConnection() {
return connection;
}

@Override
public String getTransactionIsolationLevel() {
return connection.getTransactionIsolationLevel();
}

@Override
public void validate(FailureCollector collector) {
ConfigUtil.validateConnection(this, useConnection, connection, collector);
Expand Down
14 changes: 14 additions & 0 deletions mysql-plugin/widgets/MySQL-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@
"widget-attributes": {
"default": "3306"
}
},
{
"widget-type": "select",
"label": "Transaction Isolation Level",
"name": "transactionIsolationLevel",
"widget-attributes": {
"values": [
"TRANSACTION_READ_UNCOMMITTED",
"TRANSACTION_READ_COMMITTED",
"TRANSACTION_REPEATABLE_READ",
"TRANSACTION_SERIALIZABLE"
],
"default": "TRANSACTION_SERIALIZABLE"
}
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions mysql-plugin/widgets/Mysql-batchsink.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
"label": "Password",
"name": "password"
},
{
"widget-type": "select",
"label": "Transaction Isolation Level",
"name": "transactionIsolationLevel",
"widget-attributes": {
"values": [
"TRANSACTION_READ_UNCOMMITTED",
"TRANSACTION_READ_COMMITTED",
"TRANSACTION_REPEATABLE_READ",
"TRANSACTION_SERIALIZABLE"
],
"default": "TRANSACTION_SERIALIZABLE"
}
},
{
"widget-type": "keyvalue",
"label": "Connection Arguments",
Expand Down Expand Up @@ -225,6 +239,10 @@
"type": "property",
"name": "password"
},
{
"type": "property",
"name": "transactionIsolationLevel"
},
{
"type": "property",
"name": "host"
Expand Down
18 changes: 18 additions & 0 deletions mysql-plugin/widgets/Mysql-batchsource.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
"label": "Password",
"name": "password"
},
{
"widget-type": "select",
"label": "Transaction Isolation Level",
"name": "transactionIsolationLevel",
"widget-attributes": {
"values": [
"TRANSACTION_READ_UNCOMMITTED",
"TRANSACTION_READ_COMMITTED",
"TRANSACTION_REPEATABLE_READ",
"TRANSACTION_SERIALIZABLE"
],
"default": "TRANSACTION_SERIALIZABLE"
}
},
{
"widget-type": "keyvalue",
"label": "Connection Arguments",
Expand Down Expand Up @@ -277,6 +291,10 @@
"type": "property",
"name": "password"
},
{
"type": "property",
"name": "transactionIsolationLevel"
},
{
"type": "property",
"name": "host"
Expand Down
Loading
Loading