Repository: sentry Updated Branches: refs/heads/master 99aea6fcc -> 1a238c0ec
SENTRY-1534: Oracle supports serializable instead of repeatable-read (Alexander Kolbasov, Reviewed by: Hao Hao) Change-Id: I2309be2b8f081d0d87e6caa6993cec81faead1b4 Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/1a238c0e Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/1a238c0e Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/1a238c0e Branch: refs/heads/master Commit: 1a238c0ecf1788a7bda93ae99b7744dac67f5c43 Parents: 99aea6f Author: hahao <[email protected]> Authored: Mon Jan 9 15:07:00 2017 -0800 Committer: hahao <[email protected]> Committed: Mon Jan 9 15:07:00 2017 -0800 ---------------------------------------------------------------------- .../sentry/service/thrift/ServiceConstants.java | 5 +++- .../db/service/persistent/SentryStore.java | 26 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/1a238c0e/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java ---------------------------------------------------------------------- diff --git a/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java b/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java index 919fdaf..f9fb0f3 100644 --- a/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java +++ b/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java @@ -100,6 +100,9 @@ public class ServiceConstants { public static final String JAVAX_JDO_PASS = "javax.jdo.option.ConnectionPassword"; public static final String JAVAX_JDO_DRIVER_NAME = "javax.jdo.option.ConnectionDriverName"; + public static final String DATANUCLEUS_ISOLATION_LEVEL = "datanucleus.transactionIsolation"; + public static final String DATANUCLEUS_REPEATABLE_READ = "repeatable-read"; + public static final String SENTRY_DB_PROPERTY_PREFIX = "sentry."; public static final String SENTRY_JAVAX_JDO_PROPERTY_PREFIX = SENTRY_DB_PROPERTY_PREFIX + "javax.jdo"; public static final String SENTRY_DATANUCLEUS_PROPERTY_PREFIX = SENTRY_DB_PROPERTY_PREFIX + "datanucleus"; @@ -147,7 +150,7 @@ public class ServiceConstants { .put("datanucleus.autoCreateSchema", "false") .put("datanucleus.fixedDatastore", "true") .put("datanucleus.autoStartMechanismMode", "checked") - .put("datanucleus.transactionIsolation", "repeatable-read") + .put(DATANUCLEUS_ISOLATION_LEVEL, DATANUCLEUS_REPEATABLE_READ) .put("datanucleus.cache.level2", "false") .put("datanucleus.cache.level2.type", "none") .put("datanucleus.identifierFactory", "datanucleus1") http://git-wip-us.apache.org/repos/asf/sentry/blob/1a238c0e/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java ---------------------------------------------------------------------- diff --git a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java index f83d721..0a4b3e1 100644 --- a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java +++ b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java @@ -62,6 +62,7 @@ import org.apache.sentry.provider.db.service.thrift.TSentryMappingData; import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege; import org.apache.sentry.provider.db.service.thrift.TSentryPrivilegeMap; import org.apache.sentry.provider.db.service.thrift.TSentryRole; +import org.apache.sentry.service.thrift.ServiceConstants; import org.apache.sentry.service.thrift.ServiceConstants.PrivilegeScope; import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig; import org.datanucleus.store.rdbms.exceptions.MissingTableException; @@ -148,6 +149,31 @@ public class SentryStore { prop.setProperty(ServerConfig.JAVAX_JDO_USER, user); prop.setProperty(ServerConfig.JAVAX_JDO_PASS, pass); prop.setProperty(ServerConfig.JAVAX_JDO_DRIVER_NAME, driverName); + + /* + * Oracle doesn't support "repeatable-read" isolation level, so we use + * "serializable" instead. This should be handled by Datanucleus, but it + * incorrectly states that "repeatable-read" is supported and Oracle barks + * at run-time. This code is a hack, but until it is fixed in Datanucleus + * we can't do much. + * + * JDBC URL always looks like jdbc:oracle:<drivertype>:@<database> + * we look at the second component. + * + * The isolation property can be overwritten via configuration property. + */ + final String oracleDb = "oracle"; + if (prop.getProperty(ServerConfig.DATANUCLEUS_ISOLATION_LEVEL, ""). + equals(ServerConfig.DATANUCLEUS_REPEATABLE_READ) && + jdbcUrl.contains(oracleDb)) { + String parts[] = jdbcUrl.split(":"); + if (parts.length > 1 && parts[1].equals(oracleDb)) { + // For Oracle JDBC driver, replace "repeatable-read" with "serializable" + prop.setProperty(ServerConfig.DATANUCLEUS_ISOLATION_LEVEL, + "serializable"); + } + } + for (Map.Entry<String, String> entry : conf) { String key = entry.getKey(); if (key.startsWith(ServerConfig.SENTRY_JAVAX_JDO_PROPERTY_PREFIX) ||
