This is an automated email from the ASF dual-hosted git repository.
stefanegli 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 0dc38bc30e OAK-10281 : osgi config variant of recovery delay - vs
system propert… (#1288)
0dc38bc30e is described below
commit 0dc38bc30e17a752303cce532ca6bef25a9628aa
Author: stefan-egli <[email protected]>
AuthorDate: Wed Feb 14 19:28:19 2024 +0100
OAK-10281 : osgi config variant of recovery delay - vs system propert…
(#1288)
* OAK-10281 : osgi config variant of recovery delay - vs system property atm
* OAK-10281 : reverting erroneous re-inclusion via git merge conflict
resolving
* OAK-10281 : more recoveryDelayMillis test cases added - plus fixed
missing link from config to builder in DocumentNodeStoreService
---
.../oak/plugins/document/ClusterNodeInfo.java | 14 ++++++------
.../oak/plugins/document/Configuration.java | 9 +++++++-
.../plugins/document/DocumentNodeStoreBuilder.java | 10 +++++++++
.../plugins/document/DocumentNodeStoreService.java | 8 +++++--
.../DocumentNodeStoreServiceConfigurationTest.java | 15 +++++++++++++
.../document/DocumentNodeStoreServiceTest.java | 26 ++++++++++++++++++++++
6 files changed, 72 insertions(+), 10 deletions(-)
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
index dc2e43a771..fe83374122 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
@@ -237,13 +237,14 @@ public class ClusterNodeInfo {
/** OAK-10622 : millis to prevent reuse of clusterId if it crashed and
thus required a recover */
static final int DEFAULT_REUSE_DELAY_AFTER_RECOVERY_MILLIS = 0;
- /** OAK-10281 : seconds to delay a recovery after a lease timeout */
- private static final int DEFAULT_RECOVERY_DELAY_SECS =
SystemPropertySupplier.create("oak.documentMK.recoveryDelaySecs", 0)
- .loggingTo(LOG).validateWith(value -> value >= 0)
- .formatSetMessage((name, value) -> String.format("recovery delay
set to (secs): %ss (using system property %s)", name, value)).get();
- private static final long DEFAULT_RECOVERY_DELAY_MILLIS = 1000L *
(long)DEFAULT_RECOVERY_DELAY_SECS;
+ /** OAK-10281 : default millis to delay a recovery after a lease timeout */
+ static final long DEFAULT_RECOVERY_DELAY_MILLIS = 0;
- // kept non-final for testing purpose
+ /**
+ * Actual millis to delay a recovery after a lease timeout.
+ * <p>
+ * Initialized by DocumentNodeStore constructor.
+ */
static long recoveryDelayMillis = DEFAULT_RECOVERY_DELAY_MILLIS;
/**
@@ -1238,7 +1239,6 @@ public class ClusterNodeInfo {
return recoveryDelayMillis;
}
- /** <b>only used for testing</b> **/
static void setRecoveryDelayMillis(long recoveryDelayMillis) {
ClusterNodeInfo.recoveryDelayMillis = recoveryDelayMillis;
}
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java
index b2628efbea..cee47efde0 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java
@@ -23,6 +23,7 @@ import
org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.osgi.service.metatype.annotations.Option;
+import static
org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo.DEFAULT_RECOVERY_DELAY_MILLIS;
import static
org.apache.jackrabbit.oak.plugins.document.CommitQueue.DEFAULT_SUSPEND_TIMEOUT;
import static
org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo.DEFAULT_REUSE_DELAY_AFTER_RECOVERY_MILLIS;
import static org.apache.jackrabbit.oak.plugins.document.Configuration.PID;
@@ -291,11 +292,17 @@ import static
org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreServic
" (milliseconds).")
long suspendTimeoutMillis() default DEFAULT_SUSPEND_TIMEOUT;
+ @AttributeDefinition(
+ name = "Recovery delay",
+ description = "Delay (in milliseconds) before a recovery is done,
" +
+ "0 or negative for no delay. Default: " +
DEFAULT_RECOVERY_DELAY_MILLIS +
+ " (milliseconds).")
+ long recoveryDelayMillis() default DEFAULT_RECOVERY_DELAY_MILLIS;
+
@AttributeDefinition(
name = "ClusterId reuse delay after recovery",
description = "Minimal delay (in milliseconds) before a clusterId
" +
"can be reused after a recovery, 0 or negative for no
delay. Default: " + DEFAULT_REUSE_DELAY_AFTER_RECOVERY_MILLIS +
" (milliseconds).")
long clusterIdReuseDelayAfterRecoveryMillis() default
DEFAULT_REUSE_DELAY_AFTER_RECOVERY_MILLIS;
-
}
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
index 8820dabb3e..070db7ad08 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
@@ -121,6 +121,7 @@ public class DocumentNodeStoreBuilder<T extends
DocumentNodeStoreBuilder<T>> {
private long clusterIdReuseDelayAfterRecovery =
ClusterNodeInfo.DEFAULT_REUSE_DELAY_AFTER_RECOVERY_MILLIS;
private boolean timing;
private boolean logging;
+ private long recoveryDelayMillis =
ClusterNodeInfo.DEFAULT_RECOVERY_DELAY_MILLIS;
private String loggingPrefix;
private LeaseCheckMode leaseCheck =
ClusterNodeInfo.DEFAULT_LEASE_CHECK_MODE; // OAK-2739 is enabled by default
also for non-osgi
private boolean isReadOnlyMode = false;
@@ -710,6 +711,15 @@ public class DocumentNodeStoreBuilder<T extends
DocumentNodeStoreBuilder<T>> {
return suspendTimeoutMillis;
}
+ public T setRecoveryDelayMillis(long recoveryDelayMillis) {
+ this.recoveryDelayMillis = recoveryDelayMillis;
+ return thisBuilder();
+ }
+
+ public long getRecoveryDelayMillis() {
+ return recoveryDelayMillis;
+ }
+
public T setGCMonitor(@NotNull GCMonitor gcMonitor) {
this.gcMonitor = checkNotNull(gcMonitor);
return thisBuilder();
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
index 5d188ab4f1..e0f1222cd0 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
@@ -310,10 +310,10 @@ public class DocumentNodeStoreService {
// might contain passwords
log.info("Starting DocumentNodeStore with host={}, db={},
cache size (MB)={}, persistentCache={}, " +
"journalCache={}, blobCacheSize (MB)={},
maxReplicationLagInSecs={}, " +
- "clusterIdReuseDelayAfterRecoveryMillis={}",
+ "clusterIdReuseDelayAfterRecoveryMillis={},
recoveryDelayMillis={}",
mongoURI.getHosts(), db, config.cache(),
persistentCache,
journalCache, config.blobCacheSize(),
config.maxReplicationLagInSecs(),
- config.clusterIdReuseDelayAfterRecoveryMillis());
+ config.clusterIdReuseDelayAfterRecoveryMillis(),
config.recoveryDelayMillis());
log.info("Mongo Connection details {}",
MongoConnection.toString(mongoURI.getOptions()));
}
@@ -478,6 +478,7 @@ public class DocumentNodeStoreService {
setThrottlingEnabled(config.throttlingEnabled()).
setSuspendTimeoutMillis(config.suspendTimeoutMillis()).
setClusterIdReuseDelayAfterRecovery(config.clusterIdReuseDelayAfterRecoveryMillis()).
+ setRecoveryDelayMillis(config.recoveryDelayMillis()).
setLeaseFailureHandler(new LeaseFailureHandler() {
private final LeaseFailureHandler
defaultLeaseFailureHandler = createDefaultLeaseFailureHandler();
@@ -531,6 +532,9 @@ public class DocumentNodeStoreService {
if (isThrottlingEnabled(builder)) {
builder.setThrottlingStatsCollector(new
ThrottlingStatsCollectorImpl(statisticsProvider));
}
+
+ // initialize the (global) recoveryDelayMillis
+
ClusterNodeInfo.setRecoveryDelayMillis(builder.getRecoveryDelayMillis());
}
private boolean isWrappingCustomBlobStore() {
diff --git
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceConfigurationTest.java
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceConfigurationTest.java
index c46b6f699e..3576ed6ab6 100644
---
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceConfigurationTest.java
+++
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceConfigurationTest.java
@@ -166,6 +166,21 @@ public class DocumentNodeStoreServiceConfigurationTest {
assertArrayEquals(new String[]{"/foo", "/bar"},
config.persistentCacheIncludes());
}
+ @Test
+ public void recoveryDelayMillis() throws Exception {
+ addConfigurationEntry(preset, "recoveryDelayMillis", 0L);
+ Configuration config = createConfiguration();
+ assertEquals(0L, config.recoveryDelayMillis());
+
+ addConfigurationEntry(preset, "recoveryDelayMillis", -1L);
+ config = createConfiguration();
+ assertEquals(-1L, config.recoveryDelayMillis());
+
+ addConfigurationEntry(preset, "recoveryDelayMillis", 60000L);
+ config = createConfiguration();
+ assertEquals(60000L, config.recoveryDelayMillis());
+ }
+
private Configuration createConfiguration() throws IOException {
return DocumentNodeStoreServiceConfiguration.create(
context.componentContext(), configAdmin,
diff --git
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
index 1040dbc8eb..de2f205705 100644
---
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
+++
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
@@ -77,6 +77,7 @@ public class DocumentNodeStoreServiceTest {
public void tearDown() throws Exception {
MockOsgi.deactivate(service, context.bundleContext());
MongoUtils.dropCollections(MongoUtils.DB);
+ ClusterNodeInfo.resetRecoveryDelayMillisToDefault();
}
@Test
@@ -340,6 +341,31 @@ public class DocumentNodeStoreServiceTest {
assertEquals(suspendTimeoutMillis,
dns.commitQueue.getSuspendTimeoutMillis());
}
+ @Test
+ public void recoveryDelayMillis0() {
+ doRecoveryDelayMillis(0);
+ }
+
+ @Test
+ public void recoveryDelayMillisNegative() {
+ doRecoveryDelayMillis(-1);
+ }
+
+ @Test
+ public void recoveryDelayMillisMinute() {
+ doRecoveryDelayMillis(60000);
+ }
+
+ private void doRecoveryDelayMillis(long recoveryDelayMillis) {
+ Map<String, Object> config = newConfig(repoHome);
+ config.put("recoveryDelayMillis", recoveryDelayMillis);
+ MockOsgi.setConfigForPid(context.bundleContext(), PID, config);
+ MockOsgi.activate(service, context.bundleContext());
+
+ DocumentNodeStore dns = context.getService(DocumentNodeStore.class);
+ assertEquals(recoveryDelayMillis,
ClusterNodeInfo.getRecoveryDelayMillis());
+ }
+
@NotNull
private static MongoDocumentStore getMongoDocumentStore(DocumentNodeStore
s) {
try {