You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/09/19 14:45:27 UTC

[01/50] [abbrv] ignite git commit: ignite-6180: restoring marshaller mappings on node start is implemented

Repository: ignite
Updated Branches:
  refs/heads/ignite-6181-1 [created] 2468e0090


ignite-6180: restoring marshaller mappings on node start is implemented


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9399610d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9399610d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9399610d

Branch: refs/heads/ignite-6181-1
Commit: 9399610d2dd4b67b1da6475ce2141787fb8dbb0e
Parents: b2b596b
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Fri Aug 25 13:12:32 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Fri Aug 25 13:12:32 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/MarshallerContextImpl.java  |   3 +
 .../internal/MarshallerMappingFileStore.java    |  76 +++++++++++-
 ...MarshallerMappingRestoreOnNodeStartTest.java | 116 +++++++++++++++++++
 .../IgnitePdsWithIndexingCoreTestSuite.java     |   2 +
 4 files changed, 196 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9399610d/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
index 6f15507..33b6ff8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -519,6 +519,9 @@ public class MarshallerContextImpl implements MarshallerContext {
         this.transport = transport;
         closProc = ctx.closure();
         clientNode = ctx.clientNode();
+
+        if (ctx.config().isPersistentStoreEnabled())
+            fileStore.restoreMappings(this);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/9399610d/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
index 03f79c9..e4a844e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
@@ -34,6 +34,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.util.GridStripedLock;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContext;
 
 /**
  * File-based persistence provider for {@link MarshallerContextImpl}.
@@ -53,6 +54,9 @@ final class MarshallerMappingFileStore {
     /** */
     private final File workDir;
 
+    /** */
+    private final String FILE_EXTENSION = ".classname";
+
     /**
      * @param log Logger.
      */
@@ -137,11 +141,81 @@ final class MarshallerMappingFileStore {
     }
 
     /**
+     * Restores all mappings available in file system to marshaller context.
+     * This method should be used only on node startup.
+     *
+     * @param marshCtx Marshaller context to register mappings.
+     */
+    void restoreMappings(MarshallerContext marshCtx) throws IgniteCheckedException {
+        for (File file : workDir.listFiles()) {
+            String name = file.getName();
+
+            byte platformId = getPlatformId(name);
+
+            int typeId = getTypeId(name);
+
+            try (FileInputStream in = new FileInputStream(file)) {
+                try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
+                    String className = reader.readLine();
+
+                    marshCtx.registerClassNameLocally(platformId, typeId, className);
+                }
+            }
+            catch (IOException e) {
+                throw new IgniteCheckedException("Reading marshaller mapping from file "
+                    + name
+                    + " failed."
+                    , e);
+            }
+        }
+    }
+
+    /**
+     * @param fileName Name of file with marshaller mapping information.
+     * @throws IgniteCheckedException If file name format is broken.
+     */
+    private byte getPlatformId(String fileName) throws IgniteCheckedException {
+        String lastSymbol = fileName.substring(fileName.length() - 1);
+
+        byte platformId;
+
+        try {
+            platformId = Byte.parseByte(lastSymbol);
+        }
+        catch (NumberFormatException e) {
+            throw new IgniteCheckedException("Reading marshaller mapping from file "
+                + fileName
+                + " failed; last symbol of file name is expected to be numeric.", e);
+        }
+
+        return platformId;
+    }
+
+    /**
+     * @param fileName Name of file with marshaller mapping information.
+     * @throws IgniteCheckedException If file name format is broken.
+     */
+    private int getTypeId(String fileName) throws IgniteCheckedException {
+        int typeId;
+
+        try {
+            typeId = Integer.parseInt(fileName.substring(0, fileName.indexOf(FILE_EXTENSION)));
+        }
+        catch (NumberFormatException e) {
+            throw new IgniteCheckedException("Reading marshaller mapping from file "
+                + fileName
+                + " failed; type ID is expected to be numeric.", e);
+        }
+
+        return typeId;
+    }
+
+    /**
      * @param platformId Platform id.
      * @param typeId Type id.
      */
     private String getFileName(byte platformId, int typeId) {
-        return typeId + ".classname" + platformId;
+        return typeId + FILE_EXTENSION + platformId;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/9399610d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java
new file mode 100644
index 0000000..517b9ea
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.persistence;
+
+import java.nio.file.Paths;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgnitePdsMarshallerMappingRestoreOnNodeStartTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        int gridIndex = getTestIgniteInstanceIndex(gridName);
+
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        String tmpDir = System.getProperty("java.io.tmpdir");
+
+        cfg.setWorkDirectory(Paths.get(tmpDir, "srv" + gridIndex).toString());
+
+        cfg.setPersistentStoreConfiguration(
+            new PersistentStoreConfiguration()
+        );
+
+        cfg.setCacheConfiguration(new CacheConfiguration()
+            .setName(DEFAULT_CACHE_NAME)
+            .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
+            .setCacheMode(CacheMode.REPLICATED));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        String tmpDir = System.getProperty("java.io.tmpdir");
+
+        deleteRecursively(Paths.get(tmpDir, "srv0").toFile());
+        deleteRecursively(Paths.get(tmpDir, "srv1").toFile());
+    }
+
+    /**
+     * Test verifies that binary metadata from regular java classes is saved and restored correctly
+     * on cluster restart.
+     */
+    public void testStaticMetadataIsRestoredOnRestart() throws Exception {
+        startGrids(1);
+
+        Ignite ignite0 = grid(0);
+
+        ignite0.active(true);
+
+        IgniteCache<Object, Object> cache0 = ignite0.cache(DEFAULT_CACHE_NAME);
+
+        cache0.put(0, new TestValue1(0));
+
+        stopAllGrids();
+
+        startGrids(1);
+
+        ignite0 = grid(0);
+
+        ignite0.active(true);
+
+        Ignite ignite1 = startGrid(1);
+
+        awaitPartitionMapExchange();
+
+        ignite1.cache(DEFAULT_CACHE_NAME).get(0);
+    }
+
+    /**
+     *
+     */
+    private static class TestValue1 {
+        /** */
+        @AffinityKeyMapped
+        private final int val;
+
+        /**
+         * @param val Value.
+         */
+        TestValue1(int val) {
+            this.val = val;
+        }
+
+        /** */
+        int getValue() {
+            return val;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/9399610d/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
index bb9c9d1..ae8ea18 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
@@ -19,6 +19,7 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsAtomicCacheRebalancingTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsBinaryMetadataOnClusterRestartTest;
+import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsMarshallerMappingRestoreOnNodeStartTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsTxCacheRebalancingTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistentStoreCacheGroupsTest;
 import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsMultiNodePutGetRestartTest;
@@ -51,6 +52,7 @@ public class IgnitePdsWithIndexingCoreTestSuite extends TestSuite {
         suite.addTestSuite(IgnitePdsTxCacheRebalancingTest.class);
 
         suite.addTestSuite(IgnitePdsBinaryMetadataOnClusterRestartTest.class);
+        suite.addTestSuite(IgnitePdsMarshallerMappingRestoreOnNodeStartTest.class);
 
         return suite;
     }


[02/50] [abbrv] ignite git commit: IGNITE-6178 Make CheckpointWriteOrder.SEQUENTIAL and checkpointingThreads=4 default in persistent store confguration

Posted by sb...@apache.org.
IGNITE-6178 Make CheckpointWriteOrder.SEQUENTIAL and checkpointingThreads=4 default in persistent store confguration


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5bda4090
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5bda4090
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5bda4090

Branch: refs/heads/ignite-6181-1
Commit: 5bda4090f1580ea7b6557c8716e57a12572c322f
Parents: 9399610
Author: Ivan Rakov <iv...@gmail.com>
Authored: Thu Aug 24 18:18:31 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Fri Aug 25 13:32:24 2017 +0300

----------------------------------------------------------------------
 .../ignite/configuration/PersistentStoreConfiguration.java    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5bda4090/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
index 5b902ac..888bf42 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
@@ -16,12 +16,11 @@
  */
 package org.apache.ignite.configuration;
 
+import java.io.Serializable;
 import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
 import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
 import org.apache.ignite.internal.util.typedef.internal.S;
 
-import java.io.Serializable;
-
 /**
  * Configures Apache Ignite Persistent store.
  */
@@ -45,10 +44,10 @@ public class PersistentStoreConfiguration implements Serializable {
     public static final int DFLT_RATE_TIME_INTERVAL_MILLIS = 60_000;
 
     /** Default number of checkpointing threads. */
-    public static final int DFLT_CHECKPOINTING_THREADS = 1;
+    public static final int DFLT_CHECKPOINTING_THREADS = 4;
 
     /** Default checkpoint write order. */
-    public static final CheckpointWriteOrder DFLT_CHECKPOINT_WRITE_ORDER = CheckpointWriteOrder.RANDOM;
+    public static final CheckpointWriteOrder DFLT_CHECKPOINT_WRITE_ORDER = CheckpointWriteOrder.SEQUENTIAL;
 
     /** Default number of checkpoints to be kept in WAL after checkpoint is finished */
     public static final int DFLT_WAL_HISTORY_SIZE = 20;


[18/50] [abbrv] ignite git commit: gg-12686 : Fixed null CacheMapHolder if node is restarted with partition in RENTING state.

Posted by sb...@apache.org.
gg-12686 : Fixed null CacheMapHolder if node is restarted with partition in RENTING state.

Signed-off-by: Andrey Gura <ag...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/01c627a0
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/01c627a0
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/01c627a0

Branch: refs/heads/ignite-6181-1
Commit: 01c627a0a36692a045a646d4d165820bb3b7cf04
Parents: 6c45ede
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Wed Aug 30 16:58:32 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Wed Aug 30 17:39:05 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/dht/GridDhtLocalPartition.java         | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/01c627a0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index 4d1bb38..f0e0d47 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -932,12 +932,8 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements
                     try {
                         CacheDataRow row = it0.next();
 
-                        if (grp.sharedGroup() && (hld == null || hld.cctx.cacheId() != row.cacheId())) {
-                            hld = cacheMaps.get(row.cacheId());
-
-                            if (hld == null)
-                                continue;
-                        }
+                        if (grp.sharedGroup() && (hld == null || hld.cctx.cacheId() != row.cacheId()))
+                            hld = cacheMapHolder(ctx.cacheContext(row.cacheId()));
 
                         assert hld != null;
 


[08/50] [abbrv] ignite git commit: Fixed update sequence.

Posted by sb...@apache.org.
Fixed update sequence.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a857c5ba
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a857c5ba
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a857c5ba

Branch: refs/heads/ignite-6181-1
Commit: a857c5ba5a24f41b5ebfaef0a15fde2906a7e0fd
Parents: 8c249b7
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Sat Aug 26 17:21:44 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Sat Aug 26 17:21:44 2017 +0300

----------------------------------------------------------------------
 .../dht/GridDhtPartitionTopologyImpl.java       | 33 ++++++++++++++------
 1 file changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a857c5ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index a881130..e0f54b3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -521,7 +521,7 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                             DiscoveryEvent evt = evts0.get(i);
 
                             if (ExchangeDiscoveryEvents.serverLeftEvent(evt))
-                                removeNode(evt.eventNode().id());
+                                updateSeq = removeNode(evt.eventNode().id(), updateSeq);
                         }
                     }
 
@@ -1379,6 +1379,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
             long updateSeq = this.updateSeq.incrementAndGet();
 
+            node2part.newUpdateSequence(updateSeq);
+
             if (readyTopVer.initialized() && readyTopVer.equals(lastTopChangeVer)) {
                 AffinityAssignment  aff = grp.affinity().readyAffinity(readyTopVer);
 
@@ -1535,8 +1537,11 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
             GridDhtPartitionMap cur = node2part.get(parts.nodeId());
 
             if (force) {
-                if (cur != null && cur.topologyVersion().initialized())
+                if (cur != null && cur.topologyVersion().initialized()) {
                     parts.updateSequence(cur.updateSequence(), cur.topologyVersion());
+
+                    this.updateSeq.setIfGreater(cur.updateSequence());
+                }
             }
             else  if (isStaleUpdate(cur, parts)) {
                 U.warn(log, "Stale update for single partition map update (will ignore) [exchId=" + exchId +
@@ -1546,10 +1551,6 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                 return false;
             }
 
-            long updateSeq = this.updateSeq.incrementAndGet();
-
-            node2part.newUpdateSequence(updateSeq);
-
             boolean changed = false;
 
             if (cur == null || !cur.equals(parts))
@@ -1557,6 +1558,10 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
             node2part.put(parts.nodeId(), parts);
 
+            this.updateSeq.setIfGreater(parts.updateSequence());
+
+            long updateSeq = this.updateSeq.incrementAndGet();
+
             // During exchange diff is calculated after all messages are received and affinity initialized.
             if (exchId == null && !grp.isReplicated()) {
                 if (readyTopVer.initialized() && readyTopVer.compareTo(diffFromAffinityVer) >= 0) {
@@ -2110,8 +2115,11 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
     /**
      * @param nodeId Node to remove.
+     * @param updateSeq Update sequence.
+     *
+     * @return Update sequence.
      */
-    private void removeNode(UUID nodeId) {
+    private long removeNode(UUID nodeId, long updateSeq) {
         assert nodeId != null;
         assert lock.isWriteLockedByCurrentThread();
 
@@ -2122,11 +2130,14 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         ClusterNode loc = ctx.localNode();
 
         if (node2part != null) {
-            updateSeq.setIfGreater(node2part.updateSequence());
+            assert updateSeq >= node2part.updateSequence();
 
-            if (loc.equals(oldest) && !node2part.nodeId().equals(loc.id()))
-                node2part = new GridDhtPartitionFullMap(loc.id(), loc.order(), updateSeq.incrementAndGet(),
+            if (loc.equals(oldest) && !node2part.nodeId().equals(loc.id())) {
+                updateSeq++;
+
+                node2part = new GridDhtPartitionFullMap(loc.id(), loc.order(), updateSeq,
                     node2part, false);
+            }
             else
                 node2part = new GridDhtPartitionFullMap(node2part, node2part.updateSequence());
 
@@ -2145,6 +2156,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
             consistencyCheck();
         }
+
+        return updateSeq;
     }
 
     /** {@inheritDoc} */


[21/50] [abbrv] ignite git commit: Merge branches 'ignite-2.1.4' and 'ignite-6181' of https://github.com/gridgain/apache-ignite into ignite-6181

Posted by sb...@apache.org.
Merge branches 'ignite-2.1.4' and 'ignite-6181' of https://github.com/gridgain/apache-ignite into ignite-6181


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/94acdf5e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/94acdf5e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/94acdf5e

Branch: refs/heads/ignite-6181-1
Commit: 94acdf5e3f4d9daced8cb75f651d5c87fa5c4def
Parents: d6f0b26 01c627a
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Wed Aug 30 19:49:18 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Wed Aug 30 19:49:18 2017 +0300

----------------------------------------------------------------------
 .../dht/GridClientPartitionTopology.java        | 18 ++++--
 .../distributed/dht/GridDhtLocalPartition.java  |  8 +--
 .../dht/GridDhtPartitionTopologyImpl.java       | 59 +++++++++-----------
 .../GridDhtPartitionsExchangeFuture.java        | 15 ++++-
 .../IgnitePdsCacheRebalancingAbstractTest.java  | 44 ++++++++++++++-
 .../query/h2/opt/GridLuceneDirectory.java       |  2 +-
 .../query/h2/opt/GridLuceneIndex.java           |  2 +-
 .../PersistentStoreConfiguration.cs             |  2 +-
 8 files changed, 96 insertions(+), 54 deletions(-)
----------------------------------------------------------------------



[26/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8ab36ce2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8ab36ce2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8ab36ce2

Branch: refs/heads/ignite-6181-1
Commit: 8ab36ce2ba4219fcf9d5272d999267878c0e20a5
Parents: 685e69a
Author: ascherbakoff <al...@gmail.com>
Authored: Thu Sep 7 19:53:58 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Thu Sep 7 19:53:58 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/distributed/near/GridNearTxLocal.java     | 6 +++---
 .../processors/cache/transactions/TxRollbackOnTimeoutTest.java | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8ab36ce2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 965a502..0c76aec 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -3256,9 +3256,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
      * @throws IgniteCheckedException If failed.
      */
     public void rollback() throws IgniteCheckedException {
-        if (timeout() > 0)
-            cctx.time().removeTimeoutObject(this);
-
         rollbackNearTxLocalAsync().get();
     }
 
@@ -3269,6 +3266,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (log.isDebugEnabled())
             log.debug("Rolling back near tx: " + this);
 
+        if (remainingTime() > 0)
+            cctx.time().removeTimeoutObject(this);
+
         if (fastFinish()) {
             state(PREPARING);
             state(PREPARED);

http://git-wip-us.apache.org/repos/asf/ignite/blob/8ab36ce2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 4799534..d854cf0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -60,7 +60,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     private final CountDownLatch blocked = new CountDownLatch(1);
 
     /** */
-    private CountDownLatch unblocked = new CountDownLatch(1);
+    private final CountDownLatch unblocked = new CountDownLatch(1);
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {


[23/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6a928460
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6a928460
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6a928460

Branch: refs/heads/ignite-6181-1
Commit: 6a928460877ba42d965cb7ec38e7962f338eacbe
Parents: d5f3a67
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Fri Sep 1 19:17:31 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Fri Sep 1 19:17:31 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      |  6 ++++++
 .../cache/distributed/near/GridNearTxLocal.java | 21 ++++++++++----------
 .../cache/transactions/IgniteInternalTx.java    |  2 +-
 .../transactions/IgniteTransactionsImpl.java    |  4 +++-
 .../cache/transactions/IgniteTxAdapter.java     |  4 +++-
 .../transactions/IgniteTxLocalAdapter.java      |  3 ---
 .../cache/transactions/IgniteTxManager.java     | 20 +++++++++++++++++--
 .../cache/IgniteTxConfigCacheSelfTest.java      | 12 +++++++++++
 .../transactions/TxRollbackOnTimeoutTest.java   |  2 +-
 9 files changed, 54 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index fed716c..2be738a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -102,6 +102,7 @@ import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFi
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
+import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException;
 import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -138,6 +139,7 @@ import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
+import org.apache.ignite.transactions.TransactionState;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.LongAdder8;
 
@@ -4032,6 +4034,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
 
+        if (tx != null && tx.state() == TransactionState.ROLLED_BACK && tx.timedOut())
+            throw new IgniteTxTimeoutCheckedException("Previous transaction was rolled back by timeout. " +
+                "Please start new transaction and retry an operation.");
+
         if (tx == null || tx.implicit()) {
             TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 84c9790..f5ecdd8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -109,6 +109,7 @@ import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxE
 import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_NOT_EMPTY_VER;
 import static org.apache.ignite.transactions.TransactionState.COMMITTED;
 import static org.apache.ignite.transactions.TransactionState.COMMITTING;
+import static org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK;
 import static org.apache.ignite.transactions.TransactionState.PREPARED;
 import static org.apache.ignite.transactions.TransactionState.PREPARING;
 import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
@@ -182,9 +183,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     private TransactionProxyImpl proxy;
 
     /** */
-    private long endTime;
-
-    /** */
     private transient Exception trackE;
 
     /**
@@ -246,8 +244,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             if (TRACK_TRANSACTION_INITIATOR)
                 trackE = new Exception();
 
-            endTime = U.currentTimeMillis() + this.timeout;
-
             cctx.time().addTimeoutObject(this);
         }
 
@@ -3169,7 +3165,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             // Prepare was called explicitly.
             return fut;
 
-        if (endTime > 0)
+        if (timeout() > 0)
             cctx.time().removeTimeoutObject(this);
 
         mapExplicitLocks();
@@ -3274,7 +3270,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
      * @throws IgniteCheckedException If failed.
      */
     public void rollback() throws IgniteCheckedException {
-        if (endTime > 0)
+        if (timeout() > 0)
             cctx.time().removeTimeoutObject(this);
 
         rollbackNearTxLocalAsync().get();
@@ -3719,6 +3715,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
 
+        cctx.tm().onLocalClose(threadId(), this);
+
         synchronized (this) {
             try {
                 while (!done())
@@ -4080,15 +4078,16 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public long endTime() {
-        return endTime;
+        return startTime() + timeout();
     }
 
     /** {@inheritDoc} */
     @Override public void onTimeout() {
-        log.error("Transaction is timed out and will be rolled back: [tx=" + this + ']', trackE);
+        if (state(MARKED_ROLLBACK, true)) {
+            log.error("Transaction is timed out and will be rolled back: [" + this + ']', trackE);
 
-        if (setRollbackOnly())
-            rollbackAsync();
+            rollbackNearTxLocalAsync();
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
index 7598003..9e06d9d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
@@ -634,4 +634,4 @@ public interface IgniteInternalTx {
      * @param e Commit error.
      */
     public void commitError(Throwable e);
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 12f655a..9891484 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -29,6 +29,7 @@ import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
 import org.apache.ignite.transactions.TransactionMetrics;
 import org.apache.ignite.transactions.TransactionException;
+import org.apache.ignite.transactions.TransactionState;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -154,7 +155,8 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
         try {
             GridNearTxLocal tx = cctx.tm().userTx(sysCacheCtx);
 
-            if (tx != null)
+            // Allow to start new transaction if previous transaction was rolled back by timeout.
+            if (tx != null && !(tx.state() == TransactionState.ROLLED_BACK && tx.timedOut()))
                 throw new IllegalStateException("Failed to start new transaction " +
                     "(current thread already has a transaction): " + tx);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
index 65f8af2..7d4464a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
@@ -1047,7 +1047,9 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter implement
 
             if (valid) {
                 this.state = state;
-                this.timedOut = timedOut;
+
+                if (timedOut)
+                    this.timedOut = true;
 
                 if (log.isDebugEnabled())
                     log.debug("Changed transaction state [prev=" + prev + ", new=" + this.state + ", tx=" + this + ']');

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/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 e7ebaae..ea105ae 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
@@ -1237,9 +1237,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter implements Ig
      * @throws IgniteCheckedException If transaction check failed.
      */
     protected void checkValid() throws IgniteCheckedException {
-        if (local() && !dht() && remainingTime() == -1)
-            state(MARKED_ROLLBACK, true);
-
         if (isRollbackOnly()) {
             if (remainingTime() == -1)
                 throw new IgniteTxTimeoutCheckedException("Cache transaction timed out: " + this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/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 a3bf205..ee7d922 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
@@ -31,6 +31,7 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteClientDisconnectedException;
+import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.cluster.ClusterNode;
@@ -1423,8 +1424,14 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
-            if (!tx.system())
-                threadMap.remove(tx.threadId(), tx);
+            if (!tx.system()) {
+                /**
+                 * Timed out local transactions are cleared in {@link #onLocalClose}
+                 * TODO reduce heap size of timed out transaction.
+                 */
+                if (!(tx.timedOut() && tx.pessimistic() && tx.local() && !tx.dht()))
+                    threadMap.remove(tx.threadId(), tx);
+            }
             else {
                 Integer cacheId = tx.txState().firstCacheId();
 
@@ -2316,6 +2323,15 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
+     * Remove thread completely.
+     * @param threadId Thread ID.
+     * @param tx Local transaction.
+     */
+    public void onLocalClose(long threadId, GridNearTxLocal tx) {
+        threadMap.remove(threadId, tx);
+    }
+
+    /**
      * Timeout object for node failure handler.
      */
     private final class NodeFailureTimeoutObject extends GridTimeoutObjectAdapter {

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
index 2efa0cb..8574f0c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
@@ -185,6 +185,8 @@ public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest {
         try (final Transaction tx = ignite.transactions().txStart()) {
             assert tx != null;
 
+            cache.put("key0", "val0");
+
             sleepForTxFailure();
 
             cache.put("key", "val");
@@ -195,7 +197,17 @@ public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest {
             assert e.getCause() instanceof TransactionTimeoutException;
         }
 
+        assert !cache.containsKey("key0");
         assert !cache.containsKey("key");
+
+        // New transaction must succeed.
+        try (final Transaction tx = ignite.transactions().txStart()) {
+            cache.put("key", "val");
+
+            tx.commit();
+        }
+
+        assert cache.containsKey("key");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a928460/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 9243f58..bb1bbc7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -266,7 +266,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     tx.commit();
                 }
             }
-        }, 2, "Second");
+        }, 1, "Second");
 
         fut2.get();
 


[20/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d6f0b261
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d6f0b261
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d6f0b261

Branch: refs/heads/ignite-6181-1
Commit: d6f0b261bb120d719a0af865f10df55c351eabb5
Parents: 9da2dde
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Wed Aug 30 19:47:11 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Wed Aug 30 19:47:11 2017 +0300

----------------------------------------------------------------------
 .../apache/ignite/IgniteSystemProperties.java   |  6 +++
 .../cache/distributed/near/GridNearTxLocal.java | 15 ++++++-
 .../transactions/TxRollbackOnTimeoutTest.java   | 43 ++++++++++++++------
 3 files changed, 50 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d6f0b261/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index d3cba2b..c22d552 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -706,6 +706,12 @@ public final class IgniteSystemProperties {
     public static final String IGNITE_ENABLE_FORCIBLE_NODE_KILL = "IGNITE_ENABLE_FORCIBLE_NODE_KILL";
 
     /**
+     * If this property is set, a node will track transaction initiators, printing them in tx timeout error.
+     * Useful for debugging.
+     */
+    public static final String IGNITE_TRACK_TRANSACTION_INITIATOR = "IGNITE_TRACK_TRANSACTION_INITIATOR";
+
+    /**
      * Enforces singleton.
      */
     private IgniteSystemProperties() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/d6f0b261/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index ebae49f..84c9790 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -34,6 +34,7 @@ import javax.cache.CacheException;
 import javax.cache.expiry.ExpiryPolicy;
 import javax.cache.processor.EntryProcessor;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.NodeStoppingException;
@@ -114,11 +115,17 @@ import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
 import static org.apache.ignite.transactions.TransactionState.ROLLING_BACK;
 import static org.apache.ignite.transactions.TransactionState.UNKNOWN;
 
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TRACK_TRANSACTION_INITIATOR;
+
 /**
  * Replicated user transaction.
  */
 @SuppressWarnings("unchecked")
 public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeoutObject, AutoCloseable {
+    /** {@link IgniteSystemProperties#IGNITE_TRACK_TRANSACTION_INITIATOR} */
+    private static final boolean TRACK_TRANSACTION_INITIATOR =
+        IgniteSystemProperties.getBoolean(IGNITE_TRACK_TRANSACTION_INITIATOR, false);
+
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -177,6 +184,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     /** */
     private long endTime;
 
+    /** */
+    private transient Exception trackE;
+
     /**
      * Empty constructor required for {@link Externalizable}.
      */
@@ -233,6 +243,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
         if (this.timeout > 0) {
+            if (TRACK_TRANSACTION_INITIATOR)
+                trackE = new Exception();
+
             endTime = U.currentTimeMillis() + this.timeout;
 
             cctx.time().addTimeoutObject(this);
@@ -4072,7 +4085,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public void onTimeout() {
-        log.error("Transaction is timed out and will be rolled back: [tx=" + this + ']');
+        log.error("Transaction is timed out and will be rolled back: [tx=" + this + ']', trackE);
 
         if (setRollbackOnly())
             rollbackAsync();

http://git-wip-us.apache.org/repos/asf/ignite/blob/d6f0b261/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index e93cff1..52f099d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -22,12 +22,14 @@ import java.util.concurrent.TimeUnit;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
@@ -53,13 +55,13 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
 
     /** */
-    private final CountDownLatch blocked = new CountDownLatch(1);
+    private static final int GRID_CNT = 3;
 
     /** */
-    private CountDownLatch unblocked = new CountDownLatch(1);
+    private final CountDownLatch blocked = new CountDownLatch(1);
 
     /** */
-    private static int GRID_CNT = 3;
+    private CountDownLatch unblocked = new CountDownLatch(1);
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
@@ -84,6 +86,20 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        System.setProperty(IgniteSystemProperties.IGNITE_TRACK_TRANSACTION_INITIATOR, "true");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        System.clearProperty(IgniteSystemProperties.IGNITE_TRACK_TRANSACTION_INITIATOR);
+    }
+
+    /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
@@ -114,11 +130,11 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
      */
-    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
-        Ignite client = startGrid("client");
-
-        testWaitingTxUnblockedOnTimeout0(grid(0), client);
-    }
+//    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
+//        Ignite client = startGrid("client");
+//
+//        testWaitingTxUnblockedOnTimeout0(grid(0), client);
+//    }
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
@@ -155,11 +171,11 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
      */
-    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
-        Ignite client = startGrid("client");
-
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
-    }
+//    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
+//        Ignite client = startGrid("client");
+//
+//        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
+//    }
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
@@ -259,6 +275,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         fut1.get(5, TimeUnit.SECONDS);
     }
 
+    /** */
     private void testWaitingTxUnblockedOnThreadDeath0(final Ignite near, final Ignite other) throws Exception {
         final int recordsCnt = 100;
 


[17/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/61dfb65f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/61dfb65f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/61dfb65f

Branch: refs/heads/ignite-6181-1
Commit: 61dfb65f97c1d2d532d0f69b78ef4db37a727caf
Parents: 7f5d80d
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Tue Aug 29 20:14:31 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Tue Aug 29 20:14:31 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java | 39 +++++++++++++++++-
 .../cache/transactions/IgniteTxManager.java     | 43 +++++++++++++++++++-
 .../transactions/TxTimeoutHandlingTest.java     |  4 +-
 3 files changed, 81 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/61dfb65f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 2fb0ff3..ac35ad9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -34,6 +34,7 @@ import javax.cache.CacheException;
 import javax.cache.expiry.ExpiryPolicy;
 import javax.cache.processor.EntryProcessor;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.NodeStoppingException;
@@ -67,6 +68,7 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.transactions.TransactionProxy;
 import org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
 import org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException;
@@ -105,14 +107,12 @@ import static org.apache.ignite.internal.processors.cache.GridCacheOperation.TRA
 import static org.apache.ignite.internal.processors.cache.GridCacheOperation.UPDATE;
 import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER;
 import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_NOT_EMPTY_VER;
-import static org.apache.ignite.transactions.TransactionState.ACTIVE;
 import static org.apache.ignite.transactions.TransactionState.COMMITTED;
 import static org.apache.ignite.transactions.TransactionState.COMMITTING;
 import static org.apache.ignite.transactions.TransactionState.PREPARED;
 import static org.apache.ignite.transactions.TransactionState.PREPARING;
 import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
 import static org.apache.ignite.transactions.TransactionState.ROLLING_BACK;
-import static org.apache.ignite.transactions.TransactionState.SUSPENDED;
 import static org.apache.ignite.transactions.TransactionState.UNKNOWN;
 
 /**
@@ -175,6 +175,10 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     @GridToStringExclude
     private TransactionProxyImpl proxy;
 
+    /** */
+    @GridToStringExclude
+    private GridTimeoutObject timeoutHandler;
+
     /**
      * Empty constructor required for {@link Externalizable}.
      */
@@ -3148,6 +3152,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
             // Prepare was called explicitly.
             return fut;
 
+        // Clears timeout handler before prepare, because prepare phase will clean up everything right up.
+        if (!clearTimeoutHandler()) {
+            // Timeout closure has been invoked, tx will be rolled back.
+            throw new IgniteException("Bad");
+        }
+
         mapExplicitLocks();
 
         fut.prepare();
@@ -3170,6 +3180,15 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     }
 
     /**
+     * Clears timeout handler.
+     */
+    public boolean clearTimeoutHandler() {
+        timeoutHandler = null;
+
+        return true;
+    }
+
+    /**
      * @return Prepare future.
      */
     private IgniteInternalFuture<?> prepareAsync() {
@@ -3250,6 +3269,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
      * @throws IgniteCheckedException If failed.
      */
     public void rollback() throws IgniteCheckedException {
+        clearTimeoutHandler();
+
         rollbackNearTxLocalAsync().get();
     }
 
@@ -3765,6 +3786,20 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     }
 
     /**
+     * @return Timeout handler.
+     */
+    public GridTimeoutObject timeoutHandler() {
+        return timeoutHandler;
+    }
+
+    /**
+     * @param timeoutHnd New timeout handler.
+     */
+    public void timeoutHandler(GridTimeoutObject timeoutHnd) {
+        timeoutHandler = timeoutHnd;
+    }
+
+    /**
      * @return Public API proxy.
      */
     public TransactionProxy proxy() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/61dfb65f/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 6c59706..64624dd 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
@@ -69,6 +69,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearOpti
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter;
 import org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException;
@@ -459,7 +460,12 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 tx.topologyVersion(topVer);
         }
 
-        return onCreated(sysCacheCtx, tx);
+        tx = onCreated(sysCacheCtx, tx);
+
+        if (tx != null && tx.timeout() > 0)
+            cctx.time().addTimeoutObject(new TxEagerTimeoutObject(tx));
+
+        return tx;
     }
 
     /**
@@ -2399,6 +2405,41 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
+     * Timeout object for tx timeout handler.
+     */
+    private final class TxEagerTimeoutObject extends GridTimeoutObjectAdapter {
+        /** */
+        private final GridNearTxLocal tx;
+
+        /**
+         * @param tx Tx.
+         */
+        public TxEagerTimeoutObject(final GridNearTxLocal tx) {
+            super(tx.timeout());
+
+            this.tx = tx;
+
+            tx.timeoutHandler(this);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onTimeout() {
+            GridTimeoutObject hnd = tx.timeoutHandler();
+
+            if (hnd == null)
+                return;
+
+            if (!tx.clearTimeoutHandler()) // Transaction is prepared or rolled back concurrently.
+                return;
+
+            log.error("Transaction is timed out and will be rolled back: [tx=" + tx + ']');
+
+            if (tx.setRollbackOnly())
+                tx.rollbackAsync();
+        }
+    }
+
+    /**
      * Per-thread key for system transactions.
      */
     private static class TxThreadKey {

http://git-wip-us.apache.org/repos/asf/ignite/blob/61dfb65f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
index 2ac0f1a..8b17127 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
@@ -130,7 +130,7 @@ public class TxTimeoutHandlingTest extends GridCommonAbstractTest {
 
             Thread.sleep(TX_TIMEOUT + 1_000);
 
-            fut2.get(1, TimeUnit.SECONDS);
+            fut2.get();
 
             startGrid(1);
 
@@ -144,4 +144,4 @@ public class TxTimeoutHandlingTest extends GridCommonAbstractTest {
             stopAllGrids();
         }
     }
-}
+}
\ No newline at end of file


[32/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/19383384
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/19383384
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/19383384

Branch: refs/heads/ignite-6181-1
Commit: 1938338407f68d19dea3255144cfcca01cf16ef7
Parents: 467e0ba
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Mon Sep 11 13:08:25 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Mon Sep 11 13:08:25 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      |  5 --
 .../cache/distributed/near/GridNearTxLocal.java | 15 ++--
 .../cache/transactions/IgniteTxManager.java     | 75 +++++++-------------
 3 files changed, 33 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/19383384/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 8e075b2..fed716c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -102,7 +102,6 @@ import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFi
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
-import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException;
 import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -4031,10 +4030,6 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         awaitLastFut();
 
-        if (ctx.tm().isTimedOutThread(Thread.currentThread().getId()))
-            throw new IgniteTxTimeoutCheckedException("Previous transaction was rolled back due to timeout. " +
-                    "Please start new transaction and retry an operation.");
-
         GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
 
         if (tx == null || tx.implicit()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/19383384/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 3d93289..289096d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -2486,7 +2486,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                         processLoaded(map, keys, needVer, c);
 
                         return null;
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         setRollbackOnly();
 
                         throw new GridClosureException(e);
@@ -3225,13 +3226,15 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                     prepareFut.get();
 
                     fut0.finish(true);
-                } catch (Error | RuntimeException e) {
+                }
+                catch (Error | RuntimeException e) {
                     COMMIT_ERR_UPD.compareAndSet(GridNearTxLocal.this, null, e);
 
                     fut0.finish(false);
 
                     throw e;
-                } catch (IgniteCheckedException e) {
+                }
+                catch (IgniteCheckedException e) {
                     COMMIT_ERR_UPD.compareAndSet(GridNearTxLocal.this, null, e);
 
                     if (!(e instanceof NodeStoppingException))
@@ -3276,9 +3279,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             return new GridFinishedFuture<>((IgniteInternalTx)this);
         }
 
-        if (timedOut())
-            cctx.tm().markTimedOut(this);
-
         GridNearTxFinishFuture fut = rollbackFut;
 
         if (fut != null)
@@ -3694,6 +3694,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public void close() throws IgniteCheckedException {
+        // If tx was rolled back asynchronously by timeout, user tx will not be cleared.
+        cctx.tm().resetUserTx();
+
         TransactionState state = state();
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)

http://git-wip-us.apache.org/repos/asf/ignite/blob/19383384/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 41e10cb..fb04c2b 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
@@ -29,8 +29,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentSkipListSet;
-
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteClientDisconnectedException;
 import org.apache.ignite.IgniteSystemProperties;
@@ -150,11 +148,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /** Topology version should be used when mapping internal tx. */
     private final ThreadLocal<AffinityTopologyVersion> txTop = new ThreadLocal<>();
 
-    /** Per-thread transaction map. */
-    private final ConcurrentMap<Long, IgniteInternalTx> threadMap = newMap();
-
-    /** Thread ids associated with rolled back transactions. */
-    private final ConcurrentSkipListSet<Long> rolledBackByTimeoutThreads = new ConcurrentSkipListSet<>();
+    /** User transaction. */
+    private final static ThreadLocal<IgniteInternalTx> userTx = new ThreadLocal<>();
 
     /** Per-thread system transaction map. */
     private final ConcurrentMap<TxThreadKey, IgniteInternalTx> sysThreadMap = newMap();
@@ -287,19 +282,15 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param cacheId Cache ID.
      */
     public void rollbackTransactionsForCache(int cacheId) {
-        rollbackTransactionsForCache(cacheId, nearIdMap);
-
-        rollbackTransactionsForCache(cacheId, threadMap);
+        rollbackTransactionsForCache(cacheId, activeTransactions());
     }
 
     /**
      * @param cacheId Cache ID.
      * @param txMap Transactions map.
      */
-    private void rollbackTransactionsForCache(int cacheId, ConcurrentMap<?, IgniteInternalTx> txMap) {
-        for (Map.Entry<?, IgniteInternalTx> e : txMap.entrySet()) {
-            IgniteInternalTx tx = e.getValue();
-
+    private void rollbackTransactionsForCache(int cacheId, Collection<IgniteInternalTx> txMap) {
+        for (IgniteInternalTx tx : txMap) {
             for (IgniteTxEntry entry : tx.allEntries()) {
                 if (entry.cacheId() == cacheId) {
                     rollbackTx(tx);
@@ -314,8 +305,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void onDisconnected(IgniteFuture reconnectFut) {
         txFinishSync.onDisconnected(reconnectFut);
 
-        for (Map.Entry<Long, IgniteInternalTx> e : threadMap.entrySet())
-            rollbackTx(e.getValue());
+        for (IgniteInternalTx tx : activeTransactions())
+            rollbackTx(tx);
 
         IgniteClientDisconnectedException err =
             new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.");
@@ -374,8 +365,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void printMemoryStats() {
         X.println(">>> ");
         X.println(">>> Transaction manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ']');
-        X.println(">>>   threadMapSize: " + threadMap.size());
-        X.println(">>>   idMap [size=" + idMap.size() + ']');
+        X.println(">>>   activeSize [size=" + activeTransactions().size() + ']');
         X.println(">>>   completedVersSortedSize: " + completedVersSorted.size());
         X.println(">>>   completedVersHashMapSize: " + completedVersHashMap.sizex());
     }
@@ -384,7 +374,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Thread map size.
      */
     public int threadMapSize() {
-        return threadMap.size();
+        return 0;
     }
 
     /**
@@ -493,7 +483,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // and overwrite local transaction.
             if (tx.local() && !tx.dht()) {
                 if (cacheCtx == null || !cacheCtx.systemTx())
-                    threadMap.put(tx.threadId(), tx);
+                    userTx.set(tx);
                 else
                     sysThreadMap.put(new TxThreadKey(tx.threadId(), cacheCtx.cacheId()), tx);
             }
@@ -670,7 +660,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Not null topology version if current thread holds lock preventing topology change.
      */
     @Nullable public AffinityTopologyVersion lockedTopologyVersion(long threadId, IgniteInternalTx ignore) {
-        IgniteInternalTx tx = threadMap.get(threadId);
+        IgniteInternalTx tx = userTx.get();
 
         if (tx != null) {
             AffinityTopologyVersion topVer = tx.topologyVersionSnapshot();
@@ -777,7 +767,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @SuppressWarnings({"unchecked"})
     private <T> T tx(GridCacheContext cctx, long threadId) {
         if (cctx == null || !cctx.systemTx())
-            return (T)threadMap.get(threadId);
+            return (T) userTx.get();
 
         TxThreadKey key = new TxThreadKey(threadId, cctx.cacheId());
 
@@ -1428,7 +1418,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
             if (!tx.system())
-                threadMap.remove(tx.threadId(), tx);
+                userTx.set(null);
             else {
                 Integer cacheId = tx.txState().firstCacheId();
 
@@ -1712,12 +1702,17 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * Commit ended.
      */
     public void resetContext() {
-        rolledBackByTimeoutThreads.remove(Thread.currentThread().getId());
-
         threadCtx.set(null);
     }
 
     /**
+     * Reset user tx.
+     */
+    public void resetUserTx() {
+        userTx.set(null);
+    }
+
+    /**
      * @return All transactions.
      */
     public Collection<IgniteInternalTx> txs() {
@@ -2291,35 +2286,13 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                     + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
         }
 
-        long threadId = Thread.currentThread().getId();
+        if (userTx.get() != null)
+            throw new IgniteCheckedException("The thread already has active transaction.");
 
-        if (threadMap.putIfAbsent(threadId, tx) != null)
-            throw new IgniteCheckedException("Thread already has started a transaction.");
+        userTx.set(tx);
 
         if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
-            throw new IgniteCheckedException("Thread already has started a transaction.");
-
-        tx.threadId(threadId);
-    }
-
-    /**
-     * Checks if thread belongs to timed out ids.
-     *
-     * @param threadId Thread id.
-     * @return {@code True} if current thread had a transaction rolled back by timeout.
-     */
-    public boolean isTimedOutThread(long threadId) {
-        return rolledBackByTimeoutThreads.contains(threadId);
-    }
-
-    /**
-     * Mark transaction thread as rolled back by timeout.
-     * Thread may not perform transactional ops until it will explicitly start a new transaction.
-     *
-     * @param tx Transaction.
-     */
-    public void markTimedOut(GridNearTxLocal tx) {
-        rolledBackByTimeoutThreads.add(tx.threadId());
+            throw new IgniteCheckedException("The thread already has active transaction.");
     }
 
     /**


[48/50] [abbrv] ignite git commit: ignite-6181-1

Posted by sb...@apache.org.
ignite-6181-1


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f950cb15
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f950cb15
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f950cb15

Branch: refs/heads/ignite-6181-1
Commit: f950cb15d55b6858987e3baca31ce1d350ec0c5d
Parents: ea5cd0d
Author: sboikov <sb...@gridgain.com>
Authored: Tue Sep 19 12:55:06 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Sep 19 12:56:44 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java |  81 +++++---------
 .../transactions/IgniteTransactionsImpl.java    |   3 +-
 .../cache/transactions/IgniteTxManager.java     |  15 +--
 .../cache/IgniteTxConfigCacheSelfTest.java      |   2 +-
 .../IgniteOptimisticTxSuspendResumeTest.java    |   3 +-
 .../transactions/TxRollbackOnTimeoutTest.java   | 109 +++++++++++++++----
 .../hadoop/impl/HadoopTxConfigCacheTest.java    |   2 +-
 7 files changed, 121 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 0e75b69..ad3b464 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -46,7 +46,6 @@ import org.apache.ignite.internal.processors.cache.EntryGetResult;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
-import org.apache.ignite.internal.processors.cache.GridCacheFuture;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccFuture;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
@@ -57,14 +56,11 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocalAdapter;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture;
-import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry;
 import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
-import org.apache.ignite.internal.processors.cache.local.GridLocalLockFuture;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
@@ -94,7 +90,6 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiClosure;
 import org.apache.ignite.lang.IgniteClosure;
-import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.plugin.security.SecurityPermission;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -140,13 +135,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     private static final AtomicReferenceFieldUpdater<GridNearTxLocal, GridNearTxFinishFuture> ROLLBACK_FUT_UPD =
         AtomicReferenceFieldUpdater.newUpdater(GridNearTxLocal.class, GridNearTxFinishFuture.class, "rollbackFut");
 
-    /** Lock future predicate. */
-    private static final IgnitePredicate<GridCacheFuture<?>> LOCK_FUTURES = new IgnitePredicate<GridCacheFuture<?>>() {
-        @Override public boolean apply(GridCacheFuture<?> fut) {
-            return fut instanceof GridDhtColocatedLockFuture;
-        }
-    };
-
     /** DHT mappings. */
     private IgniteTxMappings mappings;
 
@@ -242,10 +230,10 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
-        if (this.timeout() > 0 && !implicit())
-            cctx.time().addTimeoutObject(this);
-
         initResult();
+
+        if (trackTimeout())
+            cctx.time().addTimeoutObject(this);
     }
 
     /** {@inheritDoc} */
@@ -446,12 +434,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         Object... invokeArgs
     ) {
         return (IgniteInternalFuture<GridCacheReturn>)putAllAsync0(cacheCtx,
-                entryTopVer,
-                null,
-                map,
-                invokeArgs,
-                null,
-                true);
+            entryTopVer,
+            null,
+            map,
+            invokeArgs,
+            null,
+            true);
     }
 
     /**
@@ -470,12 +458,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         });
 
         return this.<Object, Object>putAllAsync0(cacheCtx,
-                null,
-                map,
-                null,
-                null,
-                drMap,
-                false);
+            null,
+            map,
+            null,
+            null,
+            drMap,
+            false);
     }
 
     /**
@@ -2857,7 +2845,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         if (log.isDebugEnabled())
             log.debug("Added mappings to transaction [locId=" + cctx.localNodeId() + ", key=" + key + ", node=" + node +
-                    ", tx=" + this + ']');
+                ", tx=" + this + ']');
     }
 
     /**
@@ -3532,7 +3520,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                     }
                     catch (IgniteCheckedException e) {
                         log.debug("Failed to prepare transaction during rollback (will ignore) [tx=" + this + ", msg=" +
-                                e.getMessage() + ']');
+                            e.getMessage() + ']');
                     }
 
                     fut.finish(false);
@@ -3710,11 +3698,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
-        else {
-            cctx.tm().onLocalClose(this);
-
+        else
             removeTimeoutHandler();
-        }
 
         synchronized (this) {
             try {
@@ -4026,10 +4011,17 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     }
 
     /**
+     * @return {@code True} if need register callback which cancels tx on timeout.
+     */
+    private boolean trackTimeout() {
+        return timeout() > 0 && !implicit();
+    }
+
+    /**
      * Removes timeout handler.
      */
     private void removeTimeoutHandler() {
-        if (timeout() > 0 && !implicit())
+        if (trackTimeout())
             cctx.time().removeTimeoutObject(this);
     }
 
@@ -4048,27 +4040,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (state(MARKED_ROLLBACK, true)) {
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
-                    // Wait for active local lock futures completion to prevent races with deadlock detection.
-                    Collection<GridCacheFuture<?>> lockFuts = F.view(cctx.mvcc().activeFutures(), LOCK_FUTURES);
-
-                    for (GridCacheFuture<?> fut : lockFuts) {
-                        try {
-                            GridDhtColocatedLockFuture locFut = (GridDhtColocatedLockFuture)fut;
-
-                            if (locFut.timeout() > 0)
-                                fut.get();
-                        }
-                        catch (IgniteCheckedException e) {
-                            log.error("Failed to wait for lock future completion [fut=" + fut + ']', e);
-                        }
-                    }
-
-                    if (state() != MARKED_ROLLBACK)
-                        return;
-
-                    log().error("Transaction is timed out and will be rolled back [timeout=" + timeout() +
-                        ", tx=" + GridNearTxLocal.this + ']');
-
                     rollbackNearTxLocalAsync();
                 }
             });

http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 7adfb82..12f655a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -154,8 +154,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
         try {
             GridNearTxLocal tx = cctx.tm().userTx(sysCacheCtx);
 
-            // Allow overriding timed out transaction.
-            if (tx != null && !tx.timedOut())
+            if (tx != null)
                 throw new IllegalStateException("Failed to start new transaction " +
                     "(current thread already has a transaction): " + tx);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/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 827f2f6..6aa04ac 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
@@ -1422,7 +1422,9 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
-            if (tx.system()) {
+            if (!tx.system())
+                threadMap.remove(tx.threadId(), tx);
+            else {
                 Integer cacheId = tx.txState().firstCacheId();
 
                 if (cacheId != null)
@@ -1439,9 +1441,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                     }
                 }
             }
-            else if (!tx.timedOut())
-                threadMap.remove(tx.threadId(), tx);
-
         }
     }
 
@@ -1712,13 +1711,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Removes tx from map.
-     */
-    public void onLocalClose(IgniteInternalTx tx) {
-        threadMap.remove(tx.threadId(), tx);
-    }
-
-    /**
      * @return All transactions.
      */
     public Collection<IgniteInternalTx> txs() {
@@ -2284,6 +2276,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     public void resumeTx(GridNearTxLocal tx) throws IgniteCheckedException {
         assert tx != null && !tx.system() : tx;
+        assert !threadMap.containsValue(tx) : tx;
         assert !transactionMap(tx).containsValue(tx) : tx;
         assert !haveSystemTxForThread(Thread.currentThread().getId());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
index af09858..f2e17e4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
@@ -63,7 +63,7 @@ public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest {
     private static final String CACHE_NAME = "cache_name";
 
     /** Timeout of transaction. */
-    private static final long TX_TIMEOUT = 300;
+    private static final long TX_TIMEOUT = 100;
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {

http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
index 7b88b6d..ae691f5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
@@ -45,7 +45,6 @@ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
 import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
 import static org.apache.ignite.transactions.TransactionState.ACTIVE;
 import static org.apache.ignite.transactions.TransactionState.COMMITTED;
-import static org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK;
 import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
 import static org.apache.ignite.transactions.TransactionState.SUSPENDED;
 
@@ -54,7 +53,7 @@ import static org.apache.ignite.transactions.TransactionState.SUSPENDED;
  */
 public class IgniteOptimisticTxSuspendResumeTest extends GridCommonAbstractTest {
     /** Transaction timeout. */
-    private static final long TX_TIMEOUT = 300;
+    private static final long TX_TIMEOUT = 100;
 
     /** Future timeout */
     private static final int FUT_TIMEOUT = 5000;

http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 360cba1..2d6264c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.transactions;
 import java.util.concurrent.CountDownLatch;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -29,10 +30,13 @@ import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
+import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -106,13 +110,83 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         stopAllGrids();
     }
 
-    /** */
+    /**
+     * @param e Exception.
+     */
     protected void validateException(Exception e) {
         assertEquals("Deadlock report is expected",
             TransactionDeadlockException.class, e.getCause().getCause().getClass());
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testLockAndConcurrentTimeout() throws Exception {
+        startGrid("client");
+
+        for (Ignite node : G.allGrids()) {
+            log.info("Test with node: " + node.name());
+
+            lock(node, false);
+
+            lock(node, false);
+
+            lock(node, true);
+        }
+    }
+
+    /**
+     * @param node Node.
+     * @param retry {@code True}
+     * @throws Exception If failed.
+     */
+    private void lock(final Ignite node, final boolean retry) throws Exception {
+        final IgniteCache<Object, Object> cache = node.cache(CACHE_NAME);
+
+        final int KEYS_PER_THREAD = 10_000;
+
+        GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
+            @Override public void apply(Integer idx) {
+                int start = idx * KEYS_PER_THREAD;
+                int end = start + KEYS_PER_THREAD;
+
+                int locked = 0;
+
+                try {
+                    try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 500, 0)) {
+                        for (int i = start; i < end; i++) {
+                            cache.get(i);
+
+                            locked++;
+                        }
+
+                        tx.commit();
+                    }
+                }
+                catch (Exception e) {
+                    info("Expected error: " + e);
+                }
+
+                info("Done, locked: " + locked);
+
+                if (retry) {
+                    try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 10 * 60_000, 0)) {
+                        for (int i = start; i < end; i++) {
+                            cache.get(i);
+
+                            locked++;
+                        }
+
+                        cache.put(start, 0);
+
+                        tx.commit();
+                    }
+                }
+            }
+        }, 8, "tx-thread");
+    }
+
+    /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
      *
      * @throws Exception If failed.
@@ -245,7 +319,10 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if deadlock is resolved on timeout with correct message.
-     * @throws Exception
+     *
+     * @param node1 First node.
+     * @param node2 Second node.
+     * @throws Exception If failed.
      */
     private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2) throws Exception {
         final CountDownLatch l = new CountDownLatch(2);
@@ -265,7 +342,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
                         fail();
                     }
-                } catch (CacheException e) {
+                }
+                catch (CacheException e) {
                     // No-op.
                     validateException(e);
                 }
@@ -352,7 +430,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                 tx.commit();
 
                 fail("Tx must timeout");
-            } catch (IgniteException e) {
+            }
+            catch (IgniteException e) {
                 assertTrue("Expected timeout exception", X.hasCause(e, TransactionTimeoutException.class));
             }
         }
@@ -364,6 +443,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @param near Node.
      * @param mode Test mode.
      *
+     * @param timeout Tx timeout.
      * @throws Exception If failed.
      */
     private void testTimeoutRemoval0(IgniteEx near, int mode, long timeout) throws Exception {
@@ -402,12 +482,13 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         GridConcurrentSkipListSet set = U.field(near.context().cache().context().time(), "timeoutObjs");
 
-        for (Object obj : set)
+        for (Object obj : set) {
             if (obj.getClass().isAssignableFrom(GridNearTxLocal.class)) {
-                log.error("Last saved exception", saved);
+                log.error("Last saved exception: " + saved, saved);
 
                 fail("Not remove for mode=" + mode + " and timeout=" + timeout);
             }
+        }
     }
 
     /**
@@ -525,20 +606,4 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         fut2.get();
     }
-
-    /**
-     * Returns root cause for an exception.
-     * @param t Throwable.
-     *
-     * @return Root cause or input if none.
-     */
-    private static Throwable getRootCause(Throwable t) {
-        Throwable cause;
-        Throwable res = t;
-
-        while(null != (cause = res.getCause()) && (res != cause) )
-            res = cause;
-
-        return res;
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/f950cb15/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
index 554c489..f404732 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
@@ -29,7 +29,7 @@ public class HadoopTxConfigCacheTest extends IgniteTxConfigCacheSelfTest {
     /**
      * Success if system caches weren't timed out.
      *
-     * @throws Exception
+     * @throws Exception If failed.
      */
     public void testSystemCacheTx() throws Exception {
         final Ignite ignite = grid(0);


[04/50] [abbrv] ignite git commit: Added test for rebalance after restart.

Posted by sb...@apache.org.
Added test for rebalance after restart.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6f7011aa
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6f7011aa
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6f7011aa

Branch: refs/heads/ignite-6181-1
Commit: 6f7011aa9c69280c76e03335ce4851a38cfc334e
Parents: 316312d
Author: sboikov <sb...@gridgain.com>
Authored: Fri Aug 25 16:59:02 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Aug 25 16:59:02 2017 +0300

----------------------------------------------------------------------
 .../IgnitePdsCacheRebalancingAbstractTest.java  | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6f7011aa/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
index 2f43951..91838fc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
@@ -498,6 +498,43 @@ public abstract class IgnitePdsCacheRebalancingAbstractTest extends GridCommonAb
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testForceRebalance() throws Exception {
+        final Ignite ig = startGrids(4);
+
+        ig.active(true);
+
+        awaitPartitionMapExchange();
+
+        IgniteCache<Object, Object> c = ig.cache(cacheName);
+
+        Integer val = 0;
+
+        for (int i = 0; i < 5; i++) {
+            Integer key = primaryKey(ignite(3).cache(cacheName));
+
+            c.put(key, val);
+
+            stopGrid(3);
+
+            val++;
+
+            c.put(key, val);
+
+            assertEquals(val, c.get(key));
+
+            startGrid(3);
+
+            awaitPartitionMapExchange();
+
+            Object val0 = ignite(3).cache(cacheName).get(key);
+
+            assertEquals(val, val0);
+        }
+    }
+
+    /**
      * @throws Exception If failed
      */
     public void testPartitionCounterConsistencyOnUnstableTopology() throws Exception {


[30/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ec4b16cc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ec4b16cc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ec4b16cc

Branch: refs/heads/ignite-6181-1
Commit: ec4b16cc51a623c9f8106b7b3d3359881a46f4ae
Parents: 02f94ae
Author: ascherbakoff <al...@gmail.com>
Authored: Sun Sep 10 14:17:19 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Sun Sep 10 14:17:19 2017 +0300

----------------------------------------------------------------------
 .../internal/IgniteDiagnosticPrepareContext.java     |  2 +-
 .../internal/processors/cache/GridCacheAdapter.java  |  2 +-
 .../cache/distributed/near/GridNearLockFuture.java   |  5 ++++-
 .../cache/distributed/near/GridNearTxLocal.java      |  6 ++----
 .../cache/transactions/IgniteTransactionsImpl.java   |  1 -
 .../cache/transactions/IgniteTxLocalAdapter.java     |  4 ++++
 .../cache/transactions/IgniteTxManager.java          | 10 ++++------
 .../cache/transactions/TxRollbackOnTimeoutTest.java  | 15 ++++++++-------
 8 files changed, 24 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
index 14783d5..ed8d35e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
@@ -280,4 +280,4 @@ public class IgniteDiagnosticPrepareContext {
             }
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 2be738a..18fb2ff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -4035,7 +4035,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
 
         if (tx != null && tx.state() == TransactionState.ROLLED_BACK && tx.timedOut())
-            throw new IgniteTxTimeoutCheckedException("Previous transaction was rolled back by timeout. " +
+            throw new IgniteTxTimeoutCheckedException("Previous transaction was rolled back due to timeout. " +
                 "Please start new transaction and retry an operation.");
 
         if (tx == null || tx.implicit()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
index 9cad49e..bb71337 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
@@ -770,7 +770,10 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
      * part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
      */
     void map() {
-        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(Thread.currentThread().getId());
+        // Obtain the topology version to use.
+        long threadId = Thread.currentThread().getId();
+
+        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
 
         // If there is another system transaction in progress, use it's topology version to prevent deadlock.
         if (topVer == null && tx != null && tx.system())

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index fb4c5e1..67782ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -3151,9 +3151,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             // Prepare was called explicitly.
             return fut;
 
-        if (timeout() > 0 && !implicit())
-            cctx.time().removeTimeoutObject(this);
-
         mapExplicitLocks();
 
         fut.prepare();
@@ -3701,7 +3698,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
 
-        cctx.tm().onLocalClose();
+        if (!system())
+            cctx.tm().resetUserTx();
 
         synchronized (this) {
             try {

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index df5c90e..12f655a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -29,7 +29,6 @@ import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
 import org.apache.ignite.transactions.TransactionMetrics;
 import org.apache.ignite.transactions.TransactionException;
-import org.apache.ignite.transactions.TransactionState;
 import org.jetbrains.annotations.Nullable;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/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 e6e19e3..e7ebaae 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
@@ -92,6 +92,7 @@ import static org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE;
 import static org.apache.ignite.internal.processors.dr.GridDrType.DR_PRIMARY;
 import static org.apache.ignite.transactions.TransactionState.COMMITTED;
 import static org.apache.ignite.transactions.TransactionState.COMMITTING;
+import static org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK;
 import static org.apache.ignite.transactions.TransactionState.PREPARING;
 import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
 import static org.apache.ignite.transactions.TransactionState.ROLLING_BACK;
@@ -1236,6 +1237,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter implements Ig
      * @throws IgniteCheckedException If transaction check failed.
      */
     protected void checkValid() throws IgniteCheckedException {
+        if (local() && !dht() && remainingTime() == -1)
+            state(MARKED_ROLLBACK, true);
+
         if (isRollbackOnly()) {
             if (remainingTime() == -1)
                 throw new IgniteTxTimeoutCheckedException("Cache transaction timed out: " + this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/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 d65832c..0722275 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
@@ -282,9 +282,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param cacheId Cache ID.
      */
     public void rollbackTransactionsForCache(int cacheId) {
-        rollbackTransactionsForCache(cacheId, nearIdMap.values());
-
-        rollbackTransactionsForCache(cacheId, Collections.singleton(userTx.get()));
+        rollbackTransactionsForCache(cacheId, activeTransactions());
     }
 
     /**
@@ -2278,12 +2276,12 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         }
 
         if (userTx.get() != null)
-            throw new IgniteCheckedException("Thread already has started transaction.");
+            throw new IgniteCheckedException("Thread already has active transaction.");
 
         userTx.set(tx);
 
         if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
-            throw new IgniteCheckedException("Thread already has started transaction.");
+            throw new IgniteCheckedException("Thread already has active transaction.");
     }
 
     /**
@@ -2305,7 +2303,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /** */
-    public void onLocalClose() {
+    public void resetUserTx() {
         userTx.set(null);
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec4b16cc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index cdbceda..01829ce 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -18,12 +18,10 @@
 package org.apache.ignite.internal.processors.cache.transactions;
 
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.locks.LockSupport;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
@@ -50,12 +48,15 @@ import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_REA
  */
 public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /** */
-    private static final long TX_TIMEOUT_MIN = 1;
+    private static final long TX_MIN_TIMEOUT = 1;
 
     /** */
     private static final long TX_TIMEOUT = 300;
 
     /** */
+    private static final long TX_DEFAULT_TIMEOUT = 3_000;
+
+    /** */
     private static final String CACHE_NAME = "test";
 
     /** IP finder. */
@@ -79,7 +80,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
         TransactionConfiguration txCfg = new TransactionConfiguration();
-        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
+        txCfg.setDefaultTxTimeout(TX_DEFAULT_TIMEOUT);
 
         cfg.setTransactionConfiguration(txCfg);
 
@@ -223,14 +224,14 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             testTimeoutRemoval0(client, i, TX_TIMEOUT);
 
         for (int i = 0; i < 5; i++)
-            testTimeoutRemoval0(grid(0), i, TX_TIMEOUT_MIN);
+            testTimeoutRemoval0(grid(0), i, TX_MIN_TIMEOUT);
 
         for (int i = 0; i < 5; i++)
-            testTimeoutRemoval0(client, i, TX_TIMEOUT_MIN);
+            testTimeoutRemoval0(client, i, TX_MIN_TIMEOUT);
 
         // Repeat with more iterations to make sure everything is cleared.
         for (int i = 0; i < 500; i++)
-            testTimeoutRemoval0(client, 2, TX_TIMEOUT_MIN);
+            testTimeoutRemoval0(client, 2, TX_MIN_TIMEOUT);
     }
 
     /**


[06/50] [abbrv] ignite git commit: Fixed update sequence.

Posted by sb...@apache.org.
Fixed update sequence.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/85fd8ce9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/85fd8ce9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/85fd8ce9

Branch: refs/heads/ignite-6181-1
Commit: 85fd8ce91f1e5827600aa32645552039e5a2298a
Parents: d31c43c
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Fri Aug 25 21:23:19 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Fri Aug 25 21:23:19 2017 +0300

----------------------------------------------------------------------
 .../distributed/dht/GridDhtPartitionTopologyImpl.java | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/85fd8ce9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index 87b3670..a881130 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -1910,6 +1910,14 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                 }
             }
 
+            long seqVal = 0;
+
+            if (updateSeq) {
+                seqVal = this.updateSeq.incrementAndGet();
+
+                node2part = new GridDhtPartitionFullMap(node2part, seqVal);
+            }
+
             for (Map.Entry<UUID, GridDhtPartitionMap> e : node2part.entrySet()) {
                 GridDhtPartitionMap partMap = e.getValue();
 
@@ -1925,16 +1933,14 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                         result.add(e.getKey());
                     }
 
-                    partMap.updateSequence(partMap.updateSequence() + 1, partMap.topologyVersion());
+                    if (updateSeq)
+                        partMap.updateSequence(seqVal, partMap.topologyVersion());
 
                     U.warn(log, "Partition has been scheduled for rebalancing due to outdated update counter " +
                         "[nodeId=" + e.getKey() + ", cacheOrGroupName=" + grp.cacheOrGroupName() +
                         ", partId=" + p + ", haveHistory=" + haveHistory + "]");
                 }
             }
-
-            if (updateSeq)
-                node2part = new GridDhtPartitionFullMap(node2part, this.updateSeq.incrementAndGet());
         }
         finally {
             lock.writeLock().unlock();


[05/50] [abbrv] ignite git commit: Increment GridDhtPartitionMap update sequence when assign new state on coordinator.

Posted by sb...@apache.org.
Increment GridDhtPartitionMap update sequence when assign new state on coordinator.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d31c43c1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d31c43c1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d31c43c1

Branch: refs/heads/ignite-6181-1
Commit: d31c43c1465ec33f9a1be81dedb958296ecc5068
Parents: 6f7011a
Author: sboikov <sb...@gridgain.com>
Authored: Fri Aug 25 17:50:01 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Aug 25 17:50:01 2017 +0300

----------------------------------------------------------------------
 .../dht/GridDhtPartitionTopologyImpl.java         | 18 ++++++++++++------
 .../IgnitePdsCacheRebalancingAbstractTest.java    |  2 ++
 2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d31c43c1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index f25ae21..87b3670 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -1186,7 +1186,9 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         lock.writeLock().lock();
 
         try {
-            if (stopping || !lastTopChangeVer.initialized())
+            if (stopping || !lastTopChangeVer.initialized() ||
+                // Ignore message not-related to exchange if exchange is in progress.
+                (exchangeVer == null && !lastTopChangeVer.equals(readyTopVer)))
                 return false;
 
             if (incomeCntrMap != null) {
@@ -1909,20 +1911,24 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
             }
 
             for (Map.Entry<UUID, GridDhtPartitionMap> e : node2part.entrySet()) {
-                if (!e.getValue().containsKey(p))
+                GridDhtPartitionMap partMap = e.getValue();
+
+                if (!partMap.containsKey(p))
                     continue;
 
-                if (e.getValue().get(p) == OWNING && !owners.contains(e.getKey())) {
+                if (partMap.get(p) == OWNING && !owners.contains(e.getKey())) {
                     if (haveHistory)
-                        e.getValue().put(p, MOVING);
+                        partMap.put(p, MOVING);
                     else {
-                        e.getValue().put(p, RENTING);
+                        partMap.put(p, RENTING);
 
                         result.add(e.getKey());
                     }
 
+                    partMap.updateSequence(partMap.updateSequence() + 1, partMap.topologyVersion());
+
                     U.warn(log, "Partition has been scheduled for rebalancing due to outdated update counter " +
-                        "[nodeId=" + ctx.localNodeId() + ", cacheOrGroupName=" + grp.cacheOrGroupName() +
+                        "[nodeId=" + e.getKey() + ", cacheOrGroupName=" + grp.cacheOrGroupName() +
                         ", partId=" + p + ", haveHistory=" + haveHistory + "]");
                 }
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d31c43c1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
index 91838fc..7b047f8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
@@ -512,6 +512,8 @@ public abstract class IgnitePdsCacheRebalancingAbstractTest extends GridCommonAb
         Integer val = 0;
 
         for (int i = 0; i < 5; i++) {
+            info("Iteration: " + i);
+
             Integer key = primaryKey(ignite(3).cache(cacheName));
 
             c.put(key, val);


[44/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/13100084
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/13100084
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/13100084

Branch: refs/heads/ignite-6181-1
Commit: 13100084823678d304c4ab392cb6283e876c8f49
Parents: 933b1d7
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Fri Sep 15 12:30:51 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Fri Sep 15 12:30:51 2017 +0300

----------------------------------------------------------------------
 .../cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/13100084/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
index cb1ab57..4420a4e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
@@ -36,4 +36,4 @@ public class IgniteTxConfigCacheForceTxTimeoutSelfTest extends IgniteTxConfigCac
 
         System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
     }
-}
+}
\ No newline at end of file


[35/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/225d4f52
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/225d4f52
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/225d4f52

Branch: refs/heads/ignite-6181-1
Commit: 225d4f52a777ac14d4a941f7eb9de505947962ff
Parents: 4c3df8f
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Tue Sep 12 20:11:32 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Tue Sep 12 20:11:32 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java     |  6 ++++--
 .../cache/transactions/IgniteTxLocalAdapter.java    |  3 +++
 .../cache/transactions/TxRollbackOnTimeoutTest.java | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/225d4f52/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index aa0c85b..2308d71 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -230,7 +230,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
-        if (this.timeout() > 0 && !implicit())
+        if (this.timeout() > 0 && !implicit() && !cctx.tm().deadlockDetectionEnabled())
             cctx.time().addTimeoutObject(this);
 
         initResult();
@@ -4014,7 +4014,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
      * Removes timeout handler used for eager rollbacks on timeouts.
      */
     private void removeTimeoutHandler() {
-        if (timeout() > 0 && !implicit() && !timedOut())
+        if (timeout() > 0 && !implicit() && !timedOut() && !cctx.tm().deadlockDetectionEnabled())
             cctx.time().removeTimeoutObject(this);
     }
 
@@ -4033,6 +4033,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (state(MARKED_ROLLBACK, true)) {
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
+                    log().error("Transaction is timed out and will be rolled back: " + GridNearTxLocal.this);
+
                     rollbackNearTxLocalAsync();
                 }
             });

http://git-wip-us.apache.org/repos/asf/ignite/blob/225d4f52/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 ea105ae..7f30981 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
@@ -1237,6 +1237,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter implements Ig
      * @throws IgniteCheckedException If transaction check failed.
      */
     protected void checkValid() throws IgniteCheckedException {
+        if (local() && !dht() && remainingTime() == -1 && cctx.tm().deadlockDetectionEnabled())
+            state(MARKED_ROLLBACK, true);
+
         if (isRollbackOnly()) {
             if (remainingTime() == -1)
                 throw new IgniteTxTimeoutCheckedException("Cache transaction timed out: " + this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/225d4f52/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 529fdc3..0a2601d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -22,6 +22,7 @@ import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
@@ -43,6 +44,7 @@ import org.jsr166.ThreadLocalRandom8;
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS;
 
 /**
  * Tests an ability to eagerly rollback timed out transactions.
@@ -95,6 +97,20 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
+    }
+
+    /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 


[27/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/12669b86
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/12669b86
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/12669b86

Branch: refs/heads/ignite-6181-1
Commit: 12669b86a0ea2e91ebff778ef9b1661b37ffc781
Parents: 8ab36ce
Author: ascherbakoff <al...@gmail.com>
Authored: Sat Sep 9 16:04:08 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Sat Sep 9 16:04:08 2017 +0300

----------------------------------------------------------------------
 .../IgniteDiagnosticPrepareContext.java         |  2 +-
 .../distributed/near/GridNearLockFuture.java    |  5 +-
 .../cache/distributed/near/GridNearTxLocal.java | 18 ++---
 .../transactions/IgniteTransactionsImpl.java    |  3 +-
 .../cache/transactions/IgniteTxManager.java     | 77 ++++++++------------
 5 files changed, 38 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/12669b86/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
index 378dc74..14783d5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteDiagnosticPrepareContext.java
@@ -75,7 +75,7 @@ public class IgniteDiagnosticPrepareContext {
      * @param keys Entry keys.
      * @param msg Initial message.
      */
-    public void  txKeyInfo(UUID nodeId, int cacheId, Collection<KeyCacheObject> keys, String msg) {
+    public void txKeyInfo(UUID nodeId, int cacheId, Collection<KeyCacheObject> keys, String msg) {
         closure(nodeId).add(msg, new TxEntriesInfoClosure(cacheId, keys));
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/12669b86/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
index bb71337..9cad49e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
@@ -770,10 +770,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
      * part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
      */
     void map() {
-        // Obtain the topology version to use.
-        long threadId = Thread.currentThread().getId();
-
-        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
+        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(Thread.currentThread().getId());
 
         // If there is another system transaction in progress, use it's topology version to prevent deadlock.
         if (topVer == null && tx != null && tx.system())

http://git-wip-us.apache.org/repos/asf/ignite/blob/12669b86/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 0c76aec..8d15e87 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -220,7 +220,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             plc,
             concurrency,
             isolation,
-            timeout == 0 ? 0 : Math.max(100, timeout),
+            timeout,
             false,
             storeEnabled,
             false,
@@ -230,7 +230,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
-        if (this.timeout > 0)
+        if (this.timeout() > 0 && !implicit())
             cctx.time().addTimeoutObject(this);
 
         initResult();
@@ -3151,7 +3151,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             // Prepare was called explicitly.
             return fut;
 
-        if (timeout() > 0)
+        if (timeout() > 0 && !implicit())
             cctx.time().removeTimeoutObject(this);
 
         mapExplicitLocks();
@@ -3266,7 +3266,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (log.isDebugEnabled())
             log.debug("Rolling back near tx: " + this);
 
-        if (remainingTime() > 0)
+        if (remainingTime() > 0 && !implicit())
             cctx.time().removeTimeoutObject(this);
 
         if (fastFinish()) {
@@ -3701,7 +3701,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
 
-        cctx.tm().onLocalClose(threadId(), this);
+        cctx.tm().onLocalClose();
 
         synchronized (this) {
             try {
@@ -4006,14 +4006,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     }
 
     /**
-     * @param threadId new owner of transaction.
-     * @throws IgniteCheckedException if method executed not in the middle of resume or suspend.
-     */
-    public void threadId(long threadId) {
-        this.threadId = threadId;
-    }
-
-    /**
      * Post-lock closure.
      *
      * @param <T> Return type.

http://git-wip-us.apache.org/repos/asf/ignite/blob/12669b86/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 9891484..df5c90e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -155,8 +155,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
         try {
             GridNearTxLocal tx = cctx.tm().userTx(sysCacheCtx);
 
-            // Allow to start new transaction if previous transaction was rolled back by timeout.
-            if (tx != null && !(tx.state() == TransactionState.ROLLED_BACK && tx.timedOut()))
+            if (tx != null)
                 throw new IllegalStateException("Failed to start new transaction " +
                     "(current thread already has a transaction): " + tx);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/12669b86/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 7ff36ac..d65832c 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
@@ -148,8 +148,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /** Topology version should be used when mapping internal tx. */
     private final ThreadLocal<AffinityTopologyVersion> txTop = new ThreadLocal<>();
 
-    /** Per-thread transaction map. */
-    private final ConcurrentMap<Long, IgniteInternalTx> threadMap = newMap();
+    /** User transaction. */
+    private final static ThreadLocal<IgniteInternalTx> userTx = new ThreadLocal<>();
 
     /** Per-thread system transaction map. */
     private final ConcurrentMap<TxThreadKey, IgniteInternalTx> sysThreadMap = newMap();
@@ -282,19 +282,17 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param cacheId Cache ID.
      */
     public void rollbackTransactionsForCache(int cacheId) {
-        rollbackTransactionsForCache(cacheId, nearIdMap);
+        rollbackTransactionsForCache(cacheId, nearIdMap.values());
 
-        rollbackTransactionsForCache(cacheId, threadMap);
+        rollbackTransactionsForCache(cacheId, Collections.singleton(userTx.get()));
     }
 
     /**
      * @param cacheId Cache ID.
      * @param txMap Transactions map.
      */
-    private void rollbackTransactionsForCache(int cacheId, ConcurrentMap<?, IgniteInternalTx> txMap) {
-        for (Map.Entry<?, IgniteInternalTx> e : txMap.entrySet()) {
-            IgniteInternalTx tx = e.getValue();
-
+    private void rollbackTransactionsForCache(int cacheId, Collection<IgniteInternalTx> txMap) {
+        for (IgniteInternalTx tx : txMap) {
             for (IgniteTxEntry entry : tx.allEntries()) {
                 if (entry.cacheId() == cacheId) {
                     rollbackTx(tx);
@@ -309,8 +307,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void onDisconnected(IgniteFuture reconnectFut) {
         txFinishSync.onDisconnected(reconnectFut);
 
-        for (Map.Entry<Long, IgniteInternalTx> e : threadMap.entrySet())
-            rollbackTx(e.getValue());
+        for (IgniteInternalTx tx : activeTransactions())
+            rollbackTx(tx);
 
         IgniteClientDisconnectedException err =
             new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.");
@@ -369,8 +367,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void printMemoryStats() {
         X.println(">>> ");
         X.println(">>> Transaction manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ']');
-        X.println(">>>   threadMapSize: " + threadMap.size());
-        X.println(">>>   idMap [size=" + idMap.size() + ']');
+        X.println(">>>   activeSize [size=" + activeTransactions().size() + ']');
         X.println(">>>   completedVersSortedSize: " + completedVersSorted.size());
         X.println(">>>   completedVersHashMapSize: " + completedVersHashMap.sizex());
     }
@@ -379,7 +376,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Thread map size.
      */
     public int threadMapSize() {
-        return threadMap.size();
+        return 0;
     }
 
     /**
@@ -488,7 +485,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // and overwrite local transaction.
             if (tx.local() && !tx.dht()) {
                 if (cacheCtx == null || !cacheCtx.systemTx())
-                    threadMap.put(tx.threadId(), tx);
+                    userTx.set(tx);
                 else
                     sysThreadMap.put(new TxThreadKey(tx.threadId(), cacheCtx.cacheId()), tx);
             }
@@ -665,7 +662,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Not null topology version if current thread holds lock preventing topology change.
      */
     @Nullable public AffinityTopologyVersion lockedTopologyVersion(long threadId, IgniteInternalTx ignore) {
-        IgniteInternalTx tx = threadMap.get(threadId);
+        IgniteInternalTx tx = userTx.get();
 
         if (tx != null) {
             AffinityTopologyVersion topVer = tx.topologyVersionSnapshot();
@@ -772,7 +769,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @SuppressWarnings({"unchecked"})
     private <T> T tx(GridCacheContext cctx, long threadId) {
         if (cctx == null || !cctx.systemTx())
-            return (T)threadMap.get(threadId);
+            return (T) userTx.get();
 
         TxThreadKey key = new TxThreadKey(threadId, cctx.cacheId());
 
@@ -1421,26 +1418,19 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param tx Transaction to clear.
      */
     private void clearThreadMap(IgniteInternalTx tx) {
-        if (tx.local() && !tx.dht()) {
-            if (!tx.system()) {
-                /** Timed out local transactions are cleared in {@link #onLocalClose}. */
-                if (!tx.timedOut() || !tx.pessimistic())
-                    threadMap.remove(tx.threadId(), tx);
-            }
-            else {
-                Integer cacheId = tx.txState().firstCacheId();
+        if (tx.local() && !tx.dht() && tx.system()) {
+            Integer cacheId = tx.txState().firstCacheId();
 
-                if (cacheId != null)
-                    sysThreadMap.remove(new TxThreadKey(tx.threadId(), cacheId), tx);
-                else {
-                    for (Iterator<IgniteInternalTx> it = sysThreadMap.values().iterator(); it.hasNext(); ) {
-                        IgniteInternalTx txx = it.next();
+            if (cacheId != null)
+                sysThreadMap.remove(new TxThreadKey(tx.threadId(), cacheId), tx);
+            else {
+                for (Iterator<IgniteInternalTx> it = sysThreadMap.values().iterator(); it.hasNext(); ) {
+                    IgniteInternalTx txx = it.next();
 
-                        if (tx == txx) {
-                            it.remove();
+                    if (tx == txx) {
+                        it.remove();
 
-                            break;
-                        }
+                        break;
                     }
                 }
             }
@@ -2279,7 +2269,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     public void resumeTx(GridNearTxLocal tx) throws IgniteCheckedException {
         assert tx != null && !tx.system() : tx;
-        assert !threadMap.containsValue(tx) : tx;
         assert !transactionMap(tx).containsValue(tx) : tx;
         assert !haveSystemTxForThread(Thread.currentThread().getId());
 
@@ -2288,15 +2277,13 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
         }
 
-        long threadId = Thread.currentThread().getId();
+        if (userTx.get() != null)
+            throw new IgniteCheckedException("Thread already has started transaction.");
 
-        if (threadMap.putIfAbsent(threadId, tx) != null)
-            throw new IgniteCheckedException("Thread already start a transaction.");
+        userTx.set(tx);
 
         if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
-            throw new IgniteCheckedException("Thread already start a transaction.");
-
-        tx.threadId(threadId);
+            throw new IgniteCheckedException("Thread already has started transaction.");
     }
 
     /**
@@ -2317,13 +2304,9 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         return false;
     }
 
-    /**
-     * Callback for closing local transaction.
-     * @param threadId Thread ID.
-     * @param tx Local transaction.
-     */
-    public void onLocalClose(long threadId, GridNearTxLocal tx) {
-        threadMap.remove(threadId, tx);
+    /** */
+    public void onLocalClose() {
+        userTx.set(null);
     }
 
     /**


[13/50] [abbrv] ignite git commit: Disable leading wildcard in query.

Posted by sb...@apache.org.
Disable leading wildcard in query.

(cherry picked from commit 75cc957)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5a6808f1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5a6808f1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5a6808f1

Branch: refs/heads/ignite-6181-1
Commit: 5a6808f13e1f55ae76afb8f6b201396f3340a351
Parents: 4907f7d
Author: Andrey V. Mashenkov <an...@gmail.com>
Authored: Mon Aug 28 12:31:15 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Mon Aug 28 20:30:16 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/processors/query/h2/opt/GridLuceneIndex.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5a6808f1/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
index 0776a54..c9d0159 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
@@ -272,7 +272,7 @@ public class GridLuceneIndex implements AutoCloseable {
             MultiFieldQueryParser parser = new MultiFieldQueryParser(idxdFields,
                 writer.getAnalyzer());
 
-            parser.setAllowLeadingWildcard(true);
+//            parser.setAllowLeadingWildcard(true);
 
             // Filter expired items.
             Query filter = NumericRangeQuery.newLongRange(EXPIRATION_TIME_FIELD_NAME, U.currentTimeMillis(),


[22/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d5f3a67d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d5f3a67d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d5f3a67d

Branch: refs/heads/ignite-6181-1
Commit: d5f3a67dc258dfb19279481c831377b97955b365
Parents: 94acdf5
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Thu Aug 31 15:25:00 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Thu Aug 31 15:25:00 2017 +0300

----------------------------------------------------------------------
 .../cache/transactions/IgniteTxHandler.java     |  8 +++---
 .../transactions/TxRollbackOnTimeoutTest.java   | 26 ++++++++++----------
 2 files changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d5f3a67d/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 de0e415..6f96b4b 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
@@ -673,8 +673,8 @@ public class IgniteTxHandler {
      * @param res Response.
      */
     private void processNearTxFinishResponse(UUID nodeId, GridNearTxFinishResponse res) {
-        if (txFinishMsgLog.isDebugEnabled())
-            txFinishMsgLog.debug("Received near finish response [txId=" + res.xid() + ", node=" + nodeId + ']');
+        //if (txFinishMsgLog.isDebugEnabled())
+            txFinishMsgLog.info("Received near finish response [txId=" + res.xid() + ", node=" + nodeId + ']');
 
         ctx.tm().onFinishedRemote(nodeId, res.threadId());
 
@@ -783,8 +783,8 @@ public class IgniteTxHandler {
         UUID nodeId,
         GridNearTxFinishRequest req
     ) {
-        if (txFinishMsgLog.isDebugEnabled())
-            txFinishMsgLog.debug("Received near finish request [txId=" + req.version() + ", node=" + nodeId + ']');
+        //if (txFinishMsgLog.isDebugEnabled())
+            txFinishMsgLog.info("Received near finish request [txId=" + req.version() + ", node=" + nodeId + ']');
 
         IgniteInternalFuture<IgniteInternalTx> fut = finish(nodeId, null, req);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d5f3a67d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 52f099d..9243f58 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -130,11 +130,11 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
      */
-//    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
-//        Ignite client = startGrid("client");
-//
-//        testWaitingTxUnblockedOnTimeout0(grid(0), client);
-//    }
+    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnTimeout0(grid(0), client);
+    }
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
@@ -171,11 +171,11 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
      */
-//    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
-//        Ignite client = startGrid("client");
-//
-//        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
-//    }
+    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
+    }
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
@@ -268,11 +268,11 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             }
         }, 2, "Second");
 
-        fut2.get(5, TimeUnit.SECONDS);
+        fut2.get();
 
         unblocked.countDown();
 
-        fut1.get(5, TimeUnit.SECONDS);
+        fut1.get();
     }
 
     /** */
@@ -315,6 +315,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             // No-op.
         }
 
-        fut2.get(5, TimeUnit.SECONDS);
+        fut2.get();
     }
 }
\ No newline at end of file


[12/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7f5d80de
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7f5d80de
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7f5d80de

Branch: refs/heads/ignite-6181-1
Commit: 7f5d80de8108257e8184b0654fe7034f6c7e2527
Parents: a01837b
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Mon Aug 28 19:51:09 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Mon Aug 28 19:51:09 2017 +0300

----------------------------------------------------------------------
 .../transactions/TxTimeoutHandlingTest.java     | 147 +++++++++++++++++++
 1 file changed, 147 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7f5d80de/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
new file mode 100644
index 0000000..2ac0f1a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.transactions;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+
+/**
+ * Tests ability to rollback not properly closed transaction.
+ */
+public class TxTimeoutHandlingTest extends GridCommonAbstractTest {
+    /** */
+    private static final long TX_TIMEOUT = 3_000L;
+
+    /** */
+    private static final String CACHE_NAME = "test";
+
+    /** IP finder. */
+    private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private final CountDownLatch l = new CountDownLatch(1);
+
+    /** */
+    private final Object mux = new Object();
+
+    /** */
+    private volatile boolean released;
+
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
+
+        TransactionConfiguration txCfg = new TransactionConfiguration();
+        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
+
+        cfg.setTransactionConfiguration(txCfg);
+
+        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** */
+    public void testTxTimeoutHandling() throws Exception {
+        try {
+            final Ignite ignite = startGrid(0);
+
+            IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+                @Override public void run() {
+                    // Start tx with default settings.
+                    try (Transaction tx = ignite.transactions().txStart()) {
+                        ignite.cache(CACHE_NAME).put(1, 1);
+
+                        l.countDown();
+
+                        // Wait longer than default timeout.
+                        synchronized (mux) {
+                            while (!released) {
+                                try {
+                                    mux.wait();
+                                }
+                                catch (InterruptedException e) {
+                                    throw new IgniteException(e);
+                                }
+                            }
+                        }
+
+                        try {
+                            tx.commit();
+
+                            fail();
+                        }
+                        catch (IgniteException e) {
+                            // Expect exception - tx is rolled back.
+                        }
+                    }
+                }
+            }, 1, "Locker");
+
+            IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+                @Override public void run() {
+                    U.awaitQuiet(l);
+
+                    // Try to acquire lock.
+                    // Acquisition will be successful then first transaction will be rolled back after timeout.
+                    try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
+                        TransactionIsolation.REPEATABLE_READ, 0, 1)) {
+                        ignite.cache(CACHE_NAME).put(1, 1);
+
+                        tx.commit();
+                    }
+                }
+            }, 1, "Waiter");
+
+            Thread.sleep(TX_TIMEOUT + 1_000);
+
+            fut2.get(1, TimeUnit.SECONDS);
+
+            startGrid(1);
+
+            released = true;
+
+            synchronized (mux) {
+                mux.notify();
+            }
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+}


[28/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3097d8d8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3097d8d8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3097d8d8

Branch: refs/heads/ignite-6181-1
Commit: 3097d8d81872a353970031ef115b4f18a67c19e2
Parents: 12669b8
Author: ascherbakoff <al...@gmail.com>
Authored: Sat Sep 9 17:23:36 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Sat Sep 9 17:23:36 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java |  6 ++--
 .../transactions/TxRollbackOnTimeoutTest.java   | 29 ++++++++++++++++----
 2 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3097d8d8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 8d15e87..fb4c5e1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -3266,9 +3266,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (log.isDebugEnabled())
             log.debug("Rolling back near tx: " + this);
 
-        if (remainingTime() > 0 && !implicit())
-            cctx.time().removeTimeoutObject(this);
-
         if (fastFinish()) {
             state(PREPARING);
             state(PREPARED);
@@ -3696,6 +3693,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public void close() throws IgniteCheckedException {
+        if (timeout() > 0 && !implicit())
+            cctx.time().removeTimeoutObject(this);
+
         TransactionState state = state();
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)

http://git-wip-us.apache.org/repos/asf/ignite/blob/3097d8d8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index d854cf0..3d25d10 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -30,11 +30,13 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
+import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionTimeoutException;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
@@ -209,10 +211,20 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         IgniteEx client = (IgniteEx)startGrid("client");
 
         for (int i = 0; i < 5; i++)
-            testTimeoutRemoval(grid(0), i);
+            testTimeoutRemoval0(grid(0), i, TX_TIMEOUT);
 
         for (int i = 0; i < 5; i++)
-            testTimeoutRemoval(client, i);
+            testTimeoutRemoval0(client, i, TX_TIMEOUT);
+
+        for (int i = 0; i < 5; i++)
+            testTimeoutRemoval0(grid(0), i, 1);
+
+        for (int i = 0; i < 5; i++)
+            testTimeoutRemoval0(client, i, 1);
+
+        // Repeat with more iterations to make sure everything is cleared.
+        for (int i = 0; i < 500; i++)
+            testTimeoutRemoval0(client, 2, 1);
     }
 
     /**
@@ -220,10 +232,10 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @param mode Test mode.
      * @throws Exception If failed.
      */
-    private void testTimeoutRemoval(IgniteEx near, int mode) throws Exception {
+    private void testTimeoutRemoval0(IgniteEx near, int mode, long timeout) throws Exception {
         GridTimeoutProcessor timeProc = near.context().cache().context().time();
 
-        try (Transaction tx = near.transactions().txStart()) {
+        try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, timeout, 1)) {
             near.cache(CACHE_NAME).put(1, 1);
 
             switch (mode) {
@@ -250,11 +262,18 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     fail();
             }
         }
+        catch (TransactionTimeoutException e) {
+            // No-op.
+        }
+        catch (CacheException e) {
+            assertTrue("Only timeout exception is possible", X.hasCause(e, TransactionTimeoutException.class));
+        }
 
         GridConcurrentSkipListSet set = U.field(timeProc, "timeoutObjs");
 
         for (Object obj : set)
-            assertFalse("Not remove for mode: " + mode, obj.getClass().isAssignableFrom(GridNearTxLocal.class));
+            assertFalse("Not remove for mode=" + mode + " and timeout=" + timeout,
+                    obj.getClass().isAssignableFrom(GridNearTxLocal.class));
     }
 
     /**


[42/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7d05fb10
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7d05fb10
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7d05fb10

Branch: refs/heads/ignite-6181-1
Commit: 7d05fb101fd19ddd89a2356d79f35deea3fcf4f0
Parents: 6353158
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Fri Sep 15 11:49:18 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Fri Sep 15 11:49:18 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/IgniteOptimisticTxSuspendResumeTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7d05fb10/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
index d16aebd..deb58bc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
@@ -438,7 +438,7 @@ public class IgniteOptimisticTxSuspendResumeTest extends GridCommonAbstractTest
                         }
                     }, TransactionTimeoutException.class);
 
-                    assertEquals(MARKED_ROLLBACK, tx.state());
+                    assertEquals(ROLLED_BACK, tx.state());
 
                     tx.close();
                 }
@@ -469,7 +469,7 @@ public class IgniteOptimisticTxSuspendResumeTest extends GridCommonAbstractTest
                         }
                     }, TransactionTimeoutException.class);
 
-                    assertEquals(MARKED_ROLLBACK, tx.state());
+                    assertEquals(ROLLED_BACK, tx.state());
 
                     tx.close();
 


[34/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4c3df8f7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4c3df8f7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4c3df8f7

Branch: refs/heads/ignite-6181-1
Commit: 4c3df8f78b47dcfbed15778a87e173d8bace27b0
Parents: 6ee98d1
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Tue Sep 12 16:31:32 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Tue Sep 12 16:31:32 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/IgniteTransactions.java   |  3 +-
 .../configuration/TransactionConfiguration.java |  6 +++
 .../processors/cache/GridCacheProcessor.java    |  2 +-
 .../cache/distributed/near/GridNearTxLocal.java |  5 +-
 .../transactions/IgniteTransactionsImpl.java    |  3 +-
 .../transactions/IgniteTxLocalAdapter.java      |  3 --
 .../cache/transactions/IgniteTxManager.java     | 49 +++++++++++---------
 .../transactions/TxRollbackOnTimeoutTest.java   | 13 ++++--
 8 files changed, 49 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java b/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
index dfe6a1a..9da862d 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
@@ -77,7 +77,8 @@ public interface IgniteTransactions {
      *
      * @param concurrency Concurrency.
      * @param isolation Isolation.
-     * @param timeout Timeout.
+     * @param timeout Timeout. See {@link TransactionConfiguration#setDefaultTxTimeout(long)}
+     * for additional info on transaction timeouts.
      * @param txSize Number of entries participating in transaction (may be approximate).
      * @return New transaction.
      * @throws IllegalStateException If transaction is already started by this thread.

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
index 0063afc..cbd2d82 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.ignite.configuration;
 
 import java.io.Serializable;
 import javax.cache.configuration.Factory;
+import org.apache.ignite.IgniteTransactions;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
@@ -181,6 +182,11 @@ public class TransactionConfiguration implements Serializable {
     /**
      * Sets default transaction timeout in milliseconds. By default this value is defined by {@link
      * #DFLT_TRANSACTION_TIMEOUT}.
+     * <p>
+     * If transaction's execution is not completed by calling {@link Transaction#commit()},
+     * {@link Transaction#rollback()} or {@link Transaction#close()}
+     * before timeout expires, it will be rolled back asynchronously. All further caches operations will fail until new
+     * explicit transaction is started in current thread by calling {@link IgniteTransactions#txStart()}.
      *
      * @param dfltTxTimeout Default transaction timeout.
      * @return {@code this} for chaining.

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 1efb500..bd950fa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -3654,7 +3654,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @throws IgniteException If transaction exist.
      */
     private void checkEmptyTransactions() throws IgniteException {
-        if (transactions().tx() != null)
+        if (transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
             throw new IgniteException("Cannot start/stop cache within lock or transaction.");
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 289096d..aa0c85b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -3694,13 +3694,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public void close() throws IgniteCheckedException {
-        // If tx was rolled back asynchronously by timeout, user tx will not be cleared.
-        cctx.tm().resetUserTx();
-
         TransactionState state = state();
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
+        else
+            cctx.tm().onLocalClose(this);
 
         synchronized (this) {
             try {

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 12f655a..997fd8c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -154,7 +154,8 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
         try {
             GridNearTxLocal tx = cctx.tm().userTx(sysCacheCtx);
 
-            if (tx != null)
+            // Allow to override timed out transactions.
+            if (tx != null && !tx.timedOut())
                 throw new IllegalStateException("Failed to start new transaction " +
                     "(current thread already has a transaction): " + tx);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/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 e7ebaae..ea105ae 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
@@ -1237,9 +1237,6 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter implements Ig
      * @throws IgniteCheckedException If transaction check failed.
      */
     protected void checkValid() throws IgniteCheckedException {
-        if (local() && !dht() && remainingTime() == -1)
-            state(MARKED_ROLLBACK, true);
-
         if (isRollbackOnly()) {
             if (remainingTime() == -1)
                 throw new IgniteTxTimeoutCheckedException("Cache transaction timed out: " + this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/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 fb04c2b..2214e10 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
@@ -148,8 +148,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /** Topology version should be used when mapping internal tx. */
     private final ThreadLocal<AffinityTopologyVersion> txTop = new ThreadLocal<>();
 
-    /** User transaction. */
-    private final static ThreadLocal<IgniteInternalTx> userTx = new ThreadLocal<>();
+    /** Per-thread transaction map. */
+    private final ConcurrentMap<Long, IgniteInternalTx> threadMap = newMap();
 
     /** Per-thread system transaction map. */
     private final ConcurrentMap<TxThreadKey, IgniteInternalTx> sysThreadMap = newMap();
@@ -282,15 +282,19 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param cacheId Cache ID.
      */
     public void rollbackTransactionsForCache(int cacheId) {
-        rollbackTransactionsForCache(cacheId, activeTransactions());
+        rollbackTransactionsForCache(cacheId, nearIdMap);
+
+        rollbackTransactionsForCache(cacheId, threadMap);
     }
 
     /**
      * @param cacheId Cache ID.
      * @param txMap Transactions map.
      */
-    private void rollbackTransactionsForCache(int cacheId, Collection<IgniteInternalTx> txMap) {
-        for (IgniteInternalTx tx : txMap) {
+    private void rollbackTransactionsForCache(int cacheId, ConcurrentMap<?, IgniteInternalTx> txMap) {
+        for (Map.Entry<?, IgniteInternalTx> e : txMap.entrySet()) {
+            IgniteInternalTx tx = e.getValue();
+
             for (IgniteTxEntry entry : tx.allEntries()) {
                 if (entry.cacheId() == cacheId) {
                     rollbackTx(tx);
@@ -305,8 +309,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void onDisconnected(IgniteFuture reconnectFut) {
         txFinishSync.onDisconnected(reconnectFut);
 
-        for (IgniteInternalTx tx : activeTransactions())
-            rollbackTx(tx);
+        for (Map.Entry<Long, IgniteInternalTx> e : threadMap.entrySet())
+            rollbackTx(e.getValue());
 
         IgniteClientDisconnectedException err =
             new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.");
@@ -365,7 +369,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void printMemoryStats() {
         X.println(">>> ");
         X.println(">>> Transaction manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ']');
-        X.println(">>>   activeSize [size=" + activeTransactions().size() + ']');
+        X.println(">>>   threadMapSize: " + threadMap.size());
+        X.println(">>>   idMap [size=" + idMap.size() + ']');
         X.println(">>>   completedVersSortedSize: " + completedVersSorted.size());
         X.println(">>>   completedVersHashMapSize: " + completedVersHashMap.sizex());
     }
@@ -374,7 +379,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Thread map size.
      */
     public int threadMapSize() {
-        return 0;
+        return threadMap.size();
     }
 
     /**
@@ -483,7 +488,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // and overwrite local transaction.
             if (tx.local() && !tx.dht()) {
                 if (cacheCtx == null || !cacheCtx.systemTx())
-                    userTx.set(tx);
+                    threadMap.put(tx.threadId(), tx);
                 else
                     sysThreadMap.put(new TxThreadKey(tx.threadId(), cacheCtx.cacheId()), tx);
             }
@@ -660,7 +665,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Not null topology version if current thread holds lock preventing topology change.
      */
     @Nullable public AffinityTopologyVersion lockedTopologyVersion(long threadId, IgniteInternalTx ignore) {
-        IgniteInternalTx tx = userTx.get();
+        IgniteInternalTx tx = threadMap.get(threadId);
 
         if (tx != null) {
             AffinityTopologyVersion topVer = tx.topologyVersionSnapshot();
@@ -767,7 +772,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @SuppressWarnings({"unchecked"})
     private <T> T tx(GridCacheContext cctx, long threadId) {
         if (cctx == null || !cctx.systemTx())
-            return (T) userTx.get();
+            return (T)threadMap.get(threadId);
 
         TxThreadKey key = new TxThreadKey(threadId, cctx.cacheId());
 
@@ -1417,8 +1422,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
-            if (!tx.system())
-                userTx.set(null);
+            if (!tx.system() && !tx.timedOut())
+                threadMap.remove(tx.threadId(), tx);
             else {
                 Integer cacheId = tx.txState().firstCacheId();
 
@@ -1706,10 +1711,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Reset user tx.
+     * Remove tx from map.
      */
-    public void resetUserTx() {
-        userTx.set(null);
+    public void onLocalClose(IgniteInternalTx tx) {
+        threadMap.remove(tx.threadId(), tx);
     }
 
     /**
@@ -2286,13 +2291,15 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                     + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
         }
 
-        if (userTx.get() != null)
-            throw new IgniteCheckedException("The thread already has active transaction.");
+        long threadId = Thread.currentThread().getId();
 
-        userTx.set(tx);
+        if (threadMap.putIfAbsent(threadId, tx) != null)
+            throw new IgniteCheckedException("Thread already has started a transaction.");
 
         if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
-            throw new IgniteCheckedException("The thread already has active transaction.");
+            throw new IgniteCheckedException("Thread already has started a transaction.");
+
+        tx.threadId(threadId);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c3df8f7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 01829ce..529fdc3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -38,6 +38,7 @@ import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
 import org.apache.ignite.transactions.TransactionTimeoutException;
+import org.jsr166.ThreadLocalRandom8;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
@@ -217,21 +218,23 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     public void testTimeoutRemoval() throws Exception {
         IgniteEx client = (IgniteEx)startGrid("client");
 
-        for (int i = 0; i < 5; i++)
+        int modesCnt = 5;
+
+        for (int i = 0; i < modesCnt; i++)
             testTimeoutRemoval0(grid(0), i, TX_TIMEOUT);
 
-        for (int i = 0; i < 5; i++)
+        for (int i = 0; i < modesCnt; i++)
             testTimeoutRemoval0(client, i, TX_TIMEOUT);
 
-        for (int i = 0; i < 5; i++)
+        for (int i = 0; i < modesCnt; i++)
             testTimeoutRemoval0(grid(0), i, TX_MIN_TIMEOUT);
 
-        for (int i = 0; i < 5; i++)
+        for (int i = 0; i < modesCnt; i++)
             testTimeoutRemoval0(client, i, TX_MIN_TIMEOUT);
 
         // Repeat with more iterations to make sure everything is cleared.
         for (int i = 0; i < 500; i++)
-            testTimeoutRemoval0(client, 2, TX_MIN_TIMEOUT);
+            testTimeoutRemoval0(client, ThreadLocalRandom8.current().nextInt(modesCnt), TX_MIN_TIMEOUT);
     }
 
     /**


[43/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/933b1d74
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/933b1d74
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/933b1d74

Branch: refs/heads/ignite-6181-1
Commit: 933b1d7444b8223ab66d0e54a0c1847d83f25359
Parents: 7d05fb1
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Fri Sep 15 12:30:43 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Fri Sep 15 12:30:43 2017 +0300

----------------------------------------------------------------------
 .../cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java         | 4 ----
 1 file changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/933b1d74/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
index 34a1dc5..cb1ab57 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
@@ -36,8 +36,4 @@ public class IgniteTxConfigCacheForceTxTimeoutSelfTest extends IgniteTxConfigCac
 
         System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
     }
-
-    @Override public void testUserTxTimeout() throws Exception {
-        super.testUserTxTimeout();
-    }
 }


[29/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/02f94ae9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/02f94ae9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/02f94ae9

Branch: refs/heads/ignite-6181-1
Commit: 02f94ae941d2985afec1cf8eb26f96048a207707
Parents: 3097d8d
Author: ascherbakoff <al...@gmail.com>
Authored: Sun Sep 10 13:12:47 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Sun Sep 10 13:12:47 2017 +0300

----------------------------------------------------------------------
 .../transactions/TxRollbackOnTimeoutTest.java   | 60 +++++++++++++++++---
 1 file changed, 52 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/02f94ae9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 3d25d10..cdbceda 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -18,17 +18,18 @@
 package org.apache.ignite.internal.processors.cache.transactions;
 
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.locks.LockSupport;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
-import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -36,6 +37,8 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
 import org.apache.ignite.transactions.TransactionTimeoutException;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -47,7 +50,10 @@ import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_REA
  */
 public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /** */
-    private static final long TX_TIMEOUT = 3_000L;
+    private static final long TX_TIMEOUT_MIN = 1;
+
+    /** */
+    private static final long TX_TIMEOUT = 300;
 
     /** */
     private static final String CACHE_NAME = "test";
@@ -217,24 +223,62 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             testTimeoutRemoval0(client, i, TX_TIMEOUT);
 
         for (int i = 0; i < 5; i++)
-            testTimeoutRemoval0(grid(0), i, 1);
+            testTimeoutRemoval0(grid(0), i, TX_TIMEOUT_MIN);
 
         for (int i = 0; i < 5; i++)
-            testTimeoutRemoval0(client, i, 1);
+            testTimeoutRemoval0(client, i, TX_TIMEOUT_MIN);
 
         // Repeat with more iterations to make sure everything is cleared.
         for (int i = 0; i < 500; i++)
-            testTimeoutRemoval0(client, 2, 1);
+            testTimeoutRemoval0(client, 2, TX_TIMEOUT_MIN);
+    }
+
+    /**
+     * Tests timeouts in all tx configurations.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimple() throws Exception {
+        for (TransactionConcurrency concurrency : TransactionConcurrency.values())
+            for (TransactionIsolation isolation : TransactionIsolation.values())
+                testSimple0(concurrency, isolation);
+    }
+
+    /**
+     * @param concurrency Concurrency.
+     * @param isolation Isolation.
+     *
+     * @throws Exception If failed.
+     */
+    private void testSimple0(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
+        Ignite near = grid(0);
+
+        final int key = 1, val = 1;
+
+        try (Transaction tx = near.transactions().txStart(concurrency, isolation, TX_TIMEOUT, 1)) {
+            near.cache(CACHE_NAME).put(key, val);
+
+            U.sleep(TX_TIMEOUT * 3);
+
+            try {
+                tx.commit();
+
+                fail("Tx must timeout");
+            } catch (IgniteException e) {
+                assertTrue("Expected timeout exception", X.hasCause(e, TransactionTimeoutException.class));
+            }
+        }
+
+        assertFalse("Must be removed by rollback on timeout", near.cache(CACHE_NAME).containsKey(key));
     }
 
     /**
      * @param near Node.
      * @param mode Test mode.
+     *
      * @throws Exception If failed.
      */
     private void testTimeoutRemoval0(IgniteEx near, int mode, long timeout) throws Exception {
-        GridTimeoutProcessor timeProc = near.context().cache().context().time();
-
         try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, timeout, 1)) {
             near.cache(CACHE_NAME).put(1, 1);
 
@@ -269,7 +313,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             assertTrue("Only timeout exception is possible", X.hasCause(e, TransactionTimeoutException.class));
         }
 
-        GridConcurrentSkipListSet set = U.field(timeProc, "timeoutObjs");
+        GridConcurrentSkipListSet set = U.field(near.context().cache().context().time(), "timeoutObjs");
 
         for (Object obj : set)
             assertFalse("Not remove for mode=" + mode + " and timeout=" + timeout,


[14/50] [abbrv] ignite git commit: gg-12688 : Fixed updateSequence in ClientTopology.

Posted by sb...@apache.org.
gg-12688 : Fixed updateSequence in ClientTopology.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ac7f2129
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ac7f2129
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ac7f2129

Branch: refs/heads/ignite-6181-1
Commit: ac7f21298f8fd49c2a42034fb955d3c78089ed70
Parents: 5a6808f
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Mon Aug 28 20:31:18 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Mon Aug 28 20:31:18 2017 +0300

----------------------------------------------------------------------
 .../dht/GridClientPartitionTopology.java        | 18 +++++---
 .../GridDhtPartitionsExchangeFuture.java        | 15 +++++--
 .../IgnitePdsCacheRebalancingAbstractTest.java  | 44 +++++++++++++++++++-
 3 files changed, 66 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ac7f2129/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
index c8856fd..299394f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
@@ -1092,20 +1092,26 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
 
         try {
             for (Map.Entry<UUID, GridDhtPartitionMap> e : node2part.entrySet()) {
-                if (!e.getValue().containsKey(p))
+                GridDhtPartitionMap partMap = e.getValue();
+
+                if (!partMap.containsKey(p))
                     continue;
 
-                if (e.getValue().get(p) == OWNING && !owners.contains(e.getKey())) {
+                if (partMap.get(p) == OWNING && !owners.contains(e.getKey())) {
                     if (haveHistory)
-                        e.getValue().put(p, MOVING);
+                        partMap.put(p, MOVING);
                     else {
-                        e.getValue().put(p, RENTING);
+                        partMap.put(p, RENTING);
 
                         result.add(e.getKey());
                     }
+
+                    partMap.updateSequence(partMap.updateSequence() + 1, partMap.topologyVersion());
+
+                    U.warn(log, "Partition has been scheduled for rebalancing due to outdated update counter " +
+                        "[nodeId=" + e.getKey() + ", groupId=" + grpId +
+                        ", partId=" + p + ", haveHistory=" + haveHistory + "]");
                 }
-                else if (owners.contains(e.getKey()))
-                    e.getValue().put(p, OWNING);
             }
 
             part2node.put(p, owners);

http://git-wip-us.apache.org/repos/asf/ignite/blob/ac7f2129/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index 299284d..240b5f0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -2437,11 +2437,20 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
      */
     private void assignPartitionsStates() {
         if (cctx.database().persistenceEnabled()) {
-            for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
-                if (grp.isLocal())
+            for (Map.Entry<Integer, CacheGroupDescriptor> e : cctx.affinity().cacheGroups().entrySet()) {
+                if (e.getValue().config().getCacheMode() == CacheMode.LOCAL)
                     continue;
 
-                assignPartitionStates(grp.topology());
+                GridDhtPartitionTopology top;
+
+                CacheGroupContext grpCtx = cctx.cache().cacheGroup(e.getKey());
+
+                if (grpCtx != null)
+                    top = grpCtx.topology();
+                else
+                    top = cctx.exchange().clientTopology(e.getKey());
+
+                assignPartitionStates(top);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ac7f2129/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
index 7b047f8..2d237cb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheRebalancingAbstractTest.java
@@ -35,6 +35,7 @@ import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cache.PartitionLossPolicy;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.MemoryConfiguration;
@@ -46,6 +47,7 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -96,7 +98,19 @@ public abstract class IgnitePdsCacheRebalancingAbstractTest extends GridCommonAb
 
         ccfg2.setQueryEntities(Collections.singleton(qryEntity));
 
-        cfg.setCacheConfiguration(ccfg1, ccfg2);
+        // Do not start filtered cache on coordinator.
+        if (gridName.endsWith("0")) {
+            cfg.setCacheConfiguration(ccfg1, ccfg2);
+        }
+        else {
+            CacheConfiguration ccfg3 = cacheConfiguration("filtered");
+            ccfg3.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE);
+            ccfg3.setBackups(1);
+            ccfg3.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+            ccfg3.setNodeFilter(new CoordinatorNodeFilter());
+
+            cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg3);
+        }
 
         MemoryConfiguration memCfg = new MemoryConfiguration();
 
@@ -501,7 +515,23 @@ public abstract class IgnitePdsCacheRebalancingAbstractTest extends GridCommonAb
      * @throws Exception If failed.
      */
     public void testForceRebalance() throws Exception {
-        final Ignite ig = startGrids(4);
+        testForceRebalance(cacheName);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testForceRebalanceClientTopology() throws Exception {
+        testForceRebalance("filtered");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testForceRebalance(String cacheName) throws Exception {
+        startGrids(4);
+
+        final Ignite ig = grid(1);
 
         ig.active(true);
 
@@ -653,4 +683,14 @@ public abstract class IgnitePdsCacheRebalancingAbstractTest extends GridCommonAb
                 '}';
         }
     }
+
+    /**
+     *
+     */
+    private static class CoordinatorNodeFilter implements IgnitePredicate<ClusterNode> {
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode node) {
+            return node.order() > 1;
+        }
+    }
 }


[41/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/63531589
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/63531589
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/63531589

Branch: refs/heads/ignite-6181-1
Commit: 635315892b995dbe59462a55914c26735125e1da
Parents: ab4316a
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Thu Sep 14 18:38:42 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Thu Sep 14 18:38:42 2017 +0300

----------------------------------------------------------------------
 .../internal/processors/cache/transactions/IgniteTxManager.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/63531589/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 fd4f1b2..827f2f6 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
@@ -1422,7 +1422,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
-            if (!tx.system()) {
+            if (tx.system()) {
                 Integer cacheId = tx.txState().firstCacheId();
 
                 if (cacheId != null)


[49/50] [abbrv] ignite git commit: ignite-6181-1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 2d6264c..caa1545 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -25,7 +25,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
@@ -57,9 +56,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     private static final long TX_MIN_TIMEOUT = 1;
 
     /** */
-    private static final long TX_TIMEOUT = 500;
-
-    /** */
     private static final String CACHE_NAME = "test";
 
     /** IP finder. */
@@ -68,12 +64,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /** */
     private static final int GRID_CNT = 3;
 
-    /** */
-    private final CountDownLatch blocked = new CountDownLatch(1);
-
-    /** */
-    private final CountDownLatch unblocked = new CountDownLatch(1);
-
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
@@ -82,12 +72,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
-        TransactionConfiguration txCfg = new TransactionConfiguration();
-        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
-
-        cfg.setTransactionConfiguration(txCfg);
-
         CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+
         ccfg.setAtomicityMode(TRANSACTIONAL);
         ccfg.setBackups(2);
 
@@ -113,7 +99,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /**
      * @param e Exception.
      */
-    protected void validateException(Exception e) {
+    protected void validateDeadlockException(Exception e) {
         assertEquals("Deadlock report is expected",
             TransactionDeadlockException.class, e.getCause().getCause().getClass());
     }
@@ -191,50 +177,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      *
      * @throws Exception If failed.
      */
-    public void testWaitingTxUnblockedOnTimeout1() throws Exception {
-        testWaitingTxUnblockedOnTimeout0(grid(0), grid(0));
-    }
+    public void testWaitingTxUnblockedOnTimeout() throws Exception {
+        waitingTxUnblockedOnTimeout(grid(0), grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout2() throws Exception {
-        testWaitingTxUnblockedOnTimeout0(grid(0), grid(1));
-    }
+        waitingTxUnblockedOnTimeout(grid(0), grid(1));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
         Ignite client = startGrid("client");
 
-        testWaitingTxUnblockedOnTimeout0(grid(0), client);
-    }
+        waitingTxUnblockedOnTimeout(grid(0), client);
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout4() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnTimeout(grid(1), client);
 
-        testWaitingTxUnblockedOnTimeout0(client, grid(0));
-    }
+        waitingTxUnblockedOnTimeout(client, grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout5() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnTimeout(client, grid(1));
 
-        testWaitingTxUnblockedOnTimeout0(client, client);
+        waitingTxUnblockedOnTimeout(client, client);
     }
 
     /**
@@ -242,50 +200,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      *
      * @throws Exception If failed.
      */
-    public void testWaitingTxUnblockedOnTimeout6() throws Exception {
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(0));
-    }
+    public void testWaitingTxUnblockedOnThreadDeath() throws Exception {
+        waitingTxUnblockedOnThreadDeath(grid(0), grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout7() throws Exception {
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(1));
-    }
+        waitingTxUnblockedOnThreadDeath(grid(0), grid(1));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
         Ignite client = startGrid("client");
 
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
-    }
+        waitingTxUnblockedOnThreadDeath(grid(0), client);
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout9() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnThreadDeath(grid(1), client);
 
-        testWaitingTxUnblockedOnThreadDeath0(client, grid(0));
-    }
+        waitingTxUnblockedOnThreadDeath(client, grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout10() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnThreadDeath(client, grid(1));
 
-        testWaitingTxUnblockedOnThreadDeath0(client, client);
+        waitingTxUnblockedOnThreadDeath(client, client);
     }
 
     /**
@@ -293,28 +223,16 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      *
      * @throws Exception If failed.
      */
-    public void testDeadlockUnblockedOnTimeout1() throws Exception {
-        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(1));
-    }
+    public void testDeadlockUnblockedOnTimeout() throws Exception {
+        deadlockUnblockedOnTimeout(ignite(0), ignite(1));
 
-    /**
-     * Tests if deadlock is resolved on timeout with correct message.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDeadlockUnblockedOnTimeout2() throws Exception {
-        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(0));
-    }
+        deadlockUnblockedOnTimeout(ignite(0), ignite(0));
 
-    /**
-     * Tests if deadlock is resolved on timeout with correct message.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDeadlockUnblockedOnTimeout3() throws Exception {
         Ignite client = startGrid("client");
 
-        testDeadlockUnblockedOnTimeout0(ignite(0), client);
+        deadlockUnblockedOnTimeout(ignite(0), client);
+
+        deadlockUnblockedOnTimeout(client, ignite(0));
     }
 
     /**
@@ -324,19 +242,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @param node2 Second node.
      * @throws Exception If failed.
      */
-    private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2) throws Exception {
+    private void deadlockUnblockedOnTimeout(final Ignite node1, final Ignite node2) throws Exception {
+        info("Start test [node1=" + node1.name() + ", node2=" + node2.name() + ']');
+
         final CountDownLatch l = new CountDownLatch(2);
 
-        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+        IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
                 try {
-                    try (Transaction tx = node1.transactions().txStart()) {
-                        node1.cache(CACHE_NAME).put(1, 1);
+                    try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 5000, 2)) {
+                        node1.cache(CACHE_NAME).put(1, 10);
 
                         l.countDown();
+
                         U.awaitQuiet(l);
 
-                        node1.cache(CACHE_NAME).put(2, 2);
+                        node1.cache(CACHE_NAME).put(2, 20);
 
                         tx.commit();
 
@@ -345,17 +266,18 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                 }
                 catch (CacheException e) {
                     // No-op.
-                    validateException(e);
+                    validateDeadlockException(e);
                 }
             }
-        }, 1, "First");
+        }, "First");
 
-        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+        IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
                 try (Transaction tx = node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) {
                     node2.cache(CACHE_NAME).put(2, 2);
 
                     l.countDown();
+
                     U.awaitQuiet(l);
 
                     node2.cache(CACHE_NAME).put(1, 1);
@@ -363,13 +285,13 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     tx.commit();
                 }
             }
-        }, 1, "Second");
+        }, "Second");
 
         fut1.get();
         fut2.get();
 
-        assertTrue("Expecting commited key 2", node1.cache(CACHE_NAME).containsKey(2));
-        assertTrue("Expecting commited key 1", node1.cache(CACHE_NAME).containsKey(1));
+        assertTrue("Expecting committed key 2", node1.cache(CACHE_NAME).containsKey(2));
+        assertTrue("Expecting committed key 1", node1.cache(CACHE_NAME).containsKey(1));
     }
 
     /**
@@ -380,6 +302,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     public void testTimeoutRemoval() throws Exception {
         IgniteEx client = (IgniteEx)startGrid("client");
 
+        final long TX_TIMEOUT = 250;
+
         int modesCnt = 5;
 
         for (int i = 0; i < modesCnt; i++)
@@ -421,6 +345,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         final int key = 1, val = 1;
 
+        final long TX_TIMEOUT = 250;
+
         try (Transaction tx = near.transactions().txStart(concurrency, isolation, TX_TIMEOUT, 1)) {
             near.cache(CACHE_NAME).put(key, val);
 
@@ -496,16 +422,30 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @param other Node starting second tx.
      * @throws Exception If failed.
      */
-    private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final Ignite other) throws Exception {
-        final int recordsCnt = 100;
+    private void waitingTxUnblockedOnTimeout(final Ignite near, final Ignite other) throws Exception {
+        info("Start test [node1=" + near.name() + ", node2=" + other.name() + ']');
 
-        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+        final CountDownLatch blocked = new CountDownLatch(1);
+
+        final CountDownLatch unblocked = new CountDownLatch(1);
+
+        final int recordsCnt = 5;
+
+        IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
-                try (Transaction tx = near.transactions().txStart()) {
-                    for (int i = 0; i < recordsCnt; i++)
-                        near.cache(CACHE_NAME).put(i, i);
+                try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 1000, 0)) {
+                    try {
+                        for (int i = 0; i < recordsCnt; i++)
+                            near.cache(CACHE_NAME).put(i, i);
 
-                    blocked.countDown();
+                        info("Locked all keys.");
+                    }
+                    catch (CacheException e) {
+                        info("Failed to lock keys: " + e);
+                    }
+                    finally {
+                        blocked.countDown();
+                    }
 
                     // Will be unblocked after tx timeout occurs.
                     U.awaitQuiet(unblocked);
@@ -530,16 +470,16 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                 }
 
                 // Check thread is able to start new tx.
-                try (Transaction tx = near.transactions().txStart()) {
+                try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 60_000, 0)) {
                     for (int i = 0; i < recordsCnt; i++)
                         near.cache(CACHE_NAME).put(i, i);
 
                     tx.commit();
                 }
             }
-        }, 1, "First");
+        }, "First");
 
-        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+        IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
                 U.awaitQuiet(blocked);
 
@@ -551,7 +491,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     tx.commit();
                 }
             }
-        }, 1, "Second");
+        }, "Second");
 
         fut2.get();
 
@@ -565,17 +505,45 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @param other Node starting second tx.
      * @throws Exception If failed.
      */
-    private void testWaitingTxUnblockedOnThreadDeath0(final Ignite near, final Ignite other) throws Exception {
-        final int recordsCnt = 100;
+    private void waitingTxUnblockedOnThreadDeath(final Ignite near, final Ignite other) throws Exception {
+        waitingTxUnblockedOnThreadDeath0(near, other, 10, 1000); // Try provoke timeout after all keys are locked.
+
+        waitingTxUnblockedOnThreadDeath0(near, other, 1000, 100);  // Try provoke timeout while trying to lock keys.
+    }
+
+    /**
+     * @param near Node starting tx which is timed out.
+     * @param other Node starting second tx.
+     * @param recordsCnt Number of records to locks.
+     * @param timeout Transaction timeout.
+     * @throws Exception If failed.
+     */
+    private void waitingTxUnblockedOnThreadDeath0(final Ignite near,
+        final Ignite other,
+        final int recordsCnt,
+        final long timeout)
+        throws Exception
+    {
+        info("Start test [node1=" + near.name() + ", node2=" + other.name() + ']');
+
+        final CountDownLatch blocked = new CountDownLatch(1);
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {
-                near.transactions().txStart();
+                near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, timeout, recordsCnt);
 
-                for (int i = 0; i < recordsCnt; i++)
-                    near.cache(CACHE_NAME).put(i, i);
+                try {
+                    for (int i = 0; i < recordsCnt; i++)
+                        near.cache(CACHE_NAME).put(i, i);
 
-                blocked.countDown();
+                    log.info("Locked all records.");
+                }
+                catch (Exception e) {
+                    log.info("Failed to locked all records: " + e);
+                }
+                finally {
+                    blocked.countDown();
+                }
 
                 throw new IgniteException("Failure");
             }
@@ -585,7 +553,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             @Override public void run() {
                 U.awaitQuiet(blocked);
 
-                try (Transaction tx = other.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 1)) {
+                try (Transaction tx = other.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, recordsCnt)) {
                     for (int i = 0; i < recordsCnt; i++)
                         other.cache(CACHE_NAME).put(i, i);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index bf01c0c..99de6c8 100755
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -82,8 +82,8 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicLocalInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicLocalWithStoreInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicNearEnabledInvokeTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicWithStoreInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicStopBusySelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicWithStoreInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheEntryListenerAtomicLocalTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheEntryListenerAtomicReplicatedTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheEntryListenerAtomicTest;
@@ -123,6 +123,7 @@ import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheConnec
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheMessageRecoveryIdleConnectionTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheMessageWriteTimeoutTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheSystemTransactionsSelfTest;
+import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheThreadLocalTxTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheTxMessageRecoveryTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCrossCacheTxStoreSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicNearCacheSelfTest;
@@ -318,6 +319,7 @@ public class IgniteCacheTestSuite extends TestSuite {
 
         suite.addTestSuite(TxRollbackOnTimeoutTest.class);
         suite.addTestSuite(TxRollbackOnTimeoutNoDeadlockDetectionTest.class);
+        suite.addTestSuite(IgniteCacheThreadLocalTxTest.class);
 
         return suite;
     }


[40/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ab4316ae
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ab4316ae
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ab4316ae

Branch: refs/heads/ignite-6181-1
Commit: ab4316ae965bb46af6521ff545956614b2dec62a
Parents: 0e2ff6a
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Thu Sep 14 18:31:28 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Thu Sep 14 18:31:28 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java | 30 ++++++-----
 .../transactions/TxRollbackOnTimeoutTest.java   | 56 +++++++++++++++-----
 2 files changed, 61 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ab4316ae/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index ee3d1d9..0e75b69 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -3139,6 +3139,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         GridNearTxPrepareFutureAdapter fut = (GridNearTxPrepareFutureAdapter)prepFut;
 
         if (fut == null) {
+            removeTimeoutHandler();
+
             long timeout = remainingTime();
 
             // Future must be created before any exception can be thrown.
@@ -3163,8 +3165,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             // Prepare was called explicitly.
             return fut;
 
-        removeTimeoutHandler();
-
         mapExplicitLocks();
 
         fut.prepare();
@@ -3710,9 +3710,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
-        else
+        else {
             cctx.tm().onLocalClose(this);
 
+            removeTimeoutHandler();
+        }
+
         synchronized (this) {
             try {
                 while (!done())
@@ -4023,10 +4026,10 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     }
 
     /**
-     * Removes timeout handler used for eager rollbacks on timeouts.
+     * Removes timeout handler.
      */
     private void removeTimeoutHandler() {
-        if (timeout() > 0 && !implicit() && !timedOut())
+        if (timeout() > 0 && !implicit())
             cctx.time().removeTimeoutObject(this);
     }
 
@@ -4037,12 +4040,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public long endTime() {
-        return startTime() + timeout() - 150;
+        return startTime() + timeout();
     }
 
     /** {@inheritDoc} */
     @Override public void onTimeout() {
-        //if (state(MARKED_ROLLBACK, true)) {
+        if (state(MARKED_ROLLBACK, true)) {
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
                     // Wait for active local lock futures completion to prevent races with deadlock detection.
@@ -4060,15 +4063,16 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                         }
                     }
 
-                    if (state(MARKED_ROLLBACK, true)) {
-                        log().error("Transaction is timed out and will be rolled back [timeout=" + timeout() +
-                            ", tx=" + GridNearTxLocal.this + ']');
+                    if (state() != MARKED_ROLLBACK)
+                        return;
 
-                        rollbackNearTxLocalAsync();
-                    }
+                    log().error("Transaction is timed out and will be rolled back [timeout=" + timeout() +
+                        ", tx=" + GridNearTxLocal.this + ']');
+
+                    rollbackNearTxLocalAsync();
                 }
             });
-        //}
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/ab4316ae/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 025332ae..4bbff17 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -23,7 +23,6 @@ import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
@@ -218,12 +217,43 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      *
      * @throws Exception If failed.
      */
-    public void testDeadlockUnblockedOnTimeout() throws Exception {
+    public void testDeadlockUnblockedOnTimeout1() throws Exception {
         testDeadlockUnblockedOnTimeout0(ignite(0), ignite(1));
     }
 
     /**
      * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDeadlockUnblockedOnTimeout2() throws Exception {
+        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(0));
+    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDeadlockUnblockedOnTimeout3() throws Exception {
+        Ignite client = startGrid("client");
+
+        testDeadlockUnblockedOnTimeout0(ignite(0), client);
+    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
+     */
+//    public void testDeadlockUnblockedOnTimeout4() throws Exception {
+//        Ignite client = startGrid("client");
+//
+//        testDeadlockUnblockedOnTimeout0(client, ignite(0));
+//    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
      * @throws Exception
      */
     private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2) throws Exception {
@@ -232,7 +262,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {
                 try {
-                    try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 2)) {
+                    try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 2)) {
                         node1.cache(CACHE_NAME).put(1, 1);
 
                         l.countDown();
@@ -253,7 +283,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
             @Override public void run() {
-                try (Transaction tx = ignite(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) {
+                try (Transaction tx = node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) {
                     node2.cache(CACHE_NAME).put(2, 2);
 
                     l.countDown();
@@ -346,6 +376,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     private void testTimeoutRemoval0(IgniteEx near, int mode, long timeout) throws Exception {
+        Throwable saved = null;
+
         try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, timeout, 1)) {
             near.cache(CACHE_NAME).put(1, 1);
 
@@ -373,18 +405,18 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     fail();
             }
         }
-        catch (TransactionTimeoutException e) {
-            // No-op.
-        }
-        catch (CacheException e) {
-            assertTrue("Only timeout exception is possible", X.hasCause(e, TransactionTimeoutException.class));
+        catch (Throwable t) {
+            saved = t;
         }
 
         GridConcurrentSkipListSet set = U.field(near.context().cache().context().time(), "timeoutObjs");
 
         for (Object obj : set)
-            assertFalse("Not remove for mode=" + mode + " and timeout=" + timeout,
-                    obj.getClass().isAssignableFrom(GridNearTxLocal.class));
+            if (obj.getClass().isAssignableFrom(GridNearTxLocal.class)) {
+                log.error("Last saved exception", saved);
+
+                fail("Not remove for mode=" + mode + " and timeout=" + timeout);
+            }
     }
 
     /**
@@ -393,7 +425,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final Ignite other) throws Exception {
-        final int recordsCnt = 1;
+        final int recordsCnt = 100;
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {


[39/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0e2ff6a8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0e2ff6a8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0e2ff6a8

Branch: refs/heads/ignite-6181-1
Commit: 0e2ff6a89a223991f5ce35d9656301f2004973e4
Parents: 047ac12
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Thu Sep 14 17:12:08 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Thu Sep 14 17:12:08 2017 +0300

----------------------------------------------------------------------
 .../colocated/GridDhtColocatedLockFuture.java   |  36 +++----
 .../cache/distributed/near/GridNearTxLocal.java |  39 ++++++-
 .../transactions/TxRollbackOnTimeoutTest.java   | 107 ++++---------------
 3 files changed, 74 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0e2ff6a8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
index 7500549..82b0e6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
@@ -147,7 +147,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
     private final Map<KeyCacheObject, IgniteBiTuple<GridCacheVersion, CacheObject>> valMap;
 
     /** Trackable flag (here may be non-volatile). */
-    private boolean trackable;
+    private boolean trackable = true;
 
     /** TTL for create operation. */
     private final long createTtl;
@@ -631,6 +631,13 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         }
     }
 
+    /**
+     * @return Timeout.
+     */
+    public long timeout() {
+        return timeout;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         Collection<String> futs = F.viewReadOnly(futures(), new C1<IgniteInternalFuture<?>, String>() {
@@ -849,8 +856,12 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         assert !remap || (clientNode && (tx == null || !tx.hasRemoteLocks()));
 
         // First assume this node is primary for all keys passed in.
-        if (!clientNode && mapAsPrimary(keys, topVer))
+        if (!clientNode && mapAsPrimary(keys, topVer)) {
+            if (!cctx.mvcc().addFuture(this))
+                throw new IllegalStateException("Duplicate future ID: " + this);
+
             return;
+        }
 
         mappings = new ArrayDeque<>();
 
@@ -881,8 +892,6 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         if (log.isDebugEnabled())
             log.debug("Starting (re)map for mappings [mappings=" + mappings + ", fut=" + this + ']');
 
-        boolean hasRmtNodes = false;
-
         boolean first = true;
 
         // Create mini futures.
@@ -1029,11 +1038,8 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
                 }
             }
 
-            if (!distributedKeys.isEmpty()) {
+            if (!distributedKeys.isEmpty())
                 mapping.distributedKeys(distributedKeys);
-
-                hasRmtNodes |= !mapping.node().isLocal();
-            }
             else {
                 assert mapping.request() == null;
 
@@ -1041,14 +1047,8 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
             }
         }
 
-        if (hasRmtNodes) {
-            trackable = true;
-
-            if (!remap && !cctx.mvcc().addFuture(this))
-                throw new IllegalStateException("Duplicate future ID: " + this);
-        }
-        else
-            trackable = false;
+        if (!remap && !cctx.mvcc().addFuture(this))
+            throw new IllegalStateException("Duplicate future ID: " + this);
 
         proceedMapping();
     }
@@ -1264,8 +1264,6 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
                 return true;
         }
 
-        trackable = false;
-
         if (tx != null) {
             if (explicit)
                 tx.markExplicit(cctx.localNodeId());
@@ -1673,4 +1671,4 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
             return S.toString(MiniFuture.class, this, "node", node.id(), "super", super.toString());
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0e2ff6a8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 0a59cd0..ee3d1d9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -46,6 +46,7 @@ import org.apache.ignite.internal.processors.cache.EntryGetResult;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
+import org.apache.ignite.internal.processors.cache.GridCacheFuture;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccFuture;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
@@ -56,11 +57,14 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocalAdapter;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture;
+import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry;
 import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
+import org.apache.ignite.internal.processors.cache.local.GridLocalLockFuture;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
@@ -90,6 +94,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiClosure;
 import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.plugin.security.SecurityPermission;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -135,6 +140,13 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     private static final AtomicReferenceFieldUpdater<GridNearTxLocal, GridNearTxFinishFuture> ROLLBACK_FUT_UPD =
         AtomicReferenceFieldUpdater.newUpdater(GridNearTxLocal.class, GridNearTxFinishFuture.class, "rollbackFut");
 
+    /** Lock future predicate. */
+    private static final IgnitePredicate<GridCacheFuture<?>> LOCK_FUTURES = new IgnitePredicate<GridCacheFuture<?>>() {
+        @Override public boolean apply(GridCacheFuture<?> fut) {
+            return fut instanceof GridDhtColocatedLockFuture;
+        }
+    };
+
     /** DHT mappings. */
     private IgniteTxMappings mappings;
 
@@ -4025,21 +4037,38 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public long endTime() {
-        return startTime() + timeout() - 50;
+        return startTime() + timeout() - 150;
     }
 
     /** {@inheritDoc} */
     @Override public void onTimeout() {
-        if (state(MARKED_ROLLBACK, true)) {
+        //if (state(MARKED_ROLLBACK, true)) {
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
-                    log().error("Transaction is timed out and will be rolled back [timeout=" + timeout() +
+                    // Wait for active local lock futures completion to prevent races with deadlock detection.
+                    Collection<GridCacheFuture<?>> lockFuts = F.view(cctx.mvcc().activeFutures(), LOCK_FUTURES);
+
+                    for (GridCacheFuture<?> fut : lockFuts) {
+                        try {
+                            GridDhtColocatedLockFuture locFut = (GridDhtColocatedLockFuture)fut;
+
+                            if (locFut.timeout() > 0)
+                                fut.get();
+                        }
+                        catch (IgniteCheckedException e) {
+                            log.error("Failed to wait for lock future completion [fut=" + fut + ']', e);
+                        }
+                    }
+
+                    if (state(MARKED_ROLLBACK, true)) {
+                        log().error("Transaction is timed out and will be rolled back [timeout=" + timeout() +
                             ", tx=" + GridNearTxLocal.this + ']');
 
-                    rollbackNearTxLocalAsync();
+                        rollbackNearTxLocalAsync();
+                    }
                 }
             });
-        }
+        //}
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/0e2ff6a8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index d22b682..025332ae 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.cache.transactions;
 
+import java.util.Collections;
 import java.util.concurrent.CountDownLatch;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
@@ -45,7 +46,6 @@ import org.jsr166.ThreadLocalRandom8;
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS;
 
 /**
  * Tests an ability to eagerly rollback timed out transactions.
@@ -98,20 +98,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        super.beforeTestsStarted();
-
-        //System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        super.afterTestsStopped();
-
-        //System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
-    }
-
-    /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
@@ -228,23 +214,31 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Tests if deadlock is unblocked on timeout.
-     * @throws Exception
+     * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
      */
     public void testDeadlockUnblockedOnTimeout() throws Exception {
+        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(1));
+    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
+     * @throws Exception
+     */
+    private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2) throws Exception {
         final CountDownLatch l = new CountDownLatch(2);
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
-            @Override
-            public void run() {
+            @Override public void run() {
                 try {
-                    try (Transaction tx = ignite(0).transactions().txStart()) {
-                        ignite(0).cache(CACHE_NAME).put(1, 1);
+                    try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 2)) {
+                        node1.cache(CACHE_NAME).put(1, 1);
 
                         l.countDown();
                         U.awaitQuiet(l);
 
-                        ignite(0).cache(CACHE_NAME).put(2, 2);
+                        node1.cache(CACHE_NAME).putAll(Collections.singletonMap(2, 2));
 
                         tx.commit();
 
@@ -252,21 +246,20 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     }
                 } catch (CacheException e) {
                     // No-op.
+                    assertTrue(X.hasCause(e, TransactionDeadlockException.class));
                 }
             }
         }, 1, "First");
 
         IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
             @Override public void run() {
-                U.awaitQuiet(blocked);
-
-                try (Transaction tx = ignite(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 1)) {
-                    ignite(1).cache(CACHE_NAME).put(2, 2);
+                try (Transaction tx = ignite(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) {
+                    node2.cache(CACHE_NAME).put(2, 2);
 
                     l.countDown();
                     U.awaitQuiet(l);
 
-                    ignite(1).cache(CACHE_NAME).put(1, 1);
+                    node2.cache(CACHE_NAME).put(1, 1);
 
                     tx.commit();
                 }
@@ -276,8 +269,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         fut1.get();
         fut2.get();
 
-        assertTrue(ignite(0).cache(CACHE_NAME).containsKey(1));
-        assertTrue(ignite(0).cache(CACHE_NAME).containsKey(2));
+        assertTrue(node1.cache(CACHE_NAME).containsKey(1));
+        assertTrue(node1.cache(CACHE_NAME).containsKey(2));
     }
 
     /**
@@ -319,60 +312,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Tests tx timeout on deadlock.
-     *
-     * @throws Exception
-     */
-    public void testTimeoutOnDeadlock() throws Exception {
-        final CountDownLatch l = new CountDownLatch(2);
-
-        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
-            @Override public void run() {
-                try(Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 1)) {
-                    grid(0).cache(CACHE_NAME).put(1, 1);
-
-                    l.countDown();
-                    U.awaitQuiet(l);
-
-                    grid(0).cache(CACHE_NAME).put(2, 2);
-                }
-
-            }
-        }, 1, "First");
-
-        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
-            @Override public void run() {
-                try(Transaction tx = grid(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 1)) {
-                    grid(1).cache(CACHE_NAME).put(2, 2);
-
-                    l.countDown();
-                    U.awaitQuiet(l);
-
-                    grid(1).cache(CACHE_NAME).put(1, 1);
-
-                    tx.commit();
-                }
-
-            }
-
-        }, 1, "Second");
-
-        try {
-            fut1.get();
-
-            fail();
-        }
-        catch (Exception e) {
-            assertTrue(X.hasCause(e, TransactionDeadlockException.class));
-        }
-
-        fut2.get();
-
-        assertTrue(grid(0).cache(CACHE_NAME).containsKey(1));
-        assertTrue(grid(0).cache(CACHE_NAME).containsKey(2));
-    }
-
-    /**
      * @param concurrency Concurrency.
      * @param isolation Isolation.
      *
@@ -454,7 +393,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final Ignite other) throws Exception {
-        final int recordsCnt = 100;
+        final int recordsCnt = 1;
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {


[19/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9da2dde3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9da2dde3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9da2dde3

Branch: refs/heads/ignite-6181-1
Commit: 9da2dde3e7818d07d39756f2b92255d15acc147e
Parents: 61dfb65
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Wed Aug 30 18:12:10 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Wed Aug 30 18:12:10 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java |  65 ++--
 .../cache/transactions/IgniteTxManager.java     |  42 +--
 .../transactions/TxRollbackOnTimeoutTest.java   | 303 +++++++++++++++++++
 .../transactions/TxTimeoutHandlingTest.java     | 147 ---------
 4 files changed, 335 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9da2dde3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index ac35ad9..ebae49f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -34,7 +34,6 @@ import javax.cache.CacheException;
 import javax.cache.expiry.ExpiryPolicy;
 import javax.cache.processor.EntryProcessor;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.NodeStoppingException;
@@ -119,7 +118,7 @@ import static org.apache.ignite.transactions.TransactionState.UNKNOWN;
  * Replicated user transaction.
  */
 @SuppressWarnings("unchecked")
-public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoCloseable  {
+public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeoutObject, AutoCloseable {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -176,8 +175,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     private TransactionProxyImpl proxy;
 
     /** */
-    @GridToStringExclude
-    private GridTimeoutObject timeoutHandler;
+    private long endTime;
 
     /**
      * Empty constructor required for {@link Externalizable}.
@@ -224,7 +222,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
             plc,
             concurrency,
             isolation,
-            timeout,
+            timeout == 0 ? 0 : Math.max(100, timeout),
             false,
             storeEnabled,
             false,
@@ -234,6 +232,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
 
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
+        if (this.timeout > 0) {
+            endTime = U.currentTimeMillis() + this.timeout;
+
+            cctx.time().addTimeoutObject(this);
+        }
+
         initResult();
     }
 
@@ -3152,11 +3156,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
             // Prepare was called explicitly.
             return fut;
 
-        // Clears timeout handler before prepare, because prepare phase will clean up everything right up.
-        if (!clearTimeoutHandler()) {
-            // Timeout closure has been invoked, tx will be rolled back.
-            throw new IgniteException("Bad");
-        }
+        if (endTime > 0)
+            cctx.time().removeTimeoutObject(this);
 
         mapExplicitLocks();
 
@@ -3180,15 +3181,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     }
 
     /**
-     * Clears timeout handler.
-     */
-    public boolean clearTimeoutHandler() {
-        timeoutHandler = null;
-
-        return true;
-    }
-
-    /**
      * @return Prepare future.
      */
     private IgniteInternalFuture<?> prepareAsync() {
@@ -3269,7 +3261,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
      * @throws IgniteCheckedException If failed.
      */
     public void rollback() throws IgniteCheckedException {
-        clearTimeoutHandler();
+        if (endTime > 0)
+            cctx.time().removeTimeoutObject(this);
 
         rollbackNearTxLocalAsync().get();
     }
@@ -3786,20 +3779,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     }
 
     /**
-     * @return Timeout handler.
-     */
-    public GridTimeoutObject timeoutHandler() {
-        return timeoutHandler;
-    }
-
-    /**
-     * @param timeoutHnd New timeout handler.
-     */
-    public void timeoutHandler(GridTimeoutObject timeoutHnd) {
-        timeoutHandler = timeoutHnd;
-    }
-
-    /**
      * @return Public API proxy.
      */
     public TransactionProxy proxy() {
@@ -4082,6 +4061,24 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements AutoClosea
     }
 
     /** {@inheritDoc} */
+    @Override public IgniteUuid timeoutId() {
+        return xid();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long endTime() {
+        return endTime;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onTimeout() {
+        log.error("Transaction is timed out and will be rolled back: [tx=" + this + ']');
+
+        if (setRollbackOnly())
+            rollbackAsync();
+    }
+
+    /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridNearTxLocal.class, this,
             "thread", IgniteUtils.threadName(threadId),

http://git-wip-us.apache.org/repos/asf/ignite/blob/9da2dde3/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 64624dd..a3bf205 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
@@ -460,12 +460,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 tx.topologyVersion(topVer);
         }
 
-        tx = onCreated(sysCacheCtx, tx);
-
-        if (tx != null && tx.timeout() > 0)
-            cctx.time().addTimeoutObject(new TxEagerTimeoutObject(tx));
-
-        return tx;
+        return onCreated(sysCacheCtx, tx);
     }
 
     /**
@@ -2405,41 +2400,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Timeout object for tx timeout handler.
-     */
-    private final class TxEagerTimeoutObject extends GridTimeoutObjectAdapter {
-        /** */
-        private final GridNearTxLocal tx;
-
-        /**
-         * @param tx Tx.
-         */
-        public TxEagerTimeoutObject(final GridNearTxLocal tx) {
-            super(tx.timeout());
-
-            this.tx = tx;
-
-            tx.timeoutHandler(this);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onTimeout() {
-            GridTimeoutObject hnd = tx.timeoutHandler();
-
-            if (hnd == null)
-                return;
-
-            if (!tx.clearTimeoutHandler()) // Transaction is prepared or rolled back concurrently.
-                return;
-
-            log.error("Transaction is timed out and will be rolled back: [tx=" + tx + ']');
-
-            if (tx.setRollbackOnly())
-                tx.rollbackAsync();
-        }
-    }
-
-    /**
      * Per-thread key for system transactions.
      */
     private static class TxThreadKey {

http://git-wip-us.apache.org/repos/asf/ignite/blob/9da2dde3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
new file mode 100644
index 0000000..e93cff1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -0,0 +1,303 @@
+/*
+ * 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.transactions;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
+import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+
+/**
+ * Tests an ability to eagerly rollback timed out transactions.
+ */
+public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
+    /** */
+    private static final long TX_TIMEOUT = 3_000L;
+
+    /** */
+    private static final String CACHE_NAME = "test";
+
+    /** IP finder. */
+    private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private final CountDownLatch blocked = new CountDownLatch(1);
+
+    /** */
+    private CountDownLatch unblocked = new CountDownLatch(1);
+
+    /** */
+    private static int GRID_CNT = 3;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setClientMode("client".equals(igniteInstanceName));
+
+        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
+
+        TransactionConfiguration txCfg = new TransactionConfiguration();
+        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
+
+        cfg.setTransactionConfiguration(txCfg);
+
+        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+        ccfg.setBackups(2);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        startGridsMultiThreaded(GRID_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout1() throws Exception {
+        testWaitingTxUnblockedOnTimeout0(grid(0), grid(0));
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout2() throws Exception {
+        testWaitingTxUnblockedOnTimeout0(grid(0), grid(1));
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnTimeout0(grid(0), client);
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout4() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnTimeout0(client, grid(0));
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout5() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnTimeout0(client, client);
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout6() throws Exception {
+        testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(0));
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout7() throws Exception {
+        testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(1));
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout9() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnThreadDeath0(client, grid(0));
+    }
+
+    /**
+     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     */
+    public void testWaitingTxUnblockedOnTimeout10() throws Exception {
+        Ignite client = startGrid("client");
+
+        testWaitingTxUnblockedOnThreadDeath0(client, client);
+    }
+
+    /**
+     * Tests timeout object cleanup on tx commit.
+     */
+    public void testTimeoutRemovalOnCommit() throws Exception {
+        testTimeoutRemoval(grid(0), true);
+    }
+
+    /**
+     * Tests timeout object cleanup on tx rollback.
+     */
+    public void testTimeoutRemovalOnRollback() throws Exception {
+        testTimeoutRemoval(grid(0), false);
+    }
+
+    /** */
+    private void testTimeoutRemoval(IgniteEx near, boolean commit) throws Exception {
+        GridTimeoutProcessor timeProc = near.context().cache().context().time();
+
+        try (Transaction tx = near.transactions().txStart()) {
+            near.cache(CACHE_NAME).put(1, 1);
+
+            if (commit)
+                tx.commit();
+        }
+
+        GridConcurrentSkipListSet set = U.field(timeProc, "timeoutObjs");
+
+        for (Object obj : set)
+            assertFalse(obj.getClass().isAssignableFrom(GridNearTxLocal.class));
+    }
+
+    /** */
+    private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final Ignite other) throws Exception {
+        final int recordsCnt = 100;
+
+        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                try (Transaction tx = near.transactions().txStart()) {
+                    for (int i = 0; i < recordsCnt; i++)
+                        near.cache(CACHE_NAME).put(i, i);
+
+                    blocked.countDown();
+
+                    // Will be unblocked after tx timeout occurs.
+                    U.awaitQuiet(unblocked);
+
+                    try {
+                        tx.commit();
+
+                        fail();
+                    }
+                    catch (IgniteException e) {
+                        log.info("Expecting error: " + e.getMessage());
+                    }
+                }
+            }
+        }, 1, "First");
+
+        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                U.awaitQuiet(blocked);
+
+                try (Transaction tx = other.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
+                    TransactionIsolation.REPEATABLE_READ, 0, 1)) {
+                    for (int i = 0; i < recordsCnt; i++)
+                        other.cache(CACHE_NAME).put(i, i);
+
+                    // Will wait until timeout on first tx will unblock put.
+                    tx.commit();
+                }
+            }
+        }, 2, "Second");
+
+        fut2.get(5, TimeUnit.SECONDS);
+
+        unblocked.countDown();
+
+        fut1.get(5, TimeUnit.SECONDS);
+    }
+
+    private void testWaitingTxUnblockedOnThreadDeath0(final Ignite near, final Ignite other) throws Exception {
+        final int recordsCnt = 100;
+
+        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                near.transactions().txStart();
+                for (int i = 0; i < recordsCnt; i++)
+                    near.cache(CACHE_NAME).put(i, i);
+
+                blocked.countDown();
+
+                throw new IgniteException("Failure");
+            }
+        }, 1, "First");
+
+        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                U.awaitQuiet(blocked);
+
+                try (Transaction tx = other.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
+                    TransactionIsolation.REPEATABLE_READ, 0, 1)) {
+                    for (int i = 0; i < recordsCnt; i++)
+                        other.cache(CACHE_NAME).put(i, i);
+
+                    // Will wait until timeout on first tx will unblock put.
+                    tx.commit();
+                }
+            }
+        }, 2, "Second");
+
+        try {
+            fut1.get();
+
+            fail();
+        }
+        catch (IgniteCheckedException e) {
+            // No-op.
+        }
+
+        fut2.get(5, TimeUnit.SECONDS);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/9da2dde3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
deleted file mode 100644
index 8b17127..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxTimeoutHandlingTest.java
+++ /dev/null
@@ -1,147 +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.apache.ignite.internal.processors.cache.transactions;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.TransactionConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.transactions.Transaction;
-import org.apache.ignite.transactions.TransactionConcurrency;
-import org.apache.ignite.transactions.TransactionIsolation;
-
-/**
- * Tests ability to rollback not properly closed transaction.
- */
-public class TxTimeoutHandlingTest extends GridCommonAbstractTest {
-    /** */
-    private static final long TX_TIMEOUT = 3_000L;
-
-    /** */
-    private static final String CACHE_NAME = "test";
-
-    /** IP finder. */
-    private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private final CountDownLatch l = new CountDownLatch(1);
-
-    /** */
-    private final Object mux = new Object();
-
-    /** */
-    private volatile boolean released;
-
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
-
-        TransactionConfiguration txCfg = new TransactionConfiguration();
-        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
-
-        cfg.setTransactionConfiguration(txCfg);
-
-        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
-        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
-
-        cfg.setCacheConfiguration(ccfg);
-
-        return cfg;
-    }
-
-    /** */
-    public void testTxTimeoutHandling() throws Exception {
-        try {
-            final Ignite ignite = startGrid(0);
-
-            IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
-                @Override public void run() {
-                    // Start tx with default settings.
-                    try (Transaction tx = ignite.transactions().txStart()) {
-                        ignite.cache(CACHE_NAME).put(1, 1);
-
-                        l.countDown();
-
-                        // Wait longer than default timeout.
-                        synchronized (mux) {
-                            while (!released) {
-                                try {
-                                    mux.wait();
-                                }
-                                catch (InterruptedException e) {
-                                    throw new IgniteException(e);
-                                }
-                            }
-                        }
-
-                        try {
-                            tx.commit();
-
-                            fail();
-                        }
-                        catch (IgniteException e) {
-                            // Expect exception - tx is rolled back.
-                        }
-                    }
-                }
-            }, 1, "Locker");
-
-            IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
-                @Override public void run() {
-                    U.awaitQuiet(l);
-
-                    // Try to acquire lock.
-                    // Acquisition will be successful then first transaction will be rolled back after timeout.
-                    try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
-                        TransactionIsolation.REPEATABLE_READ, 0, 1)) {
-                        ignite.cache(CACHE_NAME).put(1, 1);
-
-                        tx.commit();
-                    }
-                }
-            }, 1, "Waiter");
-
-            Thread.sleep(TX_TIMEOUT + 1_000);
-
-            fut2.get();
-
-            startGrid(1);
-
-            released = true;
-
-            synchronized (mux) {
-                mux.notify();
-            }
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-}
\ No newline at end of file


[33/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6ee98d1d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6ee98d1d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6ee98d1d

Branch: refs/heads/ignite-6181-1
Commit: 6ee98d1d6ef36933ea94ecd568fb88c6ff62fadf
Parents: 1938338
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Mon Sep 11 20:09:39 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Mon Sep 11 20:09:39 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/processors/cache/GridCacheProcessor.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6ee98d1d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index bd950fa..1efb500 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -3654,7 +3654,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @throws IgniteException If transaction exist.
      */
     private void checkEmptyTransactions() throws IgniteException {
-        if (transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
+        if (transactions().tx() != null)
             throw new IgniteException("Cannot start/stop cache within lock or transaction.");
     }
 


[45/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/eebaa6bd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/eebaa6bd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/eebaa6bd

Branch: refs/heads/ignite-6181-1
Commit: eebaa6bd064705516a85a8dc90a4f252e652390e
Parents: 1310008
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Fri Sep 15 13:30:45 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Fri Sep 15 13:30:45 2017 +0300

----------------------------------------------------------------------
 ...niteTxConfigCacheForceTxTimeoutSelfTest.java | 39 ----------------
 ...ollbackOnTimeoutNoDeadlockDetectionTest.java | 47 ++++++++++++++++++++
 .../transactions/TxRollbackOnTimeoutTest.java   | 24 +++++++++-
 .../ignite/testsuites/IgniteCacheTestSuite.java |  4 +-
 4 files changed, 72 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/eebaa6bd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
deleted file mode 100644
index 4420a4e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
+++ /dev/null
@@ -1,39 +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.apache.ignite.internal.processors.cache;
-
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS;
-
-/**
- * Test checks that grid transaction configuration doesn't influence system caches.
- */
-public class IgniteTxConfigCacheForceTxTimeoutSelfTest extends IgniteTxConfigCacheSelfTest {
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
-
-        super.beforeTestsStarted();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        super.afterTestsStopped();
-
-        System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/eebaa6bd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
new file mode 100644
index 0000000..77c383e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.transactions;
+
+import org.apache.ignite.transactions.TransactionTimeoutException;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS;
+
+/**
+ * Tests an ability to eagerly rollback timed out transactions.
+ */
+public class TxRollbackOnTimeoutNoDeadlockDetectionTest extends TxRollbackOnTimeoutTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
+
+        super.beforeTestsStarted();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
+    }
+
+    /** */
+    @Override protected void validateException(Exception e) {
+        assertEquals("Deadlock report is expected",
+            TransactionTimeoutException.class, e.getCause().getClass());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/eebaa6bd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 4bbff17..cdf1f00 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -110,6 +110,12 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         stopAllGrids();
     }
 
+    /** */
+    protected void validateException(Exception e) {
+        assertEquals("Deadlock report is expected",
+            TransactionDeadlockException.class, e.getCause().getCause().getClass());
+    }
+
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
      *
@@ -276,7 +282,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     }
                 } catch (CacheException e) {
                     // No-op.
-                    assertTrue(X.hasCause(e, TransactionDeadlockException.class));
+                    validateException(e);
                 }
             }
         }, 1, "First");
@@ -534,4 +540,20 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         fut2.get();
     }
+
+    /**
+     * Returns root cause for an exception.
+     * @param t Throwable.
+     *
+     * @return Root cause or input if none.
+     */
+    private static Throwable getRootCause(Throwable t) {
+        Throwable cause;
+        Throwable res = t;
+
+        while(null != (cause = res.getCause()) && (res != cause) )
+            res = cause;
+
+        return res;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/eebaa6bd/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 35331e9..bf01c0c 100755
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -102,7 +102,6 @@ import org.apache.ignite.internal.processors.cache.IgniteClientAffinityAssignmen
 import org.apache.ignite.internal.processors.cache.IgniteIncompleteCacheObjectSelfTest;
 import org.apache.ignite.internal.processors.cache.IgnitePutAllLargeBatchSelfTest;
 import org.apache.ignite.internal.processors.cache.IgnitePutAllUpdateNonPreloadedPartitionSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheForceTxTimeoutSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheSelfTest;
 import org.apache.ignite.internal.processors.cache.context.IgniteCacheAtomicExecutionContextTest;
 import org.apache.ignite.internal.processors.cache.context.IgniteCacheContinuousExecutionContextTest;
@@ -135,6 +134,7 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCa
 import org.apache.ignite.internal.processors.cache.local.GridCacheLocalTxExceptionSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheEntryProcessorExternalizableFailedTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheEntryProcessorNonSerializableTest;
+import org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutNoDeadlockDetectionTest;
 import org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamerImplSelfTest;
@@ -303,7 +303,6 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(CachePutEventListenerErrorSelfTest.class);
 
         suite.addTestSuite(IgniteTxConfigCacheSelfTest.class);
-        suite.addTestSuite(IgniteTxConfigCacheForceTxTimeoutSelfTest.class);
 
         suite.addTestSuite(CacheTxFastFinishTest.class);
 
@@ -318,6 +317,7 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(IgniteIncompleteCacheObjectSelfTest.class);
 
         suite.addTestSuite(TxRollbackOnTimeoutTest.class);
+        suite.addTestSuite(TxRollbackOnTimeoutNoDeadlockDetectionTest.class);
 
         return suite;
     }


[07/50] [abbrv] ignite git commit: GG-12609: Fixed OOM at initiator during LIST

Posted by sb...@apache.org.
GG-12609: Fixed OOM at initiator during LIST


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8c249b77
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8c249b77
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8c249b77

Branch: refs/heads/ignite-6181-1
Commit: 8c249b77533c95a4bef3d19ca583feb992322325
Parents: 85fd8ce
Author: Eduard Shangareev <es...@gridgain.com>
Authored: Sat Aug 26 17:01:46 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Sat Aug 26 17:01:46 2017 +0300

----------------------------------------------------------------------
 .../tcp/internal/TcpDiscoveryNode.java          | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8c249b77/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
index 6882821..b2797a40 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
@@ -649,4 +649,24 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements Cluste
     @Override public String toString() {
         return S.toString(TcpDiscoveryNode.class, this, "isClient", isClient());
     }
+
+    /**
+     * IMPORTANT!
+     * Only purpose of this constructor is creating node which contains only necessary data to store on disc
+     * @param node to copy data from
+     */
+    public TcpDiscoveryNode(
+        ClusterNode node
+    ) {
+        this.id = node.id();
+        this.consistentId = node.consistentId();
+        this.addrs = node.addresses();
+        this.hostNames = node.hostNames();
+        this.order = node.order();
+        this.ver = node.version();
+        this.daemon = node.isDaemon();
+        this.clientRouterNodeId = node.isClient() ? node.id() : null;
+
+        attrs = Collections.emptyMap();
+    }
 }


[09/50] [abbrv] ignite git commit: IGNITE-6124: fix for lastVer field on GridDhtPartitionsSingleMessage message

Posted by sb...@apache.org.
IGNITE-6124: fix for lastVer field on GridDhtPartitionsSingleMessage message


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/fc55ade9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/fc55ade9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/fc55ade9

Branch: refs/heads/ignite-6181-1
Commit: fc55ade9b5a586fb39701b4e8b7ce2105bff2fd0
Parents: a857c5b
Author: Sergey Chugunov <se...@gmail.com>
Authored: Sat Aug 26 21:44:13 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Sat Aug 26 21:44:13 2017 +0300

----------------------------------------------------------------------
 .../distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fc55ade9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index 6decb44..299284d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -1227,7 +1227,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
         if (cctx.kernalContext().clientNode()) {
             msg = new GridDhtPartitionsSingleMessage(exchangeId(),
                 true,
-                null,
+                cctx.versions().last(),
                 true);
         }
         else {


[03/50] [abbrv] ignite git commit: ignite-5682 Added stale version check for GridDhtPartFullMessage not related to exchange.

Posted by sb...@apache.org.
ignite-5682 Added stale version check for GridDhtPartFullMessage not related to exchange.

(cherry picked from commit eb9d06d)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/316312d2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/316312d2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/316312d2

Branch: refs/heads/ignite-6181-1
Commit: 316312d2ae9015228e67f959e492b2c5c4a9366d
Parents: 5bda409
Author: Dmitry Pavlov <dp...@gmail.com>
Authored: Thu Jul 27 14:51:25 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Aug 25 16:53:41 2017 +0300

----------------------------------------------------------------------
 .../cache/CacheAffinitySharedManager.java       |  5 +-
 .../processors/cache/GridCacheIoManager.java    |  2 +-
 .../GridCachePartitionExchangeManager.java      | 42 +++++++++-----
 .../dht/GridClientPartitionTopology.java        | 12 +++-
 .../dht/GridDhtPartitionTopology.java           |  5 +-
 .../dht/GridDhtPartitionTopologyImpl.java       | 12 +++-
 .../preloader/GridDhtPartitionExchangeId.java   |  2 +-
 .../GridDhtPartitionsExchangeFuture.java        | 36 ++++++++----
 .../preloader/GridDhtPartitionsFullMessage.java |  4 +-
 ...cingDelayedPartitionMapExchangeSelfTest.java | 58 ++++++++++++++++----
 .../junits/common/GridCommonAbstractTest.java   |  6 +-
 11 files changed, 136 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
index 0e03a29..ffb55e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
@@ -460,7 +460,8 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
                                 grp.topology().update(grpHolder.affinity().lastVersion(),
                                     clientTop.partitionMap(true),
                                     clientTop.fullUpdateCounters(),
-                                    Collections.<Integer>emptySet());
+                                    Collections.<Integer>emptySet(),
+                                    null);
                             }
 
                             assert grpHolder.affinity().lastVersion().equals(grp.affinity().lastVersion());
@@ -518,7 +519,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
 
                 grp.topology().updateTopologyVersion(topFut, discoCache, -1, false);
 
-                grp.topology().update(topVer, partMap, null, Collections.<Integer>emptySet());
+                grp.topology().update(topVer, partMap, null, Collections.<Integer>emptySet(), null);
 
                 topFut.validate(grp, discoCache.allNodes());
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
index 45edc53..6529795 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
@@ -551,7 +551,7 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * @param nodeId Node ID.
+     * @param nodeId Sender Node ID.
      * @param cacheMsg Cache message.
      * @param c Handler closure.
      * @param plc Message policy.

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index aad5b35..bd34a5f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@ -140,7 +140,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     /** */
     private static final IgniteProductVersion EXCHANGE_PROTOCOL_2_SINCE = IgniteProductVersion.fromString("2.1.4");
 
-    /** Atomic reference for pending timeout object. */
+    /** Atomic reference for pending partition resend timeout object. */
     private AtomicReference<ResendTimeoutObject> pendingResend = new AtomicReference<>();
 
     /** Partition resend timeout after eviction. */
@@ -161,7 +161,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     private final ConcurrentMap<Integer, GridClientPartitionTopology> clientTops = new ConcurrentHashMap8<>();
 
     /** */
-    private volatile GridDhtPartitionsExchangeFuture lastInitializedFut;
+    @Nullable private volatile GridDhtPartitionsExchangeFuture lastInitializedFut;
 
     /** */
     private final AtomicReference<GridDhtTopologyFuture> lastFinishedFut = new AtomicReference<>();
@@ -921,6 +921,8 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
 
     /**
      * Partition refresh callback.
+     * For coordinator causes {@link GridDhtPartitionsFullMessage FullMessages} send,
+     * for non coordinator -  {@link GridDhtPartitionsSingleMessage SingleMessages} send
      */
     private void refreshPartitions() {
         ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(AffinityTopologyVersion.NONE);
@@ -958,7 +960,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
             if (log.isDebugEnabled())
                 log.debug("Refreshing partitions from oldest node: " + cctx.localNodeId());
 
-            sendAllPartitions(rmts);
+            sendAllPartitions(rmts, rmtTopVer);
         }
         else {
             if (log.isDebugEnabled())
@@ -971,10 +973,14 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
 
     /**
      * @param nodes Nodes.
+     * @param msgTopVer Topology version. Will be added to full message.
      */
-    private void sendAllPartitions(Collection<ClusterNode> nodes) {
+    private void sendAllPartitions(Collection<ClusterNode> nodes,
+        AffinityTopologyVersion msgTopVer) {
         GridDhtPartitionsFullMessage m = createPartitionsFullMessage(true, false, null, null, null, null);
 
+        m.topologyVersion(msgTopVer);
+
         if (log.isDebugEnabled())
             log.debug("Sending all partitions [nodeIds=" + U.nodeIds(nodes) + ", msg=" + m + ']');
 
@@ -1126,8 +1132,8 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
-     * @param node Node.
-     * @param id ID.
+     * @param node Destination cluster node.
+     * @param id Exchange ID.
      */
     private void sendLocalPartitions(ClusterNode node, @Nullable GridDhtPartitionExchangeId id) {
         GridDhtPartitionsSingleMessage m = createPartitionsSingleMessage(id,
@@ -1153,7 +1159,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
-     * @param exchangeId ID.
+     * @param exchangeId Exchange ID.
      * @param clientOnlyExchange Client exchange flag.
      * @param sndCounters {@code True} if need send partition update counters.
      * @param newCntrMap {@code True} if possible to use {@link CachePartitionPartialCountersMap}.
@@ -1372,7 +1378,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
-     * @param node Node.
+     * @param node Sender cluster node.
      * @param msg Message.
      */
     private void processFullPartitionUpdate(ClusterNode node, GridDhtPartitionsFullMessage msg) {
@@ -1398,8 +1404,13 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
                     else if (!grp.isLocal())
                         top = grp.topology();
 
-                    if (top != null)
-                        updated |= top.update(null, entry.getValue(), null, msg.partsToReload(cctx.localNodeId(), grpId));
+                    if (top != null) {
+                        updated |= top.update(null,
+                            entry.getValue(),
+                            null,
+                            msg.partsToReload(cctx.localNodeId(), grpId),
+                            msg.topologyVersion());
+                    }
                 }
 
                 if (!cctx.kernalContext().clientNode() && updated)
@@ -1427,7 +1438,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
-     * @param node Node ID.
+     * @param node Sender cluster node.
      * @param msg Message.
      */
     private void processSinglePartitionUpdate(final ClusterNode node, final GridDhtPartitionsSingleMessage msg) {
@@ -1477,7 +1488,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
     }
 
     /**
-     * @param node Node ID.
+     * @param node Sender cluster node.
      * @param msg Message.
      */
     private void processSinglePartitionRequest(ClusterNode node, GridDhtPartitionsSingleRequest msg) {
@@ -2595,7 +2606,10 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
         /** */
         private static final long serialVersionUID = 0L;
 
-        /** {@inheritDoc} */
+        /**
+         * @param nodeId Sender node ID.
+         * @param msg Message.
+         */
         @Override public void apply(UUID nodeId, M msg) {
             ClusterNode node = cctx.node(nodeId);
 
@@ -2613,7 +2627,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
         }
 
         /**
-         * @param node Node.
+         * @param node Sender cluster node.
          * @param msg Message.
          */
         protected abstract void onMessage(ClusterNode node, M msg);

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
index 10d08b9..c8856fd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
@@ -656,8 +656,8 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
         @Nullable AffinityTopologyVersion exchangeVer,
         GridDhtPartitionFullMap partMap,
         @Nullable CachePartitionFullCountersMap cntrMap,
-        Set<Integer> partsToReload
-    ) {
+        Set<Integer> partsToReload,
+        @Nullable AffinityTopologyVersion msgTopVer) {
         if (log.isDebugEnabled())
             log.debug("Updating full partition map [exchVer=" + exchangeVer + ", parts=" + fullMapString() + ']');
 
@@ -672,6 +672,14 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
                 return false;
             }
 
+            if (msgTopVer != null && lastExchangeVer != null && lastExchangeVer.compareTo(msgTopVer) > 0) {
+                if (log.isDebugEnabled())
+                    log.debug("Stale topology version for full partition map update message (will ignore) " +
+                        "[lastExchId=" + lastExchangeVer + ", topVersion=" + msgTopVer + ']');
+
+                return false;
+            }
+
             boolean fullMapUpdated = (node2part == null);
 
             if (node2part != null) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
index f48bd352..4ae68ef 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
@@ -263,13 +263,16 @@ public interface GridDhtPartitionTopology {
      * @param partMap Update partition map.
      * @param cntrMap Partition update counters.
      * @param partsToReload Set of partitions that need to be reloaded.
+     * @param msgTopVer Topology version from incoming message. This value is not null only for case message is not
+     *      related to exchange. Value should be not less than previous 'Topology version from exchange'.
      * @return {@code True} if local state was changed.
      */
     public boolean update(
         @Nullable AffinityTopologyVersion exchangeResVer,
         GridDhtPartitionFullMap partMap,
         @Nullable CachePartitionFullCountersMap cntrMap,
-        Set<Integer> partsToReload);
+        Set<Integer> partsToReload,
+        @Nullable AffinityTopologyVersion msgTopVer);
 
     /**
      * @param exchId Exchange ID.

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index 6ab6bd8..f25ae21 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -1176,7 +1176,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         @Nullable AffinityTopologyVersion exchangeVer,
         GridDhtPartitionFullMap partMap,
         @Nullable CachePartitionFullCountersMap incomeCntrMap,
-        Set<Integer> partsToReload) {
+        Set<Integer> partsToReload,
+        @Nullable AffinityTopologyVersion msgTopVer) {
         if (log.isDebugEnabled())
             log.debug("Updating full partition map [exchVer=" + exchangeVer + ", parts=" + fullMapString() + ']');
 
@@ -1217,6 +1218,15 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                 }
             }
 
+            if (msgTopVer != null && lastTopChangeVer.compareTo(msgTopVer) > 0) {
+                U.warn(log, "Stale version for full partition map update message (will ignore) [" +
+                    "lastTopChange=" + lastTopChangeVer +
+                    ", readTopVer=" + readyTopVer +
+                    ", msgVer=" + msgTopVer + ']');
+
+                return false;
+            }
+
             boolean fullMapUpdated = (node2part == null);
 
             if (node2part != null) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
index 07daeda..33728d3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
@@ -51,7 +51,7 @@ public class GridDhtPartitionExchangeId implements Message, Comparable<GridDhtPa
     @GridToStringExclude
     private UUID nodeId;
 
-    /** Event. */
+    /** Event type. */
     @GridToStringExclude
     private int evt;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index 5755bc7..6decb44 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -137,7 +137,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     @GridToStringExclude
     private final Set<UUID> remaining = new HashSet<>();
 
-    /** */
+    /** Guarded by this */
     @GridToStringExclude
     private int pendingSingleUpdates;
 
@@ -164,7 +164,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     @GridToStringExclude
     private final CountDownLatch evtLatch = new CountDownLatch(1);
 
-    /** */
+    /** Exchange future init method completes this future. */
     private GridFutureAdapter<Boolean> initFut;
 
     /** */
@@ -213,7 +213,10 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     /** Init timestamp. Used to track the amount of time spent to complete the future. */
     private long initTs;
 
-    /** */
+    /**
+     * Centralized affinity assignment required. Activated for node left of failed. For this mode crd will send full
+     * partitions maps to nodes using discovery (ring) instead of communication.
+     */
     private boolean centralizedAff;
 
     /** Change global state exception. */
@@ -765,7 +768,8 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
                     top.update(null,
                         clientTop.partitionMap(true),
                         clientTop.fullUpdateCounters(),
-                        Collections.<Integer>emptySet());
+                        Collections.<Integer>emptySet(),
+                        null);
                 }
             }
 
@@ -1204,7 +1208,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     }
 
     /**
-     * @param node Node.
+     * @param node Target Node.
      * @throws IgniteCheckedException If failed.
      */
     private void sendLocalPartitions(ClusterNode node) throws IgniteCheckedException {
@@ -1351,7 +1355,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     }
 
     /**
-     * @param oldestNode Oldest node.
+     * @param oldestNode Oldest node. Target node to send message to.
      */
     private void sendPartitions(ClusterNode oldestNode) {
         try {
@@ -1720,6 +1724,9 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     }
 
     /**
+     * Processing of received single message. Actual processing in future may be delayed if init method was not
+     * completed, see {@link #initDone()}
+     *
      * @param node Sender node.
      * @param msg Single partition info.
      */
@@ -1823,8 +1830,11 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     }
 
     /**
+     * Note this method performs heavy updatePartitionSingleMap operation, this operation is moved out from the
+     * synchronized block. Only count of such updates {@link #pendingSingleUpdates} is managed under critical section.
+     *
      * @param nodeId Sender node.
-     * @param msg Message.
+     * @param msg Partition single message.
      */
     private void processSingleMessage(UUID nodeId, GridDhtPartitionsSingleMessage msg) {
         if (msg.client()) {
@@ -1833,7 +1843,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
             return;
         }
 
-        boolean allReceived = false;
+        boolean allReceived = false; // Received all expected messages.
         boolean updateSingleMap = false;
 
         FinishState finishState0 = null;
@@ -2509,7 +2519,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
 
     /**
      * @param node Sender node.
-     * @param msg Message.
+     * @param msg Message with full partition info.
      */
     public void onReceivePartitionRequest(final ClusterNode node, final GridDhtPartitionsSingleRequest msg) {
         assert !cctx.kernalContext().clientNode() || msg.restoreState();
@@ -2803,7 +2813,8 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
                 grp.topology().update(resTopVer,
                     entry.getValue(),
                     cntrMap,
-                    msg.partsToReload(cctx.localNodeId(), grpId));
+                    msg.partsToReload(cctx.localNodeId(), grpId),
+                    null);
             }
             else {
                 ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(AffinityTopologyVersion.NONE);
@@ -2817,7 +2828,8 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
                     top.update(resTopVer,
                         entry.getValue(),
                         cntrMap,
-                        Collections.<Integer>emptySet());
+                        Collections.<Integer>emptySet(),
+                        null);
                 }
             }
         }
@@ -2912,7 +2924,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
     }
 
     /**
-     *
+     * Moves exchange future to state 'init done' using {@link #initFut}.
      */
     private void initDone() {
         while (!isDone()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
index 19ec0a8..edbfc23 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
@@ -129,7 +129,9 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
     /**
      * @param id Exchange ID.
      * @param lastVer Last version.
-     * @param topVer Topology version.
+     * @param topVer Topology version. For messages not related to exchange may be {@link AffinityTopologyVersion#NONE}.
+     * @param partHistSuppliers
+     * @param partsToReload
      */
     public GridDhtPartitionsFullMessage(@Nullable GridDhtPartitionExchangeId id,
         @Nullable GridCacheVersion lastVer,

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRabalancingDelayedPartitionMapExchangeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRabalancingDelayedPartitionMapExchangeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRabalancingDelayedPartitionMapExchangeSelfTest.java
index dc141db..f307b6a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRabalancingDelayedPartitionMapExchangeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRabalancingDelayedPartitionMapExchangeSelfTest.java
@@ -18,14 +18,17 @@
 package org.apache.ignite.internal.processors.cache.distributed.rebalancing;
 
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CacheRebalanceMode;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.managers.communication.GridIoMessage;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteInClosure;
@@ -45,12 +48,19 @@ public class GridCacheRabalancingDelayedPartitionMapExchangeSelfTest extends Gri
     /** */
     protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
 
-    /** */
+    /** Map of destination node ID to runnable with logic for real message sending.
+     * To apply real message sending use run method */
     private final ConcurrentHashMap8<UUID, Runnable> rs = new ConcurrentHashMap8<>();
 
-    /** */
+    /**
+     * Flag to redirect {@link GridDhtPartitionsFullMessage}s from real communication channel to {@link #rs} map.
+     * Applied only to messages not related to particular exchange
+     */
     private volatile boolean record = false;
 
+    /** */
+    private AtomicBoolean replay = new AtomicBoolean();
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
         IgniteConfiguration iCfg = super.getConfiguration(igniteInstanceName);
@@ -74,13 +84,26 @@ public class GridCacheRabalancingDelayedPartitionMapExchangeSelfTest extends Gri
             final IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
             final Object msg0 = ((GridIoMessage)msg).message();
 
+            if (log.isDebugEnabled())
+                log.debug("Message [thread=" + Thread.currentThread().getName() + ", msg=" + msg0 + ']');
+
             if (msg0 instanceof GridDhtPartitionsFullMessage && record &&
-                ((GridDhtPartitionsFullMessage)msg0).exchangeId() == null) {
-                rs.putIfAbsent(node.id(), new Runnable() {
+                ((GridDhtPartitionsAbstractMessage)msg0).exchangeId() == null) {
+                if (log.isDebugEnabled())
+                    log.debug("Record message [toNode=" + node.id() + ", msg=" + msg + "]");
+
+                assert !replay.get() : "Record of message is not allowed after replay";
+
+                Runnable prevValue = rs.putIfAbsent(node.id(), new Runnable() {
                     @Override public void run() {
+                        if (log.isDebugEnabled())
+                            log.debug("Replay: " + msg);
+
                         DelayableCommunicationSpi.super.sendMessage(node, msg, ackC);
                     }
                 });
+
+                assert prevValue == null : "Duplicate message registered to [" + node.id() + "]";
             }
             else
                 try {
@@ -94,10 +117,10 @@ public class GridCacheRabalancingDelayedPartitionMapExchangeSelfTest extends Gri
     }
 
     /**
-     * @throws Exception e.
+     * @throws Exception e if failed.
      */
     public void test() throws Exception {
-        IgniteKernal ignite = (IgniteKernal)startGrid(0);
+        IgniteEx ignite = startGrid(0);
 
         CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
 
@@ -144,10 +167,7 @@ public class GridCacheRabalancingDelayedPartitionMapExchangeSelfTest extends Gri
 
         awaitPartitionMapExchange();
 
-        for (Runnable r : rs.values())
-            r.run();
-
-        U.sleep(10000); // Enough time to process delayed GridDhtPartitionsFullMessages.
+        replayMessages();
 
         stopGrid(3); // Forces exchange at all nodes and cause assertion failure in case obsolete partition map accepted.
 
@@ -167,6 +187,22 @@ public class GridCacheRabalancingDelayedPartitionMapExchangeSelfTest extends Gri
         assert grid(2).context().cache().context().exchange().readyAffinityVersion().topologyVersion() > topVer2;
     }
 
+    /**
+     * Replays all saved messages from map, actual sent is performed.
+     *
+     * @throws IgniteInterruptedCheckedException If interrupted.
+     */
+    private void replayMessages() throws IgniteInterruptedCheckedException {
+        record = false;
+
+        for (Runnable r : rs.values())
+            r.run(); // Causes real messages sending.
+
+        assertTrue(replay.compareAndSet(false, true));
+
+        U.sleep(10000); // Enough time to process delayed GridDhtPartitionsFullMessages.
+    }
+
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
         super.afterTest();

http://git-wip-us.apache.org/repos/asf/ignite/blob/316312d2/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index 307456c..f5e8eef 100755
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
@@ -524,7 +524,8 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
     /**
      * @param waitEvicts If {@code true} will wait for evictions finished.
      * @param waitNode2PartUpdate If {@code true} will wait for nodes node2part info update finished.
-     * @param nodes Optional nodes.
+     * @param nodes Optional nodes. If {@code null} method will wait for all nodes, for non null collection nodes will
+     *      be filtered
      * @throws InterruptedException If interrupted.
      */
     @SuppressWarnings("BusyWait")
@@ -546,7 +547,8 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
     /**
      * @param waitEvicts If {@code true} will wait for evictions finished.
      * @param waitNode2PartUpdate If {@code true} will wait for nodes node2part info update finished.
-     * @param nodes Optional nodes.
+     * @param nodes Optional nodes. If {@code null} method will wait for all nodes, for non null collection nodes will
+     *      be filtered
      * @param printPartState If {@code true} will print partition state if evictions not happened.
      * @throws InterruptedException If interrupted.
      */


[11/50] [abbrv] ignite git commit: Fixed update sequence.

Posted by sb...@apache.org.
Fixed update sequence.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4907f7d8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4907f7d8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4907f7d8

Branch: refs/heads/ignite-6181-1
Commit: 4907f7d87a08fb5ca5d4d74ef8b61db0fd207855
Parents: a01837b
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Mon Aug 28 14:58:50 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Mon Aug 28 14:58:50 2017 +0300

----------------------------------------------------------------------
 .../dht/GridDhtPartitionTopologyImpl.java       | 59 +++++++++-----------
 1 file changed, 25 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4907f7d8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index e0f54b3..f7f71a1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -521,7 +521,7 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                             DiscoveryEvent evt = evts0.get(i);
 
                             if (ExchangeDiscoveryEvents.serverLeftEvent(evt))
-                                updateSeq = removeNode(evt.eventNode().id(), updateSeq);
+                                removeNode(evt.eventNode().id());
                         }
                     }
 
@@ -1243,6 +1243,9 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                                 ", curPart=" + mapString(part) +
                                 ", newPart=" + mapString(newPart) + ']');
                         }
+
+                        if (newPart.nodeId().equals(ctx.localNodeId()))
+                            updateSeq.setIfGreater(newPart.updateSequence());
                     }
                     else {
                         // If for some nodes current partition has a newer map,
@@ -1272,6 +1275,12 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                     }
                 }
             }
+            else {
+                GridDhtPartitionMap locNodeMap = partMap.get(ctx.localNodeId());
+
+                if (locNodeMap != null)
+                    updateSeq.setIfGreater(locNodeMap.updateSequence());
+            }
 
             if (!fullMapUpdated) {
                 if (log.isDebugEnabled()) {
@@ -1379,8 +1388,6 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
             long updateSeq = this.updateSeq.incrementAndGet();
 
-            node2part.newUpdateSequence(updateSeq);
-
             if (readyTopVer.initialized() && readyTopVer.equals(lastTopChangeVer)) {
                 AffinityAssignment  aff = grp.affinity().readyAffinity(readyTopVer);
 
@@ -1537,11 +1544,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
             GridDhtPartitionMap cur = node2part.get(parts.nodeId());
 
             if (force) {
-                if (cur != null && cur.topologyVersion().initialized()) {
+                if (cur != null && cur.topologyVersion().initialized())
                     parts.updateSequence(cur.updateSequence(), cur.topologyVersion());
-
-                    this.updateSeq.setIfGreater(cur.updateSequence());
-                }
             }
             else  if (isStaleUpdate(cur, parts)) {
                 U.warn(log, "Stale update for single partition map update (will ignore) [exchId=" + exchId +
@@ -1551,6 +1555,10 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                 return false;
             }
 
+            long updateSeq = this.updateSeq.incrementAndGet();
+
+            node2part.newUpdateSequence(updateSeq);
+
             boolean changed = false;
 
             if (cur == null || !cur.equals(parts))
@@ -1558,10 +1566,6 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
             node2part.put(parts.nodeId(), parts);
 
-            this.updateSeq.setIfGreater(parts.updateSequence());
-
-            long updateSeq = this.updateSeq.incrementAndGet();
-
             // During exchange diff is calculated after all messages are received and affinity initialized.
             if (exchId == null && !grp.isReplicated()) {
                 if (readyTopVer.initialized() && readyTopVer.compareTo(diffFromAffinityVer) >= 0) {
@@ -1915,14 +1919,6 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                 }
             }
 
-            long seqVal = 0;
-
-            if (updateSeq) {
-                seqVal = this.updateSeq.incrementAndGet();
-
-                node2part = new GridDhtPartitionFullMap(node2part, seqVal);
-            }
-
             for (Map.Entry<UUID, GridDhtPartitionMap> e : node2part.entrySet()) {
                 GridDhtPartitionMap partMap = e.getValue();
 
@@ -1938,14 +1934,19 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                         result.add(e.getKey());
                     }
 
-                    if (updateSeq)
-                        partMap.updateSequence(seqVal, partMap.topologyVersion());
+                    partMap.updateSequence(partMap.updateSequence() + 1, partMap.topologyVersion());
+
+                    if (partMap.nodeId().equals(ctx.localNodeId()))
+                        this.updateSeq.setIfGreater(partMap.updateSequence());
 
                     U.warn(log, "Partition has been scheduled for rebalancing due to outdated update counter " +
                         "[nodeId=" + e.getKey() + ", cacheOrGroupName=" + grp.cacheOrGroupName() +
                         ", partId=" + p + ", haveHistory=" + haveHistory + "]");
                 }
             }
+
+            if (updateSeq)
+                node2part = new GridDhtPartitionFullMap(node2part, this.updateSeq.incrementAndGet());
         }
         finally {
             lock.writeLock().unlock();
@@ -2115,11 +2116,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
     /**
      * @param nodeId Node to remove.
-     * @param updateSeq Update sequence.
-     *
-     * @return Update sequence.
      */
-    private long removeNode(UUID nodeId, long updateSeq) {
+    private void removeNode(UUID nodeId) {
         assert nodeId != null;
         assert lock.isWriteLockedByCurrentThread();
 
@@ -2130,14 +2128,9 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         ClusterNode loc = ctx.localNode();
 
         if (node2part != null) {
-            assert updateSeq >= node2part.updateSequence();
-
-            if (loc.equals(oldest) && !node2part.nodeId().equals(loc.id())) {
-                updateSeq++;
-
-                node2part = new GridDhtPartitionFullMap(loc.id(), loc.order(), updateSeq,
+            if (loc.equals(oldest) && !node2part.nodeId().equals(loc.id()))
+                node2part = new GridDhtPartitionFullMap(loc.id(), loc.order(), updateSeq.get(),
                     node2part, false);
-            }
             else
                 node2part = new GridDhtPartitionFullMap(node2part, node2part.updateSequence());
 
@@ -2156,8 +2149,6 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
             consistencyCheck();
         }
-
-        return updateSeq;
     }
 
     /** {@inheritDoc} */


[16/50] [abbrv] ignite git commit: IGNITE-6178 .NET: Fix PersistentStoreConfiguration.CheckpointingThreads default value

Posted by sb...@apache.org.
IGNITE-6178 .NET: Fix PersistentStoreConfiguration.CheckpointingThreads default value

This closes #2511

(cherry picked from commit 08a831f)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6c45edea
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6c45edea
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6c45edea

Branch: refs/heads/ignite-6181-1
Commit: 6c45edeaf83f94a9c0539d9768dd8be0e25dc36e
Parents: 5df5e2c
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Tue Aug 29 18:35:49 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Tue Aug 29 19:00:30 2017 +0300

----------------------------------------------------------------------
 .../PersistentStore/PersistentStoreConfiguration.cs                | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6c45edea/modules/platforms/dotnet/Apache.Ignite.Core/PersistentStore/PersistentStoreConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/PersistentStore/PersistentStoreConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/PersistentStore/PersistentStoreConfiguration.cs
index cac6cc8..8ba45e5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/PersistentStore/PersistentStoreConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/PersistentStore/PersistentStoreConfiguration.cs
@@ -32,7 +32,7 @@ namespace Apache.Ignite.Core.PersistentStore
         /// <summary>
         /// Default value for <see cref="CheckpointingThreads"/>.
         /// </summary>
-        public const int DefaultCheckpointingThreads = 1;
+        public const int DefaultCheckpointingThreads = 4;
 
         /// <summary>
         /// Default value for <see cref="CheckpointingFrequency"/>.


[38/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/047ac12c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/047ac12c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/047ac12c

Branch: refs/heads/ignite-6181-1
Commit: 047ac12ca65c0738fb95c742b5aaac49a1b37f71
Parents: a6faebd
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Wed Sep 13 19:49:50 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Wed Sep 13 19:49:50 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java    |  6 +++---
 .../cache/transactions/IgniteTxLocalAdapter.java   |  2 +-
 .../cache/transactions/IgniteTxManager.java        |  8 ++++----
 .../transactions/TxRollbackOnTimeoutTest.java      | 17 ++++++++++++++---
 4 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/047ac12c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index ee5797e..0a59cd0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -230,7 +230,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
-        if (this.timeout() > 0 && !implicit() && !cctx.tm().deadlockDetectionEnabled())
+        if (this.timeout() > 0 && !implicit())
             cctx.time().addTimeoutObject(this);
 
         initResult();
@@ -4014,7 +4014,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
      * Removes timeout handler used for eager rollbacks on timeouts.
      */
     private void removeTimeoutHandler() {
-        if (timeout() > 0 && !implicit() && !timedOut() && !cctx.tm().deadlockDetectionEnabled())
+        if (timeout() > 0 && !implicit() && !timedOut())
             cctx.time().removeTimeoutObject(this);
     }
 
@@ -4025,7 +4025,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public long endTime() {
-        return startTime() + timeout();
+        return startTime() + timeout() - 50;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/047ac12c/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 7f30981..e7ebaae 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
@@ -1237,7 +1237,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter implements Ig
      * @throws IgniteCheckedException If transaction check failed.
      */
     protected void checkValid() throws IgniteCheckedException {
-        if (local() && !dht() && remainingTime() == -1 && cctx.tm().deadlockDetectionEnabled())
+        if (local() && !dht() && remainingTime() == -1)
             state(MARKED_ROLLBACK, true);
 
         if (isRollbackOnly()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/047ac12c/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 db7a600..fd4f1b2 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
@@ -1422,10 +1422,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
-            if (!tx.system())
-                if (deadlockDetectionEnabled() || !tx.timedOut())
-                    threadMap.remove(tx.threadId(), tx);
-            else {
+            if (!tx.system()) {
                 Integer cacheId = tx.txState().firstCacheId();
 
                 if (cacheId != null)
@@ -1442,6 +1439,9 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                     }
                 }
             }
+            else if (!tx.timedOut())
+                threadMap.remove(tx.threadId(), tx);
+
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/047ac12c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 847f2b0..d22b682 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -37,6 +37,7 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionDeadlockException;
 import org.apache.ignite.transactions.TransactionIsolation;
 import org.apache.ignite.transactions.TransactionTimeoutException;
 import org.jsr166.ThreadLocalRandom8;
@@ -100,14 +101,14 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     @Override protected void beforeTestsStarted() throws Exception {
         super.beforeTestsStarted();
 
-        System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
+        //System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
     }
 
     /** {@inheritDoc} */
     @Override protected void afterTestsStopped() throws Exception {
         super.afterTestsStopped();
 
-        System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
+        //System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
     }
 
     /** {@inheritDoc} */
@@ -348,12 +349,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     U.awaitQuiet(l);
 
                     grid(1).cache(CACHE_NAME).put(1, 1);
+
+                    tx.commit();
                 }
+
             }
 
         }, 1, "Second");
 
-        fut1.get();
+        try {
+            fut1.get();
+
+            fail();
+        }
+        catch (Exception e) {
+            assertTrue(X.hasCause(e, TransactionDeadlockException.class));
+        }
 
         fut2.get();
 


[47/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ea5cd0dc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ea5cd0dc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ea5cd0dc

Branch: refs/heads/ignite-6181-1
Commit: ea5cd0dc9eaaeeca5c36726bf7fdff32fc1e2b67
Parents: 1dcb42b
Author: ascherbakoff <al...@gmail.com>
Authored: Sat Sep 16 16:00:41 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Sat Sep 16 16:00:41 2017 +0300

----------------------------------------------------------------------
 .../IgniteOptimisticTxSuspendResumeTest.java      |  2 +-
 .../transactions/TxRollbackOnTimeoutTest.java     | 18 +++++++-----------
 2 files changed, 8 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ea5cd0dc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
index deb58bc..7b88b6d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
@@ -54,7 +54,7 @@ import static org.apache.ignite.transactions.TransactionState.SUSPENDED;
  */
 public class IgniteOptimisticTxSuspendResumeTest extends GridCommonAbstractTest {
     /** Transaction timeout. */
-    private static final long TX_TIMEOUT = 100;
+    private static final long TX_TIMEOUT = 300;
 
     /** Future timeout */
     private static final int FUT_TIMEOUT = 5000;

http://git-wip-us.apache.org/repos/asf/ignite/blob/ea5cd0dc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index c55f59e..360cba1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.cache.transactions;
 
-import java.util.Collections;
 import java.util.concurrent.CountDownLatch;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
@@ -54,10 +53,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     private static final long TX_MIN_TIMEOUT = 1;
 
     /** */
-    private static final long TX_TIMEOUT = 300;
-
-    /** */
-    private static final long TX_DEFAULT_TIMEOUT = 3_000;
+    private static final long TX_TIMEOUT = 500;
 
     /** */
     private static final String CACHE_NAME = "test";
@@ -83,7 +79,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
         TransactionConfiguration txCfg = new TransactionConfiguration();
-        txCfg.setDefaultTxTimeout(TX_DEFAULT_TIMEOUT);
+        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
 
         cfg.setTransactionConfiguration(txCfg);
 
@@ -257,13 +253,13 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {
                 try {
-                    try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 2)) {
+                    try (Transaction tx = node1.transactions().txStart()) {
                         node1.cache(CACHE_NAME).put(1, 1);
 
                         l.countDown();
                         U.awaitQuiet(l);
 
-                        node1.cache(CACHE_NAME).putAll(Collections.singletonMap(2, 2));
+                        node1.cache(CACHE_NAME).put(2, 2);
 
                         tx.commit();
 
@@ -294,8 +290,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         fut1.get();
         fut2.get();
 
-        assertTrue(node1.cache(CACHE_NAME).containsKey(1));
-        assertTrue(node1.cache(CACHE_NAME).containsKey(2));
+        assertTrue("Expecting commited key 2", node1.cache(CACHE_NAME).containsKey(2));
+        assertTrue("Expecting commited key 1", node1.cache(CACHE_NAME).containsKey(1));
     }
 
     /**
@@ -350,7 +346,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         try (Transaction tx = near.transactions().txStart(concurrency, isolation, TX_TIMEOUT, 1)) {
             near.cache(CACHE_NAME).put(key, val);
 
-            U.sleep(TX_TIMEOUT * 3);
+            U.sleep(TX_TIMEOUT * 2);
 
             try {
                 tx.commit();


[24/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b770c0a1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b770c0a1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b770c0a1

Branch: refs/heads/ignite-6181-1
Commit: b770c0a1d6b2853c8b629a5ac08ecfbc00486d35
Parents: 6a92846
Author: ascherbakoff <al...@gmail.com>
Authored: Tue Sep 5 16:50:42 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Tue Sep 5 16:50:42 2017 +0300

----------------------------------------------------------------------
 .../apache/ignite/IgniteSystemProperties.java   |  6 -----
 .../cache/distributed/near/GridNearTxLocal.java | 24 +++++---------------
 .../cache/transactions/IgniteTxHandler.java     |  8 +++----
 .../transactions/IgniteTxLocalAdapter.java      |  1 -
 .../cache/transactions/IgniteTxManager.java     | 11 +++------
 .../transactions/TxRollbackOnTimeoutTest.java   | 14 ------------
 .../ignite/testsuites/IgniteCacheTestSuite.java |  3 +++
 7 files changed, 16 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index c22d552..d3cba2b 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -706,12 +706,6 @@ public final class IgniteSystemProperties {
     public static final String IGNITE_ENABLE_FORCIBLE_NODE_KILL = "IGNITE_ENABLE_FORCIBLE_NODE_KILL";
 
     /**
-     * If this property is set, a node will track transaction initiators, printing them in tx timeout error.
-     * Useful for debugging.
-     */
-    public static final String IGNITE_TRACK_TRANSACTION_INITIATOR = "IGNITE_TRACK_TRANSACTION_INITIATOR";
-
-    /**
      * Enforces singleton.
      */
     private IgniteSystemProperties() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index f5ecdd8..965a502 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -34,7 +34,6 @@ import javax.cache.CacheException;
 import javax.cache.expiry.ExpiryPolicy;
 import javax.cache.processor.EntryProcessor;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.NodeStoppingException;
@@ -116,17 +115,11 @@ import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
 import static org.apache.ignite.transactions.TransactionState.ROLLING_BACK;
 import static org.apache.ignite.transactions.TransactionState.UNKNOWN;
 
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_TRACK_TRANSACTION_INITIATOR;
-
 /**
  * Replicated user transaction.
  */
 @SuppressWarnings("unchecked")
 public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeoutObject, AutoCloseable {
-    /** {@link IgniteSystemProperties#IGNITE_TRACK_TRANSACTION_INITIATOR} */
-    private static final boolean TRACK_TRANSACTION_INITIATOR =
-        IgniteSystemProperties.getBoolean(IGNITE_TRACK_TRANSACTION_INITIATOR, false);
-
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -182,9 +175,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     @GridToStringExclude
     private TransactionProxyImpl proxy;
 
-    /** */
-    private transient Exception trackE;
-
     /**
      * Empty constructor required for {@link Externalizable}.
      */
@@ -240,12 +230,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         mappings = implicitSingle ? new IgniteTxMappingsSingleImpl() : new IgniteTxMappingsImpl();
 
-        if (this.timeout > 0) {
-            if (TRACK_TRANSACTION_INITIATOR)
-                trackE = new Exception();
-
+        if (this.timeout > 0)
             cctx.time().addTimeoutObject(this);
-        }
 
         initResult();
     }
@@ -4084,9 +4070,11 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     /** {@inheritDoc} */
     @Override public void onTimeout() {
         if (state(MARKED_ROLLBACK, true)) {
-            log.error("Transaction is timed out and will be rolled back: [" + this + ']', trackE);
-
-            rollbackNearTxLocalAsync();
+            cctx.kernalContext().closure().runLocalSafe(new Runnable() {
+                @Override public void run() {
+                    rollbackNearTxLocalAsync();
+                }
+            });
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/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 6f96b4b..de0e415 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
@@ -673,8 +673,8 @@ public class IgniteTxHandler {
      * @param res Response.
      */
     private void processNearTxFinishResponse(UUID nodeId, GridNearTxFinishResponse res) {
-        //if (txFinishMsgLog.isDebugEnabled())
-            txFinishMsgLog.info("Received near finish response [txId=" + res.xid() + ", node=" + nodeId + ']');
+        if (txFinishMsgLog.isDebugEnabled())
+            txFinishMsgLog.debug("Received near finish response [txId=" + res.xid() + ", node=" + nodeId + ']');
 
         ctx.tm().onFinishedRemote(nodeId, res.threadId());
 
@@ -783,8 +783,8 @@ public class IgniteTxHandler {
         UUID nodeId,
         GridNearTxFinishRequest req
     ) {
-        //if (txFinishMsgLog.isDebugEnabled())
-            txFinishMsgLog.info("Received near finish request [txId=" + req.version() + ", node=" + nodeId + ']');
+        if (txFinishMsgLog.isDebugEnabled())
+            txFinishMsgLog.debug("Received near finish request [txId=" + req.version() + ", node=" + nodeId + ']');
 
         IgniteInternalFuture<IgniteInternalTx> fut = finish(nodeId, null, req);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/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 ea105ae..e6e19e3 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
@@ -92,7 +92,6 @@ import static org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE;
 import static org.apache.ignite.internal.processors.dr.GridDrType.DR_PRIMARY;
 import static org.apache.ignite.transactions.TransactionState.COMMITTED;
 import static org.apache.ignite.transactions.TransactionState.COMMITTING;
-import static org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK;
 import static org.apache.ignite.transactions.TransactionState.PREPARING;
 import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK;
 import static org.apache.ignite.transactions.TransactionState.ROLLING_BACK;

http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/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 ee7d922..7ff36ac 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
@@ -31,7 +31,6 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteClientDisconnectedException;
-import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.cluster.ClusterNode;
@@ -70,7 +69,6 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearOpti
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
-import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter;
 import org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException;
@@ -1425,11 +1423,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
             if (!tx.system()) {
-                /**
-                 * Timed out local transactions are cleared in {@link #onLocalClose}
-                 * TODO reduce heap size of timed out transaction.
-                 */
-                if (!(tx.timedOut() && tx.pessimistic() && tx.local() && !tx.dht()))
+                /** Timed out local transactions are cleared in {@link #onLocalClose}. */
+                if (!tx.timedOut() || !tx.pessimistic())
                     threadMap.remove(tx.threadId(), tx);
             }
             else {
@@ -2323,7 +2318,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Remove thread completely.
+     * Callback for closing local transaction.
      * @param threadId Thread ID.
      * @param tx Local transaction.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index bb1bbc7..84e85ff 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -86,20 +86,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        super.beforeTestsStarted();
-
-        System.setProperty(IgniteSystemProperties.IGNITE_TRACK_TRANSACTION_INITIATOR, "true");
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        super.afterTestsStopped();
-
-        System.clearProperty(IgniteSystemProperties.IGNITE_TRACK_TRANSACTION_INITIATOR);
-    }
-
-    /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b770c0a1/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index dea0eb0..c06647a 100755
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -134,6 +134,7 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCa
 import org.apache.ignite.internal.processors.cache.local.GridCacheLocalTxExceptionSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheEntryProcessorExternalizableFailedTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheEntryProcessorNonSerializableTest;
+import org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamerImplSelfTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamerMultiThreadedSelfTest;
@@ -314,6 +315,8 @@ public class IgniteCacheTestSuite extends TestSuite {
 
         suite.addTestSuite(IgniteIncompleteCacheObjectSelfTest.class);
 
+        suite.addTestSuite(TxRollbackOnTimeoutTest.class);
+
         return suite;
     }
 }


[37/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a6faebdc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a6faebdc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a6faebdc

Branch: refs/heads/ignite-6181-1
Commit: a6faebdc36bd163e59733ba0764c3059f8286afc
Parents: b017713
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Wed Sep 13 17:55:23 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Wed Sep 13 17:55:23 2017 +0300

----------------------------------------------------------------------
 .../transactions/TxRollbackOnTimeoutTest.java   | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a6faebdc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 20f6695..847f2b0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -318,6 +318,50 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /**
+     * Tests tx timeout on deadlock.
+     *
+     * @throws Exception
+     */
+    public void testTimeoutOnDeadlock() throws Exception {
+        final CountDownLatch l = new CountDownLatch(2);
+
+        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                try(Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 1)) {
+                    grid(0).cache(CACHE_NAME).put(1, 1);
+
+                    l.countDown();
+                    U.awaitQuiet(l);
+
+                    grid(0).cache(CACHE_NAME).put(2, 2);
+                }
+
+            }
+        }, 1, "First");
+
+        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                try(Transaction tx = grid(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 1)) {
+                    grid(1).cache(CACHE_NAME).put(2, 2);
+
+                    l.countDown();
+                    U.awaitQuiet(l);
+
+                    grid(1).cache(CACHE_NAME).put(1, 1);
+                }
+            }
+
+        }, 1, "Second");
+
+        fut1.get();
+
+        fut2.get();
+
+        assertTrue(grid(0).cache(CACHE_NAME).containsKey(1));
+        assertTrue(grid(0).cache(CACHE_NAME).containsKey(2));
+    }
+
+    /**
      * @param concurrency Concurrency.
      * @param isolation Isolation.
      *


[36/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b0177135
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b0177135
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b0177135

Branch: refs/heads/ignite-6181-1
Commit: b01771355b697b9bd4b23ce6c807d777510b87c0
Parents: 225d4f5
Author: ascherbakoff <al...@gmail.com>
Authored: Tue Sep 12 23:03:30 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Tue Sep 12 23:03:30 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/IgniteTransactions.java   |  3 +-
 .../configuration/TransactionConfiguration.java |  6 ---
 .../near/GridNearOptimisticTxPrepareFuture.java |  3 +-
 .../cache/distributed/near/GridNearTxLocal.java |  3 +-
 .../transactions/IgniteTransactionsImpl.java    |  2 +-
 .../cache/transactions/IgniteTxManager.java     |  7 +--
 ...niteTxConfigCacheForceTxTimeoutSelfTest.java | 43 +++++++++++++++
 .../cache/IgniteTxConfigCacheSelfTest.java      |  2 +-
 .../transactions/TxRollbackOnTimeoutTest.java   | 55 +++++++++++++++++++-
 .../ignite/testsuites/IgniteCacheTestSuite.java |  2 +
 .../hadoop/impl/HadoopTxConfigCacheTest.java    |  2 +-
 11 files changed, 110 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java b/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
index 9da862d..dfe6a1a 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteTransactions.java
@@ -77,8 +77,7 @@ public interface IgniteTransactions {
      *
      * @param concurrency Concurrency.
      * @param isolation Isolation.
-     * @param timeout Timeout. See {@link TransactionConfiguration#setDefaultTxTimeout(long)}
-     * for additional info on transaction timeouts.
+     * @param timeout Timeout.
      * @param txSize Number of entries participating in transaction (may be approximate).
      * @return New transaction.
      * @throws IllegalStateException If transaction is already started by this thread.

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
index cbd2d82..0063afc 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
@@ -19,7 +19,6 @@ package org.apache.ignite.configuration;
 
 import java.io.Serializable;
 import javax.cache.configuration.Factory;
-import org.apache.ignite.IgniteTransactions;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
@@ -182,11 +181,6 @@ public class TransactionConfiguration implements Serializable {
     /**
      * Sets default transaction timeout in milliseconds. By default this value is defined by {@link
      * #DFLT_TRANSACTION_TIMEOUT}.
-     * <p>
-     * If transaction's execution is not completed by calling {@link Transaction#commit()},
-     * {@link Transaction#rollback()} or {@link Transaction#close()}
-     * before timeout expires, it will be rolled back asynchronously. All further caches operations will fail until new
-     * explicit transaction is started in current thread by calling {@link IgniteTransactions#txStart()}.
      *
      * @param dfltTxTimeout Default transaction timeout.
      * @return {@code this} for chaining.

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
index 2c23a7a..822651c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java
@@ -913,8 +913,7 @@ public class GridNearOptimisticTxPrepareFuture extends GridNearOptimisticTxPrepa
                 return;
 
             if (RCV_RES_UPD.compareAndSet(this, 0, 1)) {
-                if (parent.cctx.tm().deadlockDetectionEnabled() &&
-                    (parent.tx.remainingTime() == -1 || res.error() instanceof IgniteTxTimeoutCheckedException)) {
+                if (parent.tx.remainingTime() == -1 || res.error() instanceof IgniteTxTimeoutCheckedException) {
                     parent.onTimeout();
 
                     return;

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 2308d71..ee5797e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -4033,7 +4033,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (state(MARKED_ROLLBACK, true)) {
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
-                    log().error("Transaction is timed out and will be rolled back: " + GridNearTxLocal.this);
+                    log().error("Transaction is timed out and will be rolled back [timeout=" + timeout() +
+                            ", tx=" + GridNearTxLocal.this + ']');
 
                     rollbackNearTxLocalAsync();
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 997fd8c..7adfb82 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -154,7 +154,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
         try {
             GridNearTxLocal tx = cctx.tm().userTx(sysCacheCtx);
 
-            // Allow to override timed out transactions.
+            // Allow overriding timed out transaction.
             if (tx != null && !tx.timedOut())
                 throw new IllegalStateException("Failed to start new transaction " +
                     "(current thread already has a transaction): " + tx);

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/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 2214e10..db7a600 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
@@ -1422,8 +1422,9 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      */
     private void clearThreadMap(IgniteInternalTx tx) {
         if (tx.local() && !tx.dht()) {
-            if (!tx.system() && !tx.timedOut())
-                threadMap.remove(tx.threadId(), tx);
+            if (!tx.system())
+                if (deadlockDetectionEnabled() || !tx.timedOut())
+                    threadMap.remove(tx.threadId(), tx);
             else {
                 Integer cacheId = tx.txState().firstCacheId();
 
@@ -1711,7 +1712,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * Remove tx from map.
+     * Removes tx from map.
      */
     public void onLocalClose(IgniteInternalTx tx) {
         threadMap.remove(tx.threadId(), tx);

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
new file mode 100644
index 0000000..34a1dc5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheForceTxTimeoutSelfTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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 static org.apache.ignite.IgniteSystemProperties.IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS;
+
+/**
+ * Test checks that grid transaction configuration doesn't influence system caches.
+ */
+public class IgniteTxConfigCacheForceTxTimeoutSelfTest extends IgniteTxConfigCacheSelfTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        System.setProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS, "0");
+
+        super.beforeTestsStarted();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        System.clearProperty(IGNITE_TX_DEADLOCK_DETECTION_MAX_ITERS);
+    }
+
+    @Override public void testUserTxTimeout() throws Exception {
+        super.testUserTxTimeout();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
index f2e17e4..af09858 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
@@ -63,7 +63,7 @@ public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest {
     private static final String CACHE_NAME = "cache_name";
 
     /** Timeout of transaction. */
-    private static final long TX_TIMEOUT = 100;
+    private static final long TX_TIMEOUT = 300;
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 0a2601d..20f6695 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -227,6 +227,59 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     }
 
     /**
+     * Tests if deadlock is unblocked on timeout.
+     * @throws Exception
+     */
+    public void testDeadlockUnblockedOnTimeout() throws Exception {
+        final CountDownLatch l = new CountDownLatch(2);
+
+        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    try (Transaction tx = ignite(0).transactions().txStart()) {
+                        ignite(0).cache(CACHE_NAME).put(1, 1);
+
+                        l.countDown();
+                        U.awaitQuiet(l);
+
+                        ignite(0).cache(CACHE_NAME).put(2, 2);
+
+                        tx.commit();
+
+                        fail();
+                    }
+                } catch (CacheException e) {
+                    // No-op.
+                }
+            }
+        }, 1, "First");
+
+        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+            @Override public void run() {
+                U.awaitQuiet(blocked);
+
+                try (Transaction tx = ignite(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 1)) {
+                    ignite(1).cache(CACHE_NAME).put(2, 2);
+
+                    l.countDown();
+                    U.awaitQuiet(l);
+
+                    ignite(1).cache(CACHE_NAME).put(1, 1);
+
+                    tx.commit();
+                }
+            }
+        }, 1, "Second");
+
+        fut1.get();
+        fut2.get();
+
+        assertTrue(ignite(0).cache(CACHE_NAME).containsKey(1));
+        assertTrue(ignite(0).cache(CACHE_NAME).containsKey(2));
+    }
+
+    /**
      * Tests timeout object cleanup on tx commit.
      *
      * @throws Exception If failed.
@@ -442,7 +495,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     tx.commit();
                 }
             }
-        }, 2, "Second");
+        }, 1, "Second");
 
         try {
             fut1.get();

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index c06647a..35331e9 100755
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -102,6 +102,7 @@ import org.apache.ignite.internal.processors.cache.IgniteClientAffinityAssignmen
 import org.apache.ignite.internal.processors.cache.IgniteIncompleteCacheObjectSelfTest;
 import org.apache.ignite.internal.processors.cache.IgnitePutAllLargeBatchSelfTest;
 import org.apache.ignite.internal.processors.cache.IgnitePutAllUpdateNonPreloadedPartitionSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheForceTxTimeoutSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheSelfTest;
 import org.apache.ignite.internal.processors.cache.context.IgniteCacheAtomicExecutionContextTest;
 import org.apache.ignite.internal.processors.cache.context.IgniteCacheContinuousExecutionContextTest;
@@ -302,6 +303,7 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(CachePutEventListenerErrorSelfTest.class);
 
         suite.addTestSuite(IgniteTxConfigCacheSelfTest.class);
+        suite.addTestSuite(IgniteTxConfigCacheForceTxTimeoutSelfTest.class);
 
         suite.addTestSuite(CacheTxFastFinishTest.class);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0177135/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
index e85baed..554c489 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/HadoopTxConfigCacheTest.java
@@ -25,7 +25,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
 /**
  * Test checks whether hadoop system cache doesn't use user defined TX config.
  */
-public class HadoopTxConfigCacheTest  extends IgniteTxConfigCacheSelfTest {
+public class HadoopTxConfigCacheTest extends IgniteTxConfigCacheSelfTest {
     /**
      * Success if system caches weren't timed out.
      *


[46/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1dcb42ba
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1dcb42ba
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1dcb42ba

Branch: refs/heads/ignite-6181-1
Commit: 1dcb42ba9b5f20214d42ebfc0773b54f636cf2ec
Parents: eebaa6b
Author: Aleksei Scherbakov <al...@gmail.com>
Authored: Fri Sep 15 19:45:59 2017 +0300
Committer: Aleksei Scherbakov <al...@gmail.com>
Committed: Fri Sep 15 19:45:59 2017 +0300

----------------------------------------------------------------------
 .../cache/transactions/TxRollbackOnTimeoutTest.java      | 11 -----------
 1 file changed, 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1dcb42ba/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index cdf1f00..c55f59e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -249,17 +249,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if deadlock is resolved on timeout with correct message.
-     *
-     * @throws Exception If failed.
-     */
-//    public void testDeadlockUnblockedOnTimeout4() throws Exception {
-//        Ignite client = startGrid("client");
-//
-//        testDeadlockUnblockedOnTimeout0(client, ignite(0));
-//    }
-
-    /**
-     * Tests if deadlock is resolved on timeout with correct message.
      * @throws Exception
      */
     private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2) throws Exception {


[15/50] [abbrv] ignite git commit: Minor. Typo fixed.

Posted by sb...@apache.org.
Minor. Typo fixed.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5df5e2cc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5df5e2cc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5df5e2cc

Branch: refs/heads/ignite-6181-1
Commit: 5df5e2cc0e42a073de9107014876a4b646dd1b65
Parents: ac7f212
Author: Andrey Gura <ag...@apache.org>
Authored: Tue Aug 29 13:14:02 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Tue Aug 29 13:14:56 2017 +0300

----------------------------------------------------------------------
 .../internal/processors/query/h2/opt/GridLuceneDirectory.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5df5e2cc/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneDirectory.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneDirectory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneDirectory.java
index f92b510..96869c4 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneDirectory.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneDirectory.java
@@ -199,7 +199,7 @@ public class GridLuceneDirectory extends BaseDirectory implements Accountable {
             catch (IOException e) {
                 if (errs == null)
                     errs = new IgniteException("Failed to close index directory."+
-                    " Some index readers was closed properly, that may leads memory leak.");
+                    " Some index readers weren't closed properly, that may leads memory leak.");
 
                 errs.addSuppressed(e);
             }


[50/50] [abbrv] ignite git commit: ignite-6181-1

Posted by sb...@apache.org.
ignite-6181-1


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2468e009
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2468e009
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2468e009

Branch: refs/heads/ignite-6181-1
Commit: 2468e009032d36404f372d1f3bd616d9320efae4
Parents: f950cb1
Author: sboikov <sb...@gridgain.com>
Authored: Tue Sep 19 16:45:29 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Sep 19 17:37:31 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/CacheMetrics.java   |   2 +
 .../processors/cache/CacheMetricsImpl.java      |   4 +-
 .../processors/cache/GridCacheAdapter.java      |  18 +-
 .../processors/cache/GridCacheMapEntry.java     |   9 +-
 .../cache/GridCacheSharedContext.java           |  11 +-
 .../dht/colocated/GridDhtColocatedCache.java    |   4 +-
 .../colocated/GridDhtColocatedLockFuture.java   |  90 ++++---
 .../distributed/near/GridNearLockFuture.java    |  58 +++--
 ...ridNearOptimisticTxPrepareFutureAdapter.java |   2 +-
 .../near/GridNearTransactionalCache.java        |   2 +-
 .../cache/distributed/near/GridNearTxLocal.java |  71 ++++--
 .../cache/transactions/IgniteTxAdapter.java     |   4 +-
 .../cache/transactions/IgniteTxHandler.java     |   4 +-
 .../cache/transactions/IgniteTxManager.java     | 230 ++++++------------
 .../timeout/GridTimeoutProcessor.java           |  17 +-
 .../IgniteCacheThreadLocalTxTest.java           | 179 ++++++++++++++
 .../IgniteOptimisticTxSuspendResumeTest.java    |   1 +
 ...ollbackOnTimeoutNoDeadlockDetectionTest.java |   4 +-
 .../transactions/TxRollbackOnTimeoutTest.java   | 238 ++++++++-----------
 .../ignite/testsuites/IgniteCacheTestSuite.java |   4 +-
 20 files changed, 550 insertions(+), 402 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/cache/CacheMetrics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheMetrics.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheMetrics.java
index 20ea692..470645b 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheMetrics.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheMetrics.java
@@ -269,6 +269,7 @@ public interface CacheMetrics {
      *
      * @return Thread map size.
      */
+    @Deprecated
     public int getTxThreadMapSize();
 
     /**
@@ -318,6 +319,7 @@ public interface CacheMetrics {
      *
      * @return DHT thread map size.
      */
+    @Deprecated
     public int getTxDhtThreadMapSize();
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
index d03a6f8..d608435 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
@@ -298,7 +298,7 @@ public class CacheMetricsImpl implements CacheMetrics {
 
     /** {@inheritDoc} */
     @Override public int getTxThreadMapSize() {
-        return cctx.tm().threadMapSize();
+        return 0;
     }
 
     /** {@inheritDoc} */
@@ -328,7 +328,7 @@ public class CacheMetricsImpl implements CacheMetrics {
 
     /** {@inheritDoc} */
     @Override public int getTxDhtThreadMapSize() {
-        return cctx.isNear() && dhtCtx != null ? dhtCtx.tm().threadMapSize() : -1;
+        return 0;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index fed716c..ebd2ab8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -1857,7 +1857,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                 return new GridFinishedFuture<>(e);
             }
 
-            tx = ctx.tm().threadLocalTx(ctx.systemTx() ? ctx : null);
+            tx = ctx.tm().currentThreadTx(ctx);
         }
 
         if (tx == null || tx.implicit()) {
@@ -3236,7 +3236,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
     /** {@inheritDoc} */
     @Nullable @Override public GridNearTxLocal tx() {
-        return ctx.tm().threadLocalTx(ctx);
+        return ctx.tm().currentThreadTx(ctx);
     }
 
     /** {@inheritDoc} */
@@ -3965,6 +3965,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      */
     @SuppressWarnings("unchecked")
     IgniteInternalFuture<IgniteInternalTx> commitTxAsync(final GridNearTxLocal tx) {
+        ctx.tm().clearThreadLocalTx(tx);
+
         FutureHolder holder = lastFut.get();
 
         holder.lock();
@@ -3976,7 +3978,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                 IgniteInternalFuture<IgniteInternalTx> f = new GridEmbeddedFuture<>(fut,
                     new C2<Object, Exception, IgniteInternalFuture<IgniteInternalTx>>() {
                         @Override public IgniteInternalFuture<IgniteInternalTx> apply(Object o, Exception e) {
-                            return tx.commitNearTxLocalAsync();
+                            return tx.commitNearTxLocalAsync(false);
                         }
                     });
 
@@ -3985,7 +3987,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                 return f;
             }
 
-            IgniteInternalFuture<IgniteInternalTx> f = tx.commitNearTxLocalAsync();
+            IgniteInternalFuture<IgniteInternalTx> f = tx.commitNearTxLocalAsync(false);
 
             saveFuture(holder, f, /*retry*/false);
 
@@ -4030,7 +4032,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         awaitLastFut();
 
-        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
+        GridNearTxLocal tx = ctx.tm().currentThreadTx(ctx);
 
         if (tx == null || tx.implicit()) {
             TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
@@ -4126,7 +4128,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         if (log.isDebugEnabled())
             log.debug("Performing async op: " + op);
 
-        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
+        GridNearTxLocal tx = ctx.tm().currentThreadTx(ctx);
 
         CacheOperationContext opCtx = ctx.operationContextPerCall();
 
@@ -4208,7 +4210,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                                     }
                                     catch (IgniteCheckedException e1) {
                                         try {
-                                            tx0.rollbackNearTxLocalAsync();
+                                            tx0.rollbackNearTxLocalAsync(false);
                                         }
                                         catch (Throwable e2) {
                                             e1.addSuppressed(e2);
@@ -4239,7 +4241,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                     }
                     catch (IgniteCheckedException e1) {
                         try {
-                            tx0.rollbackNearTxLocalAsync();
+                            tx0.rollbackNearTxLocalAsync(false);
                         }
                         catch (Throwable e2) {
                             e1.addSuppressed(e2);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index d991c86..0f54762 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -2451,7 +2451,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
     /** {@inheritDoc} */
     @Nullable @Override public CacheObject peek(@Nullable IgniteCacheExpiryPolicy plc)
         throws GridCacheEntryRemovedException, IgniteCheckedException {
-        IgniteInternalTx tx = cctx.tm().localTxx();
+        IgniteInternalTx tx = cctx.tm().localTx();
 
         AffinityTopologyVersion topVer = tx != null ? tx.topologyVersion() : cctx.affinity().affinityTopologyVersion();
 
@@ -3098,10 +3098,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
      * @return Current transaction.
      */
     private IgniteTxLocalAdapter currentTx() {
-        if (cctx.isDht())
-            return cctx.dht().near().context().tm().localTx();
-        else
-            return cctx.tm().localTx();
+        return cctx.tm().localTx();
     }
 
     /** {@inheritDoc} */
@@ -3479,7 +3476,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
             }
         }
 
-        IgniteInternalTx tx = cctx.tm().localTxx();
+        IgniteInternalTx tx = cctx.tm().localTx();
 
         if (tx != null) {
             IgniteTxEntry e = tx.entry(txKey());

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
index 3fb63dc..604cfe3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
@@ -886,12 +886,13 @@ public class GridCacheSharedContext<K, V> {
      * @return Not null topology version if current thread holds lock preventing topology change.
      */
     @Nullable public AffinityTopologyVersion lockedTopologyVersion(IgniteInternalTx ignore) {
-        long threadId = Thread.currentThread().getId();
+        AffinityTopologyVersion topVer = txMgr.lockedTopologyVersion(ignore);
 
-        AffinityTopologyVersion topVer = txMgr.lockedTopologyVersion(threadId, ignore);
+        if (topVer == null) {
+            long threadId = Thread.currentThread().getId();
 
-        if (topVer == null)
             topVer = mvccMgr.lastExplicitLockTopologyVersion(threadId);
+        }
 
         return topVer;
     }
@@ -926,7 +927,7 @@ public class GridCacheSharedContext<K, V> {
         if (ctx == null) {
             tx.txState().awaitLastFut(this);
 
-            return tx.commitNearTxLocalAsync();
+            return tx.commitNearTxLocalAsync(true);
         }
         else
             return ctx.cache().commitTxAsync(tx);
@@ -940,7 +941,7 @@ public class GridCacheSharedContext<K, V> {
     public IgniteInternalFuture rollbackTxAsync(GridNearTxLocal tx) throws IgniteCheckedException {
         tx.txState().awaitLastFut(this);
 
-        return tx.rollbackNearTxLocalAsync();
+        return tx.rollbackNearTxLocalAsync(true);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index c72f53e..de4a177 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -186,7 +186,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
         if (keyCheck)
             validateCacheKey(key);
 
-        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
+        GridNearTxLocal tx = ctx.tm().currentThreadTx(ctx);
 
         final CacheOperationContext opCtx = ctx.operationContextPerCall();
 
@@ -273,7 +273,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
         if (keyCheck)
             validateCacheKeys(keys);
 
-        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
+        GridNearTxLocal tx = ctx.tm().currentThreadTx(ctx);
 
         final CacheOperationContext opCtx = ctx.operationContextPerCall();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
index 82b0e6e..e5f94a5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
@@ -54,6 +54,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLock
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.transactions.TxDeadlock;
@@ -147,7 +148,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
     private final Map<KeyCacheObject, IgniteBiTuple<GridCacheVersion, CacheObject>> valMap;
 
     /** Trackable flag (here may be non-volatile). */
-    private boolean trackable = true;
+    private boolean trackable;
 
     /** TTL for create operation. */
     private final long createTtl;
@@ -226,12 +227,6 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
             log = U.logger(cctx.kernalContext(), logRef, GridDhtColocatedLockFuture.class);
         }
 
-        if (timeout > 0) {
-            timeoutObj = new LockTimeoutObject();
-
-            cctx.time().addTimeoutObject(timeoutObj);
-        }
-
         valMap = new ConcurrentHashMap8<>();
     }
 
@@ -399,7 +394,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
      * @param success Success flag.
      */
     public void complete(boolean success) {
-        onComplete(success, true);
+        onComplete(success, true, true);
     }
 
     /**
@@ -533,7 +528,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
     /** {@inheritDoc} */
     @Override public boolean cancel() {
         if (onCancelled())
-            onComplete(false, true);
+            onComplete(false, true, true);
 
         return isCancelled();
     }
@@ -556,7 +551,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         if (err != null)
             success = false;
 
-        return onComplete(success, true);
+        return onComplete(success, true, true);
     }
 
     /**
@@ -564,9 +559,10 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
      *
      * @param success {@code True} if lock was acquired.
      * @param distribute {@code True} if need to distribute lock removal in case of failure.
+     * @param restoreTimeout {@code True} if need restore tx timeout callback.
      * @return {@code True} if complete by this operation.
      */
-    private boolean onComplete(boolean success, boolean distribute) {
+    private boolean onComplete(boolean success, boolean distribute, boolean restoreTimeout) {
         if (log.isDebugEnabled())
             log.debug("Received onComplete(..) callback [success=" + success + ", distribute=" + distribute +
                 ", fut=" + this + ']');
@@ -577,6 +573,12 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         if (tx != null)
             cctx.tm().txContext(tx);
 
+        if (restoreTimeout && tx != null && tx.trackTimeout()) {
+            // Need restore timeout before onDone is called, but onComplete can be called concurrently,
+            // thus need ignore duplicated timeout objects.
+            tx.addTimeoutHandler(true);
+        }
+
         if (super.onDone(success, err)) {
             if (log.isDebugEnabled())
                 log.debug("Completing future: " + this);
@@ -631,13 +633,6 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         }
     }
 
-    /**
-     * @return Timeout.
-     */
-    public long timeout() {
-        return timeout;
-    }
-
     /** {@inheritDoc} */
     @Override public String toString() {
         Collection<String> futs = F.viewReadOnly(futures(), new C1<IgniteInternalFuture<?>, String>() {
@@ -682,12 +677,36 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
      * part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
      */
     void map() {
+        if (tx != null && tx.trackTimeout()) {
+            if (!tx.removeTimeoutHandler()) {
+                tx.finishFuture().listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {
+                    @Override public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
+                        IgniteTxTimeoutCheckedException err = new IgniteTxTimeoutCheckedException("Failed to " +
+                            "acquire lock, transaction was rolled back on timeout [timeout=" + tx.timeout() +
+                            ", tx=" + tx + ']');
+
+                        onError(err);
+
+                        onComplete(false, false, false);
+                    }
+                });
+
+                return;
+            }
+        }
+
+        if (timeout > 0) {
+            timeoutObj = new LockTimeoutObject();
+
+            cctx.time().addTimeoutObject(timeoutObj);
+        }
+
         // Obtain the topology version to use.
         AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
 
         // If there is another system transaction in progress, use it's topology version to prevent deadlock.
         if (topVer == null && tx != null && tx.system())
-            topVer = cctx.tm().lockedTopologyVersion(Thread.currentThread().getId(), tx);
+            topVer = cctx.tm().lockedTopologyVersion(tx);
 
         if (topVer != null && tx != null)
             tx.topologyVersion(topVer);
@@ -856,12 +875,8 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         assert !remap || (clientNode && (tx == null || !tx.hasRemoteLocks()));
 
         // First assume this node is primary for all keys passed in.
-        if (!clientNode && mapAsPrimary(keys, topVer)) {
-            if (!cctx.mvcc().addFuture(this))
-                throw new IllegalStateException("Duplicate future ID: " + this);
-
+        if (!clientNode && mapAsPrimary(keys, topVer))
             return;
-        }
 
         mappings = new ArrayDeque<>();
 
@@ -892,6 +907,8 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
         if (log.isDebugEnabled())
             log.debug("Starting (re)map for mappings [mappings=" + mappings + ", fut=" + this + ']');
 
+        boolean hasRmtNodes = false;
+
         boolean first = true;
 
         // Create mini futures.
@@ -939,7 +956,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
                             if (log.isDebugEnabled())
                                 log.debug("Entry being locked did not pass filter (will not lock): " + entry);
 
-                            onComplete(false, false);
+                            onComplete(false, false, true);
 
                             return;
                         }
@@ -1038,8 +1055,11 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
                 }
             }
 
-            if (!distributedKeys.isEmpty())
+            if (!distributedKeys.isEmpty()) {
                 mapping.distributedKeys(distributedKeys);
+
+                hasRmtNodes |= !mapping.node().isLocal();
+            }
             else {
                 assert mapping.request() == null;
 
@@ -1047,8 +1067,14 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
             }
         }
 
-        if (!remap && !cctx.mvcc().addFuture(this))
-            throw new IllegalStateException("Duplicate future ID: " + this);
+        if (hasRmtNodes) {
+            trackable = true;
+
+            if (!remap && !cctx.mvcc().addFuture(this))
+                throw new IllegalStateException("Duplicate future ID: " + this);
+        }
+        else
+            trackable = false;
 
         proceedMapping();
     }
@@ -1264,6 +1290,8 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
                 return true;
         }
 
+        trackable = false;
+
         if (tx != null) {
             if (explicit)
                 tx.markExplicit(cctx.localNodeId());
@@ -1305,7 +1333,7 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
             if (log.isDebugEnabled())
                 log.debug("Entry being locked did not pass filter (will not lock): " + entry);
 
-            onComplete(false, false);
+            onComplete(false, false, true);
 
             return false;
         }
@@ -1417,12 +1445,12 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
                             U.warn(log, "Failed to detect deadlock.", e);
                         }
 
-                        onComplete(false, true);
+                        onComplete(false, true, true);
                     }
                 });
             }
             else
-                onComplete(false, true);
+                onComplete(false, true, true);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
index bb71337..00f6ef5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
@@ -50,6 +50,7 @@ import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCa
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter;
+import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.transactions.TxDeadlock;
@@ -230,12 +231,6 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
         if (log == null)
             log = U.logger(cctx.kernalContext(), logRef, GridNearLockFuture.class);
 
-        if (timeout > 0) {
-            timeoutObj = new LockTimeoutObject();
-
-            cctx.time().addTimeoutObject(timeoutObj);
-        }
-
         valMap = new ConcurrentHashMap8<>();
     }
 
@@ -434,7 +429,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
      * @param success Success flag.
      */
     public void complete(boolean success) {
-        onComplete(success, true);
+        onComplete(success, true, true);
     }
 
     /**
@@ -655,7 +650,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
                     log.debug("Local lock acquired for entries [fut=" + this + ", entries=" + entries + "]");
             }
 
-            onComplete(true, true);
+            onComplete(true, true, true);
 
             return true;
         }
@@ -666,7 +661,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
     /** {@inheritDoc} */
     @Override public boolean cancel() {
         if (onCancelled())
-            onComplete(false, true);
+            onComplete(false, true, true);
 
         return isCancelled();
     }
@@ -690,7 +685,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
         if (err != null)
             success = false;
 
-        return onComplete(success, true);
+        return onComplete(success, true, true);
     }
 
     /**
@@ -698,9 +693,10 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
      *
      * @param success {@code True} if lock was acquired.
      * @param distribute {@code True} if need to distribute lock removal in case of failure.
+     * @param restoreTimeout {@code True} if need restore tx timeout callback.
      * @return {@code True} if complete by this operation.
      */
-    private boolean onComplete(boolean success, boolean distribute) {
+    private boolean onComplete(boolean success, boolean distribute, boolean restoreTimeout) {
         if (log.isDebugEnabled())
             log.debug("Received onComplete(..) callback [success=" + success + ", distribute=" + distribute +
                 ", fut=" + this + ']');
@@ -711,6 +707,12 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
         if (tx != null)
             cctx.tm().txContext(tx);
 
+        if (restoreTimeout && tx != null && tx.trackTimeout()) {
+            // Need restore timeout before onDone is called, but onComplete can be called concurrently,
+            // thus need ignore duplicated timeout objects.
+            tx.addTimeoutHandler(true);
+        }
+
         if (super.onDone(success, err)) {
             if (log.isDebugEnabled())
                 log.debug("Completing future: " + this);
@@ -770,6 +772,30 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
      * part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
      */
     void map() {
+        if (tx != null && tx.trackTimeout()) {
+            if (!tx.removeTimeoutHandler()) {
+                tx.finishFuture().listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {
+                    @Override public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
+                        IgniteTxTimeoutCheckedException err = new IgniteTxTimeoutCheckedException("Failed to " +
+                            "acquire lock, transaction was rolled back on timeout [timeout=" + tx.timeout() +
+                            ", tx=" + tx + ']');
+
+                        onError(err);
+
+                        onComplete(false, false, false);
+                    }
+                });
+
+                return;
+            }
+        }
+
+        if (timeout > 0) {
+            timeoutObj = new LockTimeoutObject();
+
+            cctx.time().addTimeoutObject(timeoutObj);
+        }
+
         // Obtain the topology version to use.
         long threadId = Thread.currentThread().getId();
 
@@ -777,7 +803,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
 
         // If there is another system transaction in progress, use it's topology version to prevent deadlock.
         if (topVer == null && tx != null && tx.system())
-            topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
+            topVer = cctx.tm().lockedTopologyVersion(tx);
 
         if (topVer != null && tx != null)
             tx.topologyVersion(topVer);
@@ -981,9 +1007,7 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
                                     if (log.isDebugEnabled())
                                         log.debug("Entry being locked did not pass filter (will not lock): " + entry);
 
-                                    onComplete(
-                                        false,
-                                        false);
+                                    onComplete(false, false, true);
 
                                     return;
                                 }
@@ -1476,12 +1500,12 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
                             U.warn(log, "Failed to detect deadlock.", e);
                         }
 
-                        onComplete(false, true);
+                        onComplete(false, true, true);
                     }
                 });
             }
             else
-                onComplete(false, true);
+                onComplete(false, true, true);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFutureAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFutureAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFutureAdapter.java
index f09b6c8..9e5be1c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFutureAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFutureAdapter.java
@@ -55,7 +55,7 @@ public abstract class GridNearOptimisticTxPrepareFutureAdapter extends GridNearT
 
         // If there is another system transaction in progress, use it's topology version to prevent deadlock.
         if (topVer == null && tx.system()) {
-            topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
+            topVer = cctx.tm().lockedTopologyVersion(tx);
 
             if (topVer == null)
                 topVer = tx.topologyVersionSnapshot();

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
index a691cbc..19def50 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
@@ -133,7 +133,7 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V>
         if (keyCheck)
             validateCacheKeys(keys);
 
-        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
+        GridNearTxLocal tx = ctx.tm().currentThreadTx(ctx);
 
         CacheOperationContext opCtx = ctx.operationContextPerCall();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index ad3b464..a080bfa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -233,7 +233,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         initResult();
 
         if (trackTimeout())
-            cctx.time().addTimeoutObject(this);
+            addTimeoutHandler(false);
     }
 
     /** {@inheritDoc} */
@@ -1616,7 +1616,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                 // with prepare response, if required.
                 assert loadFut.isDone();
 
-                return nonInterruptable(commitNearTxLocalAsync().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {
+                return nonInterruptable(commitNearTxLocalAsync(false).chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {
                     @Override public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut)
                         throws IgniteCheckedException {
                         try {
@@ -1626,7 +1626,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                                 implicitRes.value(), implicitRes.success());
                         }
                         catch (IgniteCheckedException | RuntimeException e) {
-                            rollbackNearTxLocalAsync();
+                            rollbackNearTxLocalAsync(false);
 
                             throw e;
                         }
@@ -2384,7 +2384,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                 return new GridFinishedFuture<>(e);
             }
 
-            return nonInterruptable(commitNearTxLocalAsync().chain(
+            return nonInterruptable(commitNearTxLocalAsync(false).chain(
                 new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {
                     @Override public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut)
                         throws IgniteCheckedException {
@@ -2403,7 +2403,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                         }
                         catch (IgniteCheckedException | RuntimeException e) {
                             if (!(e instanceof NodeStoppingException))
-                                rollbackNearTxLocalAsync();
+                                rollbackNearTxLocalAsync(false);
 
                             throw e;
                         }
@@ -3171,30 +3171,26 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
      * @throws IgniteCheckedException If failed.
      */
     public final void prepare() throws IgniteCheckedException {
-        prepareAsync().get();
-    }
-
-    /**
-     * @return Prepare future.
-     */
-    private IgniteInternalFuture<?> prepareAsync() {
-        return prepareNearTxLocal();
+        prepareNearTxLocal().get();
     }
 
     /**
      * @throws IgniteCheckedException If failed.
      */
     public void commit() throws IgniteCheckedException {
-        commitNearTxLocalAsync().get();
+        commitNearTxLocalAsync(true).get();
     }
 
     /**
      * @return Finish future.
      */
-    public IgniteInternalFuture<IgniteInternalTx> commitNearTxLocalAsync() {
+    public IgniteInternalFuture<IgniteInternalTx> commitNearTxLocalAsync(boolean clearThreadLocal) {
         if (log.isDebugEnabled())
             log.debug("Committing near local tx: " + this);
 
+        if (clearThreadLocal)
+            cctx.tm().clearThreadLocalTx(this);
+
         if (fastFinish()) {
             state(PREPARING);
             state(PREPARED);
@@ -3248,23 +3244,26 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<IgniteInternalTx> commitAsync() {
-        return commitNearTxLocalAsync();
+        return commitNearTxLocalAsync(true);
     }
 
     /**
      * @throws IgniteCheckedException If failed.
      */
     public void rollback() throws IgniteCheckedException {
-        rollbackNearTxLocalAsync().get();
+        rollbackNearTxLocalAsync(true).get();
     }
 
     /**
      * @return Rollback future.
      */
-    public IgniteInternalFuture<IgniteInternalTx> rollbackNearTxLocalAsync() {
+    public IgniteInternalFuture<IgniteInternalTx> rollbackNearTxLocalAsync(boolean clearThreadLocal) {
         if (log.isDebugEnabled())
             log.debug("Rolling back near tx: " + this);
 
+        if (clearThreadLocal)
+            cctx.tm().clearThreadLocalTx(this);
+
         removeTimeoutHandler();
 
         if (fastFinish()) {
@@ -3328,7 +3327,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<IgniteInternalTx> rollbackAsync() {
-        return rollbackNearTxLocalAsync();
+        return rollbackNearTxLocalAsync(true);
     }
 
     /**
@@ -3698,8 +3697,11 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
-        else
+        else {
+            cctx.tm().clearThreadLocalTx(this);
+
             removeTimeoutHandler();
+        }
 
         synchronized (this) {
             try {
@@ -4013,16 +4015,26 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     /**
      * @return {@code True} if need register callback which cancels tx on timeout.
      */
-    private boolean trackTimeout() {
+    public boolean trackTimeout() {
         return timeout() > 0 && !implicit();
     }
 
     /**
      * Removes timeout handler.
+     *
+     * @return {@code True} if handler was removed.
      */
-    private void removeTimeoutHandler() {
-        if (trackTimeout())
-            cctx.time().removeTimeoutObject(this);
+    public boolean removeTimeoutHandler() {
+        return trackTimeout() && cctx.time().removeTimeoutObject(this);
+    }
+
+    /**
+     * @param ignoreDuplicated {@code True} if do need check for duplicated timeout object.
+     */
+    public void addTimeoutHandler(boolean ignoreDuplicated) {
+        assert trackTimeout();
+
+        cctx.time().addTimeoutObject(this, ignoreDuplicated);
     }
 
     /** {@inheritDoc} */
@@ -4037,13 +4049,20 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public void onTimeout() {
-        if (state(MARKED_ROLLBACK, true)) {
+        if (state(MARKED_ROLLBACK, true) || (state() == MARKED_ROLLBACK)) {
+            if (log.isDebugEnabled())
+                log.debug("Will rollback tx on timeout: " + this);
+
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
-                    rollbackNearTxLocalAsync();
+                    rollbackNearTxLocalAsync(false);
                 }
             });
         }
+        else {
+            if (log.isDebugEnabled())
+                log.debug("Skip rollback tx on timeout: " + this);
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
index 7d4464a..2e4e181 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
@@ -469,7 +469,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter implement
 
         if (res.equals(AffinityTopologyVersion.NONE)) {
             if (system()) {
-                AffinityTopologyVersion topVer = cctx.tm().lockedTopologyVersion(Thread.currentThread().getId(), this);
+                AffinityTopologyVersion topVer = cctx.tm().lockedTopologyVersion(this);
 
                 if (topVer != null)
                     return topVer;
@@ -966,7 +966,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter implement
      * @return {@code True} if state changed.
      */
     @SuppressWarnings({"TooBroadScope"})
-    protected boolean state(TransactionState state, boolean timedOut) {
+    protected final boolean state(TransactionState state, boolean timedOut) {
         boolean valid = false;
 
         TransactionState prev;

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/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 de0e415..f87b786 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
@@ -261,7 +261,7 @@ public class IgniteTxHandler {
             req.last());
 
         if (locTx.isRollbackOnly())
-            locTx.rollbackNearTxLocalAsync();
+            locTx.rollbackNearTxLocalAsync(false);
 
         return fut.chain(new C1<IgniteInternalFuture<GridNearTxPrepareResponse>, GridNearTxPrepareResponse>() {
             @Override public GridNearTxPrepareResponse apply(IgniteInternalFuture<GridNearTxPrepareResponse> f) {
@@ -1021,7 +1021,7 @@ public class IgniteTxHandler {
 
             if (tx != null)
                 try {
-                    return tx.rollbackNearTxLocalAsync();
+                    return tx.rollbackNearTxLocalAsync(false);
                 }
                 catch (Throwable e1) {
                     e.addSuppressed(e1);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/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 6aa04ac..6144b27 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
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -148,11 +147,11 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /** Topology version should be used when mapping internal tx. */
     private final ThreadLocal<AffinityTopologyVersion> txTop = new ThreadLocal<>();
 
-    /** Per-thread transaction map. */
-    private final ConcurrentMap<Long, IgniteInternalTx> threadMap = newMap();
+    /** Current thread's tx. */
+    private final ThreadLocal<GridNearTxLocal> threadTx = new ThreadLocal<>();
 
-    /** Per-thread system transaction map. */
-    private final ConcurrentMap<TxThreadKey, IgniteInternalTx> sysThreadMap = newMap();
+    /** Current thread's system tx. */
+    private final ThreadLocal<GridNearTxLocal> threadSysTx = new ThreadLocal<>();
 
     /** Per-ID map. */
     private final ConcurrentMap<GridCacheVersion, IgniteInternalTx> idMap = newMap();
@@ -284,7 +283,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     public void rollbackTransactionsForCache(int cacheId) {
         rollbackTransactionsForCache(cacheId, nearIdMap);
 
-        rollbackTransactionsForCache(cacheId, threadMap);
+        rollbackTransactionsForCache(cacheId, idMap);
     }
 
     /**
@@ -309,8 +308,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void onDisconnected(IgniteFuture reconnectFut) {
         txFinishSync.onDisconnected(reconnectFut);
 
-        for (Map.Entry<Long, IgniteInternalTx> e : threadMap.entrySet())
-            rollbackTx(e.getValue());
+        for (IgniteInternalTx tx : idMap.values())
+            rollbackTx(tx);
+        for (IgniteInternalTx tx : nearIdMap.values())
+            rollbackTx(tx);
 
         IgniteClientDisconnectedException err =
             new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.");
@@ -369,20 +370,13 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void printMemoryStats() {
         X.println(">>> ");
         X.println(">>> Transaction manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ']');
-        X.println(">>>   threadMapSize: " + threadMap.size());
         X.println(">>>   idMap [size=" + idMap.size() + ']');
+        X.println(">>>   nearIdMap [size=" + nearIdMap.size() + ']');
         X.println(">>>   completedVersSortedSize: " + completedVersSorted.size());
         X.println(">>>   completedVersHashMapSize: " + completedVersHashMap.sizex());
     }
 
     /**
-     * @return Thread map size.
-     */
-    public int threadMapSize() {
-        return threadMap.size();
-    }
-
-    /**
      * @return ID map size.
      */
     public int idMapSize() {
@@ -452,7 +446,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             taskNameHash);
 
         if (tx.system()) {
-            AffinityTopologyVersion topVer = cctx.tm().lockedTopologyVersion(Thread.currentThread().getId(), tx);
+            AffinityTopologyVersion topVer = cctx.tm().lockedTopologyVersion(tx);
 
             // If there is another system transaction in progress, use it's topology version to prevent deadlock.
             if (topVer != null)
@@ -483,14 +477,15 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         IgniteInternalTx t;
 
         if ((t = txIdMap.putIfAbsent(tx.xidVersion(), tx)) == null) {
-            // Add both, explicit and implicit transactions.
-            // Do not add remote and dht local transactions as remote node may have the same thread ID
-            // and overwrite local transaction.
             if (tx.local() && !tx.dht()) {
-                if (cacheCtx == null || !cacheCtx.systemTx())
-                    threadMap.put(tx.threadId(), tx);
-                else
-                    sysThreadMap.put(new TxThreadKey(tx.threadId(), cacheCtx.cacheId()), tx);
+                assert tx instanceof GridNearTxLocal : tx;
+
+                if (!tx.implicit()) {
+                    if (cacheCtx == null || !cacheCtx.systemTx())
+                        threadTx.set((GridNearTxLocal)tx);
+                    else
+                        threadSysTx.set((GridNearTxLocal)tx);
+                }
             }
 
             // Handle mapped versions.
@@ -626,27 +621,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /**
      * @return Local transaction.
      */
-    @SuppressWarnings({"unchecked"})
-    @Nullable public <T> T localTx() {
-        IgniteInternalTx tx = tx();
+    @Nullable public IgniteTxLocalAdapter localTx() {
+        IgniteTxLocalAdapter tx = tx();
 
-        return tx != null && tx.local() ? (T)tx : null;
-    }
-
-    /**
-     * @param cctx Cache context.
-     * @return Transaction for current thread.
-     */
-    public GridNearTxLocal threadLocalTx(GridCacheContext cctx) {
-        IgniteInternalTx tx = tx(cctx, Thread.currentThread().getId());
-
-        if (tx != null && tx.local() && (!tx.dht() || tx.colocated()) && !tx.implicit()) {
-            assert tx instanceof GridNearTxLocal : tx;
-
-            return (GridNearTxLocal)tx;
-        }
-
-        return null;
+        return tx != null && tx.local() ? tx : null;
     }
 
     /**
@@ -656,16 +634,22 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     public <T> T tx() {
         IgniteInternalTx tx = txContext();
 
-        return tx != null ? (T)tx : (T)tx(null, Thread.currentThread().getId());
+        return tx != null ? (T)tx : (T)currentThreadTx(null);
     }
 
     /**
-     * @param threadId Thread ID.
      * @param ignore Transaction to ignore.
      * @return Not null topology version if current thread holds lock preventing topology change.
      */
-    @Nullable public AffinityTopologyVersion lockedTopologyVersion(long threadId, IgniteInternalTx ignore) {
-        IgniteInternalTx tx = threadMap.get(threadId);
+    @Nullable public AffinityTopologyVersion lockedTopologyVersion(IgniteInternalTx ignore) {
+        IgniteInternalTx tx = threadTx.get();
+
+        if (tx == null) {
+            tx = threadSysTx.get();
+
+            if (tx == ignore)
+                tx = null;
+        }
 
         if (tx != null) {
             AffinityTopologyVersion topVer = tx.topologyVersionSnapshot();
@@ -674,22 +658,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 return topVer;
         }
 
-        if (!sysThreadMap.isEmpty()) {
-            for (GridCacheContext cacheCtx : cctx.cache().context().cacheContexts()) {
-                if (!cacheCtx.systemTx())
-                    continue;
-
-                tx = sysThreadMap.get(new TxThreadKey(threadId, cacheCtx.cacheId()));
-
-                if (tx != null && tx != ignore) {
-                    AffinityTopologyVersion topVer = tx.topologyVersionSnapshot();
-
-                    if (topVer != null)
-                        return topVer;
-                }
-            }
-        }
-
         return txTop.get();
     }
 
@@ -712,15 +680,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     }
 
     /**
-     * @return Local transaction.
-     */
-    @Nullable public IgniteInternalTx localTxx() {
-        IgniteInternalTx tx = tx();
-
-        return tx != null && tx.local() ? tx : null;
-    }
-
-    /**
      * @return User transaction for current thread.
      */
     @Nullable public GridNearTxLocal userTx() {
@@ -729,7 +688,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         if (activeUserTx(tx))
             return (GridNearTxLocal)tx;
 
-        tx = tx(null, Thread.currentThread().getId());
+        tx = currentThreadTx(null);
 
         if (activeUserTx(tx))
             return (GridNearTxLocal)tx;
@@ -742,7 +701,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return User transaction for current thread.
      */
     @Nullable GridNearTxLocal userTx(GridCacheContext cctx) {
-        IgniteInternalTx tx = tx(cctx, Thread.currentThread().getId());
+        IgniteInternalTx tx = currentThreadTx(cctx);
 
         if (activeUserTx(tx))
             return (GridNearTxLocal)tx;
@@ -766,17 +725,14 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
 
     /**
      * @param cctx Cache context.
-     * @param threadId Id of thread for transaction.
      * @return Transaction for thread with given ID.
      */
     @SuppressWarnings({"unchecked"})
-    private <T> T tx(GridCacheContext cctx, long threadId) {
+    public GridNearTxLocal currentThreadTx(GridCacheContext cctx) {
         if (cctx == null || !cctx.systemTx())
-            return (T)threadMap.get(threadId);
+            return threadTx.get();
 
-        TxThreadKey key = new TxThreadKey(threadId, cctx.cacheId());
-
-        return (T)sysThreadMap.get(key);
+        return threadSysTx.get();
     }
 
     /**
@@ -1208,32 +1164,29 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 collectPendingVersions(dhtTxLoc);
             }
 
-            // 4. Unlock write resources.
+            // 3. Unlock write resources.
             unlockMultiple(tx, tx.writeEntries());
 
-            // 5. Unlock read resources if required.
+            // 4. Unlock read resources if required.
             if (unlockReadEntries(tx))
                 unlockMultiple(tx, tx.readEntries());
 
-            // 6. Notify evictions.
+            // 5. Notify evictions.
             notifyEvictions(tx);
 
-            // 7. Remove obsolete entries from cache.
+            // 6. Remove obsolete entries from cache.
             removeObsolete(tx);
 
-            // 8. Assign transaction number at the end of transaction.
+            // 7. Assign transaction number at the end of transaction.
             tx.endVersion(cctx.versions().next(tx.topologyVersion()));
 
-            // 9. Remove from per-thread storage.
-            clearThreadMap(tx);
-
-            // 10. Unregister explicit locks.
+            // 8. Unregister explicit locks.
             if (!tx.alternateVersions().isEmpty()) {
                 for (GridCacheVersion ver : tx.alternateVersions())
                     idMap.remove(ver);
             }
 
-            // 11. Remove Near-2-DHT mappings.
+            // 9. Remove Near-2-DHT mappings.
             if (tx instanceof GridCacheMappedVersion) {
                 GridCacheVersion mapped = ((GridCacheMappedVersion)tx).mappedVersion();
 
@@ -1241,10 +1194,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                     mappedVers.remove(mapped);
             }
 
-            // 12. Clear context.
+            // 10. Clear context.
             resetContext();
 
-            // 14. Update metrics.
+            // 11. Update metrics.
             if (!tx.dht() && tx.local()) {
                 if (!tx.system())
                     cctx.txMetrics().onTxCommit();
@@ -1294,22 +1247,19 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // 5. Remove obsolete entries.
             removeObsolete(tx);
 
-            // 6. Remove from per-thread storage.
-            clearThreadMap(tx);
-
-            // 7. Unregister explicit locks.
+            // 6. Unregister explicit locks.
             if (!tx.alternateVersions().isEmpty())
                 for (GridCacheVersion ver : tx.alternateVersions())
                     idMap.remove(ver);
 
-            // 8. Remove Near-2-DHT mappings.
+            // 7. Remove Near-2-DHT mappings.
             if (tx instanceof GridCacheMappedVersion)
                 mappedVers.remove(((GridCacheMappedVersion)tx).mappedVersion());
 
-            // 9. Clear context.
+            // 8. Clear context.
             resetContext();
 
-            // 10. Update metrics.
+            // 9. Update metrics.
             if (!tx.dht() && tx.local()) {
                 if (!tx.system())
                     cctx.txMetrics().onTxRollback();
@@ -1350,13 +1300,10 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // 3. Remove obsolete entries.
             removeObsolete(tx);
 
-            // 4. Remove from per-thread storage.
-            clearThreadMap(tx);
-
-            // 5. Clear context.
+            // 4. Clear context.
             resetContext();
 
-            // 6. Update metrics.
+            // 5. Update metrics.
             if (!tx.dht() && tx.local()) {
                 if (!tx.system()) {
                     if (commit)
@@ -1394,20 +1341,17 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // 3. Notify evictions.
             notifyEvictions(tx);
 
-            // 4. Remove from per-thread storage.
-            clearThreadMap(tx);
-
-            // 5. Unregister explicit locks.
+            // 4. Unregister explicit locks.
             if (!tx.alternateVersions().isEmpty()) {
                 for (GridCacheVersion ver : tx.alternateVersions())
                     idMap.remove(ver);
             }
 
-            // 6. Remove Near-2-DHT mappings.
+            // 5. Remove Near-2-DHT mappings.
             if (tx instanceof GridCacheMappedVersion)
                 mappedVers.remove(((GridCacheMappedVersion)tx).mappedVersion());
 
-            // 7. Clear context.
+            // 6. Clear context.
             resetContext();
 
             if (log.isDebugEnabled())
@@ -1420,28 +1364,14 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /**
      * @param tx Transaction to clear.
      */
-    private void clearThreadMap(IgniteInternalTx tx) {
-        if (tx.local() && !tx.dht()) {
-            if (!tx.system())
-                threadMap.remove(tx.threadId(), tx);
-            else {
-                Integer cacheId = tx.txState().firstCacheId();
-
-                if (cacheId != null)
-                    sysThreadMap.remove(new TxThreadKey(tx.threadId(), cacheId), tx);
-                else {
-                    for (Iterator<IgniteInternalTx> it = sysThreadMap.values().iterator(); it.hasNext(); ) {
-                        IgniteInternalTx txx = it.next();
-
-                        if (tx == txx) {
-                            it.remove();
+    public void clearThreadLocalTx(GridNearTxLocal tx) {
+        if (tx.implicit())
+            return;
 
-                            break;
-                        }
-                    }
-                }
-            }
-        }
+        if (tx.system())
+            threadSysTx.set(null);
+        else
+            threadTx.set(null);
     }
 
     /**
@@ -2250,6 +2180,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @see #resumeTx(GridNearTxLocal)
      * @see GridNearTxLocal#suspend()
      * @see GridNearTxLocal#resume()
+     * @throws IgniteCheckedException If failed to suspend transaction.
      */
     public void suspendTx(final GridNearTxLocal tx) throws IgniteCheckedException {
         assert tx != null && !tx.system() : tx;
@@ -2259,7 +2190,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
                 + "[expected=" + ACTIVE + ", actual=" + tx.state() + ']');
         }
 
-        clearThreadMap(tx);
+        clearThreadLocalTx(tx);
 
         transactionMap(tx).remove(tx.xidVersion(), tx);
     }
@@ -2273,45 +2204,30 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @see #suspendTx(GridNearTxLocal)
      * @see GridNearTxLocal#suspend()
      * @see GridNearTxLocal#resume()
+     * @throws IgniteCheckedException If failed to resume tx.
      */
     public void resumeTx(GridNearTxLocal tx) throws IgniteCheckedException {
         assert tx != null && !tx.system() : tx;
-        assert !threadMap.containsValue(tx) : tx;
         assert !transactionMap(tx).containsValue(tx) : tx;
-        assert !haveSystemTxForThread(Thread.currentThread().getId());
+        assert threadSysTx.get() == null;
 
         if (!tx.state(ACTIVE)) {
             throw new IgniteCheckedException("Trying to resume transaction with incorrect state "
-                    + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
+                + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
         }
 
-        long threadId = Thread.currentThread().getId();
-
-        if (threadMap.putIfAbsent(threadId, tx) != null)
-            throw new IgniteCheckedException("Thread already has started a transaction.");
-
-        if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
+        if (threadTx.get() != null)
             throw new IgniteCheckedException("Thread already has started a transaction.");
 
-        tx.threadId(threadId);
-    }
+        threadTx.set(tx);
 
-    /**
-     * @param threadId Thread id.
-     * @return True if thread have system transaction. False otherwise.
-     */
-    private boolean haveSystemTxForThread(long threadId) {
-        if (!sysThreadMap.isEmpty()) {
-            for (GridCacheContext cacheCtx : cctx.cache().context().cacheContexts()) {
-                if (!cacheCtx.systemTx())
-                    continue;
+        if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null) {
+            threadTx.set(null);
 
-                if (sysThreadMap.containsKey(new TxThreadKey(threadId, cacheCtx.cacheId())))
-                    return true;
-            }
+            throw new IgniteCheckedException("Thread already has started a transaction.");
         }
 
-        return false;
+        tx.threadId(Thread.currentThread().getId());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/main/java/org/apache/ignite/internal/processors/timeout/GridTimeoutProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/timeout/GridTimeoutProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/timeout/GridTimeoutProcessor.java
index 8c71f76..e69306f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/timeout/GridTimeoutProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/timeout/GridTimeoutProcessor.java
@@ -85,15 +85,23 @@ public class GridTimeoutProcessor extends GridProcessorAdapter {
     /**
      * @param timeoutObj Timeout object.
      */
-    @SuppressWarnings({"NakedNotify", "CallToNotifyInsteadOfNotifyAll"})
     public void addTimeoutObject(GridTimeoutObject timeoutObj) {
+        addTimeoutObject(timeoutObj, false);
+    }
+
+    /**
+     * @param timeoutObj Timeout object.
+     * @param ignoreDuplicated {@code True} if do need check for duplicated object.
+     */
+    @SuppressWarnings({"NakedNotify", "CallToNotifyInsteadOfNotifyAll"})
+    public void addTimeoutObject(GridTimeoutObject timeoutObj, boolean ignoreDuplicated) {
         if (timeoutObj.endTime() <= 0 || timeoutObj.endTime() == Long.MAX_VALUE)
             // Timeout will never happen.
             return;
 
         boolean added = timeoutObjs.add(timeoutObj);
 
-        assert added : "Duplicate timeout object found: " + timeoutObj;
+        assert ignoreDuplicated || added : "Duplicate timeout object found: " + timeoutObj;
 
         if (timeoutObjs.firstx() == timeoutObj) {
             synchronized (mux) {
@@ -124,9 +132,10 @@ public class GridTimeoutProcessor extends GridProcessorAdapter {
 
     /**
      * @param timeoutObj Timeout object.
+     * @return {@code True} if timeout object was removed.
      */
-    public void removeTimeoutObject(GridTimeoutObject timeoutObj) {
-        timeoutObjs.remove(timeoutObj);
+    public boolean removeTimeoutObject(GridTimeoutObject timeoutObj) {
+        return timeoutObjs.remove(timeoutObj);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
new file mode 100644
index 0000000..d62bae2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.distributed;
+
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteTransactions;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+
+/**
+ *
+ */
+public class IgniteCacheThreadLocalTxTest extends GridCommonAbstractTest {
+    /**
+     *
+     */
+    public IgniteCacheThreadLocalTxTest() {
+        super(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testThreadLocalTx() throws Exception {
+        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
+
+        ccfg.setAtomicityMode(TRANSACTIONAL);
+
+        Ignite node = grid();
+
+        IgniteCache<Object, Object> cache = node.createCache(ccfg);
+        IgniteTransactions txs = node.transactions();
+
+        checkNoTx(node);
+
+        boolean[] reads = {true, false};
+        boolean[] writes = {true, false};
+        int endOps = 5;
+
+        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
+            for (TransactionIsolation isolation : TransactionIsolation.values()) {
+                for (boolean read : reads) {
+                    for (boolean write : writes) {
+                        for (int i = 0; i < endOps; i++)
+                            checkTx(concurrency, isolation, node, cache, read, write, i);
+                    }
+                }
+            }
+        }
+
+        assertNull(txs.tx());
+    }
+
+    /**
+     * @param concurrency Tx concurrency.
+     * @param isolation Tx isolation.
+     * @param node Node.
+     * @param cache Cache.
+     * @param read {@code True} if read in tx.
+     * @param write {@code True} if write in tx.
+     * @param endOp Operation to test.
+     */
+    private void checkTx(TransactionConcurrency concurrency,
+        TransactionIsolation isolation,
+        Ignite node,
+        IgniteCache<Object, Object> cache,
+        boolean read,
+        boolean write,
+        int endOp) {
+        IgniteTransactions txs = node.transactions();
+
+        checkNoTx(node);
+
+        Transaction tx = txs.txStart(concurrency, isolation);
+
+        assertEquals(tx, txs.tx());
+
+        try {
+            txs.txStart(concurrency, isolation);
+
+            fail();
+        }
+        catch (IllegalStateException expected) {
+            // No-op.
+        }
+
+        if (read)
+            cache.get(ThreadLocalRandom.current().nextInt(100_000));
+
+        if (write)
+            cache.put(ThreadLocalRandom.current().nextInt(100_000), 1);
+
+
+        try {
+            txs.txStart(concurrency, isolation);
+
+            fail();
+        }
+        catch (IllegalStateException expected) {
+            // No-op.
+        }
+
+        assertEquals(tx, txs.tx());
+
+        IgniteFuture fut = null;
+
+        switch (endOp) {
+            case 0:
+                tx.commit();
+
+                break;
+
+            case 1:
+                fut = tx.commitAsync();
+
+                break;
+
+            case 2:
+                tx.rollback();
+
+                break;
+
+            case 3:
+                fut = tx.rollbackAsync();
+
+                break;
+
+            case 4:
+                tx.close();
+
+                break;
+
+            default:
+                fail();
+        }
+
+        checkNoTx(node);
+
+        if (fut != null)
+            fut.get();
+
+        checkNoTx(node);
+    }
+
+    /**
+     * @param node Node.
+     */
+    private void checkNoTx(Ignite node) {
+        IgniteTransactions txs = node.transactions();
+
+        assertNull(txs.tx());
+        assertNull(((IgniteKernal)node).context().cache().context().tm().tx());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
index ae691f5..51e39a7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
@@ -58,6 +58,7 @@ public class IgniteOptimisticTxSuspendResumeTest extends GridCommonAbstractTest
     /** Future timeout */
     private static final int FUT_TIMEOUT = 5000;
 
+    /** */
     private boolean client = false;
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
index 77c383e..5123329 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNoDeadlockDetectionTest.java
@@ -40,8 +40,8 @@ public class TxRollbackOnTimeoutNoDeadlockDetectionTest extends TxRollbackOnTime
     }
 
     /** */
-    @Override protected void validateException(Exception e) {
-        assertEquals("Deadlock report is expected",
+    @Override protected void validateDeadlockException(Exception e) {
+        assertEquals("TimeoutException is expected",
             TransactionTimeoutException.class, e.getCause().getClass());
     }
 }
\ No newline at end of file


[31/50] [abbrv] ignite git commit: IGNITE-6181 wip.

Posted by sb...@apache.org.
IGNITE-6181 wip.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/467e0bad
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/467e0bad
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/467e0bad

Branch: refs/heads/ignite-6181-1
Commit: 467e0bad7d25a9720738ce77f7afb5fd587727f5
Parents: ec4b16c
Author: ascherbakoff <al...@gmail.com>
Authored: Sun Sep 10 17:18:20 2017 +0300
Committer: ascherbakoff <al...@gmail.com>
Committed: Sun Sep 10 17:18:20 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      |   9 +-
 .../cache/distributed/near/GridNearTxLocal.java | 107 +++++++++++--------
 .../cache/transactions/IgniteTxManager.java     |  99 +++++++++++------
 .../cache/IgniteTxConfigCacheSelfTest.java      |   2 +
 4 files changed, 132 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/467e0bad/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 18fb2ff..8e075b2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -139,7 +139,6 @@ import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
 import org.apache.ignite.transactions.TransactionIsolation;
-import org.apache.ignite.transactions.TransactionState;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.LongAdder8;
 
@@ -4032,11 +4031,11 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         awaitLastFut();
 
-        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
-
-        if (tx != null && tx.state() == TransactionState.ROLLED_BACK && tx.timedOut())
+        if (ctx.tm().isTimedOutThread(Thread.currentThread().getId()))
             throw new IgniteTxTimeoutCheckedException("Previous transaction was rolled back due to timeout. " +
-                "Please start new transaction and retry an operation.");
+                    "Please start new transaction and retry an operation.");
+
+        GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
 
         if (tx == null || tx.implicit()) {
             TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());

http://git-wip-us.apache.org/repos/asf/ignite/blob/467e0bad/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 67782ee..3d93289 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -434,12 +434,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         Object... invokeArgs
     ) {
         return (IgniteInternalFuture<GridCacheReturn>)putAllAsync0(cacheCtx,
-            entryTopVer,
-            null,
-            map,
-            invokeArgs,
-            null,
-            true);
+                entryTopVer,
+                null,
+                map,
+                invokeArgs,
+                null,
+                true);
     }
 
     /**
@@ -458,12 +458,12 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         });
 
         return this.<Object, Object>putAllAsync0(cacheCtx,
-            null,
-            map,
-            null,
-            null,
-            drMap,
-            false);
+                null,
+                map,
+                null,
+                null,
+                drMap,
+                false);
     }
 
     /**
@@ -2486,8 +2486,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                         processLoaded(map, keys, needVer, c);
 
                         return null;
-                    }
-                    catch (Exception e) {
+                    } catch (Exception e) {
                         setRollbackOnly();
 
                         throw new GridClosureException(e);
@@ -2845,7 +2844,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
         if (log.isDebugEnabled())
             log.debug("Added mappings to transaction [locId=" + cctx.localNodeId() + ", key=" + key + ", node=" + node +
-                ", tx=" + this + ']');
+                    ", tx=" + this + ']');
     }
 
     /**
@@ -3151,6 +3150,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             // Prepare was called explicitly.
             return fut;
 
+        removeTimeoutHandler();
+
         mapExplicitLocks();
 
         fut.prepare();
@@ -3224,15 +3225,13 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                     prepareFut.get();
 
                     fut0.finish(true);
-                }
-                catch (Error | RuntimeException e) {
+                } catch (Error | RuntimeException e) {
                     COMMIT_ERR_UPD.compareAndSet(GridNearTxLocal.this, null, e);
 
                     fut0.finish(false);
 
                     throw e;
-                }
-                catch (IgniteCheckedException e) {
+                } catch (IgniteCheckedException e) {
                     COMMIT_ERR_UPD.compareAndSet(GridNearTxLocal.this, null, e);
 
                     if (!(e instanceof NodeStoppingException))
@@ -3263,6 +3262,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
         if (log.isDebugEnabled())
             log.debug("Rolling back near tx: " + this);
 
+        removeTimeoutHandler();
+
         if (fastFinish()) {
             state(PREPARING);
             state(PREPARED);
@@ -3275,6 +3276,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
             return new GridFinishedFuture<>((IgniteInternalTx)this);
         }
 
+        if (timedOut())
+            cctx.tm().markTimedOut(this);
+
         GridNearTxFinishFuture fut = rollbackFut;
 
         if (fut != null)
@@ -3516,7 +3520,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
                     }
                     catch (IgniteCheckedException e) {
                         log.debug("Failed to prepare transaction during rollback (will ignore) [tx=" + this + ", msg=" +
-                            e.getMessage() + ']');
+                                e.getMessage() + ']');
                     }
 
                     fut.finish(false);
@@ -3690,17 +3694,11 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public void close() throws IgniteCheckedException {
-        if (timeout() > 0 && !implicit())
-            cctx.time().removeTimeoutObject(this);
-
         TransactionState state = state();
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != COMMITTING && state != COMMITTED)
             rollback();
 
-        if (!system())
-            cctx.tm().resetUserTx();
-
         synchronized (this) {
             try {
                 while (!done())
@@ -4004,6 +4002,42 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     }
 
     /**
+     * @param threadId new owner of transaction.
+     */
+    public void threadId(long threadId) {
+        this.threadId = threadId;
+    }
+
+    /**
+     * Removes timeout handler used for eager rollbacks on timeouts.
+     */
+    private void removeTimeoutHandler() {
+        if (timeout() > 0 && !implicit() && !timedOut())
+            cctx.time().removeTimeoutObject(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid timeoutId() {
+        return xid();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long endTime() {
+        return startTime() + timeout();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onTimeout() {
+        if (state(MARKED_ROLLBACK, true)) {
+            cctx.kernalContext().closure().runLocalSafe(new Runnable() {
+                @Override public void run() {
+                    rollbackNearTxLocalAsync();
+                }
+            });
+        }
+    }
+
+    /**
      * Post-lock closure.
      *
      * @param <T> Return type.
@@ -4048,27 +4082,6 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteUuid timeoutId() {
-        return xid();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long endTime() {
-        return startTime() + timeout();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onTimeout() {
-        if (state(MARKED_ROLLBACK, true)) {
-            cctx.kernalContext().closure().runLocalSafe(new Runnable() {
-                @Override public void run() {
-                    rollbackNearTxLocalAsync();
-                }
-            });
-        }
-    }
-
-    /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridNearTxLocal.class, this,
             "thread", IgniteUtils.threadName(threadId),

http://git-wip-us.apache.org/repos/asf/ignite/blob/467e0bad/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 0722275..41e10cb 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
@@ -29,6 +29,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteClientDisconnectedException;
 import org.apache.ignite.IgniteSystemProperties;
@@ -148,8 +150,11 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     /** Topology version should be used when mapping internal tx. */
     private final ThreadLocal<AffinityTopologyVersion> txTop = new ThreadLocal<>();
 
-    /** User transaction. */
-    private final static ThreadLocal<IgniteInternalTx> userTx = new ThreadLocal<>();
+    /** Per-thread transaction map. */
+    private final ConcurrentMap<Long, IgniteInternalTx> threadMap = newMap();
+
+    /** Thread ids associated with rolled back transactions. */
+    private final ConcurrentSkipListSet<Long> rolledBackByTimeoutThreads = new ConcurrentSkipListSet<>();
 
     /** Per-thread system transaction map. */
     private final ConcurrentMap<TxThreadKey, IgniteInternalTx> sysThreadMap = newMap();
@@ -282,15 +287,19 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param cacheId Cache ID.
      */
     public void rollbackTransactionsForCache(int cacheId) {
-        rollbackTransactionsForCache(cacheId, activeTransactions());
+        rollbackTransactionsForCache(cacheId, nearIdMap);
+
+        rollbackTransactionsForCache(cacheId, threadMap);
     }
 
     /**
      * @param cacheId Cache ID.
      * @param txMap Transactions map.
      */
-    private void rollbackTransactionsForCache(int cacheId, Collection<IgniteInternalTx> txMap) {
-        for (IgniteInternalTx tx : txMap) {
+    private void rollbackTransactionsForCache(int cacheId, ConcurrentMap<?, IgniteInternalTx> txMap) {
+        for (Map.Entry<?, IgniteInternalTx> e : txMap.entrySet()) {
+            IgniteInternalTx tx = e.getValue();
+
             for (IgniteTxEntry entry : tx.allEntries()) {
                 if (entry.cacheId() == cacheId) {
                     rollbackTx(tx);
@@ -305,8 +314,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void onDisconnected(IgniteFuture reconnectFut) {
         txFinishSync.onDisconnected(reconnectFut);
 
-        for (IgniteInternalTx tx : activeTransactions())
-            rollbackTx(tx);
+        for (Map.Entry<Long, IgniteInternalTx> e : threadMap.entrySet())
+            rollbackTx(e.getValue());
 
         IgniteClientDisconnectedException err =
             new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.");
@@ -365,7 +374,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @Override public void printMemoryStats() {
         X.println(">>> ");
         X.println(">>> Transaction manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ']');
-        X.println(">>>   activeSize [size=" + activeTransactions().size() + ']');
+        X.println(">>>   threadMapSize: " + threadMap.size());
+        X.println(">>>   idMap [size=" + idMap.size() + ']');
         X.println(">>>   completedVersSortedSize: " + completedVersSorted.size());
         X.println(">>>   completedVersHashMapSize: " + completedVersHashMap.sizex());
     }
@@ -374,7 +384,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Thread map size.
      */
     public int threadMapSize() {
-        return 0;
+        return threadMap.size();
     }
 
     /**
@@ -483,7 +493,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
             // and overwrite local transaction.
             if (tx.local() && !tx.dht()) {
                 if (cacheCtx == null || !cacheCtx.systemTx())
-                    userTx.set(tx);
+                    threadMap.put(tx.threadId(), tx);
                 else
                     sysThreadMap.put(new TxThreadKey(tx.threadId(), cacheCtx.cacheId()), tx);
             }
@@ -660,7 +670,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @return Not null topology version if current thread holds lock preventing topology change.
      */
     @Nullable public AffinityTopologyVersion lockedTopologyVersion(long threadId, IgniteInternalTx ignore) {
-        IgniteInternalTx tx = userTx.get();
+        IgniteInternalTx tx = threadMap.get(threadId);
 
         if (tx != null) {
             AffinityTopologyVersion topVer = tx.topologyVersionSnapshot();
@@ -767,7 +777,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
     @SuppressWarnings({"unchecked"})
     private <T> T tx(GridCacheContext cctx, long threadId) {
         if (cctx == null || !cctx.systemTx())
-            return (T) userTx.get();
+            return (T)threadMap.get(threadId);
 
         TxThreadKey key = new TxThreadKey(threadId, cctx.cacheId());
 
@@ -1416,19 +1426,23 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * @param tx Transaction to clear.
      */
     private void clearThreadMap(IgniteInternalTx tx) {
-        if (tx.local() && !tx.dht() && tx.system()) {
-            Integer cacheId = tx.txState().firstCacheId();
-
-            if (cacheId != null)
-                sysThreadMap.remove(new TxThreadKey(tx.threadId(), cacheId), tx);
+        if (tx.local() && !tx.dht()) {
+            if (!tx.system())
+                threadMap.remove(tx.threadId(), tx);
             else {
-                for (Iterator<IgniteInternalTx> it = sysThreadMap.values().iterator(); it.hasNext(); ) {
-                    IgniteInternalTx txx = it.next();
+                Integer cacheId = tx.txState().firstCacheId();
 
-                    if (tx == txx) {
-                        it.remove();
+                if (cacheId != null)
+                    sysThreadMap.remove(new TxThreadKey(tx.threadId(), cacheId), tx);
+                else {
+                    for (Iterator<IgniteInternalTx> it = sysThreadMap.values().iterator(); it.hasNext(); ) {
+                        IgniteInternalTx txx = it.next();
 
-                        break;
+                        if (tx == txx) {
+                            it.remove();
+
+                            break;
+                        }
                     }
                 }
             }
@@ -1698,6 +1712,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
      * Commit ended.
      */
     public void resetContext() {
+        rolledBackByTimeoutThreads.remove(Thread.currentThread().getId());
+
         threadCtx.set(null);
     }
 
@@ -2270,18 +2286,40 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         assert !transactionMap(tx).containsValue(tx) : tx;
         assert !haveSystemTxForThread(Thread.currentThread().getId());
 
-        if(!tx.state(ACTIVE)) {
+        if (!tx.state(ACTIVE)) {
             throw new IgniteCheckedException("Trying to resume transaction with incorrect state "
-                + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
+                    + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
         }
 
-        if (userTx.get() != null)
-            throw new IgniteCheckedException("Thread already has active transaction.");
+        long threadId = Thread.currentThread().getId();
 
-        userTx.set(tx);
+        if (threadMap.putIfAbsent(threadId, tx) != null)
+            throw new IgniteCheckedException("Thread already has started a transaction.");
 
         if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
-            throw new IgniteCheckedException("Thread already has active transaction.");
+            throw new IgniteCheckedException("Thread already has started a transaction.");
+
+        tx.threadId(threadId);
+    }
+
+    /**
+     * Checks if thread belongs to timed out ids.
+     *
+     * @param threadId Thread id.
+     * @return {@code True} if current thread had a transaction rolled back by timeout.
+     */
+    public boolean isTimedOutThread(long threadId) {
+        return rolledBackByTimeoutThreads.contains(threadId);
+    }
+
+    /**
+     * Mark transaction thread as rolled back by timeout.
+     * Thread may not perform transactional ops until it will explicitly start a new transaction.
+     *
+     * @param tx Transaction.
+     */
+    public void markTimedOut(GridNearTxLocal tx) {
+        rolledBackByTimeoutThreads.add(tx.threadId());
     }
 
     /**
@@ -2302,11 +2340,6 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
         return false;
     }
 
-    /** */
-    public void resetUserTx() {
-        userTx.set(null);
-    }
-
     /**
      * Timeout object for node failure handler.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/467e0bad/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
index 8574f0c..f2e17e4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
@@ -197,6 +197,8 @@ public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest {
             assert e.getCause() instanceof TransactionTimeoutException;
         }
 
+        assertNull(ignite.transactions().tx());
+
         assert !cache.containsKey("key0");
         assert !cache.containsKey("key");
 


[10/50] [abbrv] ignite git commit: GG-12682 Restart cluster during snapshot RESTORE fails

Posted by sb...@apache.org.
GG-12682 Restart cluster during snapshot RESTORE fails


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a01837b5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a01837b5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a01837b5

Branch: refs/heads/ignite-6181-1
Commit: a01837b5028fc8739e16658d85ffe64aad01afdb
Parents: fc55ade9
Author: Eduard Shangareev <es...@gridgain.com>
Authored: Sun Aug 27 17:30:21 2017 +0300
Committer: Ilya Lantukh <il...@gridgain.com>
Committed: Sun Aug 27 17:30:21 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/persistence/file/FilePageStoreManager.java   | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a01837b5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
index 13bcd2a..d60151a 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
@@ -381,6 +381,9 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
         return new CacheStoreHolder(idxStore, partStores);
     }
 
+    /**
+     * @param cacheWorkDir Cache work directory.
+     */
     private boolean checkAndInitCacheWorkDir(File cacheWorkDir) throws IgniteCheckedException {
         boolean dirExisted = false;
 


[25/50] [abbrv] ignite git commit: ignite-6181 minor

Posted by sb...@apache.org.
ignite-6181 minor


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/685e69ac
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/685e69ac
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/685e69ac

Branch: refs/heads/ignite-6181-1
Commit: 685e69ac9014316e001353f98db6b27d2b9a74c7
Parents: b770c0a
Author: sboikov <sb...@gridgain.com>
Authored: Wed Sep 6 13:17:36 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Sep 6 14:09:50 2017 +0300

----------------------------------------------------------------------
 .../transactions/TxRollbackOnTimeoutTest.java   | 121 +++++++++++++++----
 1 file changed, 95 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/685e69ac/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 84e85ff..4799534 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -18,18 +18,15 @@
 package org.apache.ignite.internal.processors.cache.transactions;
 
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteSystemProperties;
-import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
@@ -38,8 +35,10 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
-import org.apache.ignite.transactions.TransactionConcurrency;
-import org.apache.ignite.transactions.TransactionIsolation;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
 
 /**
  * Tests an ability to eagerly rollback timed out transactions.
@@ -69,7 +68,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         cfg.setClientMode("client".equals(igniteInstanceName));
 
-        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
         TransactionConfiguration txCfg = new TransactionConfiguration();
         txCfg.setDefaultTxTimeout(TX_TIMEOUT);
@@ -77,7 +76,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         cfg.setTransactionConfiguration(txCfg);
 
         CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
-        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+        ccfg.setAtomicityMode(TRANSACTIONAL);
         ccfg.setBackups(2);
 
         cfg.setCacheConfiguration(ccfg);
@@ -101,6 +100,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout1() throws Exception {
         testWaitingTxUnblockedOnTimeout0(grid(0), grid(0));
@@ -108,6 +109,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout2() throws Exception {
         testWaitingTxUnblockedOnTimeout0(grid(0), grid(1));
@@ -115,6 +118,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout3() throws Exception {
         Ignite client = startGrid("client");
@@ -124,6 +129,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout4() throws Exception {
         Ignite client = startGrid("client");
@@ -133,6 +140,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout5() throws Exception {
         Ignite client = startGrid("client");
@@ -142,6 +151,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout6() throws Exception {
         testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(0));
@@ -149,6 +160,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout7() throws Exception {
         testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(1));
@@ -156,6 +169,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout8() throws Exception {
         Ignite client = startGrid("client");
@@ -165,6 +180,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout9() throws Exception {
         Ignite client = startGrid("client");
@@ -174,6 +191,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests if timeout on first tx unblocks second tx waiting for the locked key.
+     *
+     * @throws Exception If failed.
      */
     public void testWaitingTxUnblockedOnTimeout10() throws Exception {
         Ignite client = startGrid("client");
@@ -183,36 +202,66 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
     /**
      * Tests timeout object cleanup on tx commit.
+     *
+     * @throws Exception If failed.
      */
-    public void testTimeoutRemovalOnCommit() throws Exception {
-        testTimeoutRemoval(grid(0), true);
+    public void testTimeoutRemoval() throws Exception {
+        IgniteEx client = (IgniteEx)startGrid("client");
+
+        for (int i = 0; i < 5; i++)
+            testTimeoutRemoval(grid(0), i);
+
+        for (int i = 0; i < 5; i++)
+            testTimeoutRemoval(client, i);
     }
 
     /**
-     * Tests timeout object cleanup on tx rollback.
+     * @param near Node.
+     * @param mode Test mode.
+     * @throws Exception If failed.
      */
-    public void testTimeoutRemovalOnRollback() throws Exception {
-        testTimeoutRemoval(grid(0), false);
-    }
-
-    /** */
-    private void testTimeoutRemoval(IgniteEx near, boolean commit) throws Exception {
+    private void testTimeoutRemoval(IgniteEx near, int mode) throws Exception {
         GridTimeoutProcessor timeProc = near.context().cache().context().time();
 
         try (Transaction tx = near.transactions().txStart()) {
             near.cache(CACHE_NAME).put(1, 1);
 
-            if (commit)
-                tx.commit();
+            switch (mode) {
+                case 0:
+                    tx.commit();
+                    break;
+
+                case 1:
+                    tx.commitAsync().get();
+                    break;
+
+                case 2:
+                    tx.rollback();
+                    break;
+
+                case 3:
+                    tx.rollbackAsync().get();
+                    break;
+
+                case 4:
+                    break;
+
+                default:
+                    fail();
+            }
         }
 
         GridConcurrentSkipListSet set = U.field(timeProc, "timeoutObjs");
 
         for (Object obj : set)
-            assertFalse(obj.getClass().isAssignableFrom(GridNearTxLocal.class));
+            assertFalse("Not remove for mode: " + mode, obj.getClass().isAssignableFrom(GridNearTxLocal.class));
     }
 
-    /** */
+    /**
+     * @param near Node starting tx which is timed out.
+     * @param other Node starting second tx.
+     * @throws Exception If failed.
+     */
     private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final Ignite other) throws Exception {
         final int recordsCnt = 100;
 
@@ -228,6 +277,15 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     U.awaitQuiet(unblocked);
 
                     try {
+                        near.cache(CACHE_NAME).put(0, 0);
+
+                        fail();
+                    }
+                    catch (CacheException e) {
+                        log.info("Expecting error: " + e.getMessage());
+                    }
+
+                    try {
                         tx.commit();
 
                         fail();
@@ -236,6 +294,14 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                         log.info("Expecting error: " + e.getMessage());
                     }
                 }
+
+                // Check thread is able to start new tx.
+                try (Transaction tx = near.transactions().txStart()) {
+                    for (int i = 0; i < recordsCnt; i++)
+                        near.cache(CACHE_NAME).put(i, i);
+
+                    tx.commit();
+                }
             }
         }, 1, "First");
 
@@ -243,8 +309,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             @Override public void run() {
                 U.awaitQuiet(blocked);
 
-                try (Transaction tx = other.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
-                    TransactionIsolation.REPEATABLE_READ, 0, 1)) {
+                try (Transaction tx = other.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 1)) {
                     for (int i = 0; i < recordsCnt; i++)
                         other.cache(CACHE_NAME).put(i, i);
 
@@ -261,13 +326,18 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
         fut1.get();
     }
 
-    /** */
+    /**
+     * @param near Node starting tx which is timed out.
+     * @param other Node starting second tx.
+     * @throws Exception If failed.
+     */
     private void testWaitingTxUnblockedOnThreadDeath0(final Ignite near, final Ignite other) throws Exception {
         final int recordsCnt = 100;
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {
                 near.transactions().txStart();
+
                 for (int i = 0; i < recordsCnt; i++)
                     near.cache(CACHE_NAME).put(i, i);
 
@@ -281,8 +351,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             @Override public void run() {
                 U.awaitQuiet(blocked);
 
-                try (Transaction tx = other.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
-                    TransactionIsolation.REPEATABLE_READ, 0, 1)) {
+                try (Transaction tx = other.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 1)) {
                     for (int i = 0; i < recordsCnt; i++)
                         other.cache(CACHE_NAME).put(i, i);