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 mr...@apache.org on 2021/07/05 06:29:16 UTC
[jackrabbit-oak] branch trunk updated: OAK-9477: Time difference
warning too sensitive
This is an automated email from the ASF dual-hosted git repository.
mreutegg pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 26b6272 OAK-9477: Time difference warning too sensitive
new 83b06b4 Merge pull request #305 from mreutegg/OAK-9477
26b6272 is described below
commit 26b62726c54e61ce81c3a52ece6ef132aaf88bce
Author: Marcel Reutegger <ma...@gmail.com>
AuthorDate: Mon Jun 28 16:33:52 2021 +0200
OAK-9477: Time difference warning too sensitive
---
.../oak/plugins/document/DocumentNodeStore.java | 22 ++++---
.../oak/plugins/document/ExternalChange.java | 2 +-
.../oak/plugins/document/util/Utils.java | 22 ++++---
.../oak/plugins/document/util/UtilsTest.java | 70 +++++++++++++++++++++-
4 files changed, 95 insertions(+), 21 deletions(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
index 2df1df2..48e09cd 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
@@ -207,7 +207,10 @@ public final class DocumentNodeStore
private boolean disableSweep2 = SystemPropertySupplier.create(SYS_PROP_DISABLE_SWEEP2, Boolean.FALSE).loggingTo(LOG)
.get();
+ // OAK-2682: time difference detection applied at startup with a default
+ // max time diff of 2000 millis (2sec)
static final long DEFAULT_MAX_SERVER_TIME_DIFFERENCE = 2000L;
+ private final long maxTimeDiffMillis = SystemPropertySupplier.create("oak.documentMK.maxServerTimeDiffMillis", DEFAULT_MAX_SERVER_TIME_DIFFERENCE).loggingTo(LOG).get();
/**
* The document store without potentially lease checking wrapper.
@@ -1222,6 +1225,10 @@ public final class DocumentNodeStore
return disableBranches;
}
+ public long getMaxTimeDiffMillis() {
+ return maxTimeDiffMillis;
+ }
+
/**
* Enqueue the document with the given id as a split candidate.
*
@@ -2958,18 +2965,15 @@ public final class DocumentNodeStore
* @param s the document store to get the time difference from.
* @throws AssertionError when the time difference is too high.
*/
- private static void checkServerTimeDifference(DocumentStore s)
+ private void checkServerTimeDifference(DocumentStore s)
throws AssertionError {
- // OAK-2682: time difference detection applied at startup with a default
- // max time diff of 2000 millis (2sec)
- final long maxDiff = SystemPropertySupplier.create("oak.documentMK.maxServerTimeDiffMillis", DEFAULT_MAX_SERVER_TIME_DIFFERENCE).loggingTo(LOG).get();
try {
- if (maxDiff >= 0) {
+ if (maxTimeDiffMillis >= 0) {
final long timeDiff = s.determineServerTimeDifferenceMillis();
- LOG.info("Server time difference: {}ms (max allowed: {}ms)", timeDiff, maxDiff);
- if (Math.abs(timeDiff) > maxDiff) {
+ LOG.info("Server time difference: {}ms (max allowed: {}ms)", timeDiff, maxTimeDiffMillis);
+ if (Math.abs(timeDiff) > maxTimeDiffMillis) {
throw new AssertionError("Server clock seems off (" + timeDiff + "ms) by more than configured amount ("
- + maxDiff + "ms)");
+ + maxTimeDiffMillis + "ms)");
}
}
} catch (RuntimeException e) { // no checked exception
@@ -3094,7 +3098,7 @@ public final class DocumentNodeStore
checkState(root == null);
try {
- alignWithExternalRevisions(rootDoc, clock, clusterId);
+ alignWithExternalRevisions(rootDoc, clock, clusterId, maxTimeDiffMillis);
} catch (InterruptedException e) {
throw new DocumentStoreException("Interrupted while aligning with " +
"external revision: " + rootDoc.getLastRev());
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ExternalChange.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ExternalChange.java
index cbaa7a8..4ea1569 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ExternalChange.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ExternalChange.java
@@ -103,7 +103,7 @@ abstract class ExternalChange {
return stats;
}
try {
- alignWithExternalRevisions(doc, clock, clusterId);
+ alignWithExternalRevisions(doc, clock, clusterId, store.getMaxTimeDiffMillis());
} catch (InterruptedException e) {
throw new RuntimeException("Background read interrupted", e);
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
index 7eb72e3..c72c991 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
@@ -960,27 +960,33 @@ public class Utils {
* @param rootDoc the root document.
* @param clock the clock.
* @param clusterId the local clusterId.
+ * @param warnThresholdMillis log a warning when the an external change in
+ * the future is detected with more than this time difference.
* @throws InterruptedException if the current thread is interrupted while
* waiting. The interrupted status on the current thread is cleared
* when this exception is thrown.
*/
public static void alignWithExternalRevisions(@NotNull NodeDocument rootDoc,
@NotNull Clock clock,
- int clusterId)
+ int clusterId,
+ long warnThresholdMillis)
throws InterruptedException {
Map<Integer, Revision> lastRevMap = checkNotNull(rootDoc).getLastRev();
long externalTime = Utils.getMaxExternalTimestamp(lastRevMap.values(), clusterId);
long localTime = clock.getTime();
- if (localTime < externalTime) {
- LOG.warn("Detected clock differences. Local time is '{}', " +
- "while most recent external time is '{}'. " +
- "Current _lastRev entries: {}",
- new Date(localTime), new Date(externalTime), lastRevMap.values());
+ long timeDiff = externalTime - localTime;
+ if (timeDiff > 0) {
double delay = ((double) externalTime - localTime) / 1000d;
String fmt = "Background read will be delayed by %.1f seconds. " +
"Please check system time on cluster nodes.";
- String msg = String.format(fmt, delay);
- LOG.warn(msg);
+ if (timeDiff > warnThresholdMillis) {
+ LOG.warn("Detected clock differences. Local time is '{}', " +
+ "while most recent external time is '{}'. " +
+ "Current _lastRev entries: {}",
+ new Date(localTime), new Date(externalTime), lastRevMap.values());
+ String msg = String.format(fmt, delay);
+ LOG.warn(msg);
+ }
while (localTime + 60000 < externalTime) {
clock.waitUntil(localTime + 60000);
localTime = clock.getTime();
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
index e407799..e3ba309 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
@@ -29,6 +29,7 @@ import com.google.common.collect.Iterables;
import org.apache.commons.codec.binary.Hex;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo;
import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument;
import org.apache.jackrabbit.oak.plugins.document.Collection;
@@ -50,9 +51,12 @@ import org.apache.jackrabbit.oak.stats.Clock;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
+import org.slf4j.event.Level;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertEquals;
@@ -60,7 +64,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -71,6 +74,8 @@ import static org.mockito.Mockito.when;
*/
public class UtilsTest {
+ private static final long TIME_DIFF_WARN_THRESHOLD_MILLIS = 2000L;
+
@Test
public void getPreviousIdFor() {
Revision r = new Revision(System.currentTimeMillis(), 0, 0);
@@ -294,15 +299,74 @@ public class UtilsTest {
UpdateUtils.applyChanges(doc, op);
// must not wait even if revision is in the future
- Utils.alignWithExternalRevisions(doc, c, 2);
+ Utils.alignWithExternalRevisions(doc, c, 2, TIME_DIFF_WARN_THRESHOLD_MILLIS);
assertThat(c.getTime(), is(lessThan(lastRev2.getTimestamp())));
// must wait until after lastRev2 timestamp
- Utils.alignWithExternalRevisions(doc, c, 1);
+ Utils.alignWithExternalRevisions(doc, c, 1, TIME_DIFF_WARN_THRESHOLD_MILLIS);
assertThat(c.getTime(), is(greaterThan(lastRev2.getTimestamp())));
}
@Test
+ public void warnOnClockDifferences() throws Exception {
+ Clock c = new Clock.Virtual();
+ c.waitUntil(System.currentTimeMillis());
+ // local
+ Revision lastRev1 = new Revision(c.getTime(), 0, 1);
+ // other in the future
+ Revision lastRev2 = new Revision(c.getTime() + 5000, 0, 2);
+
+ // create a root document
+ NodeDocument doc = new NodeDocument(new MemoryDocumentStore(), c.getTime());
+ UpdateOp op = new UpdateOp(Utils.getIdFromPath("/"), true);
+ NodeDocument.setLastRev(op, lastRev1);
+ NodeDocument.setLastRev(op, lastRev2);
+ UpdateUtils.applyChanges(doc, op);
+
+ LogCustomizer customizer = LogCustomizer.forLogger(Utils.class).enable(Level.WARN).create();
+ customizer.starting();
+ try {
+ // must wait until after lastRev2 timestamp
+ Utils.alignWithExternalRevisions(doc, c, 1, TIME_DIFF_WARN_THRESHOLD_MILLIS);
+ assertThat(c.getTime(), is(greaterThan(lastRev2.getTimestamp())));
+
+ assertFalse(customizer.getLogs().isEmpty());
+ assertThat(customizer.getLogs().iterator().next(), containsString("Detected clock differences"));
+ } finally {
+ customizer.finished();
+ }
+ }
+
+ @Test
+ public void noWarnOnMinorClockDifferences() throws Exception {
+ Clock c = new Clock.Virtual();
+ c.waitUntil(System.currentTimeMillis());
+ // local
+ Revision lastRev1 = new Revision(c.getTime(), 0, 1);
+ // other slightly in the future
+ Revision lastRev2 = new Revision(c.getTime() + 100, 0, 2);
+
+ // create a root document
+ NodeDocument doc = new NodeDocument(new MemoryDocumentStore(), c.getTime());
+ UpdateOp op = new UpdateOp(Utils.getIdFromPath("/"), true);
+ NodeDocument.setLastRev(op, lastRev1);
+ NodeDocument.setLastRev(op, lastRev2);
+ UpdateUtils.applyChanges(doc, op);
+
+ LogCustomizer customizer = LogCustomizer.forLogger(Utils.class).enable(Level.WARN).create();
+ customizer.starting();
+ try {
+ // must wait until after lastRev2 timestamp
+ Utils.alignWithExternalRevisions(doc, c, 1, TIME_DIFF_WARN_THRESHOLD_MILLIS);
+ assertThat(c.getTime(), is(greaterThan(lastRev2.getTimestamp())));
+
+ assertThat(customizer.getLogs(), empty());
+ } finally {
+ customizer.finished();
+ }
+ }
+
+ @Test
public void isIdFromLongPath() {
Path path = Path.fromString("/test");
while (!Utils.isLongPath(path)) {