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 ng...@apache.org on 2020/05/29 07:51:57 UTC

svn commit: r1878258 - in /jackrabbit/oak/trunk: oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/ oak-search-elastic/src/main/java/org/apache/jackra...

Author: ngupta
Date: Fri May 29 07:51:57 2020
New Revision: 1878258

URL: http://svn.apache.org/viewvc?rev=1878258&view=rev
Log:
OAK-9089 | Adding cleanup for remote elastic index post benchmark runs

Added:
    jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexNameHelper.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java
    jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java
    jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java
    jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java
    jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java
    jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java
    jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java

Modified: jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java (original)
+++ jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java Fri May 29 07:51:57 2020
@@ -41,7 +41,7 @@ import java.io.File;
 public class ElasticFullTextWithGlobalIndexSearchTest extends SearchTest {
 
     private ElasticConnection coordinate;
-    private String ELASTIC_GLOBAL_INDEX;
+    private String elasticGlobalIndexName;
 
     ElasticFullTextWithGlobalIndexSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticConnection coordinate) {
         super(dump, flat, doReport, storageEnabled);
@@ -50,7 +50,7 @@ public class ElasticFullTextWithGlobalIn
 
     @Override
     protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
-        ELASTIC_GLOBAL_INDEX = TestHelper.getUniqueIndexName("elasticGlobal");
+        elasticGlobalIndexName = TestHelper.getUniqueIndexName("elasticGlobal");
         if (fixture instanceof OakRepositoryFixture) {
             return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
                 @Override
@@ -62,7 +62,7 @@ public class ElasticFullTextWithGlobalIn
                             .with(indexProvider)
                             .with(new PropertyIndexEditorProvider())
                             .with(new NodeTypeIndexProvider())
-                            .with(new ElasticGlobalInitializer(ELASTIC_GLOBAL_INDEX, storageEnabled))
+                            .with(new ElasticGlobalInitializer(elasticGlobalIndexName, storageEnabled))
                             .with(new UUIDInitializer());
                     return new Jcr(oak);
                 }
@@ -71,4 +71,10 @@ public class ElasticFullTextWithGlobalIn
         return super.createRepository(fixture);
     }
 
+    @Override
+    protected void afterSuite() throws Exception {
+        super.afterSuite();
+        TestHelper.cleanupRemoteElastic(coordinate, elasticGlobalIndexName);
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java (original)
+++ jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java Fri May 29 07:51:57 2020
@@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider;
 import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
-
 import javax.jcr.Repository;
 import java.io.File;
 
@@ -42,6 +41,7 @@ import static com.google.common.collect.
 public class ElasticFullTextWithoutGlobalIndexSearchTest extends SearchTest {
 
     private ElasticConnection coordinate;
+    private String indexName;
 
     ElasticFullTextWithoutGlobalIndexSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticConnection coordinate) {
         super(dump, flat, doReport, storageEnabled);
@@ -50,6 +50,7 @@ public class ElasticFullTextWithoutGloba
 
     @Override
     protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
+        indexName = TestHelper.getUniqueIndexName("elasticText");
         if (fixture instanceof OakRepositoryFixture) {
             return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
                 @Override
@@ -61,12 +62,19 @@ public class ElasticFullTextWithoutGloba
                             .with(indexProvider)
                             .with(new PropertyIndexEditorProvider())
                             .with(new NodeTypeIndexProvider())
-                            .with(new PropertyFullTextTest.FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticText"), of("text"),
+                            .with(new PropertyFullTextTest.FullTextPropertyInitialiser(indexName, of("text"),
                                     ElasticIndexDefinition.TYPE_ELASTICSEARCH).nodeScope().analyzed());
                     return new Jcr(oak);
                 }
             });
         }
         return super.createRepository(fixture);
+
+    }
+
+    @Override
+    protected void afterSuite() throws Exception {
+        super.afterSuite();
+        TestHelper.cleanupRemoteElastic(coordinate, indexName);
     }
 }

Modified: jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java (original)
+++ jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java Fri May 29 07:51:57 2020
@@ -67,7 +67,8 @@ public class ElasticPropertyFTIndexedCon
     private static final Logger LOG = LoggerFactory.getLogger(ElasticPropertyFTIndexedContentAvailability.class);
     private String currentFixtureName;
     private ElasticConnection coordinate;
