diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ImageState.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ImageState.java index c3092d07a..a86be9b7f 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ImageState.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ImageState.java @@ -188,6 +188,6 @@ public interface VersionTagEntry { public long getRegionVersion(); } - public boolean isWriteLockedBySameThread(); + //public boolean isWriteLockedBySameThread(); } diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/TXRegionState.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/TXRegionState.java index 0329c8d0a..1d391a262 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/TXRegionState.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/TXRegionState.java @@ -155,9 +155,9 @@ public TXRegionState(final LocalRegion r, final TXState tx) { // in that case don't take lock ImageState imgState = r.getImageState(); - boolean alreadyLocked = imgState.isWriteLockedBySameThread(); + //boolean alreadyLocked = imgState.isWriteLockedBySameThread(); if (!r.isInitialized() - && (alreadyLocked || imgState.lockPendingTXRegionStates(true, false))) { + && (imgState.lockPendingTXRegionStates(true, false))) { try { if (!r.getImageState().addPendingTXRegionState(this)) { this.pendingTXOps = null; @@ -167,7 +167,7 @@ public TXRegionState(final LocalRegion r, final TXState tx) { this.pendingTXLockFlags = new TIntArrayList(); } } finally { - if (!alreadyLocked) + //if (!alreadyLocked) r.getImageState().unlockPendingTXRegionStates(true); } } else { diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/UnsharedImageState.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/UnsharedImageState.java index debd3c888..bd50fbd3e 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/UnsharedImageState.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/UnsharedImageState.java @@ -21,6 +21,8 @@ import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; import com.gemstone.gemfire.i18n.LogWriterI18n; import com.gemstone.gemfire.internal.Assert; +import com.gemstone.gemfire.internal.cache.locks.LockMode; +import com.gemstone.gemfire.internal.cache.locks.ReentrantReadWriteWriteShareLock; import com.gemstone.gemfire.internal.util.concurrent.StoppableNonReentrantLock; import com.gemstone.gemfire.internal.util.concurrent.StoppableReentrantReadWriteLock; import com.gemstone.gemfire.internal.cache.locks.NonReentrantReadWriteLock; @@ -75,8 +77,10 @@ public class UnsharedImageState implements ImageState { * GII is complete */ private volatile THashMapWithCreate pendingTXRegionStates; - private final NonReentrantReadWriteLock pendingTXRegionStatesLock; - private volatile Thread pendingTXRegionStatesLockOwner; + private final ReentrantReadWriteWriteShareLock pendingTXRegionStatesLock; + + + //private volatile Thread pendingTXRegionStatesLockOwner; private final AtomicInteger pendingTXOrder; private volatile TObjectIntHashMap finishedTXIdOrders; @@ -101,7 +105,7 @@ public class UnsharedImageState implements ImageState { this.failedEvents = new ConcurrentTHashSet(2); this.pendingTXRegionStates = isLocal ? null : new THashMapWithCreate(); this.pendingTXRegionStatesLock = isLocal ? null - : new NonReentrantReadWriteLock(stopper); + : new ReentrantReadWriteWriteShareLock(); this.pendingTXOrder = new AtomicInteger(0); } @@ -133,11 +137,11 @@ public void setRequestedUnappliedDelta(boolean flag) { requestedDelta = flag; } - @Override + /*@Override public boolean isWriteLockedBySameThread() { return this.pendingTXRegionStatesLock.isWriteLocked() && (this.pendingTXRegionStatesLockOwner == Thread.currentThread()); - } + }*/ @Override public boolean requestedUnappliedDelta() { @@ -407,12 +411,13 @@ public TXRegionState getPendingTXRegionState(TXId txId, boolean lock) { } TXRegionState txrs = null; if (lock) { - if (Thread.currentThread() != this.pendingTXRegionStatesLockOwner) { - this.pendingTXRegionStatesLock.attemptReadLock(-1); - } - else { + //if (Thread.currentThread() != this.pendingTXRegionStatesLockOwner) { + this.pendingTXRegionStatesLock.attemptLock(LockMode.SH,-1, this); + //this.pendingTXRegionStatesLock.attemptReadLock(-1); + //} + //else { lock = false; - } + //} } try { if (this.pendingTXRegionStates != null) { @@ -427,7 +432,8 @@ public TXRegionState getPendingTXRegionState(TXId txId, boolean lock) { } } finally { if (lock) { - this.pendingTXRegionStatesLock.releaseReadLock(); + this.pendingTXRegionStatesLock.releaseLock(LockMode.SH,false, this); + //this.pendingTXRegionStatesLock.releaseReadLock(); } } return txrs; @@ -451,11 +457,13 @@ public boolean lockPendingTXRegionStates(final boolean forWrite, } } if (forWrite) { - this.pendingTXRegionStatesLock.attemptWriteLock(-1); - this.pendingTXRegionStatesLockOwner = Thread.currentThread(); + this.pendingTXRegionStatesLock.attemptLock(LockMode.EX,-1, this); + //this.pendingTXRegionStatesLock.attemptWriteLock(-1); + //this.pendingTXRegionStatesLockOwner = Thread.currentThread(); } else { - this.pendingTXRegionStatesLock.attemptReadLock(-1); + this.pendingTXRegionStatesLock.attemptLock(LockMode.SH,-1, this); + //this.pendingTXRegionStatesLock.attemptReadLock(-1); } if (this.pendingTXRegionStates != null) { if (TXStateProxy.LOG_FINE) { @@ -470,11 +478,14 @@ public boolean lockPendingTXRegionStates(final boolean forWrite, } else { if (forWrite) { - this.pendingTXRegionStatesLockOwner = null; - this.pendingTXRegionStatesLock.releaseWriteLock(); + //this.pendingTXRegionStatesLockOwner = null; + //this.pendingTXRegionStatesLock.releaseWriteLock(); + this.pendingTXRegionStatesLock.releaseLock(LockMode.EX, false, this); } else { - this.pendingTXRegionStatesLock.releaseReadLock(); + this.pendingTXRegionStatesLock.releaseLock(LockMode.SH, false, this); + + //this.pendingTXRegionStatesLock.releaseReadLock(); } return false; } @@ -487,11 +498,15 @@ public boolean lockPendingTXRegionStates(final boolean forWrite, public void unlockPendingTXRegionStates(final boolean forWrite) { if (this.pendingTXRegionStatesLock != null) { if (forWrite) { - this.pendingTXRegionStatesLockOwner = null; - this.pendingTXRegionStatesLock.releaseWriteLock(); + //this.pendingTXRegionStatesLockOwner = null; + //this.pendingTXRegionStatesLock.releaseWriteLock(); + this.pendingTXRegionStatesLock.releaseLock(LockMode.EX, false, this); + } else { - this.pendingTXRegionStatesLock.releaseReadLock(); + //this.pendingTXRegionStatesLock.releaseReadLock(); + this.pendingTXRegionStatesLock.releaseLock(LockMode.SH, false, this); + } if (TXStateProxy.LOG_FINE) { final LogWriterI18n logger = InternalDistributedSystem.getLoggerI18n(); @@ -535,7 +550,8 @@ public void setTXOrderForFinish(TXRegionState txrs) { if (this.pendingTXRegionStatesLock != null) { TObjectIntHashMap finishedOrders; // assume read lock on pendingTXRegionStates is already held - Assert.assertTrue(this.pendingTXRegionStatesLock.numReaders() > 0); + //Assert.assertTrue(this.pendingTXRegionStatesLock.numReaders() > 0); + Assert.assertTrue(this.pendingTXRegionStatesLock.numReadOnlyLocks() > 0); if ((finishedOrders = this.finishedTXIdOrders) != null) { int order = finishedOrders.get(txrs.getTXState().getTransactionId()); if (order != 0) { @@ -569,7 +585,8 @@ public void mergeFinishedTXOrders(final LocalRegion region, final Collection txIds) { final THashMapWithCreate pendingTXRS = this.pendingTXRegionStates; if (pendingTXRS != null) { - this.pendingTXRegionStatesLock.attemptWriteLock(-1); + //this.pendingTXRegionStatesLock.attemptWriteLock(-1); + this.pendingTXRegionStatesLock.attemptLock(LockMode.EX, -1, this); try { // first get the ordering for finished transactions from TX manager; // this is deliberately invoked under the lock to sync against @@ -603,7 +620,8 @@ public void mergeFinishedTXOrders(final LocalRegion region, this.pendingTXOrder.addAndGet(increment); this.finishedTXIdOrders = txIdOrders; } finally { - this.pendingTXRegionStatesLock.releaseWriteLock(); + //this.pendingTXRegionStatesLock.releaseWriteLock(); + this.pendingTXRegionStatesLock.releaseLock(LockMode.EX, false, this); } } }