diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java index 519fb3d..b9c245e 100644 --- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java +++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java @@ -86,6 +86,7 @@ import org.apache.jackrabbit.oak.spi.commit.Observer; import org.apache.jackrabbit.oak.spi.gc.GCMonitor; import org.apache.jackrabbit.oak.spi.gc.GCMonitorTracker; import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.spi.state.NodeStoreProvider; import org.apache.jackrabbit.oak.spi.state.ProxyNodeStore; import org.apache.jackrabbit.oak.spi.state.RevisionGC; import org.apache.jackrabbit.oak.spi.state.RevisionGCMBean; @@ -228,6 +229,12 @@ public class SegmentNodeStoreService extends ProxyNodeStore ) public static final String STANDBY = "standby"; + @Property( + label = "NodeStoreProvider role", + description = "Property indicating that this component will not register as a NodeStore but as a NodeStoreProvider with given role" + ) + public static final String ROLE = "nsProvider.role"; + @Property(boolValue = false, label = "Custom BlobStore", description = "Boolean value indicating that a custom BlobStore is to be used. " + @@ -262,6 +269,7 @@ public class SegmentNodeStoreService extends ProxyNodeStore private final List registrations = new ArrayList<>(); private WhiteboardExecutor executor; private boolean customBlobStore; + private String role; /** * Blob modified before this time duration would be considered for Blob GC @@ -296,7 +304,9 @@ public class SegmentNodeStoreService extends ProxyNodeStore @Activate public void activate(ComponentContext context) throws IOException { this.context = context; - this.customBlobStore = Boolean.parseBoolean(property(CUSTOM_BLOB_STORE)); + this.role = property(ROLE); + //In secondaryNodeStore mode customBlobStore is always enabled + this.customBlobStore = Boolean.parseBoolean(property(CUSTOM_BLOB_STORE)) || isSecondaryStoreMode(); if (blobStore == null && customBlobStore) { log.info("BlobStore use enabled. SegmentNodeStore would be initialized when BlobStore would be available"); @@ -341,6 +351,11 @@ public class SegmentNodeStoreService extends ProxyNodeStore return; } + if (role != null){ + registerNodeStoreProvider(); + return; + } + if (registerSegmentNodeStore()) { Dictionary props = new Hashtable(); props.put(Constants.SERVICE_PID, SegmentNodeStore.class.getName()); @@ -350,6 +365,25 @@ public class SegmentNodeStoreService extends ProxyNodeStore } } + private boolean isSecondaryStoreMode() { + return "secondary".equals(role); + } + + private void registerNodeStoreProvider() { + SegmentNodeStore.SegmentNodeStoreBuilder nodeStoreBuilder = SegmentNodeStoreBuilders.builder(store); + segmentNodeStore = nodeStoreBuilder.build(); + Dictionary props = new Hashtable(); + props.put(NodeStoreProvider.ROLE, property(ROLE)); + storeRegistration = context.getBundleContext().registerService(NodeStoreProvider.class.getName(), new NodeStoreProvider() { + @Override + public NodeStore getNodeStore() { + return SegmentNodeStoreService.this; + } + }, + props); + log.info("Registered NodeStoreProvider backed by SegmentNodeStore"); + } + private boolean registerSegmentStore() throws IOException { if (context == null) { log.info("Component still not activated. Ignoring the initialization call"); @@ -635,7 +669,11 @@ public class SegmentNodeStoreService extends ProxyNodeStore return new File(directory); } - return new File("tarmk"); + if (role == null) { + return new File("tarmk"); + } else { + return new File("tarmk-" + role); + } } private File getDirectory() { diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java index 6cea478..0363df6 100644 --- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java +++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java @@ -29,7 +29,9 @@ import java.io.File; import java.util.Map; import org.apache.jackrabbit.oak.spi.blob.BlobStore; +import org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore; import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.spi.state.NodeStoreProvider; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.apache.sling.testing.mock.osgi.junit.OsgiContext; import org.junit.Before; @@ -140,6 +142,18 @@ public class SegmentNodeStoreServiceTest { unregisterSegmentNodeStoreService(); } + @Test + public void nodeStoreProvider() throws Exception{ + Map properties = newHashMap(); + properties.put(SegmentNodeStoreService.ROLE, "secondary"); + properties.put(SegmentNodeStoreService.DIRECTORY, folder.getRoot().getAbsolutePath()); + context.registerService(BlobStore.class, new MemoryBlobStore()); + + segmentNodeStoreService = context.registerInjectActivateService(new SegmentNodeStoreService(), properties); + assertNull(context.getService(NodeStore.class)); + assertNotNull(context.getService(NodeStoreProvider.class)); + } + private SegmentNodeStoreService segmentNodeStoreService; private void registerSegmentNodeStoreService(boolean customBlobStore) { diff --git a/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java b/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java index 11abf49..d70f85b 100644 --- a/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java +++ b/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java @@ -243,11 +243,10 @@ public class SegmentNodeStoreService extends ProxyNodeStore public static final String STANDBY = "standby"; @Property( - boolValue = false, - label = "Secondary Store Mode", - description = "Flag indicating that this component will not register as a NodeStore but just as a SecondaryNodeStoreProvider" + label = "NodeStoreProvider role", + description = "Property indicating that this component will not register as a NodeStore but as a NodeStoreProvider with given role" ) - public static final String SECONDARY_STORE = "secondary"; + public static final String ROLE = "nsProvider.role"; @Property(boolValue = false, label = "Custom BlobStore", @@ -291,6 +290,7 @@ public class SegmentNodeStoreService extends ProxyNodeStore private Registration fileStoreStatsMBean; private WhiteboardExecutor executor; private boolean customBlobStore; + private String role; private Registration discoveryLiteDescriptorRegistration; @@ -329,6 +329,7 @@ public class SegmentNodeStoreService extends ProxyNodeStore @Activate public void activate(ComponentContext context) throws IOException { this.context = context; + this.role = property(ROLE); //In secondaryNodeStore mode customBlobStore is always enabled this.customBlobStore = Boolean.parseBoolean(property(CUSTOM_BLOB_STORE)) || isSecondaryStoreMode(); @@ -375,8 +376,8 @@ public class SegmentNodeStoreService extends ProxyNodeStore return; } - if (isSecondaryStoreMode()){ - registerSecondaryStore(); + if (role != null) { + registerNodeStoreProvider(); return; } @@ -390,15 +391,15 @@ public class SegmentNodeStoreService extends ProxyNodeStore } private boolean isSecondaryStoreMode() { - return toBoolean(property(SECONDARY_STORE), false); + return "secondary".equals(role); } - private void registerSecondaryStore() { + private void registerNodeStoreProvider() { SegmentNodeStore.SegmentNodeStoreBuilder nodeStoreBuilder = SegmentNodeStore.builder(store); nodeStoreBuilder.withCompactionStrategy(compactionStrategy); segmentNodeStore = nodeStoreBuilder.build(); Dictionary props = new Hashtable(); - props.put(NodeStoreProvider.ROLE, "secondary"); + props.put(NodeStoreProvider.ROLE, property(ROLE)); storeRegistration = context.getBundleContext().registerService(NodeStoreProvider.class.getName(), new NodeStoreProvider() { @Override public NodeStore getNodeStore() { @@ -727,7 +728,11 @@ public class SegmentNodeStoreService extends ProxyNodeStore return new File(directory); } - return new File("tarmk"); + if (role == null) { + return new File("tarmk"); + } else { + return new File("tarmk-" + role); + } } private File getDirectory() { diff --git a/oak-segment/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreServiceTest.java b/oak-segment/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreServiceTest.java index df698a6..294c949 100644 --- a/oak-segment/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreServiceTest.java +++ b/oak-segment/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreServiceTest.java @@ -145,7 +145,7 @@ public class SegmentNodeStoreServiceTest { @Test public void nodeStoreProvider() throws Exception{ Map properties = newHashMap(); - properties.put(SegmentNodeStoreService.SECONDARY_STORE, true); + properties.put(SegmentNodeStoreService.ROLE, "secondary"); properties.put(SegmentNodeStoreService.DIRECTORY, folder.getRoot().getAbsolutePath()); context.registerService(BlobStore.class, new MemoryBlobStore());