geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-3598) refactor org.apache.geode.internal.cache.DestroyRegionOperation.DestroyRegionMessage.getRegionFromPath(InternalDistributedSystem, String) to not call CacheFactory.getinstance
Date Thu, 09 Nov 2017 18:42:00 GMT

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

ASF GitHub Bot commented on GEODE-3598:
---------------------------------------

dschneider-pivotal closed pull request #1035: GEODE-3598: remove getInstance calls
URL: https://github.com/apache/geode/pull/1035
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
index 1ce742188b..43de293c18 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DM.java
@@ -24,6 +24,8 @@
 import java.util.concurrent.ExecutorService;
 
 import org.apache.geode.CancelCriterion;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.Role;
 import org.apache.geode.distributed.internal.locks.ElderState;
@@ -464,7 +466,22 @@ public void addHostedLocators(InternalDistributedMember member, Collection<Strin
 
   int getDMType();
 
+  /**
+   * The returned cache will be null if the cache does not yet exist. Note that the returned
cache
+   * may be one that is already closed. Callers of GemFireCacheImpl.getInstance() should
try to use
+   * this method.
+   */
   InternalCache getCache();
 
+  /**
+   * Returns an existing non-closed cache associated with this DM. Callers of
+   * CacheFactory.getAnyInstance(), CacheFactory.getInstance(DistributedSystem) or
+   * GemFireCacheImpl.getExisting() should try to use this method.
+   *
+   * @throws CacheClosedException if a cache has not yet been associated with this DM or
it has been
+   *         {@link Cache#isClosed closed}.
+   */
+  InternalCache getExistingCache();
+
   void setCache(InternalCache instance);
 }
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
index 339d673605..6130e12f71 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionManager.java
@@ -53,6 +53,7 @@
 import org.apache.geode.SystemFailure;
 import org.apache.geode.ToDataException;
 import org.apache.geode.admin.GemFireHealthConfig;
+import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.DistributedSystemDisconnectedException;
 import org.apache.geode.distributed.Locator;
