ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [33/51] [abbrv] incubator-ignite git commit: IGNITE-264 - WIP
Date Wed, 25 Feb 2015 00:52:11 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
index 3ba96c0..604a737 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java
@@ -40,7 +40,6 @@ import static org.apache.ignite.internal.managers.communication.GridIoPolicy.*;
 import static org.apache.ignite.internal.processors.cache.GridCacheUtils.*;
 import static org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx.FinalizationStatus.*;
 import static org.apache.ignite.transactions.TransactionConcurrency.*;
-import static org.apache.ignite.transactions.TransactionIsolation.*;
 import static org.apache.ignite.transactions.TransactionState.*;
 
 /**
@@ -275,6 +274,7 @@ public class IgniteTxHandler<K, V> {
                 req.timeout(),
                 req.isInvalidate(),
                 false,
+                req.onePhaseCommit(),
                 req.txSize(),
                 req.transactionNodes(),
                 req.subjectId(),
@@ -296,8 +296,6 @@ public class IgniteTxHandler<K, V> {
             if (req.onePhaseCommit()) {
                 assert req.last();
                 assert F.isEmpty(req.lastBackups()) || req.lastBackups().size() <= 1;
-
-                tx.onePhaseCommit(true);
             }
 
             if (req.returnValue())
@@ -524,36 +522,10 @@ public class IgniteTxHandler<K, V> {
         }
 
         try {
-            if (req.commit()) {
-                if (tx == null) {
-                    // Create transaction and add entries.
-                    tx = ctx.tm().onCreated(
-                        new GridDhtTxLocal<>(
-                            ctx,
-                            nodeId,
-                            req.version(),
-                            req.futureId(),
-                            req.miniId(),
-                            req.threadId(),
-                            true,
-                            false, /* we don't know, so assume false. */
-                            req.system(),
-                            PESSIMISTIC,
-                            READ_COMMITTED,
-                            /*timeout */0,
-                            req.isInvalidate(),
-                            req.storeEnabled(),
-                            req.txSize(),
-                            null,
-                            req.subjectId(),
-                            req.taskNameHash()));
-
-                    if (tx == null || !ctx.tm().onStarted(tx))
-                        throw new IgniteTxRollbackCheckedException("Attempt to start a completed transaction: " + req);
-
-                    tx.topologyVersion(req.topologyVersion());
-                }
+            assert tx != null : "Transaction is null for near finish request [nodeId=" +
+                nodeId + ", req=" + req + "]";
 
