Skip to content

Commit 4543c6f

Browse files
niekraaijmakersNiek RaaijmakersrishabhdaimJoscorbe
authored
OAK-11461 : DocumentNodeStoreService - disable discovery (#2057)
* OAK-11461 - Make it configurable to disable discovery for the document node store service * Update oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java Co-authored-by: Rishabh Kumar <rishabhdaim1991@gmail.com> * OAK-11461 - Add unit test * Update oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java Co-authored-by: José Andrés Cordero Benítez <Joscorbe@users.noreply.github.com> --------- Co-authored-by: Niek Raaijmakers <raaijmak@adobe.com> Co-authored-by: Rishabh Kumar <rishabhdaim1991@gmail.com> Co-authored-by: José Andrés Cordero Benítez <Joscorbe@users.noreply.github.com>
1 parent 0ab3ca6 commit 4543c6f

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Configuration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,9 @@
395395
description = "Integer value indicating the number of documents to check for garbage in each Full GC cycle." +
396396
"The default value is " + DocumentNodeStoreService.DEFAULT_FGC_PROGRESS_SIZE)
397397
int fullGCProgressSize() default DocumentNodeStoreService.DEFAULT_FGC_PROGRESS_SIZE;
398+
399+
@AttributeDefinition(
400+
name = "Invisible for discovery",
401+
description = "Boolean value indicating whether the instance should be discoverable by the cluster. The default value is " + DocumentNodeStoreService.DEFAULT_INVISIBLE_FOR_DISCOVERY)
402+
boolean invisibleForDiscovery() default DocumentNodeStoreService.DEFAULT_INVISIBLE_FOR_DISCOVERY;
398403
}

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
configurationPid = {Configuration.PID})
131131
public class DocumentNodeStoreService {
132132

133+
public static final boolean DEFAULT_INVISIBLE_FOR_DISCOVERY = false;
133134
private static final long MB = 1024 * 1024;
134135
static final String DEFAULT_URI = "mongodb://localhost:27017/oak";
135136
static final int DEFAULT_CACHE = (int) (DEFAULT_MEMORY_CACHE_SIZE / MB);
@@ -510,6 +511,7 @@ private void configureBuilder(DocumentNodeStoreBuilder<?> builder) {
510511
config.childrenCachePercentage(),
511512
config.diffCachePercentage(),
512513
config.prevNoPropCachePercentage()).
514+
setClusterInvisible(config.invisibleForDiscovery()).
513515
setCacheSegmentCount(config.cacheSegmentCount()).
514516
setCacheStackMoveDistance(config.cacheStackMoveDistance()).
515517
setBundlingDisabled(config.bundlingDisabled()).

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceConfigurationTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import static org.junit.Assert.assertEquals;
4646
import static org.junit.Assert.assertNull;
4747
import static org.junit.Assert.assertTrue;
48+
import static org.junit.Assert.assertFalse;
4849

4950
public class DocumentNodeStoreServiceConfigurationTest {
5051

@@ -169,6 +170,28 @@ public void fullGCBatchSize() throws Exception {
169170
assertEquals(batchSize, config.fullGCBatchSize());
170171
}
171172

173+
@Test
174+
public void invisibleForDiscoveryFalse() throws Exception {
175+
boolean batchSize = false;
176+
addConfigurationEntry(preset, "invisibleForDiscovery", batchSize);
177+
Configuration config = createConfiguration();
178+
assertFalse(config.invisibleForDiscovery());
179+
}
180+
181+
@Test
182+
public void invisibleForDiscoveryTrue() throws Exception {
183+
boolean batchSize = true;
184+
addConfigurationEntry(preset, "invisibleForDiscovery", batchSize);
185+
Configuration config = createConfiguration();
186+
assertTrue(config.invisibleForDiscovery());
187+
}
188+
189+
@Test
190+
public void invisibleForDiscoveryFalseByDefault() throws Exception {
191+
Configuration config = createConfiguration();
192+
assertFalse(config.invisibleForDiscovery());
193+
}
194+
172195
@Test
173196
public void fullGCProgressSize() throws Exception {
174197
int progressSize = 20000;

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,29 @@ public void strictLeaseCheckMode() {
256256
assertEquals(LeaseCheckMode.STRICT, dns.getClusterInfo().getLeaseCheckMode());
257257
}
258258

259+
@Test
260+
public void invisibleForDiscoveryTrueFalse() {
261+
Map<String, Object> config = newConfig(repoHome);
262+
MockOsgi.setConfigForPid(context.bundleContext(), PID, config);
263+
MockOsgi.activate(service, context.bundleContext());
264+
265+
DocumentNodeStore dns = context.getService(DocumentNodeStore.class);
266+
// false is the default
267+
assertFalse(dns.getClusterInfo().isInvisible());
268+
}
269+
270+
@Test
271+
public void invisibleForDiscoveryTrue() {
272+
Map<String, Object> config = newConfig(repoHome);
273+
config.put("invisibleForDiscovery", true);
274+
MockOsgi.setConfigForPid(context.bundleContext(), PID, config);
275+
MockOsgi.activate(service, context.bundleContext());
276+
277+
DocumentNodeStore dns = context.getService(DocumentNodeStore.class);
278+
assertTrue(dns.getClusterInfo().isInvisible());
279+
}
280+
281+
259282
@Test
260283
public void lenientLeaseCheckMode() {
261284
Map<String, Object> config = newConfig(repoHome);

0 commit comments

Comments
 (0)