Author: mduerig
Date: Thu Oct 6 09:03:37 2016
New Revision: 1763534
URL: http://svn.apache.org/viewvc?rev=1763534&view=rev
Log:
OAK-4621: External invocation of background operations
Replace flush and space check with scheduler
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java?rev=1763534&r1=1763533&r2=1763534&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Thu Oct 6 09:03:37 2016
@@ -179,23 +179,14 @@ public class FileStore implements Segmen
private final TarRevisions revisions;
/**
- * The background flush thread. Automatically flushes the TarMK state
- * once every five seconds.
- */
- private final PeriodicOperation flushOperation;
-
- /**
* Scheduler for running compaction and cleanup in the background
*/
private final Scheduler gcScheduler = new Scheduler("GC Scheduler");
/**
- * This background thread periodically asks the {@code SegmentGCOptions}
- * to compare the approximate size of the repository with the available
disk
- * space. The result of this comparison is stored in the state of this
- * {@code FileStore}.
+ * Scheduler for running <em>short</em> background operations
*/
- private final PeriodicOperation diskSpaceOperation;
+ private final Scheduler fileStoreScheduler = new Scheduler("FileStore
background tasks");
private final SegmentGCOptions gcOptions;
@@ -340,35 +331,30 @@ public class FileStore implements Segmen
// FileStore might have better insights on when and how these
background
// operations should be invoked. See also OAK-3468.
- flushOperation = new PeriodicOperation(format("TarMK flush thread
[%s]", directory), 5, SECONDS, new Runnable() {
+ sufficientDiskSpace = new AtomicBoolean(true);
- @Override
- public void run() {
- try {
- flush();
- } catch (IOException e) {
- log.warn("Failed to flush the TarMK at {}", directory, e);
+ if (!readOnly) {
+ fileStoreScheduler.scheduleAtFixedRate(
+ format("TarMK flush [%s]", directory), 5, SECONDS, new
Runnable() {;
+ @Override
+ public void run() {
+ try {
+ flush();
+ } catch (IOException e) {
+ log.warn("Failed to flush the TarMK at {}", directory,
e);
+ }
}
- }
-
- });
-
- diskSpaceOperation = new PeriodicOperation(format("TarMK disk space
check [%s]", directory), 1, MINUTES, new Runnable() {
-
- @Override
- public void run() {
- checkDiskSpace();
- }
-
- });
- if (!readOnly) {
- flushOperation.start();
- diskSpaceOperation.start();
+ });
+ fileStoreScheduler.scheduleAtFixedRate(
+ format("TarMK disk space check [%s]", directory), 1,
MINUTES, new Runnable() {
+ @Override
+ public void run() {
+ checkDiskSpace();
+ }
+ });
}
- sufficientDiskSpace = new AtomicBoolean(true);
-
if (readOnly) {
log.info("TarMK ReadOnly opened: {} (mmap={})", directory,
memoryMapping);
@@ -1171,30 +1157,10 @@ public class FileStore implements Segmen
// Flag the store as shutting / shut down
shutdown = true;
- gcScheduler.close();
-
// avoid deadlocks by closing (and joining) the background
// threads before acquiring the synchronization lock
-
- try {
- if (flushOperation.stop(5, SECONDS)) {
- log.debug("The flush background thread was successfully shut
down");
- } else {
- log.warn("The flush background thread takes too long to
shutdown");
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
-
- try {
- if (diskSpaceOperation.stop(5, SECONDS)) {
- log.debug("The disk space check background thread was
successfully shut down");
- } else {
- log.warn("The disk space check background thread takes too
long to shutdown");
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
+ gcScheduler.close();
+ fileStoreScheduler.close();
try {
flush();