geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject [4/7] geode git commit: GEODE-2823: The listener now forces a copy of the value to be made
Date Mon, 01 May 2017 21:59:28 GMT
GEODE-2823: The listener now forces a copy of the value to be made


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

Branch: refs/heads/feature/GEM-1353
Commit: 8da1ba353185c931d7d1626ca9e188b4f38d0761
Parents: 8239fbd
Author: Barry Oglesby <boglesby@pivotal.io>
Authored: Thu Apr 27 15:30:39 2017 -0700
Committer: Barry Oglesby <boglesby@pivotal.io>
Committed: Mon May 1 00:31:53 2017 -0700

----------------------------------------------------------------------
 .../geode/internal/cache/EntrySnapshot.java     |  6 ++-
 .../lucene/LuceneIndexExistsException.java      |  2 +-
 .../lucene/internal/LuceneEventListener.java    | 21 ++++++----
 .../internal/xml/LuceneIndexCreation.java       |  2 +-
 .../LuceneIndexMaintenanceIntegrationTest.java  | 43 ++++++++++++++++++++
 .../internal/LuceneEventListenerJUnitTest.java  |  6 +--
 6 files changed, 66 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/8da1ba35/geode-core/src/main/java/org/apache/geode/internal/cache/EntrySnapshot.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/EntrySnapshot.java b/geode-core/src/main/java/org/apache/geode/internal/cache/EntrySnapshot.java
