Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14054#discussion_r71265164
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
---
@@ -158,25 +159,41 @@ object JdbcUtils extends Logging {
rddSchema: StructType,
nullTypes: Array[Int],
batchSize: Int,
- dialect: JdbcDialect): Iterator[Byte] = {
+ dialect: JdbcDialect,
+ isolationLevel: Int): Iterator[Byte] = {
require(batchSize >= 1,
s"Invalid value `${batchSize.toString}` for parameter " +
s"`${JdbcUtils.JDBC_BATCH_INSERT_SIZE}`. The minimum value is 1.")
val conn = getConnection()
var committed = false
- val supportsTransactions = try {
- conn.getMetaData().supportsDataManipulationTransactionsOnly() ||
-
conn.getMetaData().supportsDataDefinitionAndDataManipulationTransactions()
- } catch {
- case NonFatal(e) =>
- logWarning("Exception while detecting transaction support", e)
- true
+
+ var finalIsolationLevel = Connection.TRANSACTION_NONE
+ if (isolationLevel != Connection.TRANSACTION_NONE) {
+ try {
+ val metadata = conn.getMetaData
+ if (metadata.supportsTransactions()) {
+ if (metadata.supportsTransactionIsolationLevel(isolationLevel))
{
+ finalIsolationLevel = isolationLevel
+ } else {
+ val defaultIsolation = metadata.getDefaultTransactionIsolation
+ logWarning(s"Requested isolation level $isolationLevel is not
supported; " +
+ s"falling back to isolation level $defaultIsolation")
+ finalIsolationLevel = defaultIsolation
+ }
+ } else {
+ logWarning(s"Requested isolation level $isolationLevel, but
transactions are unsupported")
+ }
+ } catch {
+ case NonFatal(e) => logWarning("Exception while detecting
transaction support", e)
+ }
}
+ val supportsTransactions = finalIsolationLevel !=
Connection.TRANSACTION_NONE
--- End diff --
Yeah, if possible, the default isolation needs to be consistent. Otherwise,
it might be hard to debug if users hit the issue in the production environment.
Sometimes, the problem is hard to reproduce it especially for the
isolation-related issues.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]