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 re...@apache.org on 2019/03/04 15:25:49 UTC
svn commit: r1854773 - in /jackrabbit/oak/trunk/oak-store-document/src:
main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
test/java/org/apache/jackrabbit/oak/plugins/document/BaseDocumentDiscoveryLiteServiceTest.java
Author: reschke
Date: Mon Mar 4 15:25:49 2019
New Revision: 1854773
URL: http://svn.apache.org/viewvc?rev=1854773&view=rev
Log:
OAK-8089: DocumentNodeStore dispose can fail when duration of final background ops exceeds lease time
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BaseDocumentDiscoveryLiteServiceTest.java
Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1854773&r1=1854772&r2=1854773&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Mon Mar 4 15:25:49 2019
@@ -248,6 +248,11 @@ public final class DocumentNodeStore
private final AtomicBoolean isDisposed = new AtomicBoolean();
/**
+ * Whether the lease update thread shall be stopped.
+ */
+ private final AtomicBoolean stopLeaseUpdateThread = new AtomicBoolean();
+
+ /**
* The cluster instance info.
*/
@NotNull
@@ -557,7 +562,7 @@ public final class DocumentNodeStore
clusterNodeInfo.setLeaseFailureHandler(builder.getLeaseFailureHandler());
}
String threadNamePostfix = "(" + clusterId + ")";
- leaseUpdateThread = new Thread(new BackgroundLeaseUpdate(this, isDisposed),
+ leaseUpdateThread = new Thread(new BackgroundLeaseUpdate(this, stopLeaseUpdateThread),
"DocumentNodeStore lease update thread " + threadNamePostfix);
leaseUpdateThread.setDaemon(true);
if (!readOnlyMode) {
@@ -777,7 +782,17 @@ public final class DocumentNodeStore
}
}
- Utils.joinQuietly(clusterUpdateThread, leaseUpdateThread);
+ Utils.joinQuietly(clusterUpdateThread);
+
+ // Stop lease update thread once no further document store operations
+ // are required
+ LOG.debug("Stopping LeaseUpdate thread...");
+ stopLeaseUpdateThread.set(true);
+ synchronized (stopLeaseUpdateThread) {
+ stopLeaseUpdateThread.notifyAll();
+ }
+ Utils.joinQuietly(leaseUpdateThread);
+ LOG.debug("Stopped LeaseUpdate thread");
// now mark this cluster node as inactive by disposing the
// clusterNodeInfo, but only if final background operations
@@ -785,6 +800,7 @@ public final class DocumentNodeStore
if (ex == null) {
clusterNodeInfo.dispose();
}
+
store.dispose();
if (blobStore instanceof Closeable) {
Modified: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BaseDocumentDiscoveryLiteServiceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BaseDocumentDiscoveryLiteServiceTest.java?rev=1854773&r1=1854772&r2=1854773&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BaseDocumentDiscoveryLiteServiceTest.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BaseDocumentDiscoveryLiteServiceTest.java Mon Mar 4 15:25:49 2019
@@ -317,6 +317,11 @@ public abstract class BaseDocumentDiscov
return isDisposed;
}
+ private AtomicBoolean getStopLeaseUpdateThread() throws NoSuchFieldException {
+ AtomicBoolean stopLeaseUpdateThread = (AtomicBoolean) PrivateAccessor.getField(ns, "stopLeaseUpdateThread");
+ return stopLeaseUpdateThread;
+ }
+
private void stopAllBackgroundThreads() throws NoSuchFieldException {
// get all those background threads...
Thread backgroundReadThread = (Thread) PrivateAccessor.getField(ns, "backgroundReadThread");
@@ -349,6 +354,12 @@ public abstract class BaseDocumentDiscov
} catch (InterruptedException e) {
// ignore
}
+ final AtomicBoolean stopLeaseUpdateThread = getStopLeaseUpdateThread();
+ assertFalse(stopLeaseUpdateThread.getAndSet(true));
+ // notify background threads waiting on stopLeaseUpdateThread
+ synchronized (stopLeaseUpdateThread) {
+ stopLeaseUpdateThread.notifyAll();
+ }
try {
leaseUpdateThread.join(5000);
assertTrue(!leaseUpdateThread.isAlive());