This is an automated email from the ASF dual-hosted git repository.

stefanegli pushed a commit to branch DetailedGC/OAK-10199
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/DetailedGC/OAK-10199 by this 
push:
     new 7fc25622ed OAK-10199 : some code cleanups (#1400)
7fc25622ed is described below

commit 7fc25622ed4de119d2e60132017b2fcd267c2d53
Author: stefan-egli <[email protected]>
AuthorDate: Wed Apr 3 14:32:56 2024 +0200

    OAK-10199 : some code cleanups (#1400)
    
    * OAK-10199 : some code cleanups
    
    * OAK-10199 : some code cleanups
---
 .../plugins/document/VersionGarbageCollector.java  | 33 +++++++--------
 .../oak/plugins/document/rdb/RDBDocumentStore.java | 48 +++++++++++-----------
 .../plugins/document/rdb/RDBDocumentStoreJDBC.java | 12 +++---
 3 files changed, 44 insertions(+), 49 deletions(-)

diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
index b0fccc6baf..42341f1cf0 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
@@ -732,8 +732,6 @@ public class VersionGarbageCollector {
          * includes: deleted properties, revision information within 
documents, branch
          * commit related garbage.
          * <p>
-         * TODO: limit this to run only on a singleton instance, eg the 
cluster leader
-         * <p>
          * The "detailed garbage" collector can be instructed to do a full 
repository scan
          * - or incrementally based on where it last left off. When doing a 
full
          * repository scan (but not limited to that), it executes in (small) 
batches
@@ -924,7 +922,6 @@ public class VersionGarbageCollector {
 
     private class DetailedGC implements Closeable {
 
-        private final RevisionVector headRevision;
         private final long toModifiedMs;
         private final GCMonitor monitor;
         private final AtomicBoolean cancel;
@@ -971,11 +968,9 @@ public class VersionGarbageCollector {
         private int garbageDocsCount;
         private int totalGarbageDocsCount;
         private final Revision revisionForModified;
-        private final Revision ownHeadRevision;
         private final DocumentNodeState root;
 
         public DetailedGC(@NotNull RevisionVector headRevision, long 
toModifiedMs, @NotNull GCMonitor monitor, @NotNull AtomicBoolean cancel) {
-            this.headRevision = requireNonNull(headRevision);
             this.toModifiedMs = toModifiedMs;
             this.monitor = monitor;
             this.cancel = cancel;
@@ -990,7 +985,6 @@ public class VersionGarbageCollector {
             this.timer = createUnstarted();
             // clusterId is not used
             this.revisionForModified = Revision.newRevision(0);
-            this.ownHeadRevision = 
headRevision.getRevision(nodeStore.getClusterId());
             this.root = nodeStore.getRoot(headRevision);
         }
 
@@ -1847,23 +1841,24 @@ public class VersionGarbageCollector {
         GCPhases phases = new GCPhases(cancel, stats, gcMonitor);
 
         final RevisionVector headRevision = store.getHeadRevision();
-        DetailedGC gc = new DetailedGC(headRevision, 0, gcMonitor, cancel);
+        try (DetailedGC gc = new DetailedGC(headRevision, 0, gcMonitor, 
cancel)) {
 
-        if (phases.start(GCPhase.DETAILED_GC_COLLECT_GARBAGE)) {
-            gc.collectGarbage(doc, phases);
-            phases.stop(GCPhase.DETAILED_GC_COLLECT_GARBAGE);
-        }
+            if (phases.start(GCPhase.DETAILED_GC_COLLECT_GARBAGE)) {
+                gc.collectGarbage(doc, phases);
+                phases.stop(GCPhase.DETAILED_GC_COLLECT_GARBAGE);
+            }
 
-        if (verbose) {
-            gcMonitor.info("GarbageCollector will run [{}] operations", 
gc.updateOpList.size());
-            for (UpdateOp update : gc.updateOpList) {
-                gcMonitor.info(update.toString());
+            if (verbose) {
+                gcMonitor.info("GarbageCollector will run [{}] operations", 
gc.updateOpList.size());
+                for (UpdateOp update : gc.updateOpList) {
+                    gcMonitor.info(update.toString());
+                }
             }
-        }
 
-        if (gc.hasGarbage() && phases.start(GCPhase.DETAILED_GC_CLEANUP)) {
-            gc.removeGarbage(phases.stats);
-            phases.stop(GCPhase.DETAILED_GC_CLEANUP);
+            if (gc.hasGarbage() && phases.start(GCPhase.DETAILED_GC_CLEANUP)) {
+                gc.removeGarbage(phases.stats);
+                phases.stop(GCPhase.DETAILED_GC_CLEANUP);
+            }
         }
     }
 
diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
index 24137fb480..82c09e213d 100755
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
@@ -99,7 +99,7 @@ import org.apache.jackrabbit.guava.common.collect.Sets;
 
 /**
  * Implementation of {@link DocumentStore} for relational databases.
- *
+ * 
  * <h3 id="apidocs.supported-databases">Supported Databases</h3>
  * <p>
  * The code is supposed to be sufficiently generic to run with a variety of
@@ -115,7 +115,7 @@ import org.apache.jackrabbit.guava.common.collect.Sets;
  * <li>Microsoft SQL Server</li>
  * <li>Oracle</li>
  * </ul>
- *
+ * 
  * <h3 id="apidocs.table-layout">Table Layout</h3>
  * <p>
  * Data for each of the DocumentStore's {@link Collection}s is stored in its 
own
@@ -237,11 +237,11 @@ import org.apache.jackrabbit.guava.common.collect.Sets;
  * create them "manually". The oak-run "<a 
href="https://jackrabbit.apache.org/oak/docs/nodestore/document/rdb-document-store.html#rdbddldump";><code>rdbddldump</code></a>"
  * command can be used to print out the DDL statements that would have been 
used for auto-creation
  * and/or automatic schema updates.
- *
+ * 
  * <h3>Caching</h3>
  * <p>
  * The cache borrows heavily from the {@link MongoDocumentStore} 
implementation.
- *
+ * 
  * <h3>Queries</h3>
  * <p>
  * The implementation currently supports only three indexed properties: "_bin",
@@ -290,7 +290,7 @@ public class RDBDocumentStore implements DocumentStore {
     @NotNull
     @Override
     public <T extends Document> List<T> query(Collection<T> collection, String 
fromKey, String toKey, String indexedProperty,
-                                              long startValue, int limit) {
+            long startValue, int limit) {
         List<QueryCondition> conditions = Collections.emptyList();
         if (indexedProperty != null) {
             conditions = Collections.singletonList(new 
QueryCondition(indexedProperty, ">=", startValue));
@@ -300,7 +300,7 @@ public class RDBDocumentStore implements DocumentStore {
 
     @NotNull
     protected <T extends Document> List<T> query(Collection<T> collection, 
String fromKey, String toKey,
-                                                 List<String> 
excludeKeyPatterns, List<QueryCondition> conditions, int limit) {
+            List<String> excludeKeyPatterns, List<QueryCondition> conditions, 
int limit) {
         return internalQuery(collection, fromKey, toKey, excludeKeyPatterns, 
conditions, limit);
     }
 
@@ -1269,7 +1269,7 @@ public class RDBDocumentStore implements DocumentStore {
         }
         return result;
     }
-
+    
     private static class IndexInformation {
         public Map<Integer, String> fields;
         public boolean nonunique;
@@ -1282,7 +1282,7 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     private void createTableFor(Connection con, Collection<? extends Document> 
col, RDBTableMetaData tmd, List<String> tablesCreated,
-                                List<String> tablesPresent, int initialSchema, 
int upgradeToSchema) throws SQLException {
+            List<String> tablesPresent, int initialSchema, int 
upgradeToSchema) throws SQLException {
 
         String dbname = this.dbInfo.toString();
         if (con.getMetaData().getURL() != null) {
@@ -1473,7 +1473,7 @@ public class RDBDocumentStore implements DocumentStore {
 
         return wasChanged;
     }
-
+    
     private static void getTableMetaData(Connection con, Collection<? extends 
Document> col, RDBTableMetaData tmd) throws SQLException {
         Statement checkStatement = null;
         ResultSet checkResultSet = null;
@@ -1612,7 +1612,7 @@ public class RDBDocumentStore implements DocumentStore {
 
     @Nullable
     private <T extends Document> T internalCreateOrUpdate(Collection<T> 
collection, UpdateOp update, boolean allowCreate,
-                                                          boolean 
checkConditions, int retries) {
+            boolean checkConditions, int retries) {
         T oldDoc = readDocumentCached(collection, update.getId(), 
Integer.MAX_VALUE);
 
         if (oldDoc == null) {
@@ -1655,9 +1655,9 @@ public class RDBDocumentStore implements DocumentStore {
                     result = internalCreateOrUpdate(collection, update, 
allowCreate, checkConditions, retries - 1);
                 }
                 else {
-                    LOG.error("update of " + update.getId() + " failed, race 
condition?");
-                    throw new DocumentStoreException("update of " + 
update.getId() + " failed, race condition?", null,
-                            DocumentStoreException.Type.TRANSIENT);
+                  LOG.error("update of " + update.getId() + " failed, race 
condition?");
+                  throw new DocumentStoreException("update of " + 
update.getId() + " failed, race condition?", null,
+                          DocumentStoreException.Type.TRANSIENT);
                 }
             }
             return result;
@@ -1669,7 +1669,7 @@ public class RDBDocumentStore implements DocumentStore {
      */
     @Nullable
     private <T extends Document> T internalUpdate(Collection<T> collection, 
UpdateOp update, T oldDoc, boolean checkConditions,
-                                                  int maxRetries) {
+            int maxRetries) {
         if (checkConditions && !UpdateUtils.checkConditions(oldDoc, 
update.getConditions())) {
             return null;
         } else {
@@ -1756,7 +1756,7 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     private <T extends Document> List<T> internalQuery(Collection<T> 
collection, String fromKey, String toKey,
-                                                       List<String> 
excludeKeyPatterns, List<QueryCondition> conditions, int limit) {
+            List<String> excludeKeyPatterns, List<QueryCondition> conditions, 
int limit) {
         Connection connection = null;
         RDBTableMetaData tmd = getTable(collection);
         for (QueryCondition cond : conditions) {
@@ -1840,7 +1840,7 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     protected <T extends Document> Iterable<T> queryAsIterable(final 
Collection<T> collection, String fromKey, String toKey,
-                                                               final 
List<String> excludeKeyPatterns, final List<QueryCondition> conditions, final 
int limit, final String sortBy) {
+            final List<String> excludeKeyPatterns, final List<QueryCondition> 
conditions, final int limit, final String sortBy) {
 
         final RDBTableMetaData tmd = getTable(collection);
         Set<String> allowedProps = Sets.intersection(INDEXEDPROPERTIES, 
tmd.getColumnProperties());
@@ -1890,19 +1890,19 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     protected <T extends Document> long queryCount(final Collection<T> 
collection, String fromKey, String toKey,
-                                                   final List<String> 
excludeKeyPatterns, final List<QueryCondition> conditions) {
+            final List<String> excludeKeyPatterns, final List<QueryCondition> 
conditions) {
 
         return internalGetAggregate(collection, "COUNT", "*", fromKey, toKey, 
excludeKeyPatterns, conditions);
     }
 
     protected <T extends Document> long getMinValue(final Collection<T> 
collection, String field, String fromKey, String toKey,
-                                                    final List<String> 
excludeKeyPatterns, final List<QueryCondition> conditions) {
+            final List<String> excludeKeyPatterns, final List<QueryCondition> 
conditions) {
 
         return internalGetAggregate(collection, "MIN", field, fromKey, toKey, 
excludeKeyPatterns, conditions);
     }
 
     private <T extends Document> long internalGetAggregate(final Collection<T> 
collection, final String aggregrate, String field,
-                                                           String fromKey, 
String toKey, final List<String> excludeKeyPatterns, final List<QueryCondition> 
conditions) {
+            String fromKey, String toKey, final List<String> 
excludeKeyPatterns, final List<QueryCondition> conditions) {
 
         final RDBTableMetaData tmd = getTable(collection);
         for (QueryCondition cond : conditions) {
@@ -2065,7 +2065,7 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     private <T extends Document> boolean updateDocument(@NotNull Collection<T> 
collection, @NotNull T document,
-                                                        @NotNull UpdateOp 
update, Long oldmodcount) {
+            @NotNull UpdateOp update, Long oldmodcount) {
         Connection connection = null;
         RDBTableMetaData tmd = getTable(collection);
         String data = null;
@@ -2129,7 +2129,7 @@ public class RDBDocumentStore implements DocumentStore {
     private static void continueIfStringOverflow(SQLException ex) throws 
SQLException {
         String state = ex.getSQLState();
         if ("22001".equals(state) /* everybody */|| ("72000".equals(state) && 
1489 == ex.getErrorCode()) /* Oracle */
-                || ("S0001".equals(state) && 2628 == ex.getErrorCode()) /* 
MSSQL update*/) {
+                       || ("S0001".equals(state) && 2628 == ex.getErrorCode()) 
/* MSSQL update*/) {
             // ok
         } else {
             throw (ex);
@@ -2395,7 +2395,7 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     private <T extends Document> DocumentStoreException handleException(String 
message, Exception ex, Collection<T> collection,
-                                                                        
java.util.Collection<String> ids) {
+            java.util.Collection<String> ids) {
         if (collection == Collection.NODES) {
             for (String id : ids) {
                 invalidateCache(collection, id, false);
@@ -2405,7 +2405,7 @@ public class RDBDocumentStore implements DocumentStore {
     }
 
     private <T extends Document> DocumentStoreException handleException(String 
message, Exception ex, Collection<T> collection,
-                                                                        String 
id) {
+            String id) {
         return handleException(message, ex, collection, 
Collections.singleton(id));
     }
 
@@ -2483,4 +2483,4 @@ public class RDBDocumentStore implements DocumentStore {
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
index 3ca7601de6..5caa65d875 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
@@ -86,7 +86,7 @@ public class RDBDocumentStoreJDBC {
     private final int queryHitsLimit, queryTimeLimit;
 
     private static final Long INITIALMODCOUNT = Long.valueOf(1);
-
+    
     public RDBDocumentStoreJDBC(RDBDocumentStoreDB dbInfo, 
RDBDocumentSerializer ser, int queryHitsLimit, int queryTimeLimit) {
         this.dbInfo = dbInfo;
         this.ser = ser;
@@ -554,7 +554,7 @@ public class RDBDocumentStoreJDBC {
 
     @NotNull
     public Iterator<RDBRow> queryAsIterator(RDBConnectionHandler ch, 
RDBTableMetaData tmd, String minId, String maxId,
-                                            List<String> excludeKeyPatterns, 
List<QueryCondition> conditions, int limit, String sortBy) throws SQLException {
+            List<String> excludeKeyPatterns, List<QueryCondition> conditions, 
int limit, String sortBy) throws SQLException {
         return new ResultSetIterator(ch, tmd, minId, maxId, 
excludeKeyPatterns, conditions, limit, sortBy);
     }
 
@@ -573,7 +573,7 @@ public class RDBDocumentStoreJDBC {
         private long pstart;
 
         public ResultSetIterator(RDBConnectionHandler ch, RDBTableMetaData 
tmd, String minId, String maxId,
-                                 List<String> excludeKeyPatterns, 
List<QueryCondition> conditions, int limit, String sortBy) throws SQLException {
+                List<String> excludeKeyPatterns, List<QueryCondition> 
conditions, int limit, String sortBy) throws SQLException {
             long start = System.currentTimeMillis();
             try {
                 this.ch = ch;
@@ -695,7 +695,7 @@ public class RDBDocumentStoreJDBC {
 
     @NotNull
     private PreparedStatement prepareQuery(Connection connection, 
RDBTableMetaData tmd, String columns, String minId, String maxId,
-                                           List<String> excludeKeyPatterns, 
List<QueryCondition> conditions, int limit, String sortBy) throws SQLException {
+            List<String> excludeKeyPatterns, List<QueryCondition> conditions, 
int limit, String sortBy) throws SQLException {
 
         StringBuilder selectClause = new StringBuilder();
 
@@ -912,7 +912,7 @@ public class RDBDocumentStoreJDBC {
     }
 
     public boolean update(Connection connection, RDBTableMetaData tmd, String 
id, Long modified, Number hasBinary,
-                          Boolean deletedOnce, Long modcount, Long cmodcount, 
Long oldmodcount, String data) throws SQLException {
+            Boolean deletedOnce, Long modcount, Long cmodcount, Long 
oldmodcount, String data) throws SQLException {
 
         StringBuilder t = new StringBuilder();
         t.append("update " + tmd.getName() + " set ");
@@ -1134,4 +1134,4 @@ public class RDBDocumentStoreJDBC {
             return input.getId();
         }
     };
-}
\ No newline at end of file
+}

Reply via email to