Author: reschke
Date: Thu May 24 04:43:43 2018
New Revision: 1832136
URL: http://svn.apache.org/viewvc?rev=1832136&view=rev
Log:
OAK-7181: RDBDocumentStore: use try-with-resources for ChangesTracker (ported
to 1.8)
Modified:
jackrabbit/oak/branches/1.8/ (props changed)
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Propchange: jackrabbit/oak/branches/1.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 24 04:43:43 2018
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821665,1821668,1821681,1822121,1822201,1822207,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1824196,1824198,1824962,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826237,1826338,1826516,1826532,1826640,1826932,1826957,1827472,1827486,1827977,1829569,1829987,1830019,1830160,1830748,1831374
+/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1822121,1822201,1822207,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1824196,1824198,1824962,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826237,1826338,1826516,1826532,1826640,1826932,1826957,1827472,1827486,1827977,1829569,1829987,1830019,1830160,1830748,1831374
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1832136&r1=1832135&r2=1832136&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Thu May 24 04:43:43 2018
@@ -486,6 +486,24 @@ public class RDBDocumentStore implements
return result;
}
+ @CheckForNull
+ private <T extends Document> CacheChangesTracker
obtainTracker(Collection<T> collection, Set<String> keys) {
+ if (collection == Collection.NODES) {
+ return this.nodesCache.registerTracker(keys);
+ } else {
+ return null;
+ }
+ }
+
+ @CheckForNull
+ private <T extends Document> CacheChangesTracker
obtainTracker(Collection<T> collection, String fromKey, String toKey) {
+ if (collection == Collection.NODES) {
+ return this.nodesCache.registerTracker(fromKey, toKey);
+ } else {
+ return null;
+ }
+ }
+
private <T extends Document> Map<UpdateOp, T> bulkUpdate(Collection<T>
collection, List<UpdateOp> updates, Map<String, T> oldDocs, boolean upsert) {
Set<String> missingDocs = new HashSet<String>();
for (UpdateOp op : updates) {
@@ -495,12 +513,7 @@ public class RDBDocumentStore implements
}
oldDocs.putAll(readDocumentsUncached(collection, missingDocs));
- CacheChangesTracker tracker = null;
- if (collection == Collection.NODES) {
- tracker = nodesCache.registerTracker(Sets.union(oldDocs.keySet(),
missingDocs));
- }
-
- try {
+ try (CacheChangesTracker tracker = obtainTracker(collection,
Sets.union(oldDocs.keySet(), missingDocs) )) {
List<T> docsToUpdate = new ArrayList<T>(updates.size());
Set<String> keysToUpdate = new HashSet<String>();
for (UpdateOp update : updates) {
@@ -547,10 +560,6 @@ public class RDBDocumentStore implements
} finally {
this.ch.closeConnection(connection);
}
- } finally {
- if (tracker != null) {
- tracker.close();
- }
}
}
@@ -1601,11 +1610,8 @@ public class RDBDocumentStore implements
final Stopwatch watch = startWatch();
int resultSize = 0;
- CacheChangesTracker tracker = null;
- try {
- if (collection == Collection.NODES) {
- tracker = nodesCache.registerTracker(fromKey, toKey);
- }
+
+ try (CacheChangesTracker tracker = obtainTracker(collection, fromKey,
toKey)) {
long now = System.currentTimeMillis();
connection = this.ch.getROConnection();
String from = collection == Collection.NODES &&
NodeDocument.MIN_ID_VALUE.equals(fromKey) ? null : fromKey;
@@ -1664,9 +1670,6 @@ public class RDBDocumentStore implements
LOG.error("SQL exception on query", ex);
throw new DocumentStoreException(ex);
} finally {
- if (tracker != null) {
- tracker.close();
- }
this.ch.closeConnection(connection);
stats.doneQuery(watch.elapsed(TimeUnit.NANOSECONDS), collection,
fromKey, toKey,
!conditions.isEmpty(), resultSize, -1, false);