Author: mreutegg
Date: Thu Jul 23 20:03:46 2015
New Revision: 1692439
URL: http://svn.apache.org/r1692439
Log:
OAK-2857: Run background read and write operation concurrently
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1692439&r1=1692438&r2=1692439&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Thu Jul 23 20:03:46 2015
@@ -272,9 +272,19 @@ public final class DocumentNodeStore
private Thread backgroundReadThread;
+ /**
+ * Monitor object to synchronize background reads.
+ */
+ private final Object backgroundReadMonitor = new Object();
+
private Thread backgroundUpdateThread;
/**
+ * Monitor object to synchronize background writes.
+ */
+ private final Object backgroundWriteMonitor = new Object();
+
+ /**
* Background thread performing the clusterId lease renew.
* Will be {@code null} if {@link #clusterNodeInfo} is {@code null}.
*/
@@ -1638,27 +1648,29 @@ public final class DocumentNodeStore
}
}
- private synchronized void internalRunBackgroundUpdateOperations() {
- long start = clock.getTime();
- long time = start;
- // clean orphaned branches and collisions
- cleanOrphanedBranches();
- cleanCollisions();
- long cleanTime = clock.getTime() - time;
- time = clock.getTime();
- // split documents (does not create new revisions)
- backgroundSplit();
- long splitTime = clock.getTime() - time;
- // write back pending updates to _lastRev
- BackgroundWriteStats stats = backgroundWrite();
- stats.split = splitTime;
- stats.clean = cleanTime;
- String msg = "Background operations stats ({})";
- if (clock.getTime() - start > TimeUnit.SECONDS.toMillis(10)) {
- // log as info if it took more than 10 seconds
- LOG.info(msg, stats);
- } else {
- LOG.debug(msg, stats);
+ private void internalRunBackgroundUpdateOperations() {
+ synchronized (backgroundWriteMonitor) {
+ long start = clock.getTime();
+ long time = start;
+ // clean orphaned branches and collisions
+ cleanOrphanedBranches();
+ cleanCollisions();
+ long cleanTime = clock.getTime() - time;
+ time = clock.getTime();
+ // split documents (does not create new revisions)
+ backgroundSplit();
+ long splitTime = clock.getTime() - time;
+ // write back pending updates to _lastRev
+ BackgroundWriteStats stats = backgroundWrite();
+ stats.split = splitTime;
+ stats.clean = cleanTime;
+ String msg = "Background operations stats ({})";
+ if (clock.getTime() - start > TimeUnit.SECONDS.toMillis(10)) {
+ // log as info if it took more than 10 seconds
+ LOG.info(msg, stats);
+ } else {
+ LOG.debug(msg, stats);
+ }
}
}
@@ -1680,17 +1692,19 @@ public final class DocumentNodeStore
}
/** OAK-2624 : background read operations are split from background update
ops */
- private synchronized void internalRunBackgroundReadOperations() {
- long start = clock.getTime();
- // pull in changes from other cluster nodes
- BackgroundReadStats readStats = backgroundRead(true);
- long readTime = clock.getTime() - start;
- String msg = "Background read operations stats (read:{} {})";
- if (clock.getTime() - start > TimeUnit.SECONDS.toMillis(10)) {
- // log as info if it took more than 10 seconds
- LOG.info(msg, readTime, readStats);
- } else {
- LOG.debug(msg, readTime, readStats);
+ private void internalRunBackgroundReadOperations() {
+ synchronized (backgroundReadMonitor) {
+ long start = clock.getTime();
+ // pull in changes from other cluster nodes
+ BackgroundReadStats readStats = backgroundRead(true);
+ long readTime = clock.getTime() - start;
+ String msg = "Background read operations stats (read:{} {})";
+ if (clock.getTime() - start > TimeUnit.SECONDS.toMillis(10)) {
+ // log as info if it took more than 10 seconds
+ LOG.info(msg, readTime, readStats);
+ } else {
+ LOG.debug(msg, readTime, readStats);
+ }
}
}