You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2015/06/22 15:07:56 UTC
svn commit: r1686859 - in /jackrabbit/oak/branches/1.2: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Author: reschke
Date: Mon Jun 22 13:07:55 2015
New Revision: 1686859
URL: http://svn.apache.org/r1686859
Log:
OAK-3010: dynamically check binary-ness of IF column using JDBC metadata, improve diagnostics (ported to 1.2)
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun 22 13:07:55 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679958,1679961,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684868,1685023,1685370,1685552,1685589,1685840,1685999,1686097,1686229,1686234,1686253,1686414,1686780
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679958,1679961,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684868,1685023,1685370,1685552,1685589,1685840,1685999,1686097,1686229,1686234,1686253,1686414,1686780,1686854
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1686859&r1=1686858&r2=1686859&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Mon Jun 22 13:07:55 2015
@@ -561,12 +561,6 @@ public class RDBDocumentStore implements
}
@Override
- public boolean isPrimaryColumnByteEncoded() {
- // TODO: we should dynamically detect this
- return true;
- }
-
- @Override
public String getTableCreationStatement(String tableName) {
// see https://issues.apache.org/jira/browse/OAK-1913
return ("create table " + tableName + " (ID varbinary(512) not null primary key, MODIFIED bigint, HASBINARY smallint, DELETEDONCE smallint, MODCOUNT bigint, CMODCOUNT bigint, DSIZE bigint, DATA varchar(16000), BDATA longblob)");
@@ -616,12 +610,6 @@ public class RDBDocumentStore implements
}
@Override
- public boolean isPrimaryColumnByteEncoded() {
- // TODO: we should dynamically detect this
- return true;
- }
-
- @Override
public String getTableCreationStatement(String tableName) {
// see https://issues.apache.org/jira/browse/OAK-2395
return ("create table " + tableName + " (ID varbinary(512) not null primary key, MODIFIED bigint, HASBINARY smallint, DELETEDONCE smallint, MODCOUNT bigint, CMODCOUNT bigint, DSIZE bigint, DATA nvarchar(4000), BDATA varbinary(max))");
@@ -679,15 +667,6 @@ public class RDBDocumentStore implements
}
/**
- * If the primary column is encoded in bytes.
- * Default false
- * @return boolean
- */
- public boolean isPrimaryColumnByteEncoded() {
- return false;
- }
-
- /**
* Allows case in select. Default true.
*/
public boolean allowsCaseInSelect() {
@@ -815,6 +794,9 @@ public class RDBDocumentStore implements
// capacity of DATA column
private int dataLimitInOctets = 16384;
+ // whether the ID column is a binary type
+ private boolean isIdBinary = false;
+
// number of retries for updates
private static final int RETRIES = 10;
@@ -891,10 +873,11 @@ public class RDBDocumentStore implements
List<String> tablesCreated = new ArrayList<String>();
List<String> tablesPresent = new ArrayList<String>();
+ StringBuilder tableDiags = new StringBuilder();
try {
- createTableFor(con, Collection.CLUSTER_NODES, tablesCreated, tablesPresent);
- createTableFor(con, Collection.NODES, tablesCreated, tablesPresent);
- createTableFor(con, Collection.SETTINGS, tablesCreated, tablesPresent);
+ createTableFor(con, Collection.CLUSTER_NODES, tablesCreated, tablesPresent, tableDiags);
+ createTableFor(con, Collection.NODES, tablesCreated, tablesPresent, tableDiags);
+ createTableFor(con, Collection.SETTINGS, tablesCreated, tablesPresent, tableDiags);
} finally {
con.commit();
con.close();
@@ -904,11 +887,15 @@ public class RDBDocumentStore implements
tablesToBeDropped.addAll(tablesCreated);
}
+ if (tableDiags.length() != 0) {
+ tableDiags.insert(0, ", ");
+ }
+
String diag = db.getAdditionalDiagnostics(this.ch, this.tnNodes);
LOG.info("RDBDocumentStore instantiated for database " + dbDesc + ", using driver: " + driverDesc + ", connecting to: "
+ dbUrl + (diag.isEmpty() ? "" : (", properties: " + diag)) + ", transaction isolation level: " + isolationDiags
- + ", detected size of DATA column: " + this.dataLimitInOctets);
+ + tableDiags);
if (!tablesPresent.isEmpty()) {
LOG.info("Tables present upon startup: " + tablesPresent);
}
@@ -918,7 +905,18 @@ public class RDBDocumentStore implements
}
}
- private void createTableFor(Connection con, Collection<? extends Document> col, List<String> tablesCreated, List<String> tablesPresent) throws SQLException {
+ private static boolean isBinaryType(int sqlType) {
+ return sqlType == Types.VARBINARY || sqlType == Types.BINARY || sqlType == Types.LONGVARBINARY;
+ }
+
+ private static String dumpTableMeta(int idType, String idTypeName, int idPrecision, int dataType, String dataTypeName,
+ int dataPrecision) {
+ return String.format("type of ID: %d (%s) precision %d (-> %s), type of DATA: %d (%s) precision %d", idType, idTypeName,
+ idPrecision, isBinaryType(idType) ? "binary" : "character", dataType, dataTypeName, dataPrecision);
+ }
+
+ private void createTableFor(Connection con, Collection<? extends Document> col, List<String> tablesCreated,
+ List<String> tablesPresent, StringBuilder diagnostics) throws SQLException {
String dbname = this.db.toString();
if (con.getMetaData().getURL() != null) {
dbname += " (" + con.getMetaData().getURL() + ")";
@@ -929,14 +927,17 @@ public class RDBDocumentStore implements
ResultSet checkResultSet = null;
Statement creatStatement = null;
try {
- checkStatement = con.prepareStatement("select DATA from " + tableName + " where ID = ?");
+ checkStatement = con.prepareStatement("select ID, DATA from " + tableName + " where ID = ?");
checkStatement.setString(1, "0:/");
checkResultSet = checkStatement.executeQuery();
if (col.equals(Collection.NODES)) {
// try to discover size of DATA column
ResultSetMetaData met = checkResultSet.getMetaData();
- this.dataLimitInOctets = met.getPrecision(1);
+ this.isIdBinary = isBinaryType(met.getColumnType(1));
+ this.dataLimitInOctets = met.getPrecision(2);
+ diagnostics.append(dumpTableMeta(met.getColumnType(1), met.getColumnTypeName(1), met.getPrecision(1),
+ met.getColumnType(2), met.getColumnTypeName(2), met.getPrecision(2)));
}
tablesPresent.add(tableName);
} catch (SQLException ex) {
@@ -959,11 +960,14 @@ public class RDBDocumentStore implements
tablesCreated.add(tableName);
if (col.equals(Collection.NODES)) {
- PreparedStatement pstmt = con.prepareStatement("select DATA from " + tableName + " where ID = ?");
+ PreparedStatement pstmt = con.prepareStatement("select ID, DATA from " + tableName + " where ID = ?");
pstmt.setString(1, "0:/");
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData met = rs.getMetaData();
- this.dataLimitInOctets = met.getPrecision(1);
+ this.isIdBinary = isBinaryType(met.getColumnType(1));
+ this.dataLimitInOctets = met.getPrecision(2);
+ diagnostics.append(dumpTableMeta(met.getColumnType(1), met.getColumnTypeName(1), met.getPrecision(1),
+ met.getColumnType(2), met.getColumnTypeName(2), met.getPrecision(2)));
}
}
catch (SQLException ex2) {
@@ -1548,7 +1552,7 @@ public class RDBDocumentStore implements
}
private void setIdInStatement(PreparedStatement stmt, int idx, String id) throws SQLException {
- if (db.isPrimaryColumnByteEncoded()) {
+ if (this.isIdBinary) {
try {
stmt.setBytes(idx, id.getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
@@ -1561,19 +1565,16 @@ public class RDBDocumentStore implements
}
private String getIdFromRS(ResultSet rs, int idx) throws SQLException {
- String id;
- if (db.isPrimaryColumnByteEncoded()) {
+ if (this.isIdBinary) {
try {
- id = new String(rs.getBytes(idx), "UTF-8");
-
+ return new String(rs.getBytes(idx), "UTF-8");
} catch (UnsupportedEncodingException ex) {
LOG.error("UTF-8 not supported??", ex);
throw new DocumentStoreException(ex);
}
} else {
- id = rs.getString(idx);
+ return rs.getString(idx);
}
- return id;
}
@CheckForNull