+            if (req.commit()) {
                 tx.storeEnabled(req.storeEnabled());
 
                 if (!tx.markFinalizing(USER_FINISH)) {
@@ -577,9 +549,6 @@ public class IgniteTxHandler<K, V> {
                 return commitFut;
             }
             else {
-                assert tx != null : "Transaction is null for near rollback request [nodeId=" +
-                    nodeId + ", req=" + req + "]";
-
                 tx.syncRollback(req.syncRollback());
 
                 tx.nearFinishFutureId(req.futureId());
@@ -749,7 +718,18 @@ public class IgniteTxHandler<K, V> {
         if (nearTx != null && nearTx.local())
             nearTx = null;
 
-        finish(nodeId, dhtTx, req);
+        if (req.checkCommitted()) {
+            boolean committed = true;
+
+            if (dhtTx == null) {
+                if (ctx.tm().addRolledbackTx(req.version()))
+                    committed = false;
+            }
+
+            sendReply(nodeId, req, committed);
+        }
+        else
+            finish(nodeId, dhtTx, req);
 
         if (nearTx != null)
             finish(nodeId, nearTx, req);
@@ -757,12 +737,12 @@ public class IgniteTxHandler<K, V> {
         if (dhtTx != null && !dhtTx.done()) {
             dhtTx.finishFuture().listenAsync(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
                 @Override public void apply(IgniteInternalFuture<IgniteInternalTx> igniteTxIgniteFuture) {
-                    sendReply(nodeId, req);
+                    sendReply(nodeId, req, true);
                 }
             });
         }
         else
-            sendReply(nodeId, req);
+            sendReply(nodeId, req, true);
     }
 
     /**
@@ -802,13 +782,13 @@ public class IgniteTxHandler<K, V> {
                     tx.systemInvalidate(req.isSystemInvalidate());
 
                     // Complete remote candidates.
-                    tx.doneRemote(req.baseVersion(), null, null, null);
+                    tx.doneRemote(req.version());
 
                     tx.commit();
                 }
             }
             else {
-                tx.doneRemote(req.baseVersion(), null, null, null);
+                tx.doneRemote(req.version());
 
                 tx.rollback();
             }
@@ -845,7 +825,7 @@ public class IgniteTxHandler<K, V> {
             tx.invalidate(req.isInvalidate());
 
             // Complete remote candidates.
-            tx.doneRemote(req.version(), null, null, null);
+            tx.doneRemote(req.version());
 
             tx.commit();
         }
@@ -870,10 +850,12 @@ public class IgniteTxHandler<K, V> {
      * @param nodeId Node id that originated finish request.
      * @param req Request.
      */
-    protected void sendReply(UUID nodeId, GridDhtTxFinishRequest<K, V> req) {
+    protected void sendReply(UUID nodeId, GridDhtTxFinishRequest<K, V> req, boolean committed) {
         if (req.replyRequired()) {
             GridCacheMessage<K, V> res = new GridDhtTxFinishResponse<>(req.version(), req.futureId(), req.miniId());
 
+
+
             try {
                 ctx.io().send(nodeId, res, req.system() ? UTILITY_CACHE_POOL : SYSTEM_POOL);
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/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 d0c9034..5ca3951 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
@@ -75,15 +75,6 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V>
     /** Flag indicating with TM commit happened. */
     protected AtomicBoolean doneFlag = new AtomicBoolean(false);
 
-    /** Committed versions, relative to base. */
-    private Collection<GridCacheVersion> committedVers = Collections.emptyList();
-
-    /** Rolled back versions, relative to base. */
-    private Collection<GridCacheVersion> rolledbackVers = Collections.emptyList();
-
-    /** Base for completed versions. */
-    private GridCacheVersion completedBase;
-
     /** Flag indicating that transformed values should be sent to remote nodes. */
     private boolean sndTransformedVals;
 
@@ -129,12 +120,13 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V>
         long timeout,
         boolean invalidate,
         boolean storeEnabled,
+        boolean onePhaseCommit,
         int txSize,
         @Nullable UUID subjId,
         int taskNameHash
     ) {
         super(cctx, xidVer, implicit, implicitSingle, /*local*/true, sys, concurrency, isolation, timeout, invalidate,
-            storeEnabled, txSize, subjId, taskNameHash);
+            storeEnabled, onePhaseCommit, txSize, subjId, taskNameHash);
 
         minVer = xidVer;
     }
@@ -982,12 +974,6 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V>
             if (doneFlag.compareAndSet(false, true)) {
                 // Unlock all locks.
                 cctx.tm().commitTx(this);
-
-                boolean needsCompletedVersions = needsCompletedVersions();
-
-                assert !needsCompletedVersions || completedBase != null;
-                assert !needsCompletedVersions || committedVers != null;
-                assert !needsCompletedVersions || rolledbackVers != null;
             }
         }
     }
@@ -1003,47 +989,10 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V>
             cctx.tm().commitTx(this);
 
             state(COMMITTED);
-
-            boolean needsCompletedVersions = needsCompletedVersions();
-
-            assert !needsCompletedVersions || completedBase != null;
-            assert !needsCompletedVersions || committedVers != null;
-            assert !needsCompletedVersions || rolledbackVers != null;
         }
     }
 
     /** {@inheritDoc} */
-    @Override public void completedVersions(
-        GridCacheVersion completedBase,
-        Collection<GridCacheVersion> committedVers,
-        Collection<GridCacheVersion> rolledbackVers) {
-        this.completedBase = completedBase;
-        this.committedVers = committedVers;
-        this.rolledbackVers = rolledbackVers;
-    }
-
-    /**
-     * @return Completed base for ordering.
-     */
-    public GridCacheVersion completedBase() {
-        return completedBase;
-    }
-
-    /**
-     * @return Committed versions.
-     */
-    public Collection<GridCacheVersion> committedVersions() {
-        return committedVers;
-    }
-
-    /**
-     * @return Rolledback versions.
-     */
-    public Collection<GridCacheVersion> rolledbackVersions() {
-        return rolledbackVers;
-    }
-
-    /** {@inheritDoc} */
     @Override public void userRollback() throws IgniteCheckedException {
         TransactionState state = state();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/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 ef5f180..f9c4c54 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
@@ -202,8 +202,7 @@ public class IgniteTxManager<K, V> extends GridCacheSharedManagerAdapter<K, V> {
                 if (tx instanceof IgniteTxRemoteEx) {
                     IgniteTxRemoteEx<K, V> rmtTx = (IgniteTxRemoteEx<K, V>)tx;
 
-                    rmtTx.doneRemote(tx.xidVersion(), Collections.<GridCacheVersion>emptyList(),
-                        Collections.<GridCacheVersion>emptyList(), Collections.<GridCacheVersion>emptyList());
+                    rmtTx.doneRemote(tx.xidVersion());
                 }
 
                 tx.commit();
@@ -1032,76 +1031,6 @@ public class IgniteTxManager<K, V> extends GridCacheSharedManagerAdapter<K, V> {
     }
 
     /**
-     * @param tx Transaction.
-     */
-    private void processCompletedEntries(IgniteInternalTx<K, V> tx) {
-        if (tx.needsCompletedVersions()) {
-            GridCacheVersion min = minVersion(tx.readEntries(), tx.xidVersion(), tx);
-
-            min = minVersion(tx.writeEntries(), min, tx);
-
-            assert min != null;
-
-            tx.completedVersions(min, committedVersions(min), rolledbackVersions(min));
-        }
-    }
-
-    /**
-     * Collects versions for all pending locks for all entries within transaction
-     *
-     * @param dhtTxLoc Transaction being committed.
-     */
-    private void collectPendingVersions(GridDhtTxLocal<K, V> dhtTxLoc) {
-        if (dhtTxLoc.needsCompletedVersions()) {
-            if (log.isDebugEnabled())
-                log.debug("Checking for pending locks with version less then tx version: " + dhtTxLoc);
-
-            Set<GridCacheVersion> vers = new LinkedHashSet<>();
-
-            collectPendingVersions(dhtTxLoc.readEntries(), dhtTxLoc.xidVersion(), vers);
-            collectPendingVersions(dhtTxLoc.writeEntries(), dhtTxLoc.xidVersion(), vers);
-
-            if (!vers.isEmpty())
-                dhtTxLoc.pendingVersions(vers);
-        }
-    }
-
-    /**
-     * Gets versions of all not acquired locks for collection of tx entries that are less then base version.
-     *
-     * @param entries Tx entries to process.
-     * @param baseVer Base version to compare with.
-     * @param vers Collection of versions that will be populated.
-     */
-    @SuppressWarnings("TypeMayBeWeakened")
-    private void collectPendingVersions(Iterable<IgniteTxEntry<K, V>> entries,
-        GridCacheVersion baseVer, Set<GridCacheVersion> vers) {
-
-        // The locks are not released yet, so we can safely list pending candidates versions.
-        for (IgniteTxEntry<K, V> txEntry : entries) {
-            GridCacheEntryEx<K, V> cached = txEntry.cached();
-
-            try {
-                // If check should be faster then exception handling.
-                if (!cached.obsolete()) {
-                    for (GridCacheMvccCandidate<K> cand : cached.localCandidates()) {
-                        if (!cand.owner() && cand.version().compareTo(baseVer) < 0) {
-                            if (log.isDebugEnabled())
-                                log.debug("Adding candidate version to pending set: " + cand);
-
-                            vers.add(cand.version());
-                        }
-                    }
-                }
-            }
-            catch (GridCacheEntryRemovedException ignored) {
-                if (log.isDebugEnabled())
-                    log.debug("There are no pending locks for entry (entry was deleted in transaction): " + txEntry);
-            }
-        }
-    }
-
-    /**
      * Go through all candidates for entries involved in transaction and find their min
      * version. We know that these candidates will commit after this transaction, and
      * therefore we can grab the min version so we can send all committed and rolled
@@ -1169,15 +1098,6 @@ public class IgniteTxManager<K, V> extends GridCacheSharedManagerAdapter<K, V> {
         ConcurrentMap<GridCacheVersion, IgniteInternalTx<K, V>> txIdMap = transactionMap(tx);
 
         if (txIdMap.remove(tx.xidVersion(), tx)) {
-            // 2. Must process completed entries before unlocking!
-            processCompletedEntries(tx);
-
-            if (tx instanceof GridDhtTxLocal) {
-                GridDhtTxLocal<K, V> dhtTxLoc = (GridDhtTxLocal<K, V>)tx;
-
-                collectPendingVersions(dhtTxLoc);
-            }
-
             // 3.1 Call dataStructures manager.
             cctx.kernalContext().dataStructures().onTxCommitted(tx);
 
@@ -1806,8 +1726,7 @@ public class IgniteTxManager<K, V> extends GridCacheSharedManagerAdapter<K, V> {
         if (tx instanceof GridDistributedTxRemoteAdapter) {
             IgniteTxRemoteEx<K,V> rmtTx = (IgniteTxRemoteEx<K, V>)tx;
 
-            rmtTx.doneRemote(tx.xidVersion(), Collections.<GridCacheVersion>emptyList(), Collections.<GridCacheVersion>emptyList(),
-                Collections.<GridCacheVersion>emptyList());
+            rmtTx.doneRemote(tx.xidVersion());
         }
 
         if (commit)
@@ -1833,8 +1752,7 @@ public class IgniteTxManager<K, V> extends GridCacheSharedManagerAdapter<K, V> {
         if (tx instanceof GridDistributedTxRemoteAdapter) {
             IgniteTxRemoteEx<K,V> rmtTx = (IgniteTxRemoteEx<K, V>)tx;
 
-            rmtTx.doneRemote(tx.xidVersion(), Collections.<GridCacheVersion>emptyList(), Collections.<GridCacheVersion>emptyList(),
-                Collections.<GridCacheVersion>emptyList());
+            rmtTx.doneRemote(tx.xidVersion());
         }
 
         try {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxRemoteEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxRemoteEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxRemoteEx.java
index adbccea..71afb51 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxRemoteEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxRemoteEx.java
@@ -32,12 +32,8 @@ public interface IgniteTxRemoteEx<K, V> extends IgniteInternalTx<K, V> {
 
     /**
      * @param baseVer Base version.
-     * @param committedVers Committed version.
-     * @param rolledbackVers Rolled back version.
-     * @param pendingVers Pending versions.
      */
-    public void doneRemote(GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers,
-        Collection<GridCacheVersion> rolledbackVers, Collection<GridCacheVersion> pendingVers);
+    public void doneRemote(GridCacheVersion baseVer);
 
     /**
      * @param e Sets write value for pessimistic transactions.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
index 5935287..71cb0fc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccPartitionedSelfTest.java
@@ -105,79 +105,24 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
         assertEquals(1, rmtCands.size());
         assertEquals(ver1, rmtCands.iterator().next().version());
 
-        entry.readyNearLocal(ver2, ver2, empty(), empty(), Arrays.asList(ver1));
+        entry.readyNearLocal(ver2, ver2);
 
-        checkLocalOwner(c2, ver2, false);
+        checkLocal(c2, ver2, true, false, false);
         checkRemote(c1, ver1, false, false);
 
-        assertNotNull(entry.anyOwner());
-        assertEquals(ver2, entry.anyOwner().version());
-    }
-
-    /**
-     * Tests remote candidates.
-     */
-    public void testNearLocalsWithCommitted() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-
-        GridCacheMvccCandidate<String> c1 = entry.addNearLocal(node1, 1, ver1, 0, true);
-        GridCacheMvccCandidate<String> c2 = entry.addRemote(node1, 1, ver2, 0, false, true);
-
-        Collection<GridCacheMvccCandidate<String>> rmtCands = entry.remoteMvccSnapshot();
-        Collection<GridCacheMvccCandidate<String>> nearLocCands = entry.localCandidates();
-
-        assertEquals(1, nearLocCands.size());
-        assertEquals(ver1, nearLocCands.iterator().next().version());
-
-        assertEquals(1, rmtCands.size());
-        assertEquals(ver2, rmtCands.iterator().next().version());
-
-        entry.readyNearLocal(ver1, ver1, Arrays.asList(ver2), empty(), empty());
-
-        checkLocal(c1, ver1, true, false, false);
-        checkRemote(c2, ver2, true, false);
-
-        assertNull(entry.anyOwner());
-    }
-
-    /**
-     * Tests remote candidates.
-     */
-    public void testNearLocalsWithRolledback() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-
-        GridCacheMvccCandidate<String> c1 = entry.addNearLocal(node1, 1, ver1, 0, true);
-        GridCacheMvccCandidate<String> c2 = entry.addRemote(node1, 1, ver2, 0, false, true);
+        entry.doneRemote(ver1);
 
-        Collection<GridCacheMvccCandidate<String>> rmtCands = entry.remoteMvccSnapshot();
-        Collection<GridCacheMvccCandidate<String>> nearLocCands = entry.localCandidates();
+        checkLocal(c2, ver2, true, false, false);
+        checkRemote(c1, ver1, true, true);
 
-        assertEquals(1, nearLocCands.size());
-        assertEquals(ver1, nearLocCands.iterator().next().version());
+        entry.removeLock(ver1);
 
-        assertEquals(1, rmtCands.size());
-        assertEquals(ver2, rmtCands.iterator().next().version());
+        assertTrue(entry.remoteMvccSnapshot().isEmpty());
 
-        entry.readyNearLocal(ver1, ver1, empty(), Arrays.asList(ver2), empty());
+        checkLocal(c2, ver2, true, true, false);
 
-        checkLocal(c1, ver1, true, false, false);
-        checkRemote(c2, ver2, true, false);
-
-        assertNull(entry.anyOwner());
+        assertNotNull(entry.anyOwner());
+        assertEquals(ver2, entry.anyOwner().version());
     }
 
     /**
@@ -196,7 +141,7 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
         GridCacheMvccCandidate<String> c1 = entry.addNearLocal(node1, 1, ver1, 0, true);
         GridCacheMvccCandidate<String> c2 = entry.addNearLocal(node1, 1, ver2, 0, true);
 
-        entry.readyNearLocal(ver2, ver2,  empty(), empty(), empty());
+        entry.readyNearLocal(ver2, ver2);
 
         checkLocalOwner(c2, ver2, false);
         checkLocal(c1, ver1, false, false, false);
@@ -237,135 +182,15 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
 
         entry.orderOwned(ver1, ver2);
 
-        entry.readyNearLocal(ver2, ver2,  empty(), empty(), empty());
+        entry.readyNearLocal(ver2, ver2);
 
         checkRemote(c1, ver1, false, false);
 
         assertFalse(c1.owner());
 
-        checkLocalOwner(c2, ver2, false);
-
-        assertNotNull(entry.anyOwner());
-        assertEquals(ver2, entry.anyOwner().version());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAddPendingRemote0() throws Exception {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-
-        GridCacheVersion ver0 = version(0);
-        GridCacheVersion ver1 = version(1);
-
-        entry.addNearLocal(node1, 1, ver1, 0, true);
-
-        entry.readyNearLocal(ver1, ver1, empty(), empty(), Collections.singletonList(ver0));
-
-        entry.addRemote(node1, 1, ver0, 0, false, true);
-
-        Collection<GridCacheMvccCandidate<String>> rmtCands = entry.remoteMvccSnapshot();
-        Collection<GridCacheMvccCandidate<String>> nearLocCands = entry.localCandidates();
-
-        assertEquals(1, nearLocCands.size());
-        assertEquals(ver1, nearLocCands.iterator().next().version());
+        checkLocal(c2, ver2, true, false, false);
 
-        assertEquals(1, rmtCands.size());
-        assertEquals(ver0, rmtCands.iterator().next().version());
-
-        assertNotNull(entry.anyOwner());
-        assertEquals(ver1, entry.anyOwner().version());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAddPendingRemote1() throws Exception {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-
-        GridCacheVersion ver0 = version(0);
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-
-        GridCacheMvccCandidate<String> c3 = entry.addNearLocal(node1, 1, ver3, 0, true);
-
-        entry.readyNearLocal(ver3, ver3, empty(), empty(), Arrays.asList(ver0, ver1, ver2));
-
-        GridCacheMvccCandidate<String> c2 = entry.addRemote(node1, 1, ver2, 0, false, true);
-        GridCacheMvccCandidate<String> c1 = entry.addRemote(node1, 1, ver1, 0, false, true);
-        GridCacheMvccCandidate<String> c0 = entry.addRemote(node1, 1, ver0, 0, false, true);
-
-        Collection<GridCacheMvccCandidate<String>> rmtCands = entry.remoteMvccSnapshot();
-
-        assert rmtCands.size() == 3;
-
-        // DHT remote candidates are not reordered and sorted.
-        GridCacheMvccCandidate[] candArr = new GridCacheMvccCandidate[] {c2, c1, c0};
-
-        rmtCands = entry.remoteMvccSnapshot();
-
-        int i = 0;
-
-        for (GridCacheMvccCandidate<String> cand : rmtCands) {
-            assert cand == candArr[i] : "Invalid candidate in position " + i;
-
-            i++;
-        }
-
-        assertEquals(c3, entry.anyOwner());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAddPendingRemote2() throws Exception {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-
-        GridCacheVersion ver0 = version(0);
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-
-        GridCacheMvccCandidate<String> c3 = entry.addNearLocal(node1, 1, ver3, 0, true);
-        entry.addNearLocal(node1, 1, ver2, 0, true);
-
-        entry.readyNearLocal(ver3, ver3, empty(), empty(), Arrays.asList(ver0, ver1, ver2));
-
-        GridCacheMvccCandidate<String> c1 = entry.addRemote(node1, 1, ver1, 0, false, true);
-        GridCacheMvccCandidate<String> c0 = entry.addRemote(node1, 1, ver0, 0, false, true);
-
-        Collection<GridCacheMvccCandidate<String>> rmtCands = entry.remoteMvccSnapshot();
-
-        assertEquals(2, rmtCands.size());
-
-        Collection<GridCacheMvccCandidate<String>> nearLocCands = entry.localCandidates();
-
-        assertEquals(2, nearLocCands.size());
-
-        GridCacheMvccCandidate[] candArr = new GridCacheMvccCandidate[] {c1, c0};
-
-        int i = 0;
-
-        for (GridCacheMvccCandidate<String> cand : rmtCands) {
-            assert cand == candArr[i] : "Invalid candidate in position " + i;
-
-            i++;
-        }
-
-        assertEquals(c3, entry.anyOwner());
+        assertNull(entry.anyOwner());
     }
 
     /**
@@ -454,10 +279,12 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
         assertEquals(2, rmtCands.size());
         assertEquals(ver1, rmtCands.iterator().next().version());
 
-        entry.readyNearLocal(nearVer2, ver2, empty(), empty(), empty());
+        entry.readyNearLocal(nearVer2, ver2);
 
         assertNull(entry.anyOwner());
 
+        entry.doneRemote(ver1);
+
         rmtCands = entry.remoteMvccSnapshot();
 
         assertEquals(ver1, rmtCands.iterator().next().version());
@@ -492,14 +319,16 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
         assertEquals(2, rmtCands.size());
         assertEquals(ver1, rmtCands.iterator().next().version());
 
-        entry.orderCompleted(nearVer2, Arrays.asList(ver3), empty());
-        entry.readyNearLocal(nearVer2, ver2, empty(), empty(), Arrays.asList(ver1));
+        entry.readyNearLocal(nearVer2, ver2);
 
         nearLocCands = entry.localCandidates();
         rmtCands = entry.remoteMvccSnapshot();
 
         assertNull(entry.anyOwner());
-        assertEquals(ver3, rmtCands.iterator().next().version());
+
+        entry.doneRemote(ver1);
+
+        assertEquals(ver1, rmtCands.iterator().next().version());
         assertTrue(rmtCands.iterator().next().owner());
 
         GridCacheMvccCandidate<String> cand = nearLocCands.iterator().next();
@@ -537,15 +366,14 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
         assertEquals(2, rmtCands.size());
         assertEquals(ver1, rmtCands.iterator().next().version());
 
-        entry.orderCompleted(nearVer2, empty(), empty());
-        entry.readyNearLocal(nearVer2, ver2, empty(), empty(), empty());
+        entry.readyNearLocal(nearVer2, ver2);
 
         nearLocCands = entry.localCandidates();
         rmtCands = entry.remoteMvccSnapshot();
 
         assertNull(entry.anyOwner());
         assertEquals(ver1, rmtCands.iterator().next().version());
-        assertTrue(rmtCands.iterator().next().owner());
+        assertFalse(rmtCands.iterator().next().owner());
 
         GridCacheMvccCandidate<String> cand = nearLocCands.iterator().next();
 
@@ -582,13 +410,12 @@ public class GridCacheMvccPartitionedSelfTest extends GridCommonAbstractTest {
         assertEquals(2, rmtCands.size());
         assertEquals(ver1, rmtCands.iterator().next().version());
 
-        entry.orderCompleted(nearVer2, empty(), empty());
-        entry.readyNearLocal(nearVer2, ver2, empty(), empty(), Arrays.asList(ver1));
+        entry.readyNearLocal(nearVer2, ver2);
 
         rmtCands = entry.remoteMvccSnapshot();
 
-        assertNotNull(entry.anyOwner());
-        checkLocalOwner(entry.anyOwner(), nearVer2, false);
+        assertNull(entry.anyOwner());
+        checkLocal(entry.candidate(nearVer2), nearVer2, true, false, false);
 
         assertEquals(ver1, rmtCands.iterator().next().version());
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccSelfTest.java
index d2de20e..ade4966 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMvccSelfTest.java
@@ -168,12 +168,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         // Check order.
         checkOrder(cands, ver1, ver5, ver3, ver2);
 
-        entry.orderCompleted(
-            new GridCacheVersion(1, 0, 2, 0, 0),
-            Arrays.asList(new GridCacheVersion(1, 0, 3, 4, 0), ver2, new GridCacheVersion(1, 0, 5, 6, 0)),
-            Collections.<GridCacheVersion>emptyList()
-        );
-
         cands = entry.remoteMvccSnapshot();
 
         info(cands);
@@ -181,16 +175,16 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         assert cands.size() == 4;
 
         // Done ver 2.
-        checkOrder(cands, ver1, ver2, ver5, ver3);
+        checkOrder(cands, ver1, ver5, ver3, ver2);
 
         checkRemote(entry.candidate(ver1), ver1, false, false);
-        checkRemote(entry.candidate(ver2), ver2, true, false);
+        checkRemote(entry.candidate(ver2), ver2, false, false);
         checkRemote(entry.candidate(ver3), ver3, true, true);
         checkRemote(entry.candidate(ver5), ver5, false, false);
 
-        entry.doneRemote(ver5);
+        entry.doneRemote(ver2);
 
-        checkDone(entry.candidate(ver5));
+        checkDone(entry.candidate(ver2));
 
         entry.addRemote(node1, 4, ver4, 0, false, true);
 
@@ -201,9 +195,7 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         assert cands.size() == 5;
 
         // Check order.
-        checkOrder(cands, ver1, ver2, ver5, ver3, ver4);
-
-        entry.orderCompleted(ver3, Arrays.asList(ver2, ver5), Collections.<GridCacheVersion>emptyList());
+        checkOrder(cands, ver1, ver5, ver3, ver2, ver4);
 
         cands = entry.remoteMvccSnapshot();
 
@@ -211,7 +203,7 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
 
         assert cands.size() == 5;
 
-        checkOrder(cands, ver1, ver2, ver5, ver3, ver4);
+        checkOrder(cands, ver1, ver5, ver3, ver2, ver4);
 
         assert entry.anyOwner() == null;
 
@@ -223,25 +215,29 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
 
         assert entry.remoteMvccSnapshot().size() == 4;
 
-        assert entry.anyOwner() == null;
+        cands = entry.remoteMvccSnapshot();
 
-        entry.doneRemote(ver2);
+        checkOrder(cands, ver5, ver3, ver2, ver4);
 
-        checkRemoteOwner(entry.anyOwner(), ver2);
+        assertNull(entry.anyOwner());
 
-        entry.removeLock(ver2);
+        entry.doneRemote(ver5);
+
+        checkRemoteOwner(entry.anyOwner(), ver5);
+
+        entry.removeLock(ver5);
 
         assert entry.remoteMvccSnapshot().size() == 3;
 
-        checkRemoteOwner(entry.anyOwner(), ver5);
+        checkRemoteOwner(entry.anyOwner(), ver3);
 
         entry.removeLock(ver3);
 
         assert entry.remoteMvccSnapshot().size() == 2;
 
-        checkRemoteOwner(entry.anyOwner(), ver5);
+        checkRemoteOwner(entry.anyOwner(), ver2);
 
-        entry.removeLock(ver5);
+        entry.removeLock(ver2);
 
         assert entry.remoteMvccSnapshot().size() == 1;
 
@@ -534,27 +530,24 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
 
         GridCacheMvccCandidate<String> doomed = entry.addRemote(node2, 6, ver6, 0, false, true);
 
+        entry.doneRemote(ver6);
+
         // No reordering happens.
         checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5, ver7, ver8, ver6);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver4, ver7);
-        List<GridCacheVersion> rolledback = Arrays.asList(ver6);
-
-        entry.orderCompleted(ver2, committed, rolledback);
-
         assert !entry.lockedBy(ver6);
 
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver4, ver7, ver2, ver3, ver5, ver8);
+        checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5, ver7, ver8, ver6);
 
         checkRemote(entry.candidate(ver1), ver1, false, false);
         checkRemote(entry.candidate(ver2), ver2, false, false);
         checkRemote(entry.candidate(ver3), ver3, false, false);
-        checkRemote(entry.candidate(ver4), ver4, true, false);
+        checkRemote(entry.candidate(ver4), ver4, false, false);
         checkRemote(entry.candidate(ver5), ver5, false, false);
-        checkRemote(entry.candidate(ver7), ver7, true, false);
+        checkRemote(entry.candidate(ver7), ver7, false, false);
         checkRemote(entry.candidate(ver8), ver8, false, false);
 
-        checkRemote(doomed, ver6, false, true);
+        checkRemote(doomed, ver6, true, true);
     }
 
     /**
@@ -584,65 +577,43 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         entry.addRemote(node2, 6, ver6, 0, false, true);
         entry.addRemote(node2, 7, ver7, 0, false, true);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver4, ver6, ver2);
-
-        entry.orderCompleted(ver2, committed, Collections.<GridCacheVersion>emptyList());
-
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver4, ver6, ver2, ver3, ver5, ver7);
+        checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5, ver6, ver7);
 
         checkRemote(entry.candidate(ver1), ver1, false, false);
-        checkRemote(entry.candidate(ver2), ver2, true, false);
+        checkRemote(entry.candidate(ver2), ver2, false, false);
         checkRemote(entry.candidate(ver3), ver3, false, false);
-        checkRemote(entry.candidate(ver4), ver4, true, false);
+        checkRemote(entry.candidate(ver4), ver4, false, false);
         checkRemote(entry.candidate(ver5), ver5, false, false);
-        checkRemote(entry.candidate(ver6), ver6, true, false);
+        checkRemote(entry.candidate(ver6), ver6, false, false);
         checkRemote(entry.candidate(ver7), ver7, false, false);
-    }
-
-    /**
-     *
-     */
-    public void testCompletedTwiceWithBaseInTheMiddle() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
 
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-        UUID node2 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-        GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
-
-        entry.addRemote(node1, 1, ver1, 0, false, true);
-        entry.addRemote(node2, 2, ver2, 0, false, true);
-        entry.addRemote(node1, 3, ver3, 0, false, true);
-        entry.addRemote(node2, 4, ver4, 0, false, true);
-        entry.addRemote(node1, 5, ver5, 0, false, true);
-        entry.addRemote(node2, 6, ver6, 0, false, true);
-        entry.addRemote(node2, 7, ver7, 0, false, true);
+        entry.doneRemote(ver2);
 
-        List<GridCacheVersion> completed = Arrays.asList(ver4, ver6);
+        checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5, ver6, ver7);
 