-    private String ELASTIC_GLOBAL_INDEX;
+    private String elasticGlobalIndexName;
+    private String elasticTitleIndexName;
 
     @Override
     public String getCurrentFixtureName() {
@@ -90,7 +91,8 @@ public class ElasticPropertyFTIndexedCon
 
     @Override
     protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
-        ELASTIC_GLOBAL_INDEX = TestHelper.getUniqueIndexName("elasticGlobal");
+        elasticGlobalIndexName = TestHelper.getUniqueIndexName("elasticGlobal");
+        elasticTitleIndexName = TestHelper.getUniqueIndexName("elasticTitle");
         if (fixture instanceof OakRepositoryFixture) {
             currentFixtureName = fixture.toString();
             return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
@@ -101,9 +103,9 @@ public class ElasticPropertyFTIndexedCon
                     ElasticIndexProvider indexProvider = new ElasticIndexProvider(coordinate);
                     oak.with(editorProvider)
                             .with(indexProvider)
-                            .with((new ElasticGlobalInitializer(ELASTIC_GLOBAL_INDEX, storageEnabled)).async())
+                            .with((new ElasticGlobalInitializer(elasticGlobalIndexName, storageEnabled)).async())
                                     // the WikipediaImporter set a property `title`
-                            .with(new FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticTitle"), of("title"),
+                            .with(new FullTextPropertyInitialiser(elasticTitleIndexName, of("title"),
                                     ElasticIndexDefinition.TYPE_ELASTICSEARCH).async())
                             .withAsyncIndexing("async", 5);
                     return new Jcr(oak);
@@ -113,5 +115,12 @@ public class ElasticPropertyFTIndexedCon
         return super.createRepository(fixture);
     }
 
+    @Override
+    protected void afterSuite() throws Exception {
+        super.afterSuite();
+        TestHelper.cleanupRemoteElastic(coordinate, elasticGlobalIndexName);
+        TestHelper.cleanupRemoteElastic(coordinate, elasticTitleIndexName);
+    }
+
 
 }

Modified: jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java (original)
+++ jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java Fri May 29 07:51:57 2020
@@ -46,7 +46,8 @@ public class ElasticPropertyFTSeparatedI
 
     private String currentFixtureName;
     private ElasticConnection coordinate;
-    private String ELASTIC_GLOBAL_INDEX;
+    private String elasticGlobalIndexName;
+    private String elasticTitleIndexName;
 
     ElasticPropertyFTSeparatedIndexedContentAvailability(final File dump,
                                                                 final boolean flat,
@@ -68,7 +69,8 @@ public class ElasticPropertyFTSeparatedI
 
     @Override
     protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
-        ELASTIC_GLOBAL_INDEX = TestHelper.getUniqueIndexName("elasticGlobal");
+        elasticGlobalIndexName = TestHelper.getUniqueIndexName("elasticGlobal");
+        elasticTitleIndexName = TestHelper.getUniqueIndexName("elasticTitle");
         if (fixture instanceof OakRepositoryFixture) {
             currentFixtureName = fixture.toString();
             return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
@@ -79,9 +81,9 @@ public class ElasticPropertyFTSeparatedI
                     ElasticIndexProvider indexProvider = new ElasticIndexProvider(coordinate);
                     oak.with(editorProvider)
                             .with(indexProvider)
-                            .with((new ElasticGlobalInitializer(ELASTIC_GLOBAL_INDEX, storageEnabled)).async("fulltext-async"))
+                            .with((new ElasticGlobalInitializer(elasticGlobalIndexName, storageEnabled)).async("fulltext-async"))
                                     // the WikipediaImporter set a property `title`
-                            .with(new FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticTitle"), of("title"),
+                            .with(new FullTextPropertyInitialiser(elasticTitleIndexName, of("title"),
                                     ElasticIndexDefinition.TYPE_ELASTICSEARCH).async())
                             .withAsyncIndexing("async", 5)
                             .withAsyncIndexing("fulltext-async", 5);
@@ -92,4 +94,11 @@ public class ElasticPropertyFTSeparatedI
         return super.createRepository(fixture);
     }
 
+    @Override
+    protected void afterSuite() throws Exception {
+        super.afterSuite();
+        TestHelper.cleanupRemoteElastic(coordinate, elasticGlobalIndexName);
+        TestHelper.cleanupRemoteElastic(coordinate, elasticTitleIndexName);
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java (original)
+++ jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java Fri May 29 07:51:57 2020
@@ -43,6 +43,7 @@ import static com.google.common.collect.
 public class ElasticPropertyTextSearchTest extends SearchTest {
 
     private ElasticConnection coordinate;
+    private String indexName;
 
     ElasticPropertyTextSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticConnection coordinate) {
         super(dump, flat, doReport, storageEnabled);
@@ -66,6 +67,7 @@ public class ElasticPropertyTextSearchTe
 
     @Override
     protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
+        indexName = TestHelper.getUniqueIndexName("elasticTitle");
         if (fixture instanceof OakRepositoryFixture) {
             return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
                 @Override
@@ -77,7 +79,7 @@ public class ElasticPropertyTextSearchTe
                             .with(indexProvider)
                             .with(new PropertyIndexEditorProvider())
                             .with(new NodeTypeIndexProvider())
-                            .with(new PropertyFullTextTest.FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticTitle"), of("title"),
+                            .with(new PropertyFullTextTest.FullTextPropertyInitialiser(indexName, of("title"),
                                     ElasticIndexDefinition.TYPE_ELASTICSEARCH));
                     return new Jcr(oak);
                 }
@@ -85,4 +87,10 @@ public class ElasticPropertyTextSearchTe
         }
         return super.createRepository(fixture);
     }
+
+    @Override
+    protected void afterSuite() throws Exception {
+        super.afterSuite();
+        TestHelper.cleanupRemoteElastic(coordinate, indexName);
+    }
 }

Modified: jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java (original)
+++ jackrabbit/oak/trunk/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java Fri May 29 07:51:57 2020
@@ -18,8 +18,19 @@
  */
 package org.apache.jackrabbit.oak.benchmark.util;
 
+import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticConnection;
+import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexNameHelper;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
+import org.elasticsearch.action.support.master.AcknowledgedResponse;
+import org.elasticsearch.client.RequestOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
 public class TestHelper {
 
+    private static final Logger LOG = LoggerFactory.getLogger(TestHelper.class);
     /**
      * Generates a unique index name from the given suggestion.
      * @param name name suggestion
@@ -29,4 +40,21 @@ public class TestHelper {
         return name + System.currentTimeMillis();
     }
 
+    /*
+    Deletes the remote elastic index from the elastic server.
+     */
+    public static void cleanupRemoteElastic(ElasticConnection connection, String indexName) throws IOException {
+        String alias =  ElasticIndexNameHelper.getIndexAlias(connection.getIndexPrefix(), "/oak:index/" + indexName);
+        /*
+        Adding index suffix as -1 because reindex count will always be 1 here (we are not doing any reindexing in the benchmark tests)
+        TODO: If we write benchmarks for elastic reindex - this needs to be changed to get the reindex count from the index def node
+        */
+        String remoteIndexName = ElasticIndexNameHelper.getElasticSafeIndexName(alias + "-1");
+        AcknowledgedResponse deleteIndexResponse = connection.getClient().indices().
+                delete(new DeleteIndexRequest(remoteIndexName), RequestOptions.DEFAULT);
+        if (!deleteIndexResponse.isAcknowledged()) {
+            LOG.warn("Delete index call not acknowledged for index " + remoteIndexName + " .Please check if remote index deleted or not.");
+        }
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java?rev=1878258&r1=1878257&r2=1878258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java Fri May 29 07:51:57 2020
@@ -19,7 +19,6 @@
 package org.apache.jackrabbit.oak.plugins.index.elastic;
 
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
 import org.apache.jackrabbit.oak.plugins.index.search.PropertyDefinition;
@@ -29,12 +28,10 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
 
 import static org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil.getOptionalValue;
-import static org.elasticsearch.common.Strings.INVALID_FILENAME_CHARS;
 
 public class ElasticIndexDefinition extends IndexDefinition {
 
@@ -55,13 +52,6 @@ public class ElasticIndexDefinition exte
     public static final String BULK_RETRIES_BACKOFF = "bulkRetriesBackoff";
     public static final long BULK_RETRIES_BACKOFF_DEFAULT = 200;
 
-    private static final int MAX_NAME_LENGTH = 255;
-
-    private static final String INVALID_CHARS_REGEX = Pattern.quote(INVALID_FILENAME_CHARS
-            .stream()
-            .map(Object::toString)
-            .collect(Collectors.joining("")));
-
     private static final Function<Integer, Boolean> isAnalyzable;
 
     static {
@@ -89,8 +79,8 @@ public class ElasticIndexDefinition exte
         boolean isReindex = defn.getBoolean(IndexConstants.REINDEX_PROPERTY_NAME);
         String indexSuffix = "-" + (getReindexCount() + (isReindex ? 1 : 0));
         this.indexPrefix = indexPrefix != null ? indexPrefix : "";
-        this.remoteAlias = setupAlias();
-        this.remoteIndexName = getElasticSafeIndexName(this.remoteAlias + indexSuffix);
+        this.remoteAlias = ElasticIndexNameHelper.getIndexAlias(indexPrefix, getIndexPath());
+        this.remoteIndexName = ElasticIndexNameHelper.getElasticSafeIndexName(this.remoteAlias + indexSuffix);
         this.bulkActions = getOptionalValue(defn, BULK_ACTIONS, BULK_ACTIONS_DEFAULT);
         this.bulkSizeBytes = getOptionalValue(defn, BULK_SIZE_BYTES, BULK_SIZE_BYTES_DEFAULT);
         this.bulkFlushIntervalMs = getOptionalValue(defn, BULK_FLUSH_INTERVAL_MS, BULK_FLUSH_INTERVAL_MS_DEFAULT);
@@ -152,42 +142,6 @@ public class ElasticIndexDefinition exte
         return propertyDefinitions.stream().anyMatch(pd -> pd.analyzed || pd.fulltextEnabled());
     }
 
-    private String setupAlias() {
-        // TODO: implement advanced remote index name strategy that takes into account multiple tenants and re-index process
-        return getElasticSafeIndexName(indexPrefix + "." + getIndexPath());
-    }
-
-    /**
-     * <ul>
-     *     <li>abc -> abc</li>
-     *     <li>xy:abc -> xyabc</li>
-     *     <li>/oak:index/abc -> abc</li>
-     * </ul>
-     * <p>
-     * The resulting file name would be truncated to MAX_NAME_LENGTH
-     */
-    private static String getElasticSafeIndexName(String indexPath) {
-        String name = StreamSupport
-                .stream(PathUtils.elements(indexPath).spliterator(), false)
-                .limit(3) //Max 3 nodeNames including oak:index which is the immediate parent for any indexPath
-                .filter(p -> !"oak:index".equals(p))
-                .map(ElasticIndexDefinition::getElasticSafeName)
-                .collect(Collectors.joining("_"));
-
-        if (name.length() > MAX_NAME_LENGTH) {
-            name = name.substring(0, MAX_NAME_LENGTH);
-        }
-        return name;
-    }
-
-    /**
-     * Convert {@code e} to Elasticsearch safe index name.
-     * Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
-     */
-    private static String getElasticSafeName(String suggestedIndexName) {
-        return suggestedIndexName.replaceAll(INVALID_CHARS_REGEX, "").toLowerCase();
-    }
-
     /**
      * Class to help with {@link ElasticIndexDefinition} creation.
      * The built object represents the index definition only without the node structure.

Added: jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexNameHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexNameHelper.java?rev=1878258&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexNameHelper.java (added)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexNameHelper.java Fri May 29 07:51:57 2020
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index.elastic;
+
+
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import static org.elasticsearch.common.Strings.INVALID_FILENAME_CHARS;
+
+public class ElasticIndexNameHelper {
+
+    private static final int MAX_NAME_LENGTH = 255;
+
+    private static final String INVALID_CHARS_REGEX = Pattern.quote(INVALID_FILENAME_CHARS
+            .stream()
+            .map(Object::toString)
+            .collect(Collectors.joining("")));
+
+    public static String getIndexAlias(String indexPrefix, String indexPath) {
+        // TODO: implement advanced remote index name strategy that takes into account multiple tenants and re-index process
+        return getElasticSafeIndexName(indexPrefix + "." + indexPath);
+    }
+
+    /**
+     * <ul>
+     *     <li>abc -> abc</li>
+     *     <li>xy:abc -> xyabc</li>
+     *     <li>/oak:index/abc -> abc</li>
+     * </ul>
+     * <p>
+     * The resulting file name would be truncated to MAX_NAME_LENGTH
+     */
+    public static String getElasticSafeIndexName(String indexPath) {
+        String name = StreamSupport
+                .stream(PathUtils.elements(indexPath).spliterator(), false)
+                .limit(3) //Max 3 nodeNames including oak:index which is the immediate parent for any indexPath
+                .filter(p -> !"oak:index".equals(p))
+                .map(ElasticIndexNameHelper::getElasticSafeName)
+                .collect(Collectors.joining("_"));
+
+        if (name.length() > MAX_NAME_LENGTH) {
+            name = name.substring(0, MAX_NAME_LENGTH);
+        }
+        return name;
+    }
+
+    /**
+     * Convert {@code e} to Elasticsearch safe index name.
+     * Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
+     */
+    private static String getElasticSafeName(String suggestedIndexName) {
+        return suggestedIndexName.replaceAll(INVALID_CHARS_REGEX, "").toLowerCase();
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexNameHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native