@@ -3939,7 +3940,7 @@ public String getDistributionConfigDescription() {
   /* -----------------------------Health Monitor------------------------------ */
   private final ConcurrentMap hmMap = new ConcurrentHashMap();
 
-  private InternalCache cache;
+  private volatile InternalCache cache;
 
   /**
    * Returns the health monitor for this distribution manager and owner.
@@ -4820,4 +4821,19 @@ public void setCache(InternalCache instance) {
   public InternalCache getCache() {
     return this.cache;
   }
+
+  @Override
+  public InternalCache getExistingCache() {
+    InternalCache result = this.cache;
+    if (result == null) {
+      throw new CacheClosedException(
+          LocalizedStrings.CacheFactory_A_CACHE_HAS_NOT_YET_BEEN_CREATED.toLocalizedString());
+    }
+    result.getCancelCriterion().checkCancelInProgress(null);
+    if (result.isClosed()) {
+      throw result.getCacheClosedException(
+          LocalizedStrings.CacheFactory_THE_CACHE_HAS_BEEN_CLOSED.toLocalizedString(), null);
+    }
+    return result;
+  }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/LonerDistributionManager.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/LonerDistributionManager.java
index 8bbe019889..ffe4054d16 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/LonerDistributionManager.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/LonerDistributionManager.java
@@ -22,6 +22,7 @@
 
 import org.apache.geode.CancelCriterion;
 import org.apache.geode.InternalGemFireError;
+import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.DurableClientAttributes;
 import org.apache.geode.distributed.Role;
@@ -1249,7 +1250,7 @@ public RuntimeException generateCancelledException(Throwable e) {
   }
 
   private final Stopper stopper = new Stopper();
-  private InternalCache cache;
+  private volatile InternalCache cache;
 
   public CancelCriterion getCancelCriterion() {
     return stopper;
@@ -1379,12 +1380,27 @@ public boolean isSharedConfigurationServiceEnabledForDS() {
   }
 
   @Override
+  public void setCache(InternalCache instance) {
+    this.cache = instance;
+  }
+
+  @Override
   public InternalCache getCache() {
     return this.cache;
   }
 
   @Override
-  public void setCache(InternalCache instance) {
-    this.cache = instance;
+  public InternalCache getExistingCache() {
+    InternalCache result = this.cache;
+    if (result == null) {
+      throw new CacheClosedException(
+          LocalizedStrings.CacheFactory_A_CACHE_HAS_NOT_YET_BEEN_CREATED.toLocalizedString());
+    }
+    result.getCancelCriterion().checkCancelInProgress(null);
+    if (result.isClosed()) {
+      throw result.getCacheClosedException(
+          LocalizedStrings.CacheFactory_THE_CACHE_HAS_BEEN_CLOSED.toLocalizedString(), null);
+    }
+    return result;
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyRegionOperation.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyRegionOperation.java
index e92367829e..1e245886c1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyRegionOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyRegionOperation.java
@@ -166,7 +166,6 @@ private Runnable destroyOp(final DistributionManager dm, final LocalRegion
lclRg
         public void run() {
           final int oldLevel =
               LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
-          // do this before CacheFactory.getInstance for bug 33471
 
           Throwable thr = null;
           try {
@@ -177,9 +176,8 @@ public void run() {
               boolean waitForBucketInitializationToComplete = true;
               CacheDistributionAdvisee advisee = null;
               try {
-                advisee =
-                    PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(),
-                        regionPath, waitForBucketInitializationToComplete);
+                advisee = PartitionedRegionHelper.getProxyBucketRegion(dm.getCache(), regionPath,
+                    waitForBucketInitializationToComplete);
               } catch (PRLocallyDestroyedException ignore) {
                 // region not found - it's been destroyed
               } catch (RegionDestroyedException ignore) {
@@ -202,7 +200,7 @@ public void run() {
             } // lclRegion == null
 
             // refetch to use special destroy region logic
-            final LocalRegion lr = getRegionFromPath(dm.getSystem(), lclRgn.getFullPath());
+            final LocalRegion lr = getRegionFromPath(dm, lclRgn.getFullPath());
             if (lr == null) {
               if (logger.isDebugEnabled())
                 logger.debug("{} region not found, nothing to do", this);
@@ -295,12 +293,12 @@ protected void basicProcess(final DistributionManager dm, final LocalRegion
lclR
       }
     }
 
-    protected LocalRegion getRegionFromPath(InternalDistributedSystem sys, String path) {
+    protected LocalRegion getRegionFromPath(DistributionManager dm, String path) {
       // allow a destroyed region to be returned if we're dealing with a
       // shared region, since another cache may
       // have already destroyed it in shared memory, in which our listeners
       // still need to be called and java region object cleaned up.
-      InternalCache cache = (InternalCache) CacheFactory.getInstance(sys);
+      InternalCache cache = dm.getExistingCache();
 
       // only get the region while holding the appropriate destroy lock.
       // this prevents us from getting a "stale" region
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index e8aac768ac..36c07d1d09 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -676,7 +676,12 @@ public void write(int i) {
   /** Map of Futures used to track Regions that are being reinitialized */
   private final ConcurrentMap reinitializingRegions = new ConcurrentHashMap();
 
-  /** Returns the last created instance of GemFireCache */
+  /**
+   * Returns the last created instance of GemFireCache
+   *
+   * @deprecated: use DM.getCache instead
+   */
+  @Deprecated
   public static GemFireCacheImpl getInstance() {
     return instance;
   }
@@ -695,7 +700,9 @@ public static GemFireCacheImpl setInstanceForTests(GemFireCacheImpl cache)
{
    *
    * @return the existing cache
    * @throws CacheClosedException if an existing cache can not be found.
+   * @deprecated use DM.getExistingCache instead.
    */
+  @Deprecated
   public static GemFireCacheImpl getExisting() {
     final GemFireCacheImpl result = instance;
     if (result != null && !result.isClosing) {
@@ -715,7 +722,9 @@ public static GemFireCacheImpl getExisting() {
    * @param reason the reason an existing cache is being requested.
    * @return the existing cache
    * @throws CacheClosedException if an existing cache can not be found.
+   * @deprecated use DM.getExistingCache instead.
    */
+  @Deprecated
   public static GemFireCacheImpl getExisting(String reason) {
     GemFireCacheImpl result = getInstance();
     if (result == null) {
diff --git a/geode-core/src/test/java/org/apache/geode/test/fake/Fakes.java b/geode-core/src/test/java/org/apache/geode/test/fake/Fakes.java
index cd75a04ddb..5148f5fe11 100644
--- a/geode-core/src/test/java/org/apache/geode/test/fake/Fakes.java
+++ b/geode-core/src/test/java/org/apache/geode/test/fake/Fakes.java
@@ -98,6 +98,7 @@ public static GemFireCacheImpl cache() {
     when(distributionManager.getSystem()).thenReturn(system);
     when(distributionManager.getCancelCriterion()).thenReturn(systemCancelCriterion);
     when(distributionManager.getCache()).thenReturn(cache);
+    when(distributionManager.getExistingCache()).thenReturn(cache);
 
     return cache;
   }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> refactor org.apache.geode.internal.cache.DestroyRegionOperation.DestroyRegionMessage.getRegionFromPath(InternalDistributedSystem,
String) to not call CacheFactory.getinstance
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GEODE-3598
>                 URL: https://issues.apache.org/jira/browse/GEODE-3598
>             Project: Geode
>          Issue Type: Sub-task
>          Components: regions
>            Reporter: Darrel Schneider
>            Assignee: Darrel Schneider
>
> DestroyRegionOperation.DestroyRegionMessage.getRegionFromPath(InternalDistributedSystem,
String)  should be changed to call "dm.getCache" instead of CacheFactory.getInstance.
> Note that it should also be changed to take a DM instead of InternalDistributedSystem
since the only caller currently has the dm and this code wants that instead of the InternalDistributedSystem.



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

Mime
View raw message