geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esh...@apache.org
Subject [geode] 01/02: Revert "Revert "GEODE-4200: get cache from DM instead of using singleton.""
Date Sat, 13 Jan 2018 00:52:52 GMT
This is an automated email from the ASF dual-hosted git repository.

eshu11 pushed a commit to branch feature/GEODE-3583-storage
in repository https://gitbox.apache.org/repos/asf/geode.git

commit e39a349463abc81dac33661dc20c294b8bf05cec
Author: eshu <eshu@pivotal.io>
AuthorDate: Fri Jan 12 15:45:02 2018 -0800

    Revert "Revert "GEODE-4200: get cache from DM instead of using singleton.""
    
    This reverts commit 97474deb5c72bf3db35bfb44cac038707ba51a95.
---
 .../internal/cache/CacheDistributionAdvisor.java   |  2 +-
 .../internal/cache/InitialImageOperation.java      | 62 +++++++++++++++++-----
 .../apache/geode/internal/cache/LocalRegion.java   | 16 ------
 .../geode/internal/cache/TXCommitMessage.java      | 10 ++--
 ...rInfoMessageTest.java => CacheProfileTest.java} | 35 +++++++++---
 ...ageTest.java => InitialImageOperationTest.java} | 32 ++++++++---
 ...rInfoMessageTest.java => RegionCommitTest.java} | 34 +++++++++---
 .../cache/RequestFilterInfoMessageTest.java        | 30 +++++++++++
 8 files changed, 169 insertions(+), 52 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheDistributionAdvisor.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheDistributionAdvisor.java
