Author: mreutegg
Date: Wed Nov 9 11:03:39 2016
New Revision: 1768904
URL: http://svn.apache.org/viewvc?rev=1768904&view=rev
Log:
OAK-4792: Replace usage of AssertionError in ClusterNodeInfo
Merged revision 1760326 from trunk
Modified:
jackrabbit/oak/branches/1.4/ (props changed)
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfoTest.java
Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 9 11:03:39 2016
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735109,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457
,1750462,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751753,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1758213,1758713,1759433,1759795,1759826,1760340,1760373,1760387,1760486,1760661-1760662,1761412,1761444,1761571,1761762,1761787,1761876,1762453,1762612,1762632,1762635,1763347,1763355-1763356,1763378,1763465,1763735,1764678,1764705,1764814,1764898,1765817,1765983,1766071,1766423,1766496,1766519,1766554,1766644,1767265,1768446,1768637
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735109,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457
,1750462,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751753,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1758213,1758713,1759433,1759795,1759826,1760326,1760340,1760373,1760387,1760486,1760661-1760662,1761412,1761444,1761571,1761762,1761787,1761876,1762453,1762612,1762632,1762635,1763347,1763355-1763356,1763378,1763465,1763735,1764678,1764705,1764814,1764898,1765817,1765983,1766071,1766423,1766496,1766519,1766554,1766644,1767265,1768446,1768637
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java?rev=1768904&r1=1768903&r2=1768904&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
(original)
+++
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
Wed Nov 9 11:03:39 2016
@@ -588,7 +588,17 @@ public class ClusterNodeInfo {
return true;
}
- public void performLeaseCheck() {
+ /**
+ * Checks if the lease for this cluster node is still valid, otherwise
+ * throws a {@link DocumentStoreException}. This method will not throw the
+ * exception immediately when the lease expires, but instead give the lease
+ * update thread a last chance of 5 seconds to renew it. This allows the
+ * DocumentNodeStore to recover from an expired lease caused by a system
+ * put to sleep or a JVM in debug mode.
+ *
+ * @throws DocumentStoreException if the lease expired.
+ */
+ public void performLeaseCheck() throws DocumentStoreException {
if (leaseCheckDisabled || !renewed) {
// if leaseCheckDisabled is set we never do the check, so return
fast
@@ -606,8 +616,7 @@ public class ClusterNodeInfo {
// (note that once a lease check failed it would not
// be updated again, ever, as guaranteed by checking
// for leaseCheckFailed in renewLease() )
- LOG.error(LEASE_CHECK_FAILED_MSG);
- throw new AssertionError(LEASE_CHECK_FAILED_MSG);
+ throw leaseExpired(LEASE_CHECK_FAILED_MSG, true);
}
long now = getCurrentTime();
// OAK-3238 put the barrier 1/3 of 60sec=20sec before the end
@@ -622,8 +631,7 @@ public class ClusterNodeInfo {
synchronized(this) {
if (leaseCheckFailed) {
// someone else won and marked leaseCheckFailed - so we only
log/throw
- LOG.error(LEASE_CHECK_FAILED_MSG);
- throw new AssertionError(LEASE_CHECK_FAILED_MSG);
+ throw leaseExpired(LEASE_CHECK_FAILED_MSG, true);
}
for(int i=0; i<MAX_RETRY_SLEEPS_BEFORE_LEASE_FAILURE; i++) {
now = getCurrentTime();
@@ -702,7 +710,7 @@ public class ClusterNodeInfo {
th.start();
}
- throw new AssertionError(errorMsg);
+ throw leaseExpired(errorMsg, false);
}
/**
@@ -710,10 +718,17 @@ public class ClusterNodeInfo {
* to ensure the same cluster id is not re-used by a different instance.
* The lease is only renewed after 'leaseUpdateInterval' millis
* since last lease update - default being every 10 sec (this used to be
30sec).
+ * <p>
+ * This method will not fail immediately with a DocumentStoreException if
+ * the lease expired. It will still try to renew the lease and only fail if
+ * {@link #performLeaseCheck()} decided the lease expired or another
cluster
+ * node initiated recover for this node.
*
* @return {@code true} if the lease was renewed; {@code false} otherwise.
+ * @throws DocumentStoreException if the operation failed or the lease
+ * expired.
*/
- public boolean renewLease() {
+ public boolean renewLease() throws DocumentStoreException {
long now = getCurrentTime();
if (LOG.isTraceEnabled()) {
@@ -735,8 +750,7 @@ public class ClusterNodeInfo {
if (leaseCheckFailed) {
// prevent lease renewal after it failed
- LOG.error(LEASE_CHECK_FAILED_MSG);
- throw new AssertionError(LEASE_CHECK_FAILED_MSG);
+ throw leaseExpired(LEASE_CHECK_FAILED_MSG, true);
}
// synchronized could have delayed the 'now', so
// set it again..
@@ -786,8 +800,7 @@ public class ClusterNodeInfo {
if (leaseCheckFailed) {
// somehow the instance figured out otherwise that the
// lease check failed - so we don't have to too - so we
just log/throw
- LOG.error(LEASE_CHECK_FAILED_MSG);
- throw new AssertionError(LEASE_CHECK_FAILED_MSG);
+ throw leaseExpired(LEASE_CHECK_FAILED_MSG, true);
}
leaseCheckFailed = true; // make sure only one thread 'wins',
ie goes any further
}
@@ -812,7 +825,7 @@ public class ClusterNodeInfo {
LOG.error(errorMsg);
handleLeaseFailure(errorMsg);
- // should never be reached: handleLeaseFailure throws an
AssertionError
+ // should never be reached: handleLeaseFailure throws a
DocumentStoreException
return false;
}
previousLeaseEndTime = leaseEndTime; // store previousLeaseEndTime for
reference for next time
@@ -1015,4 +1028,11 @@ public class ClusterNodeInfo {
private static long getCurrentTime() {
return clock.getTime();
}
+
+ private static DocumentStoreException leaseExpired(String msg, boolean
log) {
+ if (log) {
+ LOG.error(msg);
+ }
+ return new DocumentStoreException(msg);
+ }
}
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfoTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfoTest.java?rev=1768904&r1=1768903&r2=1768904&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfoTest.java
(original)
+++
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfoTest.java
Wed Nov 9 11:03:39 2016
@@ -109,13 +109,12 @@ public class ClusterNodeInfoTest {
ClusterNodeInfo info = newClusterNodeInfo(1);
clock.waitUntil(info.getLeaseEndTime() +
ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS);
recoverClusterNode(1);
- boolean renewed = false;
try {
- renewed = info.renewLease();
- } catch (AssertionError e) {
- // TODO: rather use DocumentStoreException !?
+ info.renewLease();
+ fail("must fail with DocumentStoreException");
+ } catch (DocumentStoreException e) {
+ // expected
}
- assertFalse(renewed);
for (int i = 0; i < 10; i++) {
if (handler.isLeaseFailure()) {
return;
@@ -135,14 +134,12 @@ public class ClusterNodeInfoTest {
MissingLastRevSeeker seeker = new
MissingLastRevSeeker(store.getStore());
assertTrue(seeker.acquireRecoveryLock(1, 42));
// cluster node 1 must not be able to renew the lease now
- boolean renewed = false;
try {
// must either return false
- renewed = info.renewLease();
- } catch (AssertionError e) {
+ assertFalse(info.renewLease());
+ } catch (DocumentStoreException e) {
// or throw an exception
}
- assertFalse(renewed);
}
private void recoverClusterNode(int clusterId) throws Exception {