Author: stefanegli
Date: Wed Aug 26 12:45:15 2015
New Revision: 1697913
URL: http://svn.apache.org/r1697913
Log:
OAK-3238 : update lease more often: after 20sec instead of 30sec already - this
allows to make the lease-check on the other hand to have a larger
safety-margin: the lease check now fails if the lease is only valid for another
20sec (instead of timing out at the very end, which has zero margin)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java?rev=1697913&r1=1697912&r2=1697913&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
Wed Aug 26 12:45:15 2015
@@ -401,7 +401,7 @@ public class ClusterNodeInfo {
return;
}
final long now = getCurrentTime();
- if (now < leaseEndTime) {
+ if (now < (leaseEndTime - leaseTime / 3)) { // OAK-3238 : put the
barrier 1/3 before lease end
// then all is good
return;
}
@@ -439,14 +439,14 @@ public class ClusterNodeInfo {
/**
* Renew the cluster id lease. This method needs to be called once in a
while,
* to ensure the same cluster id is not re-used by a different instance.
- * The lease is only renewed when half of the lease time passed. That is,
- * with a lease time of 60 seconds, the lease is renewed every 30 seconds.
+ * The lease is only renewed when a third of the lease time passed. That
is,
+ * with a lease time of 60 seconds, the lease is renewed every 20 seconds.
*
* @return {@code true} if the lease was renewed; {@code false} otherwise.
*/
public boolean renewLease() {
long now = getCurrentTime();
- if (now + leaseTime / 2 < leaseEndTime) {
+ if (now + 2 * leaseTime / 3 < leaseEndTime) {
return false;
}
UpdateOp update = new UpdateOp("" + id, true);
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java?rev=1697913&r1=1697912&r2=1697913&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterInfoTest.java
Wed Aug 26 12:45:15 2015
@@ -113,8 +113,8 @@ public class ClusterInfoTest {
// current lease end
long leaseEnd = getLeaseEndTime(ns);
- // wait a bit, but not more than half of the lease time
- clock.waitUntil(clock.getTime() + (ns.getClusterInfo().getLeaseTime()
/ 2) - 1000);
+ // wait a bit, but not more than a third of the lease time
+ clock.waitUntil(clock.getTime() + (ns.getClusterInfo().getLeaseTime()
/ 3) - 1000);
// must not renew lease right now
ns.renewClusterIdLease();
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java?rev=1697913&r1=1697912&r2=1697913&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java
Wed Aug 26 12:45:15 2015
@@ -313,7 +313,7 @@ public class DocumentDiscoveryLiteServic
*/
private boolean setLeaseTime(final int leaseTime) throws
NoSuchFieldException {
ns.getClusterInfo().setLeaseTime(leaseTime);
- PrivateAccessor.setField(ns.getClusterInfo(), "leaseEndTime",
System.currentTimeMillis() + (leaseTime / 2));
+ PrivateAccessor.setField(ns.getClusterInfo(), "leaseEndTime",
System.currentTimeMillis() + (leaseTime / 3) - 10 /* 10ms safety margin */);
boolean renewed = ns.renewClusterIdLease();
return renewed;
}