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 2017/10/12 09:49:36 UTC
svn commit: r1811931 -
/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
Author: reschke
Date: Thu Oct 12 09:49:36 2017
New Revision: 1811931
URL: http://svn.apache.org/viewvc?rev=1811931&view=rev
Log:
OAK-6789: RDB: RevisionGC performance on Oracle
Part 2: change JDBC code to use a batch of single DELETEs.
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java?rev=1811931&r1=1811930&r2=1811931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java Thu Oct 12 09:49:36 2017
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.newHashSet;
+import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS;
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.CHAR2OCTETRATIO;
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.asBytes;
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.closeResultSet;
@@ -52,6 +53,7 @@ import javax.annotation.Nonnull;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition;
import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key;
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition;
@@ -199,40 +201,33 @@ public class RDBDocumentStoreJDBC {
public int delete(Connection connection, RDBTableMetaData tmd, Map<String, Map<Key, Condition>> toDelete)
throws SQLException, DocumentStoreException {
- String or = "";
- StringBuilder whereClause = new StringBuilder();
+ // sanity check on parameters; see OAK-6789
for (Entry<String, Map<Key, Condition>> entry : toDelete.entrySet()) {
- whereClause.append(or);
- or = " or ";
- whereClause.append("ID=?");
if (entry.getValue().entrySet().size() != 1) {
throw new DocumentStoreException("Unsupported number of conditions in : " + entry.getValue().entrySet());
- } else {
- Entry<Key, Condition> c = entry.getValue().entrySet().iterator().next();
- if (!c.getKey().getName().equals(MODIFIED)) {
- throw new DocumentStoreException("Unsupported condition: " + c);
- } else {
- if (c.getValue().type == Condition.Type.EQUALS && c.getValue().value instanceof Long) {
- whereClause.append(" and MODIFIED=?");
- } else {
- throw new DocumentStoreException("Unsupported condition: " + c);
- }
- }
+ }
+ Entry<Key, Condition> c = entry.getValue().entrySet().iterator().next();
+ if (!c.getKey().getName().equals(MODIFIED)) {
+ throw new DocumentStoreException("Unsupported condition: " + c);
}
}
- PreparedStatement stmt = connection.prepareStatement("delete from " + tmd.getName() + " where " + whereClause);
+ PreparedStatement stmt = connection.prepareStatement("delete from " + tmd.getName() + " where ID=? and MODIFIED=?");
+ UpdateOp.Key MODIFIEDKEY = new UpdateOp.Key(MODIFIED_IN_SECS, null);
try {
- int i = 1;
for (Entry<String, Map<Key, Condition>> entry : toDelete.entrySet()) {
- setIdInStatement(tmd, stmt, i++, entry.getKey());
- for (Entry<Key, Condition> c : entry.getValue().entrySet()) {
- if (c.getValue().type == Condition.Type.EQUALS) {
- stmt.setLong(i++, (Long) c.getValue().value);
- }
+ setIdInStatement(tmd, stmt, 1, entry.getKey());
+ stmt.setLong(2, (Long) entry.getValue().get(MODIFIEDKEY).value);
+ stmt.addBatch();
+ }
+ int[] rets = stmt.executeBatch();
+ int updatedRows = 0;
+ for (int ret : rets) {
+ if (ret >= 0) {
+ updatedRows += ret;
}
}
- return stmt.executeUpdate();
+ return updatedRows;
} finally {
stmt.close();
}