Author: mduerig
Date: Thu Dec 7 12:30:58 2017
New Revision: 1817364
URL: http://svn.apache.org/viewvc?rev=1817364&view=rev
Log:
OAK-6884: TarMK disk space check is not synchronized with FileStore opened state
Refactored flush
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=1817364&r1=1817363&r2=1817364&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 Dec 7 12:30:58 2017
@@ -205,23 +205,8 @@ public class FileStore extends AbstractF
this.snfeListener = builder.getSnfeListener();
- fileStoreScheduler.scheduleAtFixedRate(format("TarMK flush [%s]",
directory), 5, SECONDS, () -> {
- try (ShutDownCloser ignore = shutDown.tryKeepAlive()) {
- if (shutDown.isShutDown()) {
- log.debug("Shut down in progress, skipping flush");
- } else if (revisions == null) {
- log.debug("No TarRevisions available, skipping flush");
- } else {
- revisions.tryFlush(() -> {
- segmentWriter.flush();
- tarFiles.flush();
- stats.flushed();
- });
- }
- } catch (IOException e) {
- log.warn("Failed to flush the TarMK at {}", directory, e);
- }
- });
+ fileStoreScheduler.scheduleAtFixedRate(format("TarMK flush [%s]",
directory), 5, SECONDS,
+ this::tryFlush);
fileStoreScheduler.scheduleAtFixedRate(format("TarMK filer reaper
[%s]", directory), 5, SECONDS,
fileReaper::reap);
@@ -333,12 +318,37 @@ public class FileStore extends AbstractF
});
}
+ /**
+ * Flush all pending changes
+ */
public void flush() throws IOException {
try (ShutDownCloser ignored = shutDown.keepAlive()) {
doFlush();
}
}
+ /**
+ * Try to flush all pending changes to disk if possible without waiting
+ * for a lock or other resources currently not available.
+ */
+ public void tryFlush() {
+ try (ShutDownCloser ignore = shutDown.tryKeepAlive()) {
+ if (shutDown.isShutDown()) {
+ log.debug("Shut down in progress, skipping flush");
+ } else if (revisions == null) {
+ log.debug("No TarRevisions available, skipping flush");
+ } else {
+ revisions.tryFlush(() -> {
+ segmentWriter.flush();
+ tarFiles.flush();
+ stats.flushed();
+ });
+ }
+ } catch (IOException e) {
+ log.warn("Failed to flush the TarMK at {}", directory, e);
+ }
+ }
+
/**
* Run full garbage collection: estimation, compaction, cleanup.
*/