[ 
https://issues.apache.org/jira/browse/GEODE-4089?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16291736#comment-16291736
 ] 

Shelley Lynn Hughes-Godfrey commented on GEODE-4089:
----------------------------------------------------

To fix this issue in geode 1.2 and 1.3 ... cherry-pick this commit from 1.4 and 
modify one line to match the correct parameters:

```
commit 01dc11fc51bdaacefccf66f7d7d449a40a6e6a45
Author: Lynn Hughes-Godfrey <lhughesgodf...@pivotal.io>
Date:   Fri Nov 3 14:59:55 2017 -0700

    GEODE-3953: Incorrect use of .equals() for comparison of fieldname arrays
    GEODE-3954: Misleading Exception message with mismatched fieldAnalyzers

    - corrected equals comparisons of fieldname arrays
    - corrected Exception message for mismatched fieldAnalyzers to refer to 
field analyzers (vs. fieldnames) when remote and local fieldAnalyzers are 
different sizes
    - corrected Exception message to display fieldAnalyzers vs. fieldnames when 
remote and local fieldAnalyzer maps are different sizes
```

Adjust the parameters for this (by removing extra null at end):
```
+  private LuceneIndexCreationProfile 
getReverseFieldsLuceneIndexCreationProfile() {
+    return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME,
+        new String[] {"field2", "field1"}, new StandardAnalyzer(), null);
+  }
+
```

