http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedCacheEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedCacheEntry.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedCacheEntry.java deleted file mode 100644 index 5fa24df..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedCacheEntry.java +++ /dev/null @@ -1,850 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.cache.distributed; - -import org.gridgain.grid.kernal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * Entry for distributed (replicated/partitioned) cache. - */ -@SuppressWarnings({"NonPrivateFieldAccessedInSynchronizedContext", "TooBroadScope"}) -public class GridDistributedCacheEntry<K, V> extends GridCacheMapEntry<K, V> { - /** */ - private static final long serialVersionUID = 0L; - - /** Remote candidates snapshot. */ - private volatile List<GridCacheMvccCandidate<K>> rmts = Collections.emptyList(); - - /** - * @param ctx Cache context. - * @param key Cache key. - * @param hash Key hash value. - * @param val Entry value. - * @param next Next entry in the linked list. - * @param ttl Time to live. - * @param hdrId Cache map header ID. - */ - public GridDistributedCacheEntry(GridCacheContext<K, V> ctx, K key, int hash, V val, - GridCacheMapEntry<K, V> next, long ttl, int hdrId) { - super(ctx, key, hash, val, next, ttl, hdrId); - } - - /** - * - */ - protected void refreshRemotes() { - GridCacheMvcc<K> mvcc = mvccExtras(); - - rmts = mvcc == null ? Collections.<GridCacheMvccCandidate<K>>emptyList() : mvcc.remoteCandidates(); - } - - /** - * Add local candidate. - * - * @param threadId Owning thread ID. - * @param ver Lock version. - * @param timeout Timeout to acquire lock. - * @param reenter Reentry flag. - * @param tx Transaction flag. - * @param implicitSingle Implicit flag. - * @return New candidate. - * @throws GridCacheEntryRemovedException If entry has been removed. - */ - @Nullable public GridCacheMvccCandidate<K> addLocal( - long threadId, - GridCacheVersion ver, - long timeout, - boolean reenter, - boolean tx, - boolean implicitSingle) throws GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> cand; - GridCacheMvccCandidate<K> prev; - GridCacheMvccCandidate<K> owner; - - V val; - - synchronized (this) { - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc == null) { - mvcc = new GridCacheMvcc<>(cctx); - - mvccExtras(mvcc); - } - - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - cand = mvcc.addLocal(this, threadId, ver, timeout, reenter, tx, implicitSingle); - - owner = mvcc.anyOwner(); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - val = this.val; - - if (emptyAfter) - mvccExtras(null); - } - - // Don't link reentries. - if (cand != null && !cand.reentry()) - // Link with other candidates in the same thread. - cctx.mvcc().addNext(cctx, cand); - - checkOwnerChanged(prev, owner, val); - - return cand; - } - - /** {@inheritDoc} */ - @Override public Collection<GridCacheMvccCandidate<K>> remoteMvccSnapshot(GridCacheVersion... exclude) { - Collection<GridCacheMvccCandidate<K>> rmts = this.rmts; - - if (rmts.isEmpty() || F.isEmpty(exclude)) - return rmts; - - Collection<GridCacheMvccCandidate<K>> cands = new ArrayList<>(rmts.size()); - - for (GridCacheMvccCandidate<K> c : rmts) { - assert !c.reentry(); - - // Don't include reentries. - if (!U.containsObjectArray(exclude, c.version())) - cands.add(c); - } - - return cands; - } - - /** - * Adds new lock candidate. - * - * @param nodeId Node ID. - * @param otherNodeId Other node ID. - * @param threadId Thread ID. - * @param ver Lock version. - * @param timeout Lock acquire timeout. - * @param tx Transaction flag. - * @param implicitSingle Implicit flag. - * @param owned Owned candidate version. - * @throws GridDistributedLockCancelledException If lock has been canceled. - * @throws GridCacheEntryRemovedException If this entry is obsolete. - */ - public void addRemote( - UUID nodeId, - @Nullable UUID otherNodeId, - long threadId, - GridCacheVersion ver, - long timeout, - boolean tx, - boolean implicitSingle, - @Nullable GridCacheVersion owned) throws GridDistributedLockCancelledException, - GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> prev; - GridCacheMvccCandidate<K> owner; - - V val; - - synchronized (this) { - // Check removed locks prior to obsolete flag. - checkRemoved(ver); - - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc == null) { - mvcc = new GridCacheMvcc<>(cctx); - - mvccExtras(mvcc); - } - - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - mvcc.addRemote( - this, - nodeId, - otherNodeId, - threadId, - ver, - timeout, - tx, - implicitSingle, - /*near-local*/false - ); - - if (owned != null) - mvcc.markOwned(ver, owned); - - owner = mvcc.anyOwner(); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - val = this.val; - - refreshRemotes(); - - if (emptyAfter) - mvccExtras(null); - } - - // This call must be outside of synchronization. - checkOwnerChanged(prev, owner, val); - } - - /** - * Adds new lock candidate. - * - * @param cand Remote lock candidate. - * @throws GridDistributedLockCancelledException If lock has been canceled. - * @throws GridCacheEntryRemovedException If this entry is obsolete. - */ - public void addRemote(GridCacheMvccCandidate<K> cand) throws GridDistributedLockCancelledException, - GridCacheEntryRemovedException { - - V val; - - GridCacheMvccCandidate<K> prev; - GridCacheMvccCandidate<K> owner; - - synchronized (this) { - cand.parent(this); - - // Check removed locks prior to obsolete flag. - checkRemoved(cand.version()); - - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc == null) { - mvcc = new GridCacheMvcc<>(cctx); - - mvccExtras(mvcc); - } - - boolean emptyBefore = mvcc.isEmpty(); - - prev = mvcc.anyOwner(); - - mvcc.addRemote(cand); - - owner = mvcc.anyOwner(); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - val = this.val; - - refreshRemotes(); - - if (emptyAfter) - mvccExtras(null); - } - - // This call must be outside of synchronization. - checkOwnerChanged(prev, owner, val); - } - - /** - * Removes all lock candidates for node. - * - * @param nodeId ID of node to remove locks from. - * @throws GridCacheEntryRemovedException If entry was removed. - */ - public void removeExplicitNodeLocks(UUID nodeId) throws GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val = null; - - synchronized (this) { - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.removeExplicitNodeCandidates(nodeId); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - val = this.val; - - refreshRemotes(); - - if (emptyAfter) - mvccExtras(null); - } - } - - // This call must be outside of synchronization. - checkOwnerChanged(prev, owner, val); - } - - /** - * Unlocks local lock. - * - * @return Removed candidate, or <tt>null</tt> if thread still holds the lock. - */ - @Nullable public GridCacheMvccCandidate<K> removeLock() { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val; - - synchronized (this) { - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.releaseLocal(); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - if (log.isDebugEnabled()) - log.debug("Released local candidate from entry [owner=" + owner + ", prev=" + prev + - ", entry=" + this + ']'); - - if (prev != null && owner != prev) - checkThreadChain(prev); - - // This call must be outside of synchronization. - checkOwnerChanged(prev, owner, val); - - return owner != prev ? prev : null; - } - - /** {@inheritDoc} */ - @Override public boolean removeLock(GridCacheVersion ver) throws GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - GridCacheMvccCandidate<K> doomed; - - V val; - - synchronized (this) { - GridCacheMvcc<K> mvcc = mvccExtras(); - - doomed = mvcc == null ? null : mvcc.candidate(ver); - - if (doomed == null || doomed.dhtLocal() || (!doomed.local() && !doomed.nearLocal())) - addRemoved(ver); - - GridCacheVersion obsoleteVer = obsoleteVersionExtras(); - - if (obsoleteVer != null && !obsoleteVer.equals(ver)) - checkObsolete(); - - if (doomed != null) { - assert mvcc != null; - - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.remove(doomed.version()); - - boolean emptyAfter = mvcc.isEmpty(); - - if (!doomed.local()) - refreshRemotes(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - if (log.isDebugEnabled()) - log.debug("Removed lock candidate from entry [doomed=" + doomed + ", owner=" + owner + ", prev=" + prev + - ", entry=" + this + ']'); - - if (doomed != null && doomed.nearLocal()) - cctx.mvcc().removeExplicitLock(doomed); - - if (doomed != null) - checkThreadChain(doomed); - - // This call must be outside of synchronization. - checkOwnerChanged(prev, owner, val); - - return doomed != null; - } - - /** - * - * @param ver Lock version. - * @throws GridDistributedLockCancelledException If lock is cancelled. - */ - protected void checkRemoved(GridCacheVersion ver) throws GridDistributedLockCancelledException { - assert Thread.holdsLock(this); - - GridCacheVersion obsoleteVer = obsoleteVersionExtras(); - - if ((obsoleteVer != null && obsoleteVer.equals(ver)) || cctx.mvcc().isRemoved(cctx, ver)) - throw new GridDistributedLockCancelledException("Lock has been cancelled [key=" + key + - ", ver=" + ver + ']'); - } - - /** - * @param ver Lock version. - * @return {@code True} if removed. - */ - public boolean addRemoved(GridCacheVersion ver) { - assert Thread.holdsLock(this); - - return cctx.mvcc().addRemoved(cctx, ver); - } - - /** - * - * @param ver Version of candidate to acquire lock for. - * @return Owner. - * @throws GridCacheEntryRemovedException If entry is removed. - */ - @Nullable public GridCacheMvccCandidate<K> readyLock(GridCacheVersion ver) - throws GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val; - - synchronized (this) { - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.readyLocal(ver); - - assert owner == null || owner.owner() : "Owner flag not set for owner: " + owner; - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - // This call must be made outside of synchronization. - checkOwnerChanged(prev, owner, val); - - return owner; - } - - /** - * Notifies mvcc that near local lock is ready to be acquired. - * - * @param ver Lock version. - * @param mapped Mapped dht lock version. - * @param committed Committed versions. - * @param rolledBack Rolled back versions. - * @param pending Pending locks on dht node with version less then mapped. - * @return Current lock owner. - * - * @throws GridCacheEntryRemovedException If entry is removed. - */ - @Nullable public GridCacheMvccCandidate<K> readyNearLock(GridCacheVersion ver, GridCacheVersion mapped, - Collection<GridCacheVersion> committed, - Collection<GridCacheVersion> rolledBack, - Collection<GridCacheVersion> pending) throws GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val; - - synchronized (this) { - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.readyNearLocal(ver, mapped, committed, rolledBack, pending); - - assert owner == null || owner.owner() : "Owner flag is not set for owner: " + owner; - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - // This call must be made outside of synchronization. - checkOwnerChanged(prev, owner, val); - - return owner; - } - - /** - * Reorders completed versions. - * - * @param baseVer Base version for reordering. - * @param committedVers Completed versions. - * @param rolledbackVers Rolled back versions. - * @throws GridCacheEntryRemovedException If entry has been removed. - */ - public void orderCompleted(GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers, - Collection<GridCacheVersion> rolledbackVers) - throws GridCacheEntryRemovedException { - if (!F.isEmpty(committedVers) || !F.isEmpty(rolledbackVers)) { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val; - - synchronized (this) { - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.orderCompleted(baseVer, committedVers, rolledbackVers); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - // This call must be made outside of synchronization. - checkOwnerChanged(prev, owner, val); - } - } - - /** - * - * @param lockVer Done version. - * @param baseVer Base version. - * @param committedVers Completed versions for reordering. - * @param rolledbackVers Rolled back versions for reordering. - * @param sysInvalidate Flag indicating if this entry is done from invalidated transaction (in case of tx - * salvage). In this case all locks before salvaged lock will marked as used and corresponding - * transactions will be invalidated. - * @throws GridCacheEntryRemovedException If entry has been removed. - * @return Owner. - */ - @Nullable public GridCacheMvccCandidate<K> doneRemote( - GridCacheVersion lockVer, - GridCacheVersion baseVer, - Collection<GridCacheVersion> committedVers, - Collection<GridCacheVersion> rolledbackVers, - boolean sysInvalidate) throws GridCacheEntryRemovedException { - return doneRemote(lockVer, baseVer, Collections.<GridCacheVersion>emptySet(), committedVers, - rolledbackVers, sysInvalidate); - } - - /** - * - * @param lockVer Done version. - * @param baseVer Base version. - * @param pendingVers Pending versions that are less than lock version. - * @param committedVers Completed versions for reordering. - * @param rolledbackVers Rolled back versions for reordering. - * @param sysInvalidate Flag indicating if this entry is done from invalidated transaction (in case of tx - * salvage). In this case all locks before salvaged lock will marked as used and corresponding - * transactions will be invalidated. - * @throws GridCacheEntryRemovedException If entry has been removed. - * @return Owner. - */ - @Nullable public GridCacheMvccCandidate<K> doneRemote( - GridCacheVersion lockVer, - GridCacheVersion baseVer, - @Nullable Collection<GridCacheVersion> pendingVers, - Collection<GridCacheVersion> committedVers, - Collection<GridCacheVersion> rolledbackVers, - boolean sysInvalidate) throws GridCacheEntryRemovedException { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val; - - synchronized (this) { - checkObsolete(); - - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - // Order completed versions. - if (!F.isEmpty(committedVers) || !F.isEmpty(rolledbackVers)) { - mvcc.orderCompleted(lockVer, committedVers, rolledbackVers); - - if (!baseVer.equals(lockVer)) - mvcc.orderCompleted(baseVer, committedVers, rolledbackVers); - } - - if (sysInvalidate && baseVer != null) - mvcc.salvageRemote(baseVer); - - owner = mvcc.doneRemote(lockVer, maskNull(pendingVers), maskNull(committedVers), - maskNull(rolledbackVers)); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - // This call must be made outside of synchronization. - checkOwnerChanged(prev, owner, val); - - return owner; - } - - /** - * Rechecks if lock should be reassigned. - * - * @return Current owner. - */ - @Nullable public GridCacheMvccCandidate<K> recheck() { - GridCacheMvccCandidate<K> prev = null; - GridCacheMvccCandidate<K> owner = null; - - V val; - - synchronized (this) { - GridCacheMvcc<K> mvcc = mvccExtras(); - - if (mvcc != null) { - prev = mvcc.anyOwner(); - - boolean emptyBefore = mvcc.isEmpty(); - - owner = mvcc.recheck(); - - boolean emptyAfter = mvcc.isEmpty(); - - checkCallbacks(emptyBefore, emptyAfter); - - if (emptyAfter) - mvccExtras(null); - } - - val = this.val; - } - - // This call must be made outside of synchronization. - checkOwnerChanged(prev, owner, val); - - return owner; - } - - /** {@inheritDoc} */ - @Override public boolean tmLock(IgniteTxEx<K, V> tx, long timeout) - throws GridCacheEntryRemovedException, GridDistributedLockCancelledException { - if (tx.local()) - // Null is returned if timeout is negative and there is other lock owner. - return addLocal( - tx.threadId(), - tx.xidVersion(), - timeout, - false, - true, - tx.implicitSingle()) != null; - - try { - addRemote( - tx.nodeId(), - tx.otherNodeId(), - tx.threadId(), - tx.xidVersion(), - tx.timeout(), - true, - tx.implicitSingle(), - tx.ownedVersion(txKey()) - ); - - return true; - } - catch (GridDistributedLockCancelledException ignored) { - if (log.isDebugEnabled()) - log.debug("Attempted to enter tx lock for cancelled ID (will ignore): " + tx); - - return false; - } - } - - /** {@inheritDoc} */ - @Override public void txUnlock(IgniteTxEx<K, V> tx) throws GridCacheEntryRemovedException { - removeLock(tx.xidVersion()); - } - - /** - * @param emptyBefore Empty flag before operation. - * @param emptyAfter Empty flag after operation. - */ - protected void checkCallbacks(boolean emptyBefore, boolean emptyAfter) { - assert Thread.holdsLock(this); - - if (emptyBefore != emptyAfter) { - if (emptyBefore) - cctx.mvcc().callback().onLocked(this); - - if (emptyAfter) - cctx.mvcc().callback().onFreed(this); - } - } - - /** - * @param prev Previous owner. - * @param owner Current owner. - * @param val Entry value. - */ - protected void checkOwnerChanged(GridCacheMvccCandidate<K> prev, GridCacheMvccCandidate<K> owner, V val) { - assert !Thread.holdsLock(this); - - if (owner != prev) { - cctx.mvcc().callback().onOwnerChanged(this, prev, owner); - - if (owner != null && owner.local()) - checkThreadChain(owner); - - if (prev != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_UNLOCKED)) { - boolean hasVal = hasValue(); - - // Event notification. - cctx.events().addEvent(partition(), key, prev.nodeId(), prev, EVT_CACHE_OBJECT_UNLOCKED, val, hasVal, - val, hasVal, null, null, null); - } - - if (owner != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_LOCKED)) { - boolean hasVal = hasValue(); - - // Event notification. - cctx.events().addEvent(partition(), key, owner.nodeId(), owner, EVT_CACHE_OBJECT_LOCKED, val, hasVal, - val, hasVal, null, null, null); - } - } - } - - /** - * @param owner Starting candidate in the chain. - */ - protected void checkThreadChain(GridCacheMvccCandidate<K> owner) { - assert !Thread.holdsLock(this); - - assert owner != null; - assert owner.owner() || owner.used() : "Neither owner or used flags are set on ready local candidate: " + - owner; - - if (owner.local() && owner.next() != null) { - for (GridCacheMvccCandidate<K> cand = owner.next(); cand != null; cand = cand.next()) { - assert cand.local() : "Remote candidate cannot be part of thread chain: " + cand; - - // Allow next lock in the thread to proceed. - if (!cand.used()) { - GridDistributedCacheEntry<K, V> e = - (GridDistributedCacheEntry<K, V>)cctx.cache().peekEx(cand.key()); - - if (e != null) - e.recheck(); - - break; - } - } - } - } - - /** - * @param col Collection to mask. - * @return Empty collection if argument is null. - */ - private Collection<GridCacheVersion> maskNull(Collection<GridCacheVersion> col) { - return col == null ? Collections.<GridCacheVersion>emptyList() : col; - } - - /** {@inheritDoc} */ - @Override public synchronized String toString() { - return S.toString(GridDistributedCacheEntry.class, this, super.toString()); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockCancelledException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockCancelledException.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockCancelledException.java deleted file mode 100644 index d284a7a..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockCancelledException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.cache.distributed; - -/** - * Exception thrown whenever an attempt is made to acquire a cancelled lock. - */ -public class GridDistributedLockCancelledException extends Exception { - /** */ - private static final long serialVersionUID = 0L; - - /** - * - */ - public GridDistributedLockCancelledException() { - // No-op. - } - - /** - * @param msg Message. - */ - public GridDistributedLockCancelledException(String msg) { - super(msg); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockRequest.java deleted file mode 100644 index 484d9c8..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockRequest.java +++ /dev/null @@ -1,833 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.transactions.*; -import org.gridgain.grid.kernal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.tostring.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.nio.*; -import java.util.*; - -/** - * Lock request message. - */ -public class GridDistributedLockRequest<K, V> extends GridDistributedBaseMessage<K, V> { - /** */ - private static final long serialVersionUID = 0L; - - /** Sender node ID. */ - private UUID nodeId; - - /** Near transaction version. */ - private GridCacheVersion nearXidVer; - - /** Thread ID. */ - private long threadId; - - /** Future ID. */ - private IgniteUuid futId; - - /** Max wait timeout. */ - private long timeout; - - /** Indicates whether lock is obtained within a scope of transaction. */ - private boolean isInTx; - - /** Invalidate flag for transactions. */ - private boolean isInvalidate; - - /** Indicates whether implicit lock so for read or write operation. */ - private boolean isRead; - - /** Transaction isolation. */ - private IgniteTxIsolation isolation; - - /** Key bytes for keys to lock. */ - @GridDirectCollection(byte[].class) - private List<byte[]> keyBytes; - - /** Keys. */ - @GridDirectTransient - private List<K> keys; - - /** Write entries. */ - @GridToStringInclude - @GridDirectTransient - private List<IgniteTxEntry<K, V>> writeEntries; - - /** Serialized write entries. */ - private byte[] writeEntriesBytes; - - /** Array indicating whether value should be returned for a key. */ - @GridToStringInclude - private boolean[] retVals; - - /** Key-bytes index. */ - @GridDirectTransient - protected int idx; - - /** Key count. */ - private int txSize; - - /** Group lock key if this is a group-lock transaction. */ - @GridDirectTransient - private IgniteTxKey grpLockKey; - - /** Group lock key bytes. */ - private byte[] grpLockKeyBytes; - - /** Partition lock flag. Only if group-lock transaction. */ - private boolean partLock; - - /** DR versions. */ - @GridToStringInclude - private GridCacheVersion[] drVersByIdx; - - /** - * Empty constructor. - */ - public GridDistributedLockRequest() { - /* No-op. */ - } - - /** - * @param nodeId Node ID. - * @param nearXidVer Near transaction ID. - * @param threadId Thread ID. - * @param futId Future ID. - * @param lockVer Cache version. - * @param isInTx {@code True} if implicit transaction lock. - * @param isRead Indicates whether implicit lock is for read or write operation. - * @param isolation Transaction isolation. - * @param isInvalidate Invalidation flag. - * @param timeout Lock timeout. - * @param keyCnt Number of keys. - * @param txSize Expected transaction size. - * @param grpLockKey Group lock key if this is a group-lock transaction. - * @param partLock {@code True} if this is a group-lock transaction request and whole partition is - * locked. - */ - public GridDistributedLockRequest( - int cacheId, - UUID nodeId, - @Nullable GridCacheVersion nearXidVer, - long threadId, - IgniteUuid futId, - GridCacheVersion lockVer, - boolean isInTx, - boolean isRead, - IgniteTxIsolation isolation, - boolean isInvalidate, - long timeout, - int keyCnt, - int txSize, - @Nullable IgniteTxKey grpLockKey, - boolean partLock - ) { - super(lockVer, keyCnt); - - assert keyCnt > 0; - assert futId != null; - assert !isInTx || isolation != null; - - this.cacheId = cacheId; - this.nodeId = nodeId; - this.nearXidVer = nearXidVer; - this.threadId = threadId; - this.futId = futId; - this.isInTx = isInTx; - this.isRead = isRead; - this.isolation = isolation; - this.isInvalidate = isInvalidate; - this.timeout = timeout; - this.txSize = txSize; - this.grpLockKey = grpLockKey; - this.partLock = partLock; - - retVals = new boolean[keyCnt]; - } - - /** - * - * @return Node ID. - */ - public UUID nodeId() { - return nodeId; - } - - /** - * @return Near transaction ID. - */ - public GridCacheVersion nearXidVersion() { - return nearXidVer; - } - - /** - * - * @return Owner node thread ID. - */ - public long threadId() { - return threadId; - } - - /** - * @return Future ID. - */ - public IgniteUuid futureId() { - return futId; - } - - /** - * @return {@code True} if implicit transaction lock. - */ - public boolean inTx() { - return isInTx; - } - - /** - * @return Invalidate flag. - */ - public boolean isInvalidate() { - return isInvalidate; - } - - /** - * @return {@code True} if lock is implicit and for a read operation. - */ - public boolean txRead() { - return isRead; - } - - /** - * @param idx Key index. - * @return Flag indicating whether a value should be returned. - */ - public boolean returnValue(int idx) { - return retVals[idx]; - } - - /** - * @return Return flags. - */ - public boolean[] returnFlags() { - return retVals; - } - - /** - * @return Transaction isolation or <tt>null</tt> if not in transaction. - */ - public IgniteTxIsolation isolation() { - return isolation; - } - - /** - * - * @return Key to lock. - */ - public List<byte[]> keyBytes() { - return keyBytes; - } - - /** - * @return Write entries list. - */ - public List<IgniteTxEntry<K, V>> writeEntries() { - return writeEntries; - } - - /** - * @return Tx size. - */ - public int txSize() { - return txSize; - } - - /** - * Adds a key. - * - * @param key Key. - * @param retVal Flag indicating whether value should be returned. - * @param keyBytes Key bytes. - * @param writeEntry Write entry. - * @param cands Candidates. - * @param drVer DR version. - * @param ctx Context. - * @throws IgniteCheckedException If failed. - */ - public void addKeyBytes( - K key, - @Nullable byte[] keyBytes, - @Nullable IgniteTxEntry<K, V> writeEntry, - boolean retVal, - @Nullable Collection<GridCacheMvccCandidate<K>> cands, - @Nullable GridCacheVersion drVer, - GridCacheContext<K, V> ctx - ) throws IgniteCheckedException { - if (ctx.deploymentEnabled()) - prepareObject(key, ctx.shared()); - - if (keyBytes != null) { - if (this.keyBytes == null) - this.keyBytes = new ArrayList<>(keysCount()); - - this.keyBytes.add(keyBytes); - } - - if (keys == null) - keys = new ArrayList<>(keysCount()); - - keys.add(key); - - candidatesByIndex(idx, cands); - drVersionByIndex(idx, drVer); - - retVals[idx] = retVal; - - if (writeEntry != null) { - if (writeEntries == null) { - assert idx == 0 : "Cannot start adding write entries in the middle of lock message [idx=" + idx + - ", writeEntry=" + writeEntry + ']'; - - writeEntries = new ArrayList<>(keysCount()); - } - - writeEntries.add(writeEntry); - } - - idx++; - } - - /** - * @return Unmarshalled keys. - */ - public List<K> keys() { - return keys; - } - - /** - * @return {@code True} if lock request for group-lock transaction. - */ - public boolean groupLock() { - return grpLockKey != null; - } - - /** - * @return Group lock key. - */ - @Nullable public IgniteTxKey groupLockKey() { - return grpLockKey; - } - - /** - * @return {@code True} if partition is locked in group-lock transaction. - */ - public boolean partitionLock() { - return partLock; - } - - /** - * @return Max lock wait time. - */ - public long timeout() { - return timeout; - } - - /** - * @param idx Key index. - * @param drVer DR version. - */ - @SuppressWarnings({"unchecked"}) - public void drVersionByIndex(int idx, GridCacheVersion drVer) { - assert idx < keysCount(); - - // If nothing to add. - if (drVer == null) - return; - - if (drVersByIdx == null) - drVersByIdx = new GridCacheVersion[keysCount()]; - - drVersByIdx[idx] = drVer; - } - - /** - * @param idx Key index. - * @return DR versions for given key. - */ - public GridCacheVersion drVersionByIndex(int idx) { - return drVersByIdx == null ? null : drVersByIdx[idx]; - } - - /** - * @return All DR versions. - */ - public GridCacheVersion[] drVersions() { - return drVersByIdx; - } - - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext<K, V> ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (grpLockKey != null && grpLockKeyBytes == null) { - if (ctx.deploymentEnabled()) - prepareObject(grpLockKey, ctx); - - grpLockKeyBytes = CU.marshal(ctx, grpLockKey); - } - - if (writeEntries != null) { - marshalTx(writeEntries, ctx); - - writeEntriesBytes = ctx.marshaller().marshal(writeEntries); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext<K, V> ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (keys == null) - keys = unmarshalCollection(keyBytes, ctx, ldr); - - if (grpLockKey == null && grpLockKeyBytes != null) - grpLockKey = ctx.marshaller().unmarshal(grpLockKeyBytes, ldr); - - if (writeEntriesBytes != null) { - writeEntries = ctx.marshaller().unmarshal(writeEntriesBytes, ldr); - - unmarshalTx(writeEntries, false, ctx, ldr); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneCallsConstructors", "OverriddenMethodCallDuringObjectConstruction", - "CloneDoesntCallSuperClone"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridDistributedLockRequest _clone = new GridDistributedLockRequest(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - super.clone0(_msg); - - GridDistributedLockRequest _clone = (GridDistributedLockRequest)_msg; - - _clone.nodeId = nodeId; - _clone.nearXidVer = nearXidVer; - _clone.threadId = threadId; - _clone.futId = futId; - _clone.timeout = timeout; - _clone.isInTx = isInTx; - _clone.isInvalidate = isInvalidate; - _clone.isRead = isRead; - _clone.isolation = isolation; - _clone.keyBytes = keyBytes; - _clone.keys = keys; - _clone.writeEntries = writeEntries; - _clone.writeEntriesBytes = writeEntriesBytes; - _clone.retVals = retVals; - _clone.idx = idx; - _clone.txSize = txSize; - _clone.grpLockKey = grpLockKey; - _clone.grpLockKeyBytes = grpLockKeyBytes; - _clone.partLock = partLock; - _clone.drVersByIdx = drVersByIdx; - } - - /** {@inheritDoc} */ - @SuppressWarnings("all") - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!super.writeTo(buf)) - return false; - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 8: - if (drVersByIdx != null) { - if (commState.it == null) { - if (!commState.putInt(drVersByIdx.length)) - return false; - - commState.it = arrayIterator(drVersByIdx); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putCacheVersion((GridCacheVersion)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; - - case 9: - if (!commState.putGridUuid(futId)) - return false; - - commState.idx++; - - case 10: - if (!commState.putByteArray(grpLockKeyBytes)) - return false; - - commState.idx++; - - case 11: - if (!commState.putBoolean(isInTx)) - return false; - - commState.idx++; - - case 12: - if (!commState.putBoolean(isInvalidate)) - return false; - - commState.idx++; - - case 13: - if (!commState.putBoolean(isRead)) - return false; - - commState.idx++; - - case 14: - if (!commState.putEnum(isolation)) - return false; - - commState.idx++; - - case 15: - if (keyBytes != null) { - if (commState.it == null) { - if (!commState.putInt(keyBytes.size())) - return false; - - commState.it = keyBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; - - case 16: - if (!commState.putCacheVersion(nearXidVer)) - return false; - - commState.idx++; - - case 17: - if (!commState.putUuid(nodeId)) - return false; - - commState.idx++; - - case 18: - if (!commState.putBoolean(partLock)) - return false; - - commState.idx++; - - case 19: - if (!commState.putBooleanArray(retVals)) - return false; - - commState.idx++; - - case 20: - if (!commState.putLong(threadId)) - return false; - - commState.idx++; - - case 21: - if (!commState.putLong(timeout)) - return false; - - commState.idx++; - - case 22: - if (!commState.putInt(txSize)) - return false; - - commState.idx++; - - case 23: - if (!commState.putByteArray(writeEntriesBytes)) - return false; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @SuppressWarnings("all") - @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!super.readFrom(buf)) - return false; - - switch (commState.idx) { - case 8: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (drVersByIdx == null) - drVersByIdx = new GridCacheVersion[commState.readSize]; - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheVersion _val = commState.getCacheVersion(); - - if (_val == CACHE_VER_NOT_READ) - return false; - - drVersByIdx[i] = (GridCacheVersion)_val; - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - - commState.idx++; - - case 9: - IgniteUuid futId0 = commState.getGridUuid(); - - if (futId0 == GRID_UUID_NOT_READ) - return false; - - futId = futId0; - - commState.idx++; - - case 10: - byte[] grpLockKeyBytes0 = commState.getByteArray(); - - if (grpLockKeyBytes0 == BYTE_ARR_NOT_READ) - return false; - - grpLockKeyBytes = grpLockKeyBytes0; - - commState.idx++; - - case 11: - if (buf.remaining() < 1) - return false; - - isInTx = commState.getBoolean(); - - commState.idx++; - - case 12: - if (buf.remaining() < 1) - return false; - - isInvalidate = commState.getBoolean(); - - commState.idx++; - - case 13: - if (buf.remaining() < 1) - return false; - - isRead = commState.getBoolean(); - - commState.idx++; - - case 14: - if (buf.remaining() < 1) - return false; - - byte isolation0 = commState.getByte(); - - isolation = IgniteTxIsolation.fromOrdinal(isolation0); - - commState.idx++; - - case 15: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (keyBytes == null) - keyBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - keyBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - - commState.idx++; - - case 16: - GridCacheVersion nearXidVer0 = commState.getCacheVersion(); - - if (nearXidVer0 == CACHE_VER_NOT_READ) - return false; - - nearXidVer = nearXidVer0; - - commState.idx++; - - case 17: - UUID nodeId0 = commState.getUuid(); - - if (nodeId0 == UUID_NOT_READ) - return false; - - nodeId = nodeId0; - - commState.idx++; - - case 18: - if (buf.remaining() < 1) - return false; - - partLock = commState.getBoolean(); - - commState.idx++; - - case 19: - boolean[] retVals0 = commState.getBooleanArray(); - - if (retVals0 == BOOLEAN_ARR_NOT_READ) - return false; - - retVals = retVals0; - - commState.idx++; - - case 20: - if (buf.remaining() < 8) - return false; - - threadId = commState.getLong(); - - commState.idx++; - - case 21: - if (buf.remaining() < 8) - return false; - - timeout = commState.getLong(); - - commState.idx++; - - case 22: - if (buf.remaining() < 4) - return false; - - txSize = commState.getInt(); - - commState.idx++; - - case 23: - byte[] writeEntriesBytes0 = commState.getByteArray(); - - if (writeEntriesBytes0 == BYTE_ARR_NOT_READ) - return false; - - writeEntriesBytes = writeEntriesBytes0; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return 22; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridDistributedLockRequest.class, this, "keysCnt", retVals.length, - "super", super.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockResponse.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockResponse.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockResponse.java deleted file mode 100644 index 472c972..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedLockResponse.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.lang.*; -import org.gridgain.grid.kernal.processors.cache.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.tostring.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.nio.*; -import java.util.*; - -/** - * Lock response message. - */ -public class GridDistributedLockResponse<K, V> extends GridDistributedBaseMessage<K, V> { - /** */ - private static final long serialVersionUID = 0L; - - /** Future ID. */ - private IgniteUuid futId; - - /** Error. */ - @GridDirectTransient - private Throwable err; - - /** Serialized error. */ - private byte[] errBytes; - - /** Value bytes. */ - @GridDirectCollection(GridCacheValueBytes.class) - private List<GridCacheValueBytes> valBytes; - - /** Values. */ - @GridToStringInclude - @GridDirectTransient - private List<V> vals; - - /** - * Empty constructor (required by {@link Externalizable}). - */ - public GridDistributedLockResponse() { - /* No-op. */ - } - - /** - * @param cacheId Cache ID. - * @param lockVer Lock version. - * @param futId Future ID. - * @param cnt Key count. - */ - public GridDistributedLockResponse(int cacheId, - GridCacheVersion lockVer, - IgniteUuid futId, - int cnt) { - super(lockVer, cnt); - - assert futId != null; - - this.cacheId = cacheId; - this.futId = futId; - - vals = new ArrayList<>(cnt); - valBytes = new ArrayList<>(cnt); - } - - /** - * @param cacheId Cache ID. - * @param lockVer Lock ID. - * @param futId Future ID. - * @param err Error. - */ - public GridDistributedLockResponse(int cacheId, - GridCacheVersion lockVer, - IgniteUuid futId, - Throwable err) { - super(lockVer, 0); - - assert futId != null; - - this.cacheId = cacheId; - this.futId = futId; - this.err = err; - } - - /** - * @param cacheId Cache ID. - * @param lockVer Lock ID. - * @param futId Future ID. - * @param cnt Count. - * @param err Error. - */ - public GridDistributedLockResponse(int cacheId, - GridCacheVersion lockVer, - IgniteUuid futId, - int cnt, - Throwable err) { - super(lockVer, cnt); - - assert futId != null; - - this.cacheId = cacheId; - this.futId = futId; - this.err = err; - - vals = new ArrayList<>(cnt); - valBytes = new ArrayList<>(cnt); - } - - /** - * - * @return Future ID. - */ - public IgniteUuid futureId() { - return futId; - } - - /** - * @return Error. - */ - public Throwable error() { - return err; - } - - /** - * @param err Error to set. - */ - public void error(Throwable err) { - this.err = err; - } - - /** - * @param idx Index of locked flag. - * @return Value of locked flag at given index. - */ - public boolean isCurrentlyLocked(int idx) { - assert idx >= 0; - - Collection<GridCacheMvccCandidate<K>> cands = candidatesByIndex(idx); - - for (GridCacheMvccCandidate<K> cand : cands) - if (cand.owner()) - return true; - - return false; - } - - /** - * @param idx Candidates index. - * @param cands Collection of candidates. - * @param committedVers Committed versions relative to lock version. - * @param rolledbackVers Rolled back versions relative to lock version. - */ - public void setCandidates(int idx, Collection<GridCacheMvccCandidate<K>> cands, - Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers) { - assert idx >= 0; - - completedVersions(committedVers, rolledbackVers); - - candidatesByIndex(idx, cands); - } - - /** - * @param idx Value index. - * - * @return Value bytes (possibly {@code null}). - */ - @Nullable public byte[] valueBytes(int idx) { - if (!F.isEmpty(valBytes)) { - GridCacheValueBytes res = valBytes.get(idx); - - if (res != null && !res.isPlain()) - return res.get(); - } - - return null; - } - - /** - * @param val Value. - * @param valBytes Value bytes (possibly {@code null}). - * @param ctx Context. - * @throws IgniteCheckedException If failed. - */ - public void addValueBytes(V val, @Nullable byte[] valBytes, GridCacheContext<K, V> ctx) throws IgniteCheckedException { - if (ctx.deploymentEnabled()) - prepareObject(val, ctx.shared()); - - GridCacheValueBytes vb = null; - - if (val != null) { - vb = val instanceof byte[] ? GridCacheValueBytes.plain(val) : valBytes != null ? - GridCacheValueBytes.marshaled(valBytes) : null; - } - else if (valBytes != null) - vb = GridCacheValueBytes.marshaled(valBytes); - - this.valBytes.add(vb); - - vals.add(val); - } - - /** - * @return Values size. - */ - protected int valuesSize() { - return vals.size(); - } - - /** - * @param idx Index. - * @return Value for given index. - */ - @Nullable public V value(int idx) { - if (!F.isEmpty(vals)) { - V res = vals.get(idx); - - if (res != null) - return res; - } - - // If there was no value in values collection, then it could be in value bytes collection in case of byte[]. - if (!F.isEmpty(valBytes)) { - GridCacheValueBytes res = valBytes.get(idx); - - if (res != null && res.isPlain()) - return (V)res.get(); - } - - // Value is not found in both value and value bytes collections. - return null; - } - - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext<K, V> ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (F.isEmpty(valBytes) && !F.isEmpty(vals)) - valBytes = marshalValuesCollection(vals, ctx); - - if (err != null) - errBytes = ctx.marshaller().marshal(err); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext<K, V> ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (F.isEmpty(vals) && !F.isEmpty(valBytes)) - vals = unmarshalValueBytesCollection(valBytes, ctx, ldr); - - if (errBytes != null) - err = ctx.marshaller().unmarshal(errBytes, ldr); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", - "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridDistributedLockResponse _clone = new GridDistributedLockResponse(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - super.clone0(_msg); - - GridDistributedLockResponse _clone = (GridDistributedLockResponse)_msg; - - _clone.futId = futId; - _clone.err = err; - _clone.errBytes = errBytes; - _clone.valBytes = valBytes; - _clone.vals = vals; - } - - /** {@inheritDoc} */ - @SuppressWarnings("all") - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!super.writeTo(buf)) - return false; - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 8: - if (!commState.putByteArray(errBytes)) - return false; - - commState.idx++; - - case 9: - if (!commState.putGridUuid(futId)) - return false; - - commState.idx++; - - case 10: - if (valBytes != null) { - if (commState.it == null) { - if (!commState.putInt(valBytes.size())) - return false; - - commState.it = valBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putValueBytes((GridCacheValueBytes)commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @SuppressWarnings("all") - @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!super.readFrom(buf)) - return false; - - switch (commState.idx) { - case 8: - byte[] errBytes0 = commState.getByteArray(); - - if (errBytes0 == BYTE_ARR_NOT_READ) - return false; - - errBytes = errBytes0; - - commState.idx++; - - case 9: - IgniteUuid futId0 = commState.getGridUuid(); - - if (futId0 == GRID_UUID_NOT_READ) - return false; - - futId = futId0; - - commState.idx++; - - case 10: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (valBytes == null) - valBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - GridCacheValueBytes _val = commState.getValueBytes(); - - if (_val == VAL_BYTES_NOT_READ) - return false; - - valBytes.add((GridCacheValueBytes)_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - - commState.idx++; - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return 23; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridDistributedLockResponse.class, this, - "valBytesLen", valBytes == null ? 0 : valBytes.size(), - "super", super.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedTxFinishRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedTxFinishRequest.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedTxFinishRequest.java deleted file mode 100644 index f66b2a3..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/GridDistributedTxFinishRequest.java +++ /dev/null @@ -1,695 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.lang.*; -import org.gridgain.grid.kernal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.transactions.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.tostring.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.nio.*; -import java.util.*; - -/** - * Transaction completion message. - */ -public class GridDistributedTxFinishRequest<K, V> extends GridDistributedBaseMessage<K, V> { - /** */ - private static final long serialVersionUID = 0L; - - /** Future ID. */ - private IgniteUuid futId; - - /** Thread ID. */ - private long threadId; - - /** Commit version. */ - private GridCacheVersion commitVer; - - /** Invalidate flag. */ - private boolean invalidate; - - /** Commit flag. */ - private boolean commit; - - /** Sync commit flag. */ - private boolean syncCommit; - - /** Sync commit flag. */ - private boolean syncRollback; - - /** Min version used as base for completed versions. */ - private GridCacheVersion baseVer; - - /** Transaction write entries. */ - @GridToStringInclude - @GridDirectTransient - private Collection<IgniteTxEntry<K, V>> writeEntries; - - /** */ - @GridDirectCollection(byte[].class) - private Collection<byte[]> writeEntriesBytes; - - /** Write entries which have not been transferred to nodes during lock request. */ - @GridToStringInclude - @GridDirectTransient - private Collection<IgniteTxEntry<K, V>> recoveryWrites; - - /** */ - @GridDirectCollection(byte[].class) - private Collection<byte[]> recoveryWritesBytes; - - /** Expected txSize. */ - private int txSize; - - /** Group lock key. */ - @GridDirectTransient - private IgniteTxKey grpLockKey; - - /** Group lock key bytes. */ - private byte[] grpLockKeyBytes; - - /** System flag. */ - private boolean sys; - - /** - * Empty constructor required by {@link Externalizable}. - */ - public GridDistributedTxFinishRequest() { - /* No-op. */ - } - - /** - * @param xidVer Transaction ID. - * @param futId future ID. - * @param threadId Thread ID. - * @param commitVer Commit version. - * @param commit Commit flag. - * @param invalidate Invalidate flag. - * @param sys System flag. - * @param baseVer Base version. - * @param committedVers Committed versions. - * @param rolledbackVers Rolled back versions. - * @param txSize Expected transaction size. - * @param writeEntries Write entries. - * @param recoveryWrites Recover entries. In pessimistic mode entries which were not transferred to remote nodes - * with lock requests. {@code Null} for optimistic mode. - * @param grpLockKey Group lock key if this is a group-lock transaction. - */ - public GridDistributedTxFinishRequest( - GridCacheVersion xidVer, - IgniteUuid futId, - @Nullable GridCacheVersion commitVer, - long threadId, - boolean commit, - boolean invalidate, - boolean sys, - boolean syncCommit, - boolean syncRollback, - GridCacheVersion baseVer, - Collection<GridCacheVersion> committedVers, - Collection<GridCacheVersion> rolledbackVers, - int txSize, - Collection<IgniteTxEntry<K, V>> writeEntries, - Collection<IgniteTxEntry<K, V>> recoveryWrites, - @Nullable IgniteTxKey grpLockKey - ) { - super(xidVer, writeEntries == null ? 0 : writeEntries.size()); - assert xidVer != null; - - this.futId = futId; - this.commitVer = commitVer; - this.threadId = threadId; - this.commit = commit; - this.invalidate = invalidate; - this.sys = sys; - this.syncCommit = syncCommit; - this.syncRollback = syncRollback; - this.baseVer = baseVer; - this.txSize = txSize; - this.writeEntries = writeEntries; - this.recoveryWrites = recoveryWrites; - this.grpLockKey = grpLockKey; - - completedVersions(committedVers, rolledbackVers); - } - - /** - * Clones write entries so that near entries are not passed to DHT cache. - */ - public void cloneEntries() { - if (F.isEmpty(writeEntries)) - return; - - Collection<IgniteTxEntry<K, V>> cp = new ArrayList<>(writeEntries.size()); - - for (IgniteTxEntry<K, V> e : writeEntries) { - GridCacheContext<K, V> cacheCtx = e.context(); - - // Clone only if it is a near cache. - if (cacheCtx.isNear()) - cp.add(e.cleanCopy(cacheCtx.nearTx().dht().context())); - else - cp.add(e); - } - - writeEntries = cp; - } - - /** - * @return System flag. - */ - public boolean system() { - return sys; - } - - /** - * @return Future ID. - */ - public IgniteUuid futureId() { - return futId; - } - - /** - * @return Thread ID. - */ - public long threadId() { - return threadId; - } - - /** - * @return Commit version. - */ - public GridCacheVersion commitVersion() { - return commitVer; - } - - /** - * @return Commit flag. - */ - public boolean commit() { - return commit; - } - - /** - * - * @return Invalidate flag. - */ - public boolean isInvalidate() { - return invalidate; - } - - /** - * @return Sync commit flag. - */ - public boolean syncCommit() { - return syncCommit; - } - - /** - * @return Sync rollback flag. - */ - public boolean syncRollback() { - return syncRollback; - } - - /** - * @return Base version. - */ - public GridCacheVersion baseVersion() { - return baseVer; - } - - /** - * @return Write entries. - */ - public Collection<IgniteTxEntry<K, V>> writes() { - return writeEntries; - } - - /** - * @return Recover entries. - */ - public Collection<IgniteTxEntry<K, V>> recoveryWrites() { - return recoveryWrites; - } - - /** - * @return Expected tx size. - */ - public int txSize() { - return txSize; - } - - /** - * - * @return {@code True} if reply is required. - */ - public boolean replyRequired() { - return commit ? syncCommit : syncRollback; - } - - /** - * @return {@code True} if group lock transaction. - */ - public boolean groupLock() { - return grpLockKey != null; - } - - /** - * @return Group lock key. - */ - @Nullable public IgniteTxKey groupLockKey() { - return grpLockKey; - } - - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext<K, V> ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (writeEntries != null) { - marshalTx(writeEntries, ctx); - - writeEntriesBytes = new ArrayList<>(writeEntries.size()); - - for (IgniteTxEntry<K, V> e : writeEntries) - writeEntriesBytes.add(ctx.marshaller().marshal(e)); - } - - if (recoveryWrites != null) { - marshalTx(recoveryWrites, ctx); - - recoveryWritesBytes = new ArrayList<>(recoveryWrites.size()); - - for (IgniteTxEntry<K, V> e : recoveryWrites) - recoveryWritesBytes.add(ctx.marshaller().marshal(e)); - } - - if (grpLockKey != null && grpLockKeyBytes == null) { - if (ctx.deploymentEnabled()) - prepareObject(grpLockKey, ctx); - - grpLockKeyBytes = CU.marshal(ctx, grpLockKey); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext<K, V> ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (writeEntriesBytes != null) { - writeEntries = new ArrayList<>(writeEntriesBytes.size()); - - for (byte[] arr : writeEntriesBytes) - writeEntries.add(ctx.marshaller().<IgniteTxEntry<K, V>>unmarshal(arr, ldr)); - - unmarshalTx(writeEntries, false, ctx, ldr); - } - - if (recoveryWritesBytes != null) { - recoveryWrites = new ArrayList<>(recoveryWritesBytes.size()); - - for (byte[] arr : recoveryWritesBytes) - recoveryWrites.add(ctx.marshaller().<IgniteTxEntry<K, V>>unmarshal(arr, ldr)); - - unmarshalTx(recoveryWrites, false, ctx, ldr); - } - - if (grpLockKeyBytes != null && grpLockKey == null) - grpLockKey = ctx.marshaller().unmarshal(grpLockKeyBytes, ldr); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors", - "OverriddenMethodCallDuringObjectConstruction"}) - @Override public GridTcpCommunicationMessageAdapter clone() { - GridDistributedTxFinishRequest _clone = new GridDistributedTxFinishRequest(); - - clone0(_clone); - - return _clone; - } - - /** {@inheritDoc} */ - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - super.clone0(_msg); - - GridDistributedTxFinishRequest _clone = (GridDistributedTxFinishRequest)_msg; - - _clone.futId = futId; - _clone.threadId = threadId; - _clone.commitVer = commitVer; - _clone.invalidate = invalidate; - _clone.commit = commit; - _clone.baseVer = baseVer; - _clone.writeEntries = writeEntries; - _clone.writeEntriesBytes = writeEntriesBytes; - _clone.recoveryWrites = recoveryWrites; - _clone.recoveryWritesBytes = recoveryWritesBytes; - _clone.txSize = txSize; - _clone.grpLockKey = grpLockKey; - _clone.grpLockKeyBytes = grpLockKeyBytes; - _clone.sys = sys; - } - - /** {@inheritDoc} */ - @SuppressWarnings("all") - @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!super.writeTo(buf)) - return false; - - if (!commState.typeWritten) { - if (!commState.putByte(directType())) - return false; - - commState.typeWritten = true; - } - - switch (commState.idx) { - case 8: - if (!commState.putCacheVersion(baseVer)) - return false; - - commState.idx++; - - case 9: - if (!commState.putBoolean(commit)) - return false; - - commState.idx++; - - case 10: - if (!commState.putCacheVersion(commitVer)) - return false; - - commState.idx++; - - case 11: - if (!commState.putGridUuid(futId)) - return false; - - commState.idx++; - - case 12: - if (!commState.putByteArray(grpLockKeyBytes)) - return false; - - commState.idx++; - - case 13: - if (!commState.putBoolean(invalidate)) - return false; - - commState.idx++; - - case 14: - if (!commState.putBoolean(syncCommit)) - return false; - - commState.idx++; - - case 15: - if (!commState.putBoolean(syncRollback)) - return false; - - commState.idx++; - - case 16: - if (recoveryWritesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(recoveryWritesBytes.size())) - return false; - - commState.it = recoveryWritesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; - - case 17: - if (!commState.putLong(threadId)) - return false; - - commState.idx++; - - case 18: - if (!commState.putInt(txSize)) - return false; - - commState.idx++; - - case 19: - if (writeEntriesBytes != null) { - if (commState.it == null) { - if (!commState.putInt(writeEntriesBytes.size())) - return false; - - commState.it = writeEntriesBytes.iterator(); - } - - while (commState.it.hasNext() || commState.cur != NULL) { - if (commState.cur == NULL) - commState.cur = commState.it.next(); - - if (!commState.putByteArray((byte[])commState.cur)) - return false; - - commState.cur = NULL; - } - - commState.it = null; - } else { - if (!commState.putInt(-1)) - return false; - } - - commState.idx++; - - case 20: - if (!commState.putBoolean(sys)) - return false; - - commState.idx++; - } - - return true; - } - - /** {@inheritDoc} */ - @SuppressWarnings("all") - @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - if (!super.readFrom(buf)) - return false; - - switch (commState.idx) { - case 8: - GridCacheVersion baseVer0 = commState.getCacheVersion(); - - if (baseVer0 == CACHE_VER_NOT_READ) - return false; - - baseVer = baseVer0; - - commState.idx++; - - case 9: - if (buf.remaining() < 1) - return false; - - commit = commState.getBoolean(); - - commState.idx++; - - case 10: - GridCacheVersion commitVer0 = commState.getCacheVersion(); - - if (commitVer0 == CACHE_VER_NOT_READ) - return false; - - commitVer = commitVer0; - - commState.idx++; - - case 11: - IgniteUuid futId0 = commState.getGridUuid(); - - if (futId0 == GRID_UUID_NOT_READ) - return false; - - futId = futId0; - - commState.idx++; - - case 12: - byte[] grpLockKeyBytes0 = commState.getByteArray(); - - if (grpLockKeyBytes0 == BYTE_ARR_NOT_READ) - return false; - - grpLockKeyBytes = grpLockKeyBytes0; - - commState.idx++; - - case 13: - if (buf.remaining() < 1) - return false; - - invalidate = commState.getBoolean(); - - commState.idx++; - - case 14: - if (buf.remaining() < 1) - return false; - - syncCommit = commState.getBoolean(); - - commState.idx++; - - case 15: - if (buf.remaining() < 1) - return false; - - syncRollback = commState.getBoolean(); - - commState.idx++; - - case 16: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (recoveryWritesBytes == null) - recoveryWritesBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - recoveryWritesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - - commState.idx++; - - case 17: - if (buf.remaining() < 8) - return false; - - threadId = commState.getLong(); - - commState.idx++; - - case 18: - if (buf.remaining() < 4) - return false; - - txSize = commState.getInt(); - - commState.idx++; - - case 19: - if (commState.readSize == -1) { - if (buf.remaining() < 4) - return false; - - commState.readSize = commState.getInt(); - } - - if (commState.readSize >= 0) { - if (writeEntriesBytes == null) - writeEntriesBytes = new ArrayList<>(commState.readSize); - - for (int i = commState.readItems; i < commState.readSize; i++) { - byte[] _val = commState.getByteArray(); - - if (_val == BYTE_ARR_NOT_READ) - return false; - - writeEntriesBytes.add((byte[])_val); - - commState.readItems++; - } - } - - commState.readSize = -1; - commState.readItems = 0; - - commState.idx++; - - case 20: - if (buf.remaining() < 1) - return false; - - sys = commState.getBoolean(); - - commState.idx++; - } - - return true; - } - - /** {@inheritDoc} */ - @Override public byte directType() { - return 24; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return GridToStringBuilder.toString(GridDistributedTxFinishRequest.class, this, - "super", super.toString()); - } -}