You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2017/03/16 18:36:16 UTC

geode git commit: GEODE-2674: Changing the lucene listener to fetch the value from the region

Repository: geode
Updated Branches:
  refs/heads/develop f329f4a54 -> 1602a2683


GEODE-2674: Changing the lucene listener to fetch the value from the region

Rather than use the value that is in the queue, use the latest value
from the region to update the lucene index.

This ensures that even if the queue contains spurious events due to
retries or other issues, we put the correct value in the index.

This also potentially saves memory and disk space for the queue, because
the queue does not need to hold the value for the entry.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/1602a268
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/1602a268
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/1602a268

Branch: refs/heads/develop
Commit: 1602a2683408ef608554d4c22a8e7c8c61f3e946
Parents: f329f4a
Author: Dan Smith <up...@apache.org>
Authored: Wed Mar 15 13:23:20 2017 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Thu Mar 16 11:29:18 2017 -0700

----------------------------------------------------------------------
 .../lucene/internal/LuceneEventListener.java    | 23 ++++++------
 .../internal/LuceneEventSubstitutionFilter.java | 37 ++++++++++++++++++++
 .../cache/lucene/internal/LuceneIndexImpl.java  |  1 +
 .../internal/LuceneEventListenerJUnitTest.java  | 24 ++++++-------
 4 files changed, 63 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/1602a268/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventListener.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventListener.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventListener.java
index 2943ce8..0f55533 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventListener.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventListener.java
@@ -20,6 +20,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.geode.cache.EntryDestroyedException;
+import org.apache.geode.cache.Region.Entry;
 import org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue;
 import org.apache.logging.log4j.Logger;
 import org.apache.geode.cache.CacheClosedException;
@@ -87,19 +89,20 @@ public class LuceneEventListener implements AsyncEventListener {
 
         IndexRepository repository = repositoryManager.getRepository(region, key, callbackArgument);
 
-        Operation op = event.getOperation();
+        final Entry entry = region.getEntry(key);
+        Object value;
+        try {
+          value = entry == null ? null : entry.getValue();
+        } catch (EntryDestroyedException e) {
+          value = null;
+        }
 
-        if (op.isCreate()) {
-          repository.update(key, event.getDeserializedValue());
-        } else if (op.isUpdate()) {
-          repository.update(key, event.getDeserializedValue());
-        } else if (op.isDestroy()) {
-          repository.delete(key);
-        } else if (op.isInvalidate()) {
-          repository.delete(key);
+        if (value != null) {
+          repository.update(key, value);
         } else {
-          throw new InternalGemFireError("Unhandled operation " + op + " on " + event.getRegion());
+          repository.delete(key);
         }
+
         affectedRepos.add(repository);
       }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/1602a268/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventSubstitutionFilter.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventSubstitutionFilter.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventSubstitutionFilter.java
new file mode 100644
index 0000000..04a465a
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneEventSubstitutionFilter.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import org.apache.geode.cache.EntryEvent;
+import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter;
+import org.apache.geode.internal.cache.Token;
+
+/**
+ * A substitution filter which throws away the value of the entry and replaces it with an empty
+ * string. For the lucene index, we will just fetch the new value from the region, so we don't need
+ * the value.
+ */
+public class LuceneEventSubstitutionFilter implements GatewayEventSubstitutionFilter {
+  @Override
+  public Object getSubstituteValue(final EntryEvent event) {
+    return "";
+  }
+
+  @Override
+  public void close() {
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/1602a268/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
index 0c9d220..66dc1f9 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
@@ -180,6 +180,7 @@ public abstract class LuceneIndexImpl implements InternalLuceneIndex {
       return null;
     }
     LuceneEventListener listener = new LuceneEventListener(repositoryManager);
+    factory.setGatewayEventSubstitutionListener(new LuceneEventSubstitutionFilter());
     String aeqId = LuceneServiceImpl.getUniqueIndexName(getName(), regionPath);
     AsyncEventQueue indexQueue = factory.create(aeqId, listener);
     return indexQueue;

http://git-wip-us.apache.org/repos/asf/geode/blob/1602a268/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneEventListenerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneEventListenerJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneEventListenerJUnitTest.java
index 0320068..79de29a 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneEventListenerJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneEventListenerJUnitTest.java
@@ -27,6 +27,8 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.geode.InternalGemFireError;
+import org.apache.geode.cache.Region.Entry;
+import org.apache.geode.internal.cache.RegionEntry;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -80,18 +82,16 @@ public class LuceneEventListenerJUnitTest {
       Mockito.when(event.getKey()).thenReturn(i);
       Mockito.when(event.getCallbackArgument()).thenReturn(callback);
 
-      switch (i % 3) {
+      switch (i % 4) {
         case 0:
-          Mockito.when(event.getOperation()).thenReturn(Operation.CREATE);
-          Mockito.when(event.getDeserializedValue()).thenReturn(i);
-          break;
         case 1:
-          Mockito.when(event.getOperation()).thenReturn(Operation.UPDATE);
-          Mockito.when(event.getDeserializedValue()).thenReturn(i);
+          final Entry entry = mock(Entry.class);
+          when(entry.getValue()).thenReturn(i);
+          when(region.getEntry(eq(i))).thenReturn(entry);
           break;
         case 2:
-          Mockito.when(event.getOperation()).thenReturn(Operation.DESTROY);
-          Mockito.when(event.getDeserializedValue()).thenThrow(new AssertionError());
+        case 3:
+          // Do nothing, get value will return a destroy
           break;
       }
 
@@ -100,10 +100,10 @@ public class LuceneEventListenerJUnitTest {
 
     listener.processEvents(events);
 
-    verify(repo1, atLeast(numEntries / 6)).delete(any());
-    verify(repo1, atLeast(numEntries / 3)).update(any(), any());
-    verify(repo2, atLeast(numEntries / 6)).delete(any());
-    verify(repo2, atLeast(numEntries / 3)).update(any(), any());
+    verify(repo1, atLeast(numEntries / 4)).delete(any());
+    verify(repo1, atLeast(numEntries / 4)).update(any(), any());
+    verify(repo2, atLeast(numEntries / 4)).delete(any());
+    verify(repo2, atLeast(numEntries / 4)).update(any(), any());
     verify(repo1, times(1)).commit();
     verify(repo2, times(1)).commit();
   }