#ignite-797: remove some checks for tx.groupLock().
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/48d416b1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/48d416b1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/48d416b1 Branch: refs/heads/ignite-797 Commit: 48d416b175499730e65754b26dd94c8dce793068 Parents: cdda7fd Author: ivasilinets <ivasilin...@gridgain.com> Authored: Fri May 15 13:13:33 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Fri May 15 13:13:33 2015 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheMapEntry.java | 36 ++---------- .../distributed/dht/GridDhtTxLocalAdapter.java | 62 -------------------- .../colocated/GridDhtColocatedLockFuture.java | 4 -- .../distributed/near/GridNearLockFuture.java | 4 -- .../near/GridNearOptimisticTxPrepareFuture.java | 4 -- .../cache/distributed/near/GridNearTxLocal.java | 7 --- .../transactions/IgniteTxLocalAdapter.java | 12 ---- .../cache/transactions/IgniteTxManager.java | 55 +---------------- 8 files changed, 8 insertions(+), 176 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java index 86ed57a..e6263f0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java @@ -961,13 +961,9 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { synchronized (this) { checkObsolete(); - if (cctx.kernalContext().config().isCacheSanityCheckEnabled()) { - if (tx != null && tx.groupLock()) - groupLockSanityCheck(tx); - else - assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) : - "Transaction does not own lock for update [entry=" + this + ", tx=" + tx + ']'; - } + if (cctx.kernalContext().config().isCacheSanityCheckEnabled()) + assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) : + "Transaction does not own lock for update [entry=" + this + ", tx=" + tx + ']'; // Load and remove from swap if it is new. boolean startVer = isStartVersion(); @@ -1125,10 +1121,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { synchronized (this) { checkObsolete(); - if (tx != null && tx.groupLock() && cctx.kernalContext().config().isCacheSanityCheckEnabled()) - groupLockSanityCheck(tx); - else - assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) : + assert tx == null || (!tx.local() && tx.onePhaseCommit()) || tx.ownsLock(this) : "Transaction does not own lock for remove[entry=" + this + ", tx=" + tx + ']'; boolean startVer = isStartVersion(); @@ -1195,7 +1188,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { obsoleteVer = newVer; else { // Only delete entry if the lock is not explicit. - if (tx.groupLock() || lockedBy(tx.xidVersion())) + if (lockedBy(tx.xidVersion())) obsoleteVer = tx.xidVersion(); else if (log.isDebugEnabled()) log.debug("Obsolete version was not set because lock was explicit: " + this); @@ -2796,25 +2789,6 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { } /** - * Checks that entries in group locks transactions are not locked during commit. - * - * @param tx Transaction to check. - * @throws GridCacheEntryRemovedException If entry is obsolete. - * @throws IgniteCheckedException If entry was externally locked. - */ - private void groupLockSanityCheck(IgniteInternalTx tx) throws GridCacheEntryRemovedException, IgniteCheckedException { - assert tx.groupLock(); - - IgniteTxEntry txEntry = tx.entry(txKey()); - - if (txEntry.groupLockEntry()) { - if (lockedByAny()) - throw new IgniteCheckedException("Failed to update cache entry (entry was externally locked while " + - "accessing entry within group lock transaction) [entry=" + this + ", tx=" + tx + ']'); - } - } - - /** * @param failFast Fail fast flag. * @param topVer Topology version. * @param filter Filter. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java index 444085f..1c30fce 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java @@ -733,68 +733,6 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter { } /** {@inheritDoc} */ - @Override protected void addGroupTxMapping(Collection<IgniteTxKey> keys) { - assert groupLock(); - - for (GridDistributedTxMapping mapping : dhtMap.values()) - mapping.entries(Collections.unmodifiableCollection(txMap.values()), true); - - // Here we know that affinity key for all given keys is our group lock key. - // Just add entries to dht mapping. - // Add near readers. If near cache is disabled on all nodes, do nothing. - Collection<UUID> backupIds = dhtMap.keySet(); - - Map<ClusterNode, List<GridDhtCacheEntry>> locNearMap = null; - - for (IgniteTxKey key : keys) { - IgniteTxEntry txEntry = entry(key); - - if (!txEntry.groupLockEntry() || txEntry.context().isNear()) - continue; - - assert txEntry.cached() instanceof GridDhtCacheEntry : "Invalid entry type: " + txEntry.cached(); - - while (true) { - try { - GridDhtCacheEntry entry = (GridDhtCacheEntry)txEntry.cached(); - - Collection<UUID> readers = entry.readers(); - - if (!F.isEmpty(readers)) { - Collection<ClusterNode> nearNodes = cctx.discovery().nodes(readers, F0.notEqualTo(nearNodeId()), - F.notIn(backupIds)); - - if (log.isDebugEnabled()) - log.debug("Mapping entry to near nodes [nodes=" + U.nodeIds(nearNodes) + ", entry=" + - entry + ']'); - - for (ClusterNode n : nearNodes) { - if (locNearMap == null) - locNearMap = new HashMap<>(); - - List<GridDhtCacheEntry> entries = locNearMap.get(n); - - if (entries == null) - locNearMap.put(n, entries = new LinkedList<>()); - - entries.add(entry); - } - } - - break; - } - catch (GridCacheEntryRemovedException ignored) { - // Retry. - txEntry.cached(txEntry.context().dht().entryExx(key.key(), topologyVersion())); - } - } - } - - if (locNearMap != null) - addNearNodeEntryMapping(locNearMap); - } - - /** {@inheritDoc} */ @SuppressWarnings({"CatchGenericClass", "ThrowableInstanceNeverThrown"}) @Override public boolean finish(boolean commit) throws IgniteCheckedException { if (log.isDebugEnabled()) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java index 2f716a6..e6a4eaf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java @@ -1088,10 +1088,6 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity // If primary node left the grid before lock acquisition, fail the whole future. throw newTopologyException(null, primary.id()); - if (inTx() && tx.groupLock() && !primary.isLocal()) - throw new IgniteCheckedException("Failed to start group lock transaction (local node is not primary for " + - " key) [key=" + key + ", primaryNodeId=" + primary.id() + ']'); - if (mapping == null || !primary.id().equals(mapping.node().id())) mapping = new GridNearLockMapping(primary, key); else http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java index 272e012..0ffb4e5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java @@ -1186,10 +1186,6 @@ public final class GridNearLockFuture<K, V> extends GridCompoundIdentityFuture<B // If primary node left the grid before lock acquisition, fail the whole future. throw newTopologyException(null, primary.id()); - if (inTx() && tx.groupLock() && !primary.isLocal()) - throw new IgniteCheckedException("Failed to start group lock transaction (local node is not primary for " + - " key) [key=" + key + ", primaryNodeId=" + primary.id() + ']'); - if (mapping == null || !primary.id().equals(mapping.node().id())) mapping = new GridNearLockMapping(primary, key); else http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java index c36b324..9a00a24 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java @@ -588,10 +588,6 @@ public class GridNearOptimisticTxPrepareFuture extends GridNearTxPrepareFutureAd ", primary=" + U.toShortString(primary) + ", topVer=" + topVer + ']'); } - if (tx.groupLock() && !primary.isLocal()) - throw new IgniteCheckedException("Failed to prepare group lock transaction (local node is not primary for " + - " key)[key=" + entry.key() + ", primaryNodeId=" + primary.id() + ']'); - // Must re-initialize cached entry while holding topology lock. if (cacheCtx.isNear()) entry.cached(cacheCtx.nearTx().entryExx(entry.key(), topVer)); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java index 50d3f3e..dc9b016 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java @@ -416,13 +416,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter { } } - /** {@inheritDoc} */ - @Override protected void addGroupTxMapping(Collection<IgniteTxKey> keys) { - super.addGroupTxMapping(keys); - - addKeyMapping(cctx.localNode(), keys); - } - /** * Adds key mapping to dht mapping. * http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java index 7e9095c..ebd3d7a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java @@ -679,9 +679,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter if (!empty || colocated()) cctx.tm().addCommittedTx(this); - if (groupLock()) - addGroupTxMapping(writeSet()); - if (!empty) { batchStoreCommit(writeMap().values()); @@ -2985,15 +2982,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter } /** - * Adds key mapping to transaction. - * @param keys Keys to add. - */ - protected void addGroupTxMapping(Collection<IgniteTxKey> keys) { - // No-op. This method is overriden in transactions that store key to remote node mapping - // for commit. - } - - /** * Checks that affinity keys are enlisted in group transaction on start. * * @param cacheCtx Cache context. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/48d416b1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java index 2122602..b08535c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java @@ -1206,14 +1206,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter { // 3.1 Call dataStructures manager. cctx.kernalContext().dataStructures().onTxCommitted(tx); - // 4. Unlock write resources. - if (tx.groupLock()) - unlockGroupLocks(tx); - else - unlockMultiple(tx, tx.writeEntries()); + unlockMultiple(tx, tx.writeEntries()); // 5. For pessimistic transaction, unlock read resources if required. - if (tx.pessimistic() && !tx.readCommitted() && !tx.groupLock()) + if (tx.pessimistic() && !tx.readCommitted()) unlockMultiple(tx, tx.readEntries()); // 6. Notify evictions. @@ -1441,7 +1437,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter { * @param tx Transaction to notify evictions for. */ private void notifyEvitions(IgniteInternalTx tx) { - if (tx.internal() && !tx.groupLock()) + if (tx.internal()) return; for (IgniteTxEntry txEntry : tx.allEntries()) @@ -1617,51 +1613,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter { } /** - * Unlocks entries locked by group transaction. - * - * @param txx Transaction. - */ - @SuppressWarnings("unchecked") - private void unlockGroupLocks(IgniteInternalTx txx) { - IgniteTxKey grpLockKey = txx.groupLockKey(); - - assert grpLockKey != null; - - if (grpLockKey == null) - return; - - IgniteTxEntry txEntry = txx.entry(grpLockKey); - - assert txEntry != null || (txx.near() && !txx.local()); - - if (txEntry != null) { - GridCacheContext cacheCtx = txEntry.context(); - - // Group-locked entries must be locked. - while (true) { - try { - GridCacheEntryEx entry = txEntry.cached(); - - assert entry != null; - - entry.txUnlock(txx); - - break; - } - catch (GridCacheEntryRemovedException ignored) { - if (log.isDebugEnabled()) - log.debug("Got removed entry in TM unlockGroupLocks(..) method (will retry): " + txEntry); - - GridCacheAdapter cache = cacheCtx.cache(); - - // Renew cache entry. - txEntry.cached(cache.entryEx(txEntry.key())); - } - } - } - } - - /** * @param tx Owning transaction. * @param entries Entries to unlock. */