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 am...@apache.org on 2016/01/28 13:58:04 UTC

svn commit: r1727331 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/ oak-...

Author: amitj
Date: Thu Jan 28 12:58:04 2016
New Revision: 1727331

URL: http://svn.apache.org/viewvc?rev=1727331&view=rev
Log:
OAK-3935: SharedDataStore - Allow unique repository ID to be specified by config

Added ability to specify custom id and to override the generated id.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ClusterRepositoryInfo.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/ClusterRepositoryInfoTest.java
    jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1727331&r1=1727330&r2=1727331&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Thu Jan 28 12:58:04 2016
@@ -313,6 +313,13 @@ public class DocumentNodeStoreService {
     public static final String PROP_DS_TYPE = "documentStoreType";
     private DocumentStoreType documentStoreType;
 
+    private static final String DEFAULT_SHARED_DS_REPO_ID = "";
+    @Property(value = DEFAULT_SHARED_DS_REPO_ID,
+            label = "SharedDataStore RepositoryID",
+            description = "Custom RepositoryID for SharedDataStore. This overrides any generated value."
+    )
+    public static final String PROP_SHARED_DS_REPO_ID = "sharedDSRepoId";
+
     @Reference
     private StatisticsProvider statisticsProvider;
 
@@ -450,8 +457,10 @@ public class DocumentNodeStoreService {
 
         // If a shared data store register the repo id in the data store
         if (SharedDataStoreUtils.isShared(blobStore)) {
+            String customRepoID = PropertiesUtil.toString(prop(PROP_SHARED_DS_REPO_ID), DEFAULT_SHARED_DS_REPO_ID);
+
             try {
-                String repoId = ClusterRepositoryInfo.createId(mk.getNodeStore());
+                String repoId = ClusterRepositoryInfo.createId(mk.getNodeStore(), customRepoID);
                 ((SharedDataStore) blobStore).addMetadataRecord(new ByteArrayInputStream(new byte[0]),
                     SharedDataStoreUtils.SharedStoreRecordType.REPOSITORY.getNameFromId(repoId));
             } catch (Exception e) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ClusterRepositoryInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ClusterRepositoryInfo.java?rev=1727331&r1=1727330&r2=1727331&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ClusterRepositoryInfo.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ClusterRepositoryInfo.java Thu Jan 28 12:58:04 2016
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.UUID;
 
+import com.google.common.base.Strings;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -36,21 +37,42 @@ public class ClusterRepositoryInfo {
     public static final String CLUSTER_ID_PROP = ":clusterId";
 
     /**
-     * Adds a new uuid for the repository in the property /:clusterConfig/:clusterId with preoperty.
+     * Adds a new uuid for the repository in the property /:clusterConfig/:clusterId if not available
      *
      * @param store the NodeStore instance
      * @return the repository id
      * @throws CommitFailedException
      */
     public static String createId(NodeStore store) throws CommitFailedException {
+        return createId(store, null);
+    }
+
+    /**
+     * Adds a new uuid for the repository in the property /:clusterConfig/:clusterId Or
+     * update the id with the customId passed.
+     *
+     * @param store the NodeStore instance
+     * @param customId customId
+     * @return the repository id
+     * @throws CommitFailedException
+     */
+    public static String createId(NodeStore store, String customId) throws CommitFailedException {
         NodeBuilder root = store.getRoot().builder();
-        if (!root.hasChildNode(CLUSTER_CONFIG_NODE)) {
-            String id = UUID.randomUUID().toString();
+        if (!root.hasChildNode(CLUSTER_CONFIG_NODE) ||
+                !root.getChildNode(CLUSTER_CONFIG_NODE).hasProperty(CLUSTER_ID_PROP)) {
+            // Set the customId if available
+            String id = (!Strings.isNullOrEmpty(customId) ? customId : UUID.randomUUID().toString());
             root.child(CLUSTER_CONFIG_NODE).setProperty(CLUSTER_ID_PROP, id);
             store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
             return id;
         } else {
-            return root.getChildNode(CLUSTER_CONFIG_NODE).getProperty(CLUSTER_ID_PROP).getValue(Type.STRING);
+            String currId = root.getChildNode(CLUSTER_CONFIG_NODE).getProperty(CLUSTER_ID_PROP).getValue(Type.STRING);
+            if (!Strings.isNullOrEmpty(customId) && !customId.equals(currId)) {
+                root.child(CLUSTER_CONFIG_NODE).setProperty(CLUSTER_ID_PROP, customId);
+                store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+                currId = customId;
+            }
+            return currId;
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/ClusterRepositoryInfoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/ClusterRepositoryInfoTest.java?rev=1727331&r1=1727330&r2=1727331&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/ClusterRepositoryInfoTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/ClusterRepositoryInfoTest.java Thu Jan 28 12:58:04 2016
@@ -110,6 +110,41 @@ public class ClusterRepositoryInfoTest {
         Assert.assertNull(id);
     }
 
+    @Test
+    public void checkCustomId() throws Exception {
+        MemoryDocumentStore store = new MemoryDocumentStore();
+        DocumentNodeStore ds1 = builderProvider.newBuilder()
+                .setAsyncDelay(0)
+                .setDocumentStore(store)
+                .setClusterId(1)
+                .getNodeStore();
+        String repoId1 = ClusterRepositoryInfo.createId(ds1, "yyyyyyy");
+        ds1.runBackgroundOperations();
+
+        String id = ClusterRepositoryInfo.getId(ds1);
+        Assert.assertEquals(id, "yyyyyyy");
+    }
+
+    @Test
+    public void checkChangeId() throws Exception {
+        MemoryDocumentStore store = new MemoryDocumentStore();
+        DocumentNodeStore ds1 = builderProvider.newBuilder()
+                .setAsyncDelay(0)
+                .setDocumentStore(store)
+                .setClusterId(1)
+                .getNodeStore();
+        String repoId1 = ClusterRepositoryInfo.createId(ds1, null);
+        ds1.runBackgroundOperations();
+
+        // Change with a custom ID
+        ClusterRepositoryInfo.createId(ds1, "xxxxxxxx");
+
+        String id = ClusterRepositoryInfo.getId(ds1);
+        Assert.assertNotNull(id);
+        Assert.assertEquals(id, "xxxxxxxx");
+    }
+
+
     @After
     public void close() throws IOException {
         FileUtils.cleanDirectory(new File(DataStoreUtils.getHomeDir()));

Modified: jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1727331&r1=1727330&r2=1727331&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java Thu Jan 28 12:58:04 2016
@@ -285,6 +285,13 @@ public class SegmentNodeStoreService ext
     )
     public static final String PROP_BLOB_GC_MAX_AGE = "blobGcMaxAgeInSecs";
 
+    private static final String DEFAULT_SHARED_DS_REPO_ID = "";
+    @Property(value = DEFAULT_SHARED_DS_REPO_ID,
+            label = "SharedDataStore RepositoryID",
+            description = "Custom RepositoryID for SharedDataStore. This overrides any generated value"
+    )
+    public static final String PROP_SHARED_DS_REPO_ID = "sharedDSRepoId";
+
     @Override
     protected SegmentNodeStore getNodeStore() {
         checkState(delegate != null, "service must be activated when used");
@@ -447,9 +454,12 @@ public class SegmentNodeStoreService ext
                 RevisionGCMBean.TYPE, "Segment node store revision garbage collection");
 
         // If a shared data store register the repo id in the data store
+        String repoId = "";
         if (SharedDataStoreUtils.isShared(blobStore)) {
+            String customRepoID = property(PROP_SHARED_DS_REPO_ID);
+
             try {
-                String repoId = ClusterRepositoryInfo.createId(delegate);
+                repoId = ClusterRepositoryInfo.createId(delegate, customRepoID);
                 ((SharedDataStore) blobStore).addMetadataRecord(new ByteArrayInputStream(new byte[0]),
                     SharedStoreRecordType.REPOSITORY.getNameFromId(repoId));
             } catch (Exception e) {
@@ -462,7 +472,7 @@ public class SegmentNodeStoreService ext
                                                     new SegmentBlobReferenceRetriever(store.getTracker()),
                                                     (GarbageCollectableBlobStore) store.getBlobStore(),
                                                     executor, TimeUnit.SECONDS.toMillis(blobGcMaxAgeInSecs),
-                                                    ClusterRepositoryInfo.getId(delegate));
+                                                    repoId);
 
             blobGCRegistration = registerMBean(whiteboard, BlobGCMBean.class, new BlobGC(gc, executor),
                     BlobGCMBean.TYPE, "Segment node store blob garbage collection");