geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] branch develop updated: GEODE-4588: remove call of getAnyInstance (#1394)
Date Thu, 08 Feb 2018 19:20:33 GMT
This is an automated email from the ASF dual-hosted git repository.

dschneider pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new f848621  GEODE-4588: remove call of getAnyInstance (#1394)
f848621 is described below

commit f848621fe5258b87fcf04ceb4af7997359ed0330
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Thu Feb 8 11:20:29 2018 -0800

    GEODE-4588: remove call of getAnyInstance (#1394)
    
    Now an InternalDistributedSystem is passed in to the TXLockServiceImpl
    constructor. Note that this service depends on the distributed system
    instead of the cache.
---
 .../internal/cache/DistTXPrecommitMessage.java     |  3 ++-
 .../geode/internal/cache/TXCommitMessage.java      |  5 ++--
 .../apache/geode/internal/cache/TXLockRequest.java | 13 +++++-----
 .../org/apache/geode/internal/cache/TXState.java   |  4 ++--
 .../geode/internal/cache/locks/TXLockService.java  |  5 ++--
 .../internal/cache/locks/TXLockServiceImpl.java    |  4 +---
 .../geode/internal/cache/tx/ClientTXStateStub.java |  2 +-
 .../cache/locks/TXLockServiceDUnitTest.java        | 28 +++++++++++-----------
 8 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXPrecommitMessage.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXPrecommitMessage.java
index e732c38..ecaac7e 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXPrecommitMessage.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXPrecommitMessage.java
@@ -88,7 +88,8 @@ public class DistTXPrecommitMessage extends TXMessage {
     // should not be commited before
     assert (!txMgr.isHostedTxRecentlyCompleted(txId));
     // @see TXCommitMessage.process(DistributionManager)
-    TXLockService.createDTLS(); // fix bug 38843; no-op if already created
+    TXLockService.createDTLS(cache.getInternalDistributedSystem()); // fix bug 38843; no-op
if
+                                                                    // already created
     final TXStateProxy txStateProxy = txMgr.getTXState();
     boolean precommitSuccess = true;
     TreeMap<String, ArrayList<DistTxThinEntryState>> entryStateSortedMap =
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 8e5c210..443027f 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
@@ -536,7 +536,7 @@ public class TXCommitMessage extends PooledDistributionMessage
     }
 
     if (this.processorId != 0) {
-      TXLockService.createDTLS(); // fix bug 38843; no-op if already created
+      TXLockService.createDTLS(this.dm.getSystem()); // fix bug 38843; no-op if already created
       synchronized (this) {
         // Handle potential origin departure
         this.dm.addMembershipListener(this);
@@ -2078,7 +2078,8 @@ public class TXCommitMessage extends PooledDistributionMessage
    */
   private void updateLockMembers() {
     if (this.lockNeedsUpdate && this.lockId != null) {
-      TXLockService.createDTLS().updateParticipants(this.lockId, this.msgMap.keySet());
+      TXLockService.createDTLS(this.dm.getSystem()).updateParticipants(this.lockId,
+          this.msgMap.keySet());
     }
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXLockRequest.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXLockRequest.java
index 919597d..5958830 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXLockRequest.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXLockRequest.java
@@ -18,6 +18,7 @@ package org.apache.geode.internal.cache;
 import java.util.*;
 
 import org.apache.geode.cache.*;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.internal.cache.locks.*;
 
 /**
@@ -74,13 +75,13 @@ public class TXLockRequest {
     this.distLocks.add(req);
   }
 
-  public void obtain() throws CommitConflictException {
+  public void obtain(InternalDistributedSystem system) throws CommitConflictException {
     if (this.localLocks != null && !this.localLocks.isEmpty()) {
       txLocalLock(this.localLocks);
       this.localLockHeld = true;
     }
     if (this.distLocks != null && !this.distLocks.isEmpty()) {
-      this.distLockId = TXLockService.createDTLS().txLock(this.distLocks, this.otherMembers);
+      this.distLockId = TXLockService.createDTLS(system).txLock(this.distLocks, this.otherMembers);
     }
   }
 
@@ -97,10 +98,10 @@ public class TXLockRequest {
   /**
    * Release any distributed locks obtained by this request
    */
-  public void releaseDistributed() {
+  public void releaseDistributed(InternalDistributedSystem system) {
     if (this.distLockId != null) {
       try {
-        TXLockService txls = TXLockService.createDTLS();
+        TXLockService txls = TXLockService.createDTLS(system);
         txls.release(this.distLockId);
       } catch (IllegalStateException ignore) {
         // IllegalStateException: TXLockService cannot be created
@@ -132,9 +133,9 @@ public class TXLockRequest {
     return sb.toString();
   }
 
-  public void cleanup() {
+  public void cleanup(InternalDistributedSystem system) {
     releaseLocal();
-    releaseDistributed();
+    releaseDistributed(system);
   }
 
   private static final TXReservationMgr resMgr = new TXReservationMgr(true);
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
index f0d7361..cf35e03 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
@@ -323,7 +323,7 @@ public class TXState implements TXStateInterface {
 
     final long conflictStart = CachePerfStats.getStatTime();
     this.locks = createLockRequest();
-    this.locks.obtain();
+    this.locks.obtain(getCache().getInternalDistributedSystem());
     // for now check account the dlock service time
     // later this stat end should be moved to a finally block
     if (CachePerfStats.enableClockStats)
@@ -845,7 +845,7 @@ public class TXState implements TXStateInterface {
       if (this.locks != null) {
         final long conflictStart = CachePerfStats.getStatTime();
         try {
-          this.locks.cleanup();
+          this.locks.cleanup(getCache().getInternalDistributedSystem());
         } catch (IllegalArgumentException e) {
           iae = e;
         }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockService.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockService.java
index b26740b..b63b82f 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockService.java
@@ -18,6 +18,7 @@ package org.apache.geode.internal.cache.locks;
 import java.util.*;
 
 import org.apache.geode.cache.CommitConflictException;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.distributed.internal.locks.*;
 
 /**
@@ -45,10 +46,10 @@ public abstract class TXLockService {
   }
 
   /** Returns (or creates) the instance of the distributed TXLockService */
-  public static TXLockService createDTLS() {
+  public static TXLockService createDTLS(InternalDistributedSystem system) {
     synchronized (TXLockService.class) {
       if (DTLS == null || DTLS.isDestroyed()) {
-        DTLS = new TXLockServiceImpl(DLockService.DTLS);
+        DTLS = new TXLockServiceImpl(DLockService.DTLS, system);
       }
       return DTLS;
     }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockServiceImpl.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockServiceImpl.java
index 3830312..c223bcc 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockServiceImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/locks/TXLockServiceImpl.java
@@ -70,9 +70,7 @@ public class TXLockServiceImpl extends TXLockService {
   /** The distributed system for cancellation checks. */
   private final InternalDistributedSystem system;
 
-  /** Constructs new instance of transaction lock service */
-  TXLockServiceImpl(String name) {
-    InternalDistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+  TXLockServiceImpl(String name, InternalDistributedSystem sys) {
     if (sys == null) {
       throw new IllegalStateException(
           LocalizedStrings.TXLockServiceImpl_TXLOCKSERVICE_CANNOT_BE_CREATED_UNTIL_CONNECTED_TO_DISTRIBUTED_SYSTEM
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
index 6b933e0..5e0156a 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
@@ -153,7 +153,7 @@ public class ClientTXStateStub extends TXStateStub {
       logger.debug("TX: client localLockRequest: {}", lockReq);
     }
     try {
-      lockReq.obtain();
+      lockReq.obtain(cache.getInternalDistributedSystem());
     } catch (CommitConflictException e) {
       rollback(); // cleanup tx artifacts on server
       throw e;
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/locks/TXLockServiceDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/locks/TXLockServiceDUnitTest.java
index 6f53ee8..b606e4e 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/locks/TXLockServiceDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/locks/TXLockServiceDUnitTest.java
@@ -62,7 +62,7 @@ import org.apache.geode.test.junit.categories.DistributedTest;
 @Category({DistributedTest.class, DLockTest.class})
 public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase {
 
-  private static DistributedSystem system;
+  private static InternalDistributedSystem system;
 
   protected static boolean testTXRecoverGrantor_replyCode_PASS = false;
   protected static boolean testTXRecoverGrantor_heldLocks_PASS = false;
@@ -127,7 +127,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
   @Test
   public void testTXRecoverGrantorMessageProcessor() throws Exception {
-    TXLockService.createDTLS();
+    TXLockService.createDTLS(system);
     checkDLockRecoverGrantorMessageProcessor();
 
     /*
@@ -188,13 +188,13 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
   public void testTXGrantorMigration() throws Exception {
     // first make sure some other VM is the grantor
     Host.getHost(0).getVM(0).invoke("become lock grantor", () -> {
-      TXLockService.createDTLS();
+      TXLockService.createDTLS(system);
       TXLockService vm0dtls = TXLockService.getDTLS();
       DLockService vm0dlock = ((TXLockServiceImpl) vm0dtls).getInternalDistributedLockService();
       vm0dlock.becomeLockGrantor();
     });
 
-    TXLockService.createDTLS();
+    TXLockService.createDTLS(system);
     checkDLockRecoverGrantorMessageProcessor();
 
     /*
@@ -327,7 +327,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
     Host.getHost(0).getVM(grantorVM).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
     sleep(20);
@@ -337,7 +337,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
     Host.getHost(0).getVM(clientA).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
 
@@ -355,7 +355,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
     Host.getHost(0).getVM(clientB).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
 
@@ -444,7 +444,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
     Host.getHost(0).getVM(grantorVM).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
 
@@ -461,7 +461,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
     Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
     Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable(
@@ -477,12 +477,12 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
     // create dtls in each participant
     Host.getHost(0).getVM(particpantA).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
     Host.getHost(0).getVM(particpantB).invoke(new SerializableRunnable() {
       public void run() {
-        TXLockService.createDTLS();
+        TXLockService.createDTLS(system);
       }
     });
 
@@ -543,7 +543,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
 
       Host.getHost(0).getVM(finalvm).invoke(new SerializableRunnable() {
         public void run() {
-          TXLockService.createDTLS();
+          TXLockService.createDTLS(system);
         }
       });
 
@@ -698,7 +698,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
   protected static void checkGetAndDestroy() {
     assertNull(TXLockService.getDTLS());
 
-    TXLockService dtls = TXLockService.createDTLS();
+    TXLockService dtls = TXLockService.createDTLS(system);
     assertNotNull(dtls);
     assertEquals(true, dtls == TXLockService.getDTLS());
     assertEquals(false, dtls.isDestroyed());
@@ -707,7 +707,7 @@ public class TXLockServiceDUnitTest extends JUnit4DistributedTestCase
{
     assertEquals(true, dtls.isDestroyed());
     assertNull(TXLockService.getDTLS());
 
-    dtls = TXLockService.createDTLS();
+    dtls = TXLockService.createDTLS(system);
     assertNotNull(dtls);
     assertEquals(true, dtls == TXLockService.getDTLS());
     assertEquals(false, dtls.isDestroyed());

-- 
To stop receiving notification emails like this one, please contact
dschneider@apache.org.

Mime
View raw message