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 st...@apache.org on 2024/04/03 12:27:45 UTC

(jackrabbit-oak) branch OAK-10199-cleanups1 created (now a552f74587)

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

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


      at a552f74587 OAK-10199 : some code cleanups

This branch includes the following new commits:

     new a552f74587 OAK-10199 : some code cleanups

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(jackrabbit-oak) 01/01: OAK-10199 : some code cleanups

Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a552f74587c313fce056752de2a05f36647bf83e
Author: Stefan Egli <st...@apache.org>
AuthorDate: Wed Apr 3 14:27:30 2024 +0200

    OAK-10199 : some code cleanups
---
 .../plugins/document/VersionGarbageCollector.java  | 33 +++++++--------
 .../oak/plugins/document/rdb/RDBDocumentStore.java | 48 +++++++++++-----------
 2 files changed, 38 insertions(+), 43 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
+}