One could also add a new test in the newer version of geode to verify this:
```
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneSearchWithRollingUpgradeDUnit.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneSearchWithRollingUpgradeDUnit.java
index b622adf..238631c 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneSearchWithRollingUpgradeDUnit.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneSearchWithRollingUpgradeDUnit.java
@@ -19,10 +19,12 @@ import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Properties;
@@ -138,6 +140,12 @@ public class LuceneSearchWithRollingUpgradeDUnit extends 
JUnit4DistributedTestCa
     executeLuceneQueryWithServerRollOvers("persistentPartitioned", oldVersion);
   }
 
+  @Test
+  public void 
luceneQueryReturnsCorrectResultsAfterServersRollOverWithMultipleIndexedFields()
+      throws Exception {
+    executeLuceneQueryWithMultipleIndexedFields("partitionedRedundant", 
oldVersion);
+  }
+
   // 2 locator, 2 servers
   @Test
   public void 
luceneQueryReturnsCorrectResultAfterTwoLocatorsWithTwoServersAreRolled()
@@ -574,6 +582,108 @@ public class LuceneSearchWithRollingUpgradeDUnit extends 
JUnit4DistributedTestCa
     }
   }
 
+  // We start an "old" locator and old servers
+  // We roll the locator
+  // Now we roll all the servers from old to new
+  public void executeLuceneQueryWithMultipleIndexedFields(String regionType, 
String startingVersion)
+      throws Exception {
+    final Host host = Host.getHost(0);
+    VM server1 = host.getVM(startingVersion, 0);
+    VM server2 = host.getVM(startingVersion, 1);
+    VM server3 = host.getVM(startingVersion, 2);
+    VM locator = host.getVM(startingVersion, 3);
+
+
+    String regionName = "aRegion";
+    String shortcutName = null;
+    if ((regionType.equals("partitionedRedundant"))) {
+      shortcutName = RegionShortcut.PARTITION_REDUNDANT.name();
+    } else if ((regionType.equals("persistentPartitioned"))) {
+      shortcutName = RegionShortcut.PARTITION_PERSISTENT.name();
+      for (int i = 0; i < testingDirs.length; i++) {
+        testingDirs[i] = new File(diskDir, "diskStoreVM_" + 
String.valueOf(host.getVM(i).getId()))
+            .getAbsoluteFile();
+        if (!testingDirs[i].exists()) {
+          System.out.println(" Creating diskdir for server: " + i);
+          testingDirs[i].mkdirs();
+        }
+      }
+    }
+
+    int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(1);
+    String hostName = NetworkUtils.getServerHostName(host);
+    String locatorString = getLocatorString(locatorPorts);
+    final Properties locatorProps = new Properties();
+    // configure all class loaders for each vm
+
+    try {
+      locator.invoke(invokeStartLocator(hostName, locatorPorts[0], 
getTestMethodName(),
+          locatorString, locatorProps));
+      
invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), 
server1, server2,
+          server3);
+
+      // Create Lucene Indexes
+      final String[] fieldNames = {"status", "type"};
+      server1.invoke(() -> createLuceneIndex(cache, regionName, INDEX_NAME, 
fieldNames));
+      server2.invoke(() -> createLuceneIndex(cache, regionName, INDEX_NAME, 
fieldNames));
+      server3.invoke(() -> createLuceneIndex(cache, regionName, INDEX_NAME, 
fieldNames));
+
+      // create region
+      if ((regionType.equals("persistentPartitioned"))) {
+        for (int i = 0; i < testingDirs.length; i++) {
+          CacheSerializableRunnable runnable =
+              invokeCreatePersistentPartitionedRegion(regionName, 
testingDirs[i]);
+          invokeRunnableInVMs(runnable, host.getVM(i));
+        }
+      } else {
+        invokeRunnableInVMs(invokeCreateRegion(regionName, shortcutName), 
server1, server2,
+            server3);
+      }
+      int expectedRegionSize = 10;
+      putSerializableObjectAndVerifyLuceneQueryResult(server1, regionName, 
expectedRegionSize, 0,
+          10, server2, server3);
+      locator = rollLocatorToCurrent(locator, hostName, locatorPorts[0], 
getTestMethodName(),
+          locatorString);
+
+      String[] reversedFieldNames = {"type", "status"};
+      server1 = rollServerToCurrentAndCreateRegion(server1, regionType, 
testingDirs[0],
+          shortcutName, regionName, reversedFieldNames, locatorPorts);
+      verifyLuceneQueryResultInEachVM(regionName, expectedRegionSize, server1);
+      expectedRegionSize += 5;
+      putSerializableObjectAndVerifyLuceneQueryResult(server1, regionName, 
expectedRegionSize, 5,
+          15, server2, server3);
+      expectedRegionSize += 5;
+      putSerializableObjectAndVerifyLuceneQueryResult(server2, regionName, 
expectedRegionSize, 10,
+          20, server1, server3);
+
+      server2 = rollServerToCurrentAndCreateRegion(server2, regionType, 
testingDirs[1],
+          shortcutName, regionName, fieldNames, locatorPorts);
+      verifyLuceneQueryResultInEachVM(regionName, expectedRegionSize, server2);
+      expectedRegionSize += 5;
+      putSerializableObjectAndVerifyLuceneQueryResult(server2, regionName, 
expectedRegionSize, 15,
+          25, server1, server3);
+      expectedRegionSize += 5;
+      putSerializableObjectAndVerifyLuceneQueryResult(server3, regionName, 
expectedRegionSize, 20,
+          30, server2, server3);
+
+      server3 = rollServerToCurrentAndCreateRegion(server3, regionType, 
testingDirs[2],
+          shortcutName, regionName, fieldNames, locatorPorts);
+      verifyLuceneQueryResultInEachVM(regionName, expectedRegionSize, server3);
+      putSerializableObjectAndVerifyLuceneQueryResult(server3, regionName, 
expectedRegionSize, 15,
+          25, server1, server2);
+      putSerializableObjectAndVerifyLuceneQueryResult(server1, regionName, 
expectedRegionSize, 20,
+          30, server1, server2, server3);
+
+
+    } finally {
+      invokeRunnableInVMs(true, invokeStopLocator(), locator);
+      invokeRunnableInVMs(true, invokeCloseCache(), server1, server2, server3);
+      if ((regionType.equals("persistentPartitioned"))) {
+        deleteDiskStores();
+      }
+    }
+  }
+
   private void putSerializableObjectAndVerifyLuceneQueryResult(VM putter, 
String regionName,
       int expectedRegionSize, int start, int end, VM... vms) throws Exception {
     // do puts
@@ -617,7 +727,7 @@ public class LuceneSearchWithRollingUpgradeDUnit extends 
JUnit4DistributedTestCa
     Object luceneService = getLuceneService.invoke(luceneServiceProvider, 
cache);
     luceneService.getClass()
         .getMethod("waitUntilFlushed", String.class, String.class, long.class, 
TimeUnit.class)
-        .invoke(luceneService, INDEX_NAME, regionName, 60, TimeUnit.SECONDS);
+        .invoke(luceneService, INDEX_NAME, regionName, 120, TimeUnit.SECONDS);
     Method createLuceneQueryFactoryMethod =
         luceneService.getClass().getMethod("createLuceneQueryFactory");
     createLuceneQueryFactoryMethod.setAccessible(true);
@@ -687,8 +797,16 @@ public class LuceneSearchWithRollingUpgradeDUnit extends 
JUnit4DistributedTestCa
 
   private VM rollServerToCurrentAndCreateRegion(VM oldServer, String 
regionType, File diskdir,
       String shortcutName, String regionName, int[] locatorPorts) throws 
Exception {
+    final String[] fieldNames = {"status"};
+    return rollServerToCurrentAndCreateRegion(oldServer, regionType, diskdir, 
shortcutName,
+        regionName, fieldNames, locatorPorts);
+  }
+
+  private VM rollServerToCurrentAndCreateRegion(VM oldServer, String 
regionType, File diskdir,
+      String shortcutName, String regionName, String[] fieldNames, int[] 
locatorPorts)
+      throws Exception {
     VM rollServer = rollServerToCurrent(oldServer, locatorPorts);
-    rollServer.invoke(() -> createLuceneIndex(cache, regionName, INDEX_NAME));
+    rollServer.invoke(() -> createLuceneIndex(cache, regionName, INDEX_NAME, 
fieldNames));
     // recreate region on "rolled" server
     if ((regionType.equals("persistentPartitioned"))) {
       CacheSerializableRunnable runnable =
@@ -958,6 +1076,12 @@ public class LuceneSearchWithRollingUpgradeDUnit extends 
JUnit4DistributedTestCa
 
   public static void createLuceneIndex(Object cache, String regionName, String 
indexName)
       throws Exception {
+    final String[] fieldNames = {"status"};
+    createLuceneIndex(cache, regionName, indexName, fieldNames);
+  }
+
+  public static void createLuceneIndex(Object cache, String regionName, String 
indexName,
+      String[] fieldNames) throws Exception {
     Class luceneServiceProvider = 
Thread.currentThread().getContextClassLoader()
         .loadClass("org.apache.geode.cache.lucene.LuceneServiceProvider");
     Method getLuceneService = luceneServiceProvider.getMethod("get", 
GemFireCache.class);
@@ -966,8 +1090,8 @@ public class LuceneSearchWithRollingUpgradeDUnit extends 
JUnit4DistributedTestCa
         luceneService.getClass().getMethod("createIndexFactory");
     createLuceneIndexFactoryMethod.setAccessible(true);
     Object luceneIndexFactory = 
createLuceneIndexFactoryMethod.invoke(luceneService);
-    luceneIndexFactory.getClass().getMethod("addField", 
String.class).invoke(luceneIndexFactory,
-        "status");
+    luceneIndexFactory.getClass().getMethod("setFields", 
String[].class).invoke(luceneIndexFactory,
+        (Object) fieldNames);
     luceneIndexFactory.getClass().getMethod("create", String.class, 
String.class)
         .invoke(luceneIndexFactory, indexName, regionName);
   }
```