-        entry.orderCompleted(ver2, completed, Collections.<GridCacheVersion>emptyList());
+        checkRemote(entry.candidate(ver1), ver1, false, false);
+        checkRemote(entry.candidate(ver2), ver2, true, true);
+        checkRemote(entry.candidate(ver3), ver3, false, false);
+        checkRemote(entry.candidate(ver4), ver4, false, false);
+        checkRemote(entry.candidate(ver5), ver5, false, false);
+        checkRemote(entry.candidate(ver6), ver6, false, false);
+        checkRemote(entry.candidate(ver7), ver7, false, false);
 
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver4, ver6, ver2, ver3, ver5, ver7);
+        assertNull(entry.anyOwner());
 
-        entry.orderCompleted(ver4, completed, Collections.<GridCacheVersion>emptyList());
+        entry.doneRemote(ver1);
 
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver6, ver4, ver2, ver3, ver5, ver7);
+        checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5, ver6, ver7);
 
-        checkRemote(entry.candidate(ver1), ver1, false, false);
-        checkRemote(entry.candidate(ver2), ver2, false, false);
+        checkRemote(entry.candidate(ver1), ver1, true, true);
+        checkRemote(entry.candidate(ver2), ver2, true, true);
         checkRemote(entry.candidate(ver3), ver3, false, false);