index 5dcf6d9..f4872dc 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheDistributionAdvisor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheDistributionAdvisor.java
@@ -752,7 +752,7 @@ public class CacheDistributionAdvisor extends DistributionAdvisor {
         LocalRegion lclRgn;
         int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
         try {
-          lclRgn = LocalRegion.getRegionFromPath(dm.getSystem(), adviseePath);
+          lclRgn = dm.getCache().getRegionByPath(adviseePath);
         } finally {
           LocalRegion.setThreadInitLevelRequirement(oldLevel);
         }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
index b8c9ff2..8ae830b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
@@ -15,14 +15,34 @@
 
 package org.apache.geode.internal.cache;
 
-import java.io.*;
-import java.util.*;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.logging.log4j.Logger;
 
-import org.apache.geode.*;
+import org.apache.geode.CancelException;
+import org.apache.geode.DataSerializable;
+import org.apache.geode.DataSerializer;
+import org.apache.geode.InternalGemFireError;
+import org.apache.geode.InternalGemFireException;
+import org.apache.geode.SystemFailure;
 import org.apache.geode.cache.DiskAccessException;
 import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.query.internal.CqStateImpl;
@@ -30,10 +50,23 @@ import org.apache.geode.cache.query.internal.DefaultQueryService;
 import org.apache.geode.cache.query.internal.cq.CqService;
 import org.apache.geode.cache.query.internal.cq.ServerCQ;
 import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.*;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.distributed.internal.DistributionMessage;
+import org.apache.geode.distributed.internal.HighPriorityDistributionMessage;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.MessageWithReply;
+import org.apache.geode.distributed.internal.ReplyException;
+import org.apache.geode.distributed.internal.ReplyMessage;
+import org.apache.geode.distributed.internal.ReplyProcessor21;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
-import org.apache.geode.internal.*;
+import org.apache.geode.internal.Assert;
+import org.apache.geode.internal.ByteArrayDataInput;
+import org.apache.geode.internal.DataSerializableFixedID;
+import org.apache.geode.internal.InternalDataSerializer;
+import org.apache.geode.internal.NullDataOutputStream;
+import org.apache.geode.internal.Version;
 import org.apache.geode.internal.cache.InitialImageFlowControl.FlowControlPermitMessage;
 import org.apache.geode.internal.cache.entries.DiskEntry;
 import org.apache.geode.internal.cache.ha.HAContainerWrapper;
@@ -43,7 +76,13 @@ import org.apache.geode.internal.cache.tier.InterestType;
 import org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier;
 import org.apache.geode.internal.cache.tier.sockets.CacheClientProxy;
 import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
-import org.apache.geode.internal.cache.versions.*;
+import org.apache.geode.internal.cache.versions.DiskRegionVersionVector;
+import org.apache.geode.internal.cache.versions.DiskVersionTag;
+import org.apache.geode.internal.cache.versions.RegionVersionHolder;
+import org.apache.geode.internal.cache.versions.RegionVersionVector;
+import org.apache.geode.internal.cache.versions.VersionSource;
+import org.apache.geode.internal.cache.versions.VersionStamp;
+import org.apache.geode.internal.cache.versions.VersionTag;
 import org.apache.geode.internal.cache.vmotion.VMotionObserverHolder;
 import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
 import org.apache.geode.internal.i18n.LocalizedStrings;
@@ -1435,13 +1474,11 @@ public class InitialImageOperation {
     int initLevel = targetReinitialized ? LocalRegion.AFTER_INITIAL_IMAGE : LocalRegion.ANY_INIT;
     int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
     try {
-      DistributedSystem system = dm.getSystem();
-      // GemFireCache cache = (GemFireCache)CacheFactory.getInstance(system);
       if (isDebugEnabled) {
         logger.debug("RequestImageMessage: attempting to get region reference for {}, initLevel={}",
             regionPath, initLevel);
       }
-      lclRgn = LocalRegion.getRegionFromPath(system, regionPath);
+      lclRgn = dm.getCache().getRegionByPath(regionPath);
       // if this is a targeted getInitialImage after a region was initialized,
       // make sure this is the region that was reinitialized.
       if (lclRgn != null && !lclRgn.isUsedForPartitionedRegionBucket() &&
targetReinitialized
@@ -1464,7 +1501,7 @@ public class InitialImageOperation {
       return null;
     }
 
-    if (lclRgn.scope.isLocal()) {
+    if (lclRgn.getScope().isLocal()) {
       if (isDebugEnabled) {
         logger.debug("local scope region, nothing to do");
       }
@@ -2197,8 +2234,7 @@ public class InitialImageOperation {
       ReplyException rex = null;
       try {
         Assert.assertTrue(this.regionPath != null, "Region path is null.");
-        DistributedSystem system = dm.getSystem();
-        lclRgn = LocalRegion.getRegionFromPath(system, this.regionPath);
+        lclRgn = dm.getCache().getRegionByPath(regionPath);
 
         if (lclRgn == null) {
           if (logger.isDebugEnabled()) {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index cbd45ee..7bc04da 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -144,7 +144,6 @@ import org.apache.geode.cache.query.internal.index.IndexUtils;
 import org.apache.geode.cache.util.ObjectSizer;
 import org.apache.geode.cache.wan.GatewaySender;
 import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.distributed.internal.DistributionAdvisor;
 import org.apache.geode.distributed.internal.DistributionAdvisor.Profile;
 import org.apache.geode.distributed.internal.DistributionConfig;
@@ -2264,21 +2263,6 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
   }
 
   /**
-   * Look up the LocalRegion with the specified full path.
-   *
-   * @param system the distributed system whose cache contains the root of interest
-   * @return the LocalRegion or null if not found
-   */
-  static LocalRegion getRegionFromPath(DistributedSystem system, String path) {
-    Cache cache = GemFireCacheImpl.getInstance();
-    if (cache == null) {
-      return null;
-    } else {
-      return (LocalRegion) cache.getRegion(path);
-    }
-  }
-
-  /**
    * Do any extra initialization required. Region is already visible in parent's subregion
map. This
    * method releases the initialization Latches, so subclasses should call this super method
last
    * after performing additional initialization.
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
index f0f7f14..fd8b7ca 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
@@ -1172,9 +1172,9 @@ public class TXCommitMessage extends PooledDistributionMessage
     }
 
     private boolean hookupRegion(DistributionManager dm) {
-      this.r = LocalRegion.getRegionFromPath(dm.getSystem(), this.regionPath);
+      this.r = getRegionByPath(dm, regionPath);
       if (this.r == null && this.parentRegionPath != null) {
-        this.r = LocalRegion.getRegionFromPath(dm.getSystem(), this.parentRegionPath);
+        this.r = getRegionByPath(dm, this.parentRegionPath);
         this.regionPath = this.parentRegionPath;
       }
       if (this.r == null && dm.getSystem().isLoner()) {
@@ -1186,6 +1186,10 @@ public class TXCommitMessage extends PooledDistributionMessage
       return true;
     }
 
+    LocalRegion getRegionByPath(DistributionManager dm, String regionPath) {
+      return dm.getCache().getRegionByPath(regionPath);
+    }
+
     /**
      * Called when processing is complete; only needs to be called if beginProcess returned
true.
      */
@@ -1355,7 +1359,7 @@ public class TXCommitMessage extends PooledDistributionMessage
 
 
     public boolean isForceFireEvent(DistributionManager dm) {
-      LocalRegion r = LocalRegion.getRegionFromPath(dm.getSystem(), this.regionPath);
+      LocalRegion r = dm.getCache().getRegionByPath(regionPath);
       if (r instanceof PartitionedRegion || (r != null && r.isUsedForPartitionedRegionBucket()))
{
         return false;
       }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/CacheProfileTest.java
similarity index 52%
copy from geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
copy to geode-core/src/test/java/org/apache/geode/internal/cache/CacheProfileTest.java
index 062b0f0..d9b400f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/CacheProfileTest.java
@@ -14,23 +14,44 @@
  */
 package org.apache.geode.internal.cache;
 
-import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.internal.cache.InitialImageOperation.RequestFilterInfoMessage;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile;
 import org.apache.geode.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
-public class RequestFilterInfoMessageTest {
+public class CacheProfileTest {
+
+  private ClusterDistributionManager dm;
+  private InternalCache cache;
+  private String adviseePath;
+  private LocalRegion region;
+
+  @Before
+  public void setUp() {
+    adviseePath = "adviseePath";
+
+    dm = mock(ClusterDistributionManager.class);
+    cache = mock(InternalCache.class);
+    region = mock(LocalRegion.class);
+
+    when(dm.getCache()).thenReturn(cache);
+    when(cache.getRegionByPath(adviseePath)).thenReturn(region);
+  }
 
   @Test
-  public void shouldBeMockable() throws Exception {
-    RequestFilterInfoMessage mockRequestFilterInfoMessage = mock(RequestFilterInfoMessage.class);
-    when(mockRequestFilterInfoMessage.getProcessorType()).thenReturn(1);
-    assertThat(mockRequestFilterInfoMessage.getProcessorType()).isEqualTo(1);
+  public void getsRegionFromCacheFromDM() {
+    CacheProfile profile = new CacheProfile();
+    profile.processIncoming(dm, adviseePath, false, false, null);
+    verify(dm, times(1)).getCache();
+    verify(cache, times(1)).getRegionByPath(adviseePath);
   }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
similarity index 56%
copy from geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
copy to geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
index 062b0f0..af98d9c 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
@@ -18,19 +18,39 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.internal.cache.InitialImageOperation.RequestFilterInfoMessage;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
 import org.apache.geode.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
-public class RequestFilterInfoMessageTest {
+public class InitialImageOperationTest {
+
+  private ClusterDistributionManager dm;
+  private String path;
+  private LocalRegion region;
+  private InternalCache cache;
+
+  @Before
+  public void setUp() {
+    path = "path";
+
+    cache = mock(InternalCache.class);
+    dm = mock(ClusterDistributionManager.class);
+    region = mock(LocalRegion.class);
+
+    when(dm.getCache()).thenReturn(cache);
+    when(cache.getRegionByPath(path)).thenReturn(region);
+    when(region.isInitialized()).thenReturn(true);
+    when(region.getScope()).thenReturn(Scope.DISTRIBUTED_ACK);
+  }
 
   @Test
-  public void shouldBeMockable() throws Exception {
-    RequestFilterInfoMessage mockRequestFilterInfoMessage = mock(RequestFilterInfoMessage.class);
-    when(mockRequestFilterInfoMessage.getProcessorType()).thenReturn(1);
-    assertThat(mockRequestFilterInfoMessage.getProcessorType()).isEqualTo(1);
+  public void getsRegionFromCacheFromDM() {
+    LocalRegion value = InitialImageOperation.getGIIRegion(dm, path, false);
+    assertThat(value).isSameAs(region);
   }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/RegionCommitTest.java
similarity index 52%
copy from geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
copy to geode-core/src/test/java/org/apache/geode/internal/cache/RegionCommitTest.java
index 062b0f0..7f4fae8 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/RegionCommitTest.java
@@ -18,19 +18,41 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.internal.cache.InitialImageOperation.RequestFilterInfoMessage;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.TXCommitMessage.RegionCommit;
 import org.apache.geode.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
-public class RequestFilterInfoMessageTest {
+public class RegionCommitTest {
+
+  private ClusterDistributionManager dm;
+  private String path;
+  private LocalRegion region;
+  private TXCommitMessage txCommitMessage;
+
+  @Before
+  public void setUp() {
+    path = "path";
+
+    InternalCache cache = mock(InternalCache.class);
+
+    dm = mock(ClusterDistributionManager.class);
+    region = mock(LocalRegion.class);
+    txCommitMessage = mock(TXCommitMessage.class);
+
+    when(dm.getCache()).thenReturn(cache);
+    when(cache.getRegionByPath(path)).thenReturn(region);
+    when(dm.getSystem()).thenReturn(mock(InternalDistributedSystem.class));
+  }
 
   @Test
-  public void shouldBeMockable() throws Exception {
-    RequestFilterInfoMessage mockRequestFilterInfoMessage = mock(RequestFilterInfoMessage.class);
-    when(mockRequestFilterInfoMessage.getProcessorType()).thenReturn(1);
-    assertThat(mockRequestFilterInfoMessage.getProcessorType()).isEqualTo(1);
+  public void getsRegionFromCacheFromDM() {
+    RegionCommit regionCommit = new RegionCommit(txCommitMessage);
+    assertThat(regionCommit.getRegionByPath(dm, path)).isEqualTo(region);
   }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
index 062b0f0..31238af 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/RequestFilterInfoMessageTest.java
@@ -16,21 +16,51 @@ package org.apache.geode.internal.cache;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
 import org.apache.geode.internal.cache.InitialImageOperation.RequestFilterInfoMessage;
 import org.apache.geode.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class RequestFilterInfoMessageTest {
 
+  private ClusterDistributionManager dm;
+  private InternalCache cache;
+  private String path;
+  private LocalRegion region;
+
+  @Before
+  public void setUp() {
+    path = "path";
+
+    dm = mock(ClusterDistributionManager.class);
+    cache = mock(InternalCache.class);
+    region = mock(LocalRegion.class);
+
+    when(dm.getCache()).thenReturn(cache);
+    when(cache.getRegionByPath(path)).thenReturn(region);
+  }
+
   @Test
   public void shouldBeMockable() throws Exception {
     RequestFilterInfoMessage mockRequestFilterInfoMessage = mock(RequestFilterInfoMessage.class);
     when(mockRequestFilterInfoMessage.getProcessorType()).thenReturn(1);
     assertThat(mockRequestFilterInfoMessage.getProcessorType()).isEqualTo(1);
   }
+
+  @Test
+  public void getsRegionFromCacheFromDM() {
+    RequestFilterInfoMessage message = new RequestFilterInfoMessage();
+    message.regionPath = path;
+    message.process(dm);
+    verify(dm, times(1)).getCache();
+    verify(cache, times(1)).getRegionByPath(path);
+  }
 }

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

Mime
View raw message