index fba4eeb..00e9c67 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/EntrySnapshot.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/EntrySnapshot.java
@@ -98,12 +98,16 @@ public class EntrySnapshot implements Region.Entry, DataSerializable {
   }
 
   public Object getRawValue() {
+    return getRawValue(false);
+  }
+
+  public Object getRawValue(boolean forceCopy) {
     Object v = this.regionEntry.getValue(null);
     if (v == null) {
       return null;
     }
     if (v instanceof CachedDeserializable) {
-      if (region.isCopyOnRead()) {
+      if (region.isCopyOnRead() || forceCopy) {
         v = ((CachedDeserializable) v).getDeserializedWritableCopy(null, null);
       } else {
         v = ((CachedDeserializable) v).getDeserializedValue(null, null);

http://git-wip-us.apache.org/repos/asf/geode/blob/8da1ba35/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndexExistsException.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndexExistsException.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndexExistsException.java
index ad0d349..3c3ce7e 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndexExistsException.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndexExistsException.java
@@ -36,7 +36,7 @@ public class LuceneIndexExistsException extends GemFireException {
   @Override
   public String getMessage() {
     return LocalizedStrings.LuceneIndexExistsException_INDEX_0_ON_REGION_1_ALREADY_EXISTS
-        .toLocalizedString(new String[] {this.indexName, this.regionPath});
+        .toLocalizedString(this.indexName, this.regionPath);
   }
 
   public String getIndexName() {

http://git-wip-us.apache.org/repos/asf/geode/blob/8da1ba35/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 0f55533..c3fa2ff 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
@@ -22,6 +22,7 @@ import java.util.Set;
 
 import org.apache.geode.cache.EntryDestroyedException;
 import org.apache.geode.cache.Region.Entry;
+import org.apache.geode.internal.cache.EntrySnapshot;
 import org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue;
 import org.apache.logging.log4j.Logger;
 import org.apache.geode.cache.CacheClosedException;
@@ -89,14 +90,7 @@ public class LuceneEventListener implements AsyncEventListener {
 
         IndexRepository repository = repositoryManager.getRepository(region, key, callbackArgument);
 
-        final Entry entry = region.getEntry(key);
-        Object value;
-        try {
-          value = entry == null ? null : entry.getValue();
-        } catch (EntryDestroyedException e) {
-          value = null;
-        }
-
+        Object value = getValue(region.getEntry(key));
         if (value != null) {
           repository.update(key, value);
         } else {
@@ -126,6 +120,17 @@ public class LuceneEventListener implements AsyncEventListener {
     }
   }
 
+  private Object getValue(Region.Entry entry) {
+    final EntrySnapshot es = (EntrySnapshot) entry;
+    Object value;
+    try {
+      value = es == null ? null : es.getRawValue(true);
+    } catch (EntryDestroyedException e) {
+      value = null;
+    }
+    return value;
+  }
+
   public static void setExceptionObserver(LuceneExceptionObserver observer) {
     if (observer == null) {
       observer = exception -> {

http://git-wip-us.apache.org/repos/asf/geode/blob/8da1ba35/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
index 06ece3b..30e6b04 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
@@ -94,7 +94,7 @@ public class LuceneIndexCreation implements LuceneIndex, Extension<Region<?,
?>>
     } catch (LuceneIndexExistsException e) {
       logger
           .info(LocalizedStrings.LuceneIndexCreation_IGNORING_DUPLICATE_INDEX_CREATION_0_ON_REGION_1
-              .toLocalizedString(new String[] {e.getIndexName(), e.getRegionPath()}));
+              .toLocalizedString(e.getIndexName(), e.getRegionPath()));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/8da1ba35/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
index f5bd83f..f9273c1 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
@@ -18,8 +18,13 @@ import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
 import static org.junit.Assert.*;
 
 import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.geode.internal.cache.CachedDeserializable;
+import org.apache.geode.internal.cache.EntrySnapshot;
+import org.apache.geode.internal.cache.RegionEntry;
 import org.awaitility.Awaitility;
 
 import org.junit.Test;
@@ -216,6 +221,31 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
     assertEquals(4, index.getIndexStats().getCommits());
   }
 
+  @Test
+  public void entriesKeptInSerializedFormInDataRegion() throws InterruptedException {
+    // Create index and region
+    luceneService.createIndexFactory().setFields("title", "description").create(INDEX_NAME,
+        REGION_NAME);
+    Region region = createRegion(REGION_NAME, RegionShortcut.PARTITION);
+
+    // Pause sender
+    LuceneTestUtilities.pauseSender(cache);
+
+    // Do puts
+    populateRegion(region);
+
+    // Verify values are in serialized form
+    verifySerializedValues(region);
+
+    // Resume sender and wait for flushed
+    LuceneTestUtilities.resumeSender(cache);
+    assertTrue(luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, WAIT_FOR_FLUSH_TIME,
+        TimeUnit.MILLISECONDS));
+
+    // Verify values are still in serialized form
+    verifySerializedValues(region);
+  }
+
   private void populateRegion(Region region) {
     region.put("object-1", new TestObject("title 1", "hello world"));
     region.put("object-2", new TestObject("title 2", "this will not match"));
@@ -223,6 +253,19 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
     region.put("object-4", new TestObject("hello world", "hello world"));
   }
 
+  private void verifySerializedValues(Region region) {
+    Set entries = region.entrySet();
+    assertFalse(entries.isEmpty());
+    for (Iterator i = entries.iterator(); i.hasNext();) {
+      EntrySnapshot entry = (EntrySnapshot) i.next();
+      RegionEntry re = entry.getRegionEntry();
+      Object reValue = re.getValue(null);
+      assertTrue(reValue instanceof CachedDeserializable);
+      Object cdValue = ((CachedDeserializable) reValue).getValue();
+      assertTrue(cdValue instanceof byte[]);
+    }
+  }
+
   private void await(Runnable runnable) {
     Awaitility.await().atMost(30, TimeUnit.SECONDS).until(runnable);
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/8da1ba35/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 79de29a..801f6b6 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,7 +27,7 @@ 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.EntrySnapshot;
 import org.apache.geode.internal.cache.RegionEntry;
 import org.junit.After;
 import org.junit.Before;
@@ -85,8 +85,8 @@ public class LuceneEventListenerJUnitTest {
       switch (i % 4) {
         case 0:
         case 1:
-          final Entry entry = mock(Entry.class);
-          when(entry.getValue()).thenReturn(i);
+          final EntrySnapshot entry = mock(EntrySnapshot.class);
+          when(entry.getRawValue(true)).thenReturn(i);
           when(region.getEntry(eq(i))).thenReturn(entry);
           break;
         case 2:


Mime
View raw message