> Lucene create index can fail due to comparison of indexedFields as an array 
> (if order of indexes is different)
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: GEODE-4089
>                 URL: https://issues.apache.org/jira/browse/GEODE-4089
>             Project: Geode
>          Issue Type: Bug
>          Components: lucene
>    Affects Versions: 1.4.0
>            Reporter: Shelley Lynn Hughes-Godfrey
>            Assignee: Shelley Lynn Hughes-Godfrey
>
> This issue was fixed in geode 1.4 (GEODE-3953: Incorrect use of .equals() for 
> comparison of fieldname arrays), but given that this issue exists in earlier 
> versions, re-initialization of members creating lucene indexes can fail when 
> upgrading from 1.2 and 1.3 to 1.4 when there is a mix of old and new version 
> members in the Distributed System.
> {noformat}
> Cannot create Lucene index index on region /region with fields [field2, 
> field1] because another member defines the same index with fields [field1, 
> field2].
>     at org.junit.Assert.fail(Assert.java:88)
>     at org.junit.Assert.failNotEquals(Assert.java:834)
>     at org.junit.Assert.assertEquals(Assert.java:118)
>     at org.junit.Assert.assertEquals(Assert.java:144)
>     at 
> org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfileJUnitTest.testCheckCompatibility(LuceneIndexCreationProfileJUnitTest.java:64)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke(Method.java:497)
>     at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>     at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>     at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>     at 
> junitparams.internal.InvokeParameterisedMethod.evaluate(InvokeParameterisedMethod.java:234)
>     at 
> junitparams.internal.ParameterisedTestMethodRunner.runMethodInvoker(ParameterisedTestMethodRunner.java:47)
>     at 
> junitparams.internal.ParameterisedTestMethodRunner.runTestMethod(ParameterisedTestMethodRunner.java:40)
>     at 
> junitparams.internal.ParameterisedTestClassRunner.runParameterisedTest(ParameterisedTestClassRunner.java:146)
>     at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:417)
>     at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:386)
>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>     at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>     at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
>     at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to