-        checkRemote(entry.candidate(ver4), ver4, true, false);
+        checkRemote(entry.candidate(ver4), ver4, false, false);
         checkRemote(entry.candidate(ver5), ver5, false, false);
-        checkRemote(entry.candidate(ver6), ver6, true, false);
+        checkRemote(entry.candidate(ver6), ver6, false, false);
         checkRemote(entry.candidate(ver7), ver7, false, false);
+
+        assertEquals(ver1, entry.anyOwner().version());
     }
 
     /**
@@ -661,8 +632,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         GridCacheVersion ver3 = version(3);
         GridCacheVersion ver4 = version(4);
         GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
 
         entry.addRemote(node1, 1, ver1, 0, false, false);
         entry.addRemote(node2, 2, ver2, 0, false, false);
@@ -670,10 +639,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         entry.addRemote(node2, 4, ver4, 0, false, false);
         entry.addRemote(node1, 5, ver5, 0, false, false);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver6, ver7);
-
-        entry.orderCompleted(ver4, committed, Collections.<GridCacheVersion>emptyList());
-
         checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5);
 
         // Nothing set to owner since there is no change.
@@ -685,48 +650,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     *
-     */
-    public void testCompletedWithBaseInTheBeginning() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-        UUID node2 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-        GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
-
-        entry.addRemote(node1, 1, ver1, 0, false, false);
-        entry.addRemote(node2, 2, ver2, 0, false, false);
-        entry.addRemote(node1, 3, ver3, 0, false, false);
-        entry.addRemote(node2, 4, ver4, 0, false, false);
-        entry.addRemote(node1, 5, ver5, 0, false, false);
-        entry.addRemote(node2, 6, ver6, 0, false, false);
-        entry.addRemote(node2, 7, ver7, 0, false, false);
-
-        List<GridCacheVersion> committed = Arrays.asList(ver4, ver6, ver3);
-
-        entry.orderCompleted(ver1, committed, Collections.<GridCacheVersion>emptyList());
-
-        checkOrder(entry.remoteMvccSnapshot(), ver3, ver4, ver6, ver1, ver2, ver5, ver7);
-
-        checkRemote(entry.candidate(ver1), ver1, false, false);
-        checkRemote(entry.candidate(ver2), ver2, false, false);
-        checkRemote(entry.candidate(ver3), ver3, true, false);
-        checkRemote(entry.candidate(ver4), ver4, true, false);
-        checkRemote(entry.candidate(ver5), ver5, false, false);
-        checkRemote(entry.candidate(ver6), ver6, true, false);
-        checkRemote(entry.candidate(ver7), ver7, false, false);
-    }
-
-    /**
      * This case should never happen, nevertheless we need to test for it.
      */
     public void testCompletedWithBaseInTheBeginningNoChange() {
@@ -742,8 +665,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         GridCacheVersion ver3 = version(3);
         GridCacheVersion ver4 = version(4);
         GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
 
         entry.addRemote(node1, 1, ver1, 0, false, false);
         entry.addRemote(node2, 2, ver2, 0, false, false);
@@ -751,10 +672,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         entry.addRemote(node2, 4, ver4, 0, false, false);
         entry.addRemote(node1, 5, ver5, 0, false, false);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver6, ver7);
-
-        entry.orderCompleted(ver1, committed, Collections.<GridCacheVersion>emptyList());
-
         checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5);
 
         // Nothing set to owner since there is no change.
@@ -781,8 +698,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         GridCacheVersion ver3 = version(3);
         GridCacheVersion ver4 = version(4);
         GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
 
         entry.addRemote(node1, 1, ver1, 0, false, false);
         entry.addRemote(node2, 2, ver2, 0, false, false);
@@ -790,10 +705,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         entry.addRemote(node2, 4, ver4, 0, false, false);
         entry.addRemote(node1, 5, ver5, 0, false, false);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver6, ver7);
-
-        entry.orderCompleted(ver5, committed, Collections.<GridCacheVersion>emptyList());
-
         checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5);
 
         // Nothing set to owner since there is no change.
@@ -807,7 +718,7 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
     /**
      *
      */
-    public void testCompletedWithBaseNotPresentInTheMiddle() {
+    public void testNoReordering() {
         GridCacheAdapter<String, String> cache = grid.internalCache();
 
         GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
@@ -823,141 +734,49 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         GridCacheVersion ver6 = version(6);
         GridCacheVersion ver7 = version(7);
 
-        // Don't add version 2.
-        entry.addRemote(node1, 1, ver1, 0, false, true);
+        entry.addRemote(node1, 2, ver2, 0, false, true);
         entry.addRemote(node1, 3, ver3, 0, false, true);
-        entry.addRemote(node2, 4, ver4, 0, false, true);
+        entry.addRemote(node1, 1, ver1, 0, false, true);
         entry.addRemote(node1, 5, ver5, 0, false, true);
+        entry.addRemote(node2, 4, ver4, 0, false, true);
         entry.addRemote(node2, 6, ver6, 0, false, true);
         entry.addRemote(node2, 7, ver7, 0, false, true);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver6, ver4);
-
-        entry.orderCompleted(ver2, committed, Collections.<GridCacheVersion>emptyList());
+        checkOrder(entry.remoteMvccSnapshot(), ver2, ver3, ver1, ver5, ver4, ver6, ver7);
 
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver4, ver6, ver3, ver5, ver7);
-
-        checkRemote(entry.candidate(ver1), ver1, false, false);
+        checkRemote(entry.candidate(ver2), ver2, false, false);
         checkRemote(entry.candidate(ver3), ver3, false, false);
-        checkRemote(entry.candidate(ver4), ver4, true, false);
-        checkRemote(entry.candidate(ver5), ver5, false, false);
-        checkRemote(entry.candidate(ver6), ver6, true, false);
-        checkRemote(entry.candidate(ver7), ver7, false, false);
-    }
-
-    /**
-     *
-     */
-    public void testCompletedWithBaseNotPresentInTheMiddleNoChange() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-        UUID node2 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-        GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
-
-        // Don't add versions 2, 5, 6, 7.
-        entry.addRemote(node1, 1, ver1, 0, false, true);
-        entry.addRemote(node1, 3, ver3, 0, false, true);
-        entry.addRemote(node2, 4, ver4, 0, false, true);
-
-        List<GridCacheVersion> committed = Arrays.asList(ver6, ver5, ver7);
-
-        entry.orderCompleted(ver2, committed, Collections.<GridCacheVersion>emptyList());
-
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver3, ver4);
-
         checkRemote(entry.candidate(ver1), ver1, false, false);
-        checkRemote(entry.candidate(ver3), ver3, false, false);
+        checkRemote(entry.candidate(ver5), ver5, false, false);
         checkRemote(entry.candidate(ver4), ver4, false, false);
-    }
-
-    /**
-     *
-     */
-    public void testCompletedWithBaseNotPresentInTheBeginning() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-        UUID node2 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-        GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
-
-        // Don't add version 1.
-        entry.addRemote(node1, 2, ver2, 0, false, true);
-        entry.addRemote(node1, 3, ver3, 0, false, true);
-        entry.addRemote(node2, 4, ver4, 0, false, true);
-        entry.addRemote(node1, 5, ver5, 0, false, true);
-        entry.addRemote(node2, 6, ver6, 0, false, true);
-        entry.addRemote(node2, 7, ver7, 0, false, true);
+        checkRemote(entry.candidate(ver6), ver6, false, false);
+        checkRemote(entry.candidate(ver7), ver7, false, false);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver4, ver6, ver3);
+        entry.doneRemote(ver3);
 
-        entry.orderCompleted(ver1, committed, Collections.<GridCacheVersion>emptyList());
+        checkOrder(entry.remoteMvccSnapshot(), ver2, ver3, ver1, ver5, ver4, ver6, ver7);
 
-        checkOrder(entry.remoteMvccSnapshot(), ver3, ver4, ver6, ver2, ver5, ver7);
+        assertNull(entry.anyOwner());
 
         checkRemote(entry.candidate(ver2), ver2, false, false);
-        checkRemote(entry.candidate(ver3), ver3, true, false);
-        checkRemote(entry.candidate(ver4), ver4, true, false);
+        checkRemote(entry.candidate(ver3), ver3, true, true);
+        checkRemote(entry.candidate(ver1), ver1, false, false);
         checkRemote(entry.candidate(ver5), ver5, false, false);
-        checkRemote(entry.candidate(ver6), ver6, true, false);
+        checkRemote(entry.candidate(ver4), ver4, false, false);
+        checkRemote(entry.candidate(ver6), ver6, false, false);
         checkRemote(entry.candidate(ver7), ver7, false, false);
-    }
-
-    /**
-     *
-     */
-    public void testCompletedWithBaseNotPresentInTheBeginningNoChange() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-        UUID node2 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-        GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
-
-        // Don't add version 6, 7
-        entry.addRemote(node1, 2, ver2, 0, false, true);
-        entry.addRemote(node1, 3, ver3, 0, false, true);
-        entry.addRemote(node2, 4, ver4, 0, false, true);
-        entry.addRemote(node1, 5, ver5, 0, false, true);
-        entry.addRemote(node1, 6, ver6, 0, false, true);
-        entry.addRemote(node1, 7, ver7, 0, false, true);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver2, ver3);
+        entry.doneRemote(ver2);
 
-        entry.orderCompleted(ver1, committed, Collections.<GridCacheVersion>emptyList());
+        checkOrder(entry.remoteMvccSnapshot(), ver2, ver3, ver1, ver5, ver4, ver6, ver7);
 
-        checkOrder(entry.remoteMvccSnapshot(), ver2, ver3, ver4, ver5, ver6, ver7);
+        assertEquals(ver2, entry.anyOwner().version());
 
-        checkRemote(entry.candidate(ver2), ver2, true, false);
-        checkRemote(entry.candidate(ver3), ver3, true, false);
-        checkRemote(entry.candidate(ver4), ver4, false, false);
+        checkRemote(entry.candidate(ver2), ver2, true, true);
+        checkRemote(entry.candidate(ver3), ver3, true, true);
+        checkRemote(entry.candidate(ver1), ver1, false, false);
         checkRemote(entry.candidate(ver5), ver5, false, false);
+        checkRemote(entry.candidate(ver4), ver4, false, false);
         checkRemote(entry.candidate(ver6), ver6, false, false);
         checkRemote(entry.candidate(ver7), ver7, false, false);
     }
@@ -977,9 +796,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         GridCacheVersion ver2 = version(2);
         GridCacheVersion ver3 = version(3);
         GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-        GridCacheVersion ver6 = version(6);
-        GridCacheVersion ver7 = version(7);
 
         // Don't add version 5, 6, 7
         entry.addRemote(node1, 1, ver1, 0, false, true);
@@ -987,10 +803,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
         entry.addRemote(node1, 3, ver3, 0, false, true);
         entry.addRemote(node2, 4, ver4, 0, false, true);
 
-        List<GridCacheVersion> committed = Arrays.asList(ver6, ver7);
-
-        entry.orderCompleted(ver5, committed, Collections.<GridCacheVersion>emptyList());
-
         checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4);
 
         checkRemote(entry.candidate(ver1), ver1, false, false);
@@ -1000,132 +812,6 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Test local and remote candidates together.
-     */
-    public void testLocalAndRemote() {
-        GridCacheAdapter<String, String> cache = grid.internalCache();
-
-        GridCacheTestEntryEx<String, String> entry = new GridCacheTestEntryEx<>(cache.context(), "1");
-
-        UUID node1 = UUID.randomUUID();
-        UUID node2 = UUID.randomUUID();
-
-        GridCacheVersion ver1 = version(1);
-        GridCacheVersion ver2 = version(2);
-        GridCacheVersion ver3 = version(3);
-        GridCacheVersion ver4 = version(4);
-        GridCacheVersion ver5 = version(5);
-
-        entry.addRemote(node1, 1, ver1, 0, false, false);
-        entry.addLocal(2, ver2, 0, true, true);
-
-        Collection<GridCacheMvccCandidate<String>> cands = entry.remoteMvccSnapshot();
-
-        assert cands.size() == 1;
-        assert cands.iterator().next().version().equals(ver1);
-
-        entry.addRemote(node2, 5, ver5, 0, false, false);
-
-        cands = entry.remoteMvccSnapshot();
-
-        assert cands.size() == 2;
-
-        info(cands);
-
-        checkOrder(cands, ver1, ver5);
-        checkOrder(entry.localCandidates(true), ver2);
-
-        entry.addRemote(node1, 3, ver3, 0, false, true);
-        entry.addLocal(4, ver4, 0, /*reenter*/true, false);
-
-        cands = entry.remoteMvccSnapshot();
-
-        assert cands.size() == 3;
-
-        // Check order.
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver5, ver3);
-        checkOrder(entry.localCandidates(), ver2, ver4);
-
-        entry.orderCompleted(
-            ver2 /*local version.*/,
-            Arrays.asList(new GridCacheVersion(1, 0, 1, 2, 0), ver3, new GridCacheVersion(1, 0, 5, 6, 0)),
-            Collections.<GridCacheVersion>emptyList()
-        );
-
-        // Done ver3.
-        checkOrder(entry.remoteMvccSnapshot(), ver1, ver3, ver5);
-        checkOrder(entry.localCandidates(), ver2, ver4);
-
-        checkRemote(entry.candidate(ver1), ver1, false, false);
-        checkRemote(entry.candidate(ver3), ver3, true, false);
-        checkRemote(entry.candidate(ver5), ver5, false, false);
-
-        checkLocal(entry.candidate(ver2), ver2, false, false, false);
-        checkLocal(entry.candidate(ver4), ver4, false, false, false);
-
-        entry.readyLocal(ver2);
-
-        checkLocal(entry.candidate(ver2), ver2, true, false, false);
-        checkLocal(entry.candidate(ver4), ver4, false, false, false);
-
-        assert entry.anyOwner() == null;
-
-        entry.doneRemote(ver1);
-
-        checkRemoteOwner(entry.anyOwner(), ver1);
-
-        entry.removeLock(ver1);
-
-        checkOrder(entry.remoteMvccSnapshot(), ver3, ver5);
-
-        assert entry.anyOwner() == null;
-
-        entry.doneRemote(ver3);
-
-        checkRemoteOwner(entry.anyOwner(), ver3);
-
-        entry.removeLock(ver3);
-
-        checkLocalOwner(entry.anyOwner(), ver2, false);
-
-        entry.removeLock(ver2);
-
-        assert !entry.lockedByAny(ver4, ver5);
-
-        checkOrder(entry.remoteMvccSnapshot(), ver5);
-        checkOrder(entry.localCandidates(), ver4);
-
-        assert entry.anyOwner() == null;
-
-        entry.readyLocal(ver4);
-
-        checkLocalOwner(entry.anyOwner(), ver4, false);
-
-        entry.removeLock(ver4);
-
-        assert entry.anyOwner() == null;
-
-        GridCacheMvccCandidate<String> c5 = entry.candidate(ver5);
-
-        assert c5 != null;
-
-        c5.setOwner();
-
-        assert entry.anyOwner() == null;
-
-        entry.doneRemote(ver5);
-
-        checkRemoteOwner(entry.anyOwner(), ver5);
-
-        assert !entry.lockedByAny(ver5);
-
-        entry.removeLock(ver5);
-
-        assert !entry.lockedByAny();
-        assert entry.anyOwner() == null;
-    }
-
-    /**
      * @throws Exception If test failed.
      */
     public void testMultipleLocalAndRemoteLocks1() throws Exception {
@@ -1646,7 +1332,7 @@ public class GridCacheMvccSelfTest extends GridCommonAbstractTest {
      * @param vers Ordered versions.
      */
     private void checkOrder(Collection<GridCacheMvccCandidate<String>> cands, GridCacheVersion... vers) {
-        assert cands.size() == vers.length;
+        assertEquals(vers.length, cands.size());
 
         int i = 0;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
index b5e226f..094c815 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
@@ -197,26 +197,10 @@ public class GridCacheTestEntryEx<K, V> extends GridMetadataAwareAdapter impleme
     }
 
     /**
-     * Moves completed candidates right before the base one. Note that
-     * if base is not found, then nothing happens and {@code false} is
-     * returned.
-     *
-     * @param baseVer Base version.
-     * @param committedVers Committed versions relative to base.
-     * @param rolledbackVers Rolled back versions relative to base.
-     * @return Lock owner.
-     */
-    @Nullable public GridCacheMvccCandidate<K> orderCompleted(GridCacheVersion baseVer,
-        Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers) {
-        return mvcc.orderCompleted(baseVer, committedVers, rolledbackVers);
-    }
-
-    /**
      * @param ver Version.
      */
     public void doneRemote(GridCacheVersion ver) {
-        mvcc.doneRemote(ver, Collections.<GridCacheVersion>emptyList(),
-            Collections.<GridCacheVersion>emptyList(), Collections.<GridCacheVersion>emptyList());
+        mvcc.doneRemote(ver);
     }
 
     /**
@@ -238,15 +222,10 @@ public class GridCacheTestEntryEx<K, V> extends GridMetadataAwareAdapter impleme
     /**
      * @param ver Ready near lock version.
      * @param mapped Mapped version.
-     * @param committedVers Committed versions.
-     * @param rolledbackVers Rolled back versions.
-     * @param pending Pending versions.
      * @return Lock owner.
      */
-    @Nullable public GridCacheMvccCandidate<K> readyNearLocal(GridCacheVersion ver, GridCacheVersion mapped,
-        Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers,
-        Collection<GridCacheVersion> pending) {
-        return mvcc.readyNearLocal(ver, mapped, committedVers, rolledbackVers, pending);
+    @Nullable public GridCacheMvccCandidate<K> readyNearLocal(GridCacheVersion ver, GridCacheVersion mapped) {
+        return mvcc.readyNearLocal(ver, mapped);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a88c019/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitNearSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitNearSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitNearSelfTest.java
new file mode 100644
index 0000000..5fc3be1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteOnePhaseCommitNearSelfTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.transactions.*;
+
+import javax.cache.*;
+
+/**
+ * Checks one-phase commit scenarios.
+ */
+public class IgniteOnePhaseCommitNearSelfTest extends GridCommonAbstractTest {
+    /** Grid count. */
+    private static final int GRID_CNT = 4;
+
+    /** */
+    private int backups = 1;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(cacheConfiguration(gridName));
+
+        return cfg;
+    }
+
+    /**
+     * @param gridName Grid name.
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration cacheConfiguration(String gridName) {
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setBackups(backups);
+        ccfg.setDistributionMode(CacheDistributionMode.NEAR_PARTITIONED);
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+        ccfg.setCacheMode(CacheMode.PARTITIONED);
+
+        return ccfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOnePhaseCommitFromNearNode() throws Exception {
+        backups = 1;
+
+        startGrids(GRID_CNT);
+
+        try {
+            awaitPartitionMapExchange();
+
+            int key = generateNearKey();
+
+            IgniteCache<Object, Object> cache = ignite(0).jcache(null);
+
+            checkKey(ignite(0).transactions(), cache, key);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * @param transactions Transactions instance.
+     * @param cache Cache instance.
+     * @param key Key.
+     */
+    private void checkKey(IgniteTransactions transactions, Cache<Object, Object> cache, int key) throws Exception {
+        cache.put(key, key);
+
+        finalCheck(key);
+
+        for (TransactionIsolation isolation : TransactionIsolation.values()) {
+            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
+                info("Checking transaction [isolation=" + isolation + ", concurrency=" + concurrency + ']');
+
+                try (Transaction tx = transactions.txStart(concurrency, isolation)) {
+                    cache.put(key, isolation + "-" + concurrency);
+
+                    tx.commit();
+                }
+
+                finalCheck(key);
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void finalCheck(final int key) throws Exception {
+        GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                try {
+                    for (int i = 0; i < GRID_CNT; i++) {
+                        GridCacheAdapter<Object, Object> cache = ((IgniteKernal)ignite(i)).internalCache();
+
+                        GridCacheEntryEx<Object, Object> entry = cache.peekEx(key);
+
+                        if (entry != null) {
+                            if (entry.lockedByAny()) {
+                                info("Near entry is still locked [i=" + i + ", entry=" + entry + ']');
+
+                                return false;
+                            }
+                        }
+
+                        entry = cache.context().near().dht().peekEx(key);
+
+                        if (entry != null) {
+                            if (entry.lockedByAny()) {
+                                info("DHT entry is still locked [i=" + i + ", entry=" + entry + ']');
+
+                                return false;
+                            }
+                        }
+                    }
+
+                    return true;
+                }
+                catch (GridCacheEntryRemovedException ignore) {
+                    info("Entry was removed, will retry");
+
+                    return false;
+                }
+            }
+        }, 10_000);
+    }
+
+    /**
+     * @return Key.
+     */
+    protected int generateNearKey() {
+        CacheAffinity<Object> aff = ignite(0).affinity(null);
+
+        int key = 0;
+
+        while (true) {
+            boolean primary = aff.isPrimary(ignite(1).cluster().localNode(), key);
+            boolean primaryOrBackup = aff.isPrimaryOrBackup(ignite(0).cluster().localNode(), key);
+
+            if (primary && !primaryOrBackup)
+                return key;
+
+            key++;
+        }
+    }
+}


Mime
View raw message