You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ja...@apache.org on 2018/01/16 22:13:52 UTC

[geode] branch develop updated: GEODE-4227 : Cluster config updated during Lucene Reindex (#1257)

This is an automated email from the ASF dual-hosted git repository.

jasonhuynh pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new cf31261  GEODE-4227 : Cluster config updated during Lucene Reindex (#1257)
cf31261 is described below

commit cf312616fd7a8586e5986ea09cb4167574a715ef
Author: Nabarun Nag <na...@users.noreply.github.com>
AuthorDate: Tue Jan 16 14:13:48 2018 -0800

    GEODE-4227 : Cluster config updated during Lucene Reindex (#1257)
    
    * Cluster config is updated when Lucene indexes are created after the region is created.
---
 .../lucene/internal/cli/LuceneIndexCommands.java   | 14 ++--
 .../cli/functions/LuceneCreateIndexFunction.java   | 24 ++++--
 .../LuceneClusterConfigurationDUnitTest.java       | 83 ++++++++++++--------
 ...onWhereRegionCreatedBeforeReindexDUnitTest.java | 91 ++++++++++++++++++++++
 ...ClusterConfigurationWithReindexFlagEnabled.java | 58 ++++++++++++++
 ...uceneIndexXmlGeneratorIntegrationJUnitTest.java | 27 ++++---
 ...onCreatedBeforeReindexIntegrationJUnitTest.java | 56 +++++++++++++
 ...WithReindexFlagEnabledIntegrationJUnitTest.java | 39 ++++++++++
 8 files changed, 337 insertions(+), 55 deletions(-)

diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
index 926b2d0..5053280 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
@@ -170,8 +170,6 @@ public class LuceneIndexCommands implements GfshCommand {
       throws CommandResultException {
 
     Result result;
-    XmlEntity xmlEntity = null;
-
     // Every lucene index potentially writes to disk.
     getSecurityService().authorize(Resource.CLUSTER, Operation.MANAGE, LucenePermission.TARGET);
 
@@ -185,23 +183,25 @@ public class LuceneIndexCommands implements GfshCommand {
     final ResultCollector<?, ?> rc =
         this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
     final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) rc.getResult();
-
+    final XmlEntity xmlEntity = funcResults.stream().filter(CliFunctionResult::isSuccessful)
+        .map(CliFunctionResult::getXmlEntity).filter(Objects::nonNull).findFirst().orElse(null);
     final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
     for (final CliFunctionResult cliFunctionResult : funcResults) {
       tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());
 
       if (cliFunctionResult.isSuccessful()) {
         tabularResult.accumulate("Status", "Successfully created lucene index");
-        // if (xmlEntity == null) {
-        // xmlEntity = cliFunctionResult.getXmlEntity();
-        // }
       } else {
         tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
       }
     }
 
     result = ResultBuilder.buildResult(tabularResult);
-
+    if (xmlEntity != null) {
+      persistClusterConfiguration(result, () -> {
+        getSharedConfiguration().addXmlEntity(xmlEntity, null);
+      });
+    }
     return result;
   }
 
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
index df8bf30..dcfd193 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
@@ -36,8 +36,10 @@ import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
 import org.apache.geode.cache.lucene.internal.cli.LuceneCliStrings;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo;
+import org.apache.geode.cache.lucene.internal.xml.LuceneXmlConstants;
 import org.apache.geode.cache.lucene.internal.security.LucenePermission;
 import org.apache.geode.internal.InternalEntity;
+import org.apache.geode.internal.cache.xmlcache.CacheXml;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -72,10 +74,13 @@ public class LuceneCreateIndexFunction implements InternalEntity, Function {
     try {
       final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
       final Cache cache = context.getCache();
+      final String indexName = indexInfo.getIndexName();
+      final String regionPath = indexInfo.getRegionPath();
+
       memberId = cache.getDistributedSystem().getDistributedMember().getId();
       LuceneService service = LuceneServiceProvider.get(cache);
 
-      INDEX_NAME.validateName(indexInfo.getIndexName());
+      INDEX_NAME.validateName(indexName);
 
       String[] fields = indexInfo.getSearchableFieldNames();
       String[] analyzerName = indexInfo.getFieldAnalyzers();
@@ -100,15 +105,17 @@ public class LuceneCreateIndexFunction implements InternalEntity, Function {
         indexFactory.setLuceneSerializer(toSerializer(serializerName));
       }
 
-      REGION_PATH.validateName(indexInfo.getRegionPath());
+      XmlEntity xmlEntity = null;
+      REGION_PATH.validateName(regionPath);
       if (LuceneServiceImpl.LUCENE_REINDEX) {
-        indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath(), true);
+        indexFactory.create(indexName, regionPath, true);
+        if (cache.getRegion(regionPath) != null) {
+          xmlEntity = getXmlEntity(indexName, regionPath);
+        }
       } else {
-        indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath(), false);
+        indexFactory.create(indexName, regionPath, false);
       }
 
-      // TODO - update cluster configuration by returning a valid XmlEntity
-      XmlEntity xmlEntity = null;
       context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
     } catch (Exception e) {
       String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE,
@@ -117,6 +124,11 @@ public class LuceneCreateIndexFunction implements InternalEntity, Function {
     }
   }
 
+  protected XmlEntity getXmlEntity(String indexName, String regionPath) {
+    String regionName = StringUtils.stripStart(regionPath, "/");
+    return new XmlEntity(CacheXml.REGION, "name", regionName);
+  }
+  
   @Override
   public Collection<ResourcePermission> getRequiredPermissions(String regionName) {
     return Collections.singleton(
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
index 46cae26..a36528b 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.Properties;
@@ -69,15 +70,13 @@ public class LuceneClusterConfigurationDUnitTest {
 
   @Test
   public void indexGetsCreatedUsingClusterConfiguration() throws Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
 
     // Create lucene index.
-    createLuceneIndexUsingGfsh();
-
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexAndDataRegion();
 
     // Start vm2. This should have lucene index created using cluster
     // configuration.
@@ -90,22 +89,27 @@ public class LuceneClusterConfigurationDUnitTest {
     });
   }
 
+  void createLuceneIndexAndDataRegion() throws Exception {
+    createLuceneIndexUsingGfsh();
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+  }
+
+  MemberVM createServer(int index) throws IOException {
+    return ls.startServerVM(index, locator.getPort());
+  }
+
 
   @Test
   public void indexWithAnalyzerGetsCreatedUsingClusterConfiguration() throws Exception {
-    ls.startServerVM(1, locator.getPort());
-
+    createServer(1);
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
 
-    // Create lucene index.
-    createLuceneIndexWithAnalyzerUsingGfsh();
-
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithAnalyzerAndDataRegion();
 
     // Start vm2. This should have lucene index created using cluster
     // configuration.
-    MemberVM vm2 = ls.startServerVM(2, locator.getPort());
+    MemberVM vm2 = createServer(2);
     vm2.invoke(() -> {
       LuceneService luceneService = LuceneServiceProvider.get(ClusterStartupRule.getCache());
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
@@ -121,17 +125,21 @@ public class LuceneClusterConfigurationDUnitTest {
     });
   }
 
+  void createLuceneIndexWithAnalyzerAndDataRegion() throws Exception {
+    // Create lucene index.
+    createLuceneIndexWithAnalyzerUsingGfsh();
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+  }
+
   @Test
   public void indexWithSerializerGetsCreatedUsingClusterConfiguration() throws Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
 
     // Create lucene index.
-    createLuceneIndexWithSerializerUsingGfsh(false);
-
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithSerializerAndDataRegion();
 
     // Start vm2. This should have lucene index created using cluster
     // configuration.
@@ -147,9 +155,15 @@ public class LuceneClusterConfigurationDUnitTest {
     });
   }
 
+  void createLuceneIndexWithSerializerAndDataRegion() throws Exception {
+    createLuceneIndexWithSerializerUsingGfsh();
+
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+  }
+
   @Test
   public void verifyClusterConfigurationAfterDestroyIndex() throws Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
@@ -157,6 +171,9 @@ public class LuceneClusterConfigurationDUnitTest {
     // Create and add indexes
     createAndAddIndexes();
 
+    // Verify cluster configuration contains the indexes
+    locator.invoke(verifyClusterConfiguration(true));
+
     // Destroy one index
     destroyLuceneIndexUsingGfsh(INDEX_NAME + "0");
 
@@ -169,7 +186,7 @@ public class LuceneClusterConfigurationDUnitTest {
 
   @Test
   public void verifyClusterConfigurationAfterDestroyIndexes() throws Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
@@ -177,6 +194,9 @@ public class LuceneClusterConfigurationDUnitTest {
     // Create and add indexes
     createAndAddIndexes();
 
+    // Verify cluster configuration contains the indexes
+    locator.invoke(verifyClusterConfiguration(true));
+
     // Destroy all indexes
     destroyLuceneIndexUsingGfsh(null);
 
@@ -187,20 +207,19 @@ public class LuceneClusterConfigurationDUnitTest {
   @Test
   public void verifyMemberWithGroupStartsAfterAlterRegion() throws Exception {
     // Start a member with no group
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Start a member with group
     String group = "group1";
     Properties properties = new Properties();
     properties.setProperty(GROUPS, group);
-    MemberVM vm2 = ls.startServerVM(2, properties, locator.getPort());
+    MemberVM vm2 = createServer(properties, 2);
 
     // Connect Gfsh to locator
     gfshConnector.connectAndVerify(locator);
 
     // Create index and region in no group
-    createLuceneIndexUsingGfsh();
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexAndDataRegion();
 
     // Alter region in group
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_REGION);
@@ -214,7 +233,7 @@ public class LuceneClusterConfigurationDUnitTest {
         .tableHasColumnWithExactValuesInExactOrder("Status", expectedStatusOutput);
 
     // Start another member with group
-    ls.startServerVM(3, properties, locator.getPort());
+    createServer(properties, 3);
 
     // Verify all members have indexes
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_LIST_INDEX);
@@ -223,7 +242,11 @@ public class LuceneClusterConfigurationDUnitTest {
             "Initialized");
   }
 
-  private void createAndAddIndexes() throws Exception {
+  MemberVM createServer(Properties properties, int index) throws Exception {
+    return ls.startServerVM(index, properties, locator.getPort());
+  }
+
+  void createAndAddIndexes() throws Exception {
     // Create lucene index.
     createLuceneIndexUsingGfsh(INDEX_NAME + "0");
 
@@ -233,11 +256,9 @@ public class LuceneClusterConfigurationDUnitTest {
     // Create region
     createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
 
-    // Verify cluster configuration contains the indexes
-    locator.invoke(verifyClusterConfiguration(true));
   }
 
-  private SerializableRunnableIF verifyClusterConfiguration(boolean verifyIndexesExist) {
+  SerializableRunnableIF verifyClusterConfiguration(boolean verifyIndexesExist) {
     return () -> {
       InternalLocator internalLocator = ClusterStartupRule.getLocator();
       ClusterConfigurationService sc = internalLocator.getSharedConfiguration();
@@ -260,11 +281,11 @@ public class LuceneClusterConfigurationDUnitTest {
   }
 
 
-  private void createLuceneIndexUsingGfsh() throws Exception {
+  void createLuceneIndexUsingGfsh() throws Exception {
     createLuceneIndexUsingGfsh(INDEX_NAME);
   }
 
-  private void createLuceneIndexUsingGfsh(String indexName) throws Exception {
+  void createLuceneIndexUsingGfsh(String indexName) throws Exception {
     // Execute Gfsh command to create lucene index.
     CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, indexName);
@@ -273,7 +294,7 @@ public class LuceneClusterConfigurationDUnitTest {
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
-  private void createLuceneIndexWithAnalyzerUsingGfsh() throws Exception {
+  void createLuceneIndexWithAnalyzerUsingGfsh() throws Exception {
     // Gfsh command to create lucene index.
     CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
@@ -288,7 +309,7 @@ public class LuceneClusterConfigurationDUnitTest {
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
-  private void createLuceneIndexWithSerializerUsingGfsh(boolean addGroup) throws Exception {
+  void createLuceneIndexWithSerializerUsingGfsh() throws Exception {
     // Gfsh command to create lucene index.
     CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
@@ -311,7 +332,7 @@ public class LuceneClusterConfigurationDUnitTest {
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
-  private void createRegionUsingGfsh(String regionName, RegionShortcut regionShortCut, String group)
+  void createRegionUsingGfsh(String regionName, RegionShortcut regionShortCut, String group)
       throws Exception {
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
     csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest.java
new file mode 100644
index 0000000..672e2eb
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.geode.cache.lucene.internal.configuration;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+public class LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest
+    extends LuceneClusterConfigurationDUnitTest {
+
+  MemberVM[] servers = new MemberVM[3];
+
+  @Override
+  MemberVM createServer(int index) throws IOException {
+    servers[index - 1] = super.createServer(index);
+    servers[index - 1].invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    return servers[index - 1];
+
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    for (MemberVM server : servers) {
+      if (server != null) {
+        server.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+      }
+    }
+  }
+
+  @Override
+  void createLuceneIndexAndDataRegion() throws Exception {
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexUsingGfsh();
+  }
+
+  @Override
+  void createLuceneIndexWithAnalyzerAndDataRegion() throws Exception {
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithAnalyzerUsingGfsh();
+  }
+
+  @Override
+  void createAndAddIndexes() throws Exception {
+    // Create region
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+
+    // Create lucene index.
+    createLuceneIndexUsingGfsh(INDEX_NAME + "0");
+
+    // Create another lucene index.
+    createLuceneIndexUsingGfsh(INDEX_NAME + "1");
+
+  }
+
+  @Override
+  void createLuceneIndexWithSerializerAndDataRegion() throws Exception {
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithSerializerUsingGfsh();
+  }
+
+  @Override
+  MemberVM createServer(Properties properties, int index) throws Exception {
+    servers[index - 1] = super.createServer(properties, index);
+    servers[index - 1].getVM().invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    return servers[index - 1];
+  }
+}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWithReindexFlagEnabled.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWithReindexFlagEnabled.java
new file mode 100644
index 0000000..a2e25ba
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWithReindexFlagEnabled.java
@@ -0,0 +1,58 @@
+/*
+ * 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.geode.cache.lucene.internal.configuration;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+
+// Delete this file when LuceneServiceImpl.LUCENE_REINDEX flag is removed.
+@Category(DistributedTest.class)
+public class LuceneClusterConfigurationWithReindexFlagEnabled
+    extends LuceneClusterConfigurationDUnitTest {
+
+  MemberVM[] servers = new MemberVM[3];
+
+  @Override
+  MemberVM createServer(int index) throws IOException {
+    servers[index - 1] = super.createServer(index);
+    servers[index - 1].invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    return servers[index - 1];
+
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    for (MemberVM server : servers) {
+      if (server != null) {
+        server.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+      }
+    }
+  }
+
+  @Override
+  MemberVM createServer(Properties properties, int index) throws Exception {
+    servers[index - 1] = super.createServer(properties, index);
+    servers[index - 1].getVM().invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    return servers[index - 1];
+  }
+}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
index eef6ed1..cd1ec06 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
@@ -31,7 +31,6 @@ import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Declarable;
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.lucene.*;
 import org.apache.geode.cache.lucene.test.LuceneDeclarable2TestSerializer;
@@ -42,13 +41,25 @@ import org.apache.geode.test.junit.categories.IntegrationTest;
 @Category(IntegrationTest.class)
 public class LuceneIndexXmlGeneratorIntegrationJUnitTest {
 
-  private Cache cache;
+  protected Cache cache;
 
   @After
   public void closeCache() {
     cache.close();
   }
 
+  protected void createDataRegionAndLuceneIndex(LuceneService service) {
+    service.createIndexFactory().setFields("a", "b", "c").create("index", "region");
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+  }
+
+  protected void createDataRegionAndLuceneIndexWithSerializer(LuceneTestSerializer luceneSerializer,
+      LuceneService service) {
+    service.createIndexFactory().setLuceneSerializer(luceneSerializer).setFields("a", "b", "c")
+        .create("index", "region");
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+  }
+
   /**
    * Test of generating and reading cache configuration back in.
    */
@@ -56,8 +67,7 @@ public class LuceneIndexXmlGeneratorIntegrationJUnitTest {
   public void generateWithFields() {
     cache = new CacheFactory().set(MCAST_PORT, "0").create();
     LuceneService service = LuceneServiceProvider.get(cache);
-    service.createIndexFactory().setFields("a", "b", "c").create("index", "region");
-    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    createDataRegionAndLuceneIndex(service);
 
 
     LuceneIndex index = generateAndParseXml(service);
@@ -92,9 +102,7 @@ public class LuceneIndexXmlGeneratorIntegrationJUnitTest {
       LuceneDeclarable2TestSerializer luceneSerializer) {
     cache = new CacheFactory().set(MCAST_PORT, "0").create();
     LuceneService service = LuceneServiceProvider.get(cache);
-    service.createIndexFactory().setLuceneSerializer(luceneSerializer).setFields("a", "b", "c")
-        .create("index", "region");
-    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    createDataRegionAndLuceneIndexWithSerializer(luceneSerializer, service);
 
     LuceneIndex index = generateAndParseXml(service);
 
@@ -104,14 +112,11 @@ public class LuceneIndexXmlGeneratorIntegrationJUnitTest {
     return ((LuceneDeclarable2TestSerializer) testSerializer).getConfig();
   }
 
-
   @Test
   public void generateWithSerializer() {
     cache = new CacheFactory().set(MCAST_PORT, "0").create();
     LuceneService service = LuceneServiceProvider.get(cache);
-    service.createIndexFactory().setLuceneSerializer(new LuceneTestSerializer())
-        .setFields("a", "b", "c").create("index", "region");
-    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    createDataRegionAndLuceneIndexWithSerializer(new LuceneTestSerializer(), service);
 
     LuceneIndex index = generateAndParseXml(service);
 
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest.java
new file mode 100644
index 0000000..49e0a37
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.geode.cache.lucene.internal.xml;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.LuceneService;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.LuceneTestSerializer;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+@Category(IntegrationTest.class)
+public class LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest
+    extends LuceneIndexXmlGeneratorIntegrationJUnitTest {
+
+  @After
+  public void clearLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = false;
+  }
+
+  @Before
+  public void setLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = true;
+  }
+
+  protected void createDataRegionAndLuceneIndex(LuceneService service) {
+    super.cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    ((LuceneIndexFactoryImpl) service.createIndexFactory().setFields("a", "b", "c")).create("index",
+        "region", true);
+
+  }
+
+  protected void createDataRegionAndLuceneIndexWithSerializer(LuceneTestSerializer luceneSerializer,
+      LuceneService service) {
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    ((LuceneIndexFactoryImpl) service.createIndexFactory().setLuceneSerializer(luceneSerializer)
+        .setFields("a", "b", "c")).create("index", "region", true);
+  }
+
+}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest.java
new file mode 100644
index 0000000..6810596
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.geode.cache.lucene.internal.xml;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+@Category(IntegrationTest.class)
+public class LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest
+    extends LuceneIndexXmlGeneratorIntegrationJUnitTest {
+  // Delete this test file after when the feature flag LuceneServiceImpl.LUCENE_REINDEX is removed
+  // from the project.
+  @After
+  public void clearLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = false;
+  }
+
+  @Before
+  public void setLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = true;
+  }
+
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].