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/07/18 14:46:56 UTC
[1/2] ignite git commit: ignite-5578
Repository: ignite
Updated Branches:
refs/heads/ignite-5578 3e22eac26 -> ef038c4cd
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheExchangeMergeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheExchangeMergeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheExchangeMergeTest.java
index ef8a1da..5e0d7e2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheExchangeMergeTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheExchangeMergeTest.java
@@ -17,18 +17,31 @@
package org.apache.ignite.internal.processors.cache.distributed;
+import java.util.List;
import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.PA;
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;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
/**
*
*/
@@ -37,7 +50,7 @@ public class CacheExchangeMergeTest extends GridCommonAbstractTest {
private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
/** */
- private boolean client;
+ private ThreadLocal<Boolean> client = new ThreadLocal<>();
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
@@ -45,18 +58,87 @@ public class CacheExchangeMergeTest extends GridCommonAbstractTest {
((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
- cfg.setClientMode(client);
+ Boolean clientMode = client.get();
+
+ if (clientMode != null) {
+ cfg.setClientMode(clientMode);
+
+ client.set(null);
+ }
+
+ cfg.setCacheConfiguration(
+ cacheConfiguration("c1", ATOMIC),
+ cacheConfiguration("c2", TRANSACTIONAL));
return cfg;
}
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /**
+ * @param name Cache name.
+ * @param atomicityMode Cache atomicity mode.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
+ CacheConfiguration ccfg = new CacheConfiguration(name);
+
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ return ccfg;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMergeServerAndClientJoin1() throws Exception {
+ final IgniteEx srv0 = startGrid(0);
+
+ mergeExchangeWaitVersion(srv0, 3);
+
+ IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ startGrid(1);
+
+ return null;
+ }
+ }, 1, "start-srv");
+
+ GridTestUtils.waitForCondition(new PA() {
+ @Override public boolean apply() {
+ return srv0.context().cache().context().exchange().lastTopologyFuture().topologyVersion().topologyVersion() == 2L;
+ }
+ }, 5000);
+
+ IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ client.set(true);
+
+ startGrid(2);
+
+ return null;
+ }
+ }, 1, "start-srv");
+
+ fut1.get();
+ fut2.get();
+
+ checkCaches();
+ }
+
/**
* @throws Exception If failed.
*/
- public void testConcurrentJoin1() throws Exception {
+ public void testMergeServersJoin1() throws Exception {
IgniteEx srv0 = startGrid(0);
- srv0.context().cache().context().exchange().mergeExchangesTestWaitVersion(new AffinityTopologyVersion(3, 0));
+ mergeExchangeWaitVersion(srv0, 3);
final AtomicInteger idx = new AtomicInteger(1);
@@ -69,5 +151,121 @@ public class CacheExchangeMergeTest extends GridCommonAbstractTest {
}, 2, "start-node");
fut.get();
+
+ checkCaches();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMergeServerJoin1ClientsInTopology() throws Exception {
+ IgniteEx srv0 = startGrid(0);
+
+ client.set(true);
+
+ startGrid(1);
+
+ client.set(true);
+
+ startGrid(2);
+
+ mergeExchangeWaitVersion(srv0, 5);
+
+ final AtomicInteger idx = new AtomicInteger(3);
+
+ IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ startGrid(idx.getAndIncrement());
+
+ return null;
+ }
+ }, 2, "start-node");
+
+ fut.get();
+
+ checkCaches();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMergeServersFail1_1() throws Exception {
+ mergeServersFail1(false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMergeServersFail1_2() throws Exception {
+ mergeServersFail1(true);
+ }
+
+ /**
+ * @param waitRebalance Wait for rebalance end before start tested topology change.
+ * @throws Exception If failed.
+ */
+ private void mergeServersFail1(boolean waitRebalance) throws Exception {
+ final Ignite srv0 = startGrids(4);
+
+ if (waitRebalance)
+ awaitPartitionMapExchange();
+
+ mergeExchangeWaitVersion(srv0, 6);
+
+ stopGrid(getTestIgniteInstanceName(3), true, false);
+ stopGrid(getTestIgniteInstanceName(2), true, false);
+
+ checkCaches();
+ }
+
+ /**
+ * @param node Node.
+ * @param topVer Ready exchange version to wait for before trying to merge exchanges.
+ */
+ private void mergeExchangeWaitVersion(Ignite node, long topVer) {
+ ((IgniteKernal)node).context().cache().context().exchange().mergeExchangesTestWaitVersion(
+ new AffinityTopologyVersion(topVer, 0));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void checkCaches() throws Exception {
+ checkCaches0();
+
+ awaitPartitionMapExchange();
+
+ checkCaches0();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void checkCaches0() throws Exception {
+ List<Ignite> nodes = G.allGrids();
+
+ assertTrue(nodes.size() > 0);
+
+ String[] cacheNames = {"c1", "c2"};
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ for (Ignite node : nodes) {
+ for (String cacheName : cacheNames) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ assertNotNull("No cache [node=" + node.name() +
+ ", order=" + node.cluster().localNode().order() +
+ ", cache=" + cacheName + ']', cache);
+
+ for (int i = 0; i < 10; i++) {
+ Integer key = rnd.nextInt(100_000);
+
+ cache.put(key, i);
+
+ assertEquals(i, cache.get(key));
+ }
+ }
+ }
}
}
[2/2] ignite git commit: ignite-5578
Posted by sb...@apache.org.
ignite-5578
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ef038c4c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ef038c4c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ef038c4c
Branch: refs/heads/ignite-5578
Commit: ef038c4cd5ca76befb10a71694cbc38c1b442456
Parents: 3e22eac
Author: sboikov <sb...@gridgain.com>
Authored: Tue Jul 18 12:10:28 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Jul 18 17:46:47 2017 +0300
----------------------------------------------------------------------
.../cache/CacheAffinitySharedManager.java | 188 ++++++++++++--
.../cache/CachePartitionExchangeWorkerTask.java | 2 +-
.../ClientCacheChangeDummyDiscoveryMessage.java | 5 +
.../cache/ClientCacheUpdateTimeout.java | 5 +
.../processors/cache/ExchangeContext.java | 15 +-
.../cache/ExchangeDiscoveryEvents.java | 33 ++-
.../processors/cache/GridCacheAdapter.java | 2 +-
.../GridCachePartitionExchangeManager.java | 70 +++---
.../processors/cache/GridCacheProcessor.java | 4 +-
.../dht/ClientCacheDhtTopologyFuture.java | 4 +
.../dht/GridDhtPartitionTopologyImpl.java | 20 +-
.../distributed/dht/GridDhtTopologyFuture.java | 2 +
.../GridNearAtomicSingleUpdateFuture.java | 2 +-
.../dht/atomic/GridNearAtomicUpdateFuture.java | 2 +-
.../preloader/CacheGroupAffinityMessage.java | 111 +++++----
.../preloader/ForceRebalanceExchangeTask.java | 5 +
.../GridDhtPartitionsExchangeFuture.java | 244 +++++++++++--------
.../preloader/GridDhtPartitionsFullMessage.java | 85 +++++--
.../RebalanceReassignExchangeTask.java | 5 +
...ridNearOptimisticTxPrepareFutureAdapter.java | 2 +-
.../cache/transactions/IgniteTxAdapter.java | 2 +-
.../query/schema/SchemaExchangeWorkerTask.java | 5 +
.../SchemaNodeLeaveExchangeWorkerTask.java | 5 +
.../distributed/CacheExchangeMergeTest.java | 206 +++++++++++++++-
24 files changed, 762 insertions(+), 262 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 0ef2999..df7bf03 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
@@ -52,10 +52,13 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffini
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAssignmentFetchFuture;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CacheGroupAffinityMessage;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
import org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage;
import org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState;
+import org.apache.ignite.internal.util.GridLongList;
import org.apache.ignite.internal.util.future.GridCompoundFuture;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -64,6 +67,7 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgniteUuid;
import org.jetbrains.annotations.Nullable;
@@ -84,6 +88,20 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
private final long clientCacheMsgTimeout =
IgniteSystemProperties.getLong(IgniteSystemProperties.IGNITE_CLIENT_CACHE_CHANGE_MESSAGE_TIMEOUT, 10_000);
+ /** */
+ static final IgniteClosure<ClusterNode, UUID> NODE_TO_ID = new IgniteClosure<ClusterNode, UUID>() {
+ @Override public UUID apply(ClusterNode node) {
+ return node.id();
+ }
+ };
+
+ /** */
+ static final IgniteClosure<ClusterNode, Long> NODE_TO_ORDER = new IgniteClosure<ClusterNode, Long>() {
+ @Override public Long apply(ClusterNode node) {
+ return node.order();
+ }
+ };
+
/** Affinity information for all started caches (initialized on coordinator). */
private ConcurrentMap<Integer, CacheGroupHolder> grpHolders = new ConcurrentHashMap<>();
@@ -1244,34 +1262,135 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
return grpHolder.affinity();
}
- public Map<Integer, Map<Integer, List<UUID>>> onTopologyChange(GridDhtPartitionsExchangeFuture fut,
- boolean crd)
- throws IgniteCheckedException
- {
- final ExchangeDiscoveryEvents evts = fut.context().events();
+ public void mergeExchangesOnServerLeft(final GridDhtPartitionsExchangeFuture fut, final GridDhtPartitionsFullMessage msg) {
+ final Map<Long, ClusterNode> nodesByOrder = new HashMap<>();
- assert evts.serverJoin() || evts.serverLeft();
+ final Map<Object, List<List<ClusterNode>>> affCache = new HashMap<>();
- if (evts.serverLeft()) {
- forAllRegisteredCacheGroups(new IgniteInClosureX<CacheGroupDescriptor>() {
- @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException {
- AffinityTopologyVersion topVer = evts.topologyVersion();
+ forAllCacheGroups(false, new IgniteInClosureX<GridAffinityAssignmentCache>() {
+ @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
+ ExchangeDiscoveryEvents evts = fut.context().events();
+
+ Map<Integer, CacheGroupAffinityMessage> idealAffDiff = msg.idealAffinityDiff();
+
+ List<List<ClusterNode>> idealAssignment =
+ aff.calculate(evts.topologyVersion(), evts.lastEvent(), evts.discoveryCache());
- CacheGroupHolder cache = groupHolder(topVer, desc);
+ CacheGroupAffinityMessage affMsg = idealAffDiff != null ? idealAffDiff.get(aff.groupId()) : null;
- cache.affinity().calculate(topVer, evts.lastEvent(), evts.discoveryCache());
+ List<List<ClusterNode>> newAssignment;
+
+ if (affMsg != null) {
+ Map<Integer, GridLongList> diff = affMsg.assignmentsDiff();
+
+ assert !F.isEmpty(diff);
+
+ newAssignment = new ArrayList<>(idealAssignment);
+
+ for (Map.Entry<Integer, GridLongList> e : diff.entrySet()) {
+ GridLongList assign = e.getValue();
+
+ newAssignment.set(e.getKey(), CacheGroupAffinityMessage.toNodes(assign,
+ nodesByOrder,
+ evts.discoveryCache()));
+ }
}
- });
+ else
+ newAssignment = idealAssignment;
- return initAffinityOnNodeLeft0(evts.topologyVersion(), fut);
+ aff.initialize(evts.topologyVersion(), cachedAssignment(aff, newAssignment, affCache));
+ }
+ });
+
+ synchronized (mux) {
+ affCalcVer = fut.context().events().waitRebalanceEventVersion();
}
- else {
- WaitRebalanceInfo waitRebalanceInfo = initAffinityOnNodeJoin(evts, crd);
+ }
- setWaitRebalanceInfo(waitRebalanceInfo, evts.topologyVersion(), crd);
+ public void onJoin(final GridDhtPartitionsExchangeFuture fut, GridDhtPartitionsFullMessage msg)
+ throws IgniteCheckedException {
+ final Set<Integer> affReq = fut.context().groupsAffinityRequestOnJoin();
- return null;
+ final Map<Long, ClusterNode> nodesByOrder = new HashMap<>();
+
+ final Map<Integer, CacheGroupAffinityMessage> joinedNodeAff = msg.joinedNodeAffinity();
+
+ assert !F.isEmpty(joinedNodeAff) : msg;
+ assert joinedNodeAff.size() >= affReq.size();
+
+ forAllCacheGroups(false, new IgniteInClosureX<GridAffinityAssignmentCache>() {
+ @Override public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
+ if (affReq.contains(aff.groupId())) {
+ assert AffinityTopologyVersion.NONE.equals(aff.lastVersion());
+
+ CacheGroupAffinityMessage affMsg = joinedNodeAff.get(aff.groupId());
+
+ assert affMsg != null;
+
+ ExchangeDiscoveryEvents evts = fut.context().events();
+
+ List<List<ClusterNode>> assignments = affMsg.createAssignments(nodesByOrder, evts.discoveryCache());
+
+ // Calculate ideal assignments.
+ if (!aff.centralizedAffinityFunction())
+ aff.calculate(evts.topologyVersion(), evts.lastEvent(), evts.discoveryCache());
+
+ aff.initialize(evts.topologyVersion(), assignments);
+
+ CacheGroupContext grp = cctx.cache().cacheGroup(aff.groupId());
+
+ assert grp != null;
+
+ grp.topology().initPartitions(fut);
+ }
+ }
+ });
+
+ if (!cctx.kernalContext().clientNode()) {
+ synchronized (mux) {
+ affCalcVer = fut.context().events().topologyVersion();
+ }
+ }
+ }
+
+ public void mergeExchangesOnServerJoin(GridDhtPartitionsExchangeFuture fut, boolean crd)
+ throws IgniteCheckedException {
+ final ExchangeDiscoveryEvents evts = fut.context().events();
+
+ assert evts.serverJoin() && !evts.serverLeft();
+
+ WaitRebalanceInfo waitRebalanceInfo = initAffinityOnNodeJoin(evts, crd);
+
+ setWaitRebalanceInfo(waitRebalanceInfo, evts.waitRebalanceEventVersion(), crd);
+ }
+
+ public Map<Integer, CacheGroupAffinityMessage> mergeExchangesInitAffinityOnServerLeft(
+ GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException
+ {
+ final ExchangeDiscoveryEvents evts = fut.context().events();
+
+ assert evts.serverLeft();
+
+ forAllRegisteredCacheGroups(new IgniteInClosureX<CacheGroupDescriptor>() {
+ @Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException {
+ AffinityTopologyVersion topVer = evts.topologyVersion();
+
+ CacheGroupHolder cache = groupHolder(topVer, desc);
+
+ cache.affinity().calculate(topVer, evts.lastEvent(), evts.discoveryCache());
+ }
+ });
+
+ synchronized (mux) {
+ affCalcVer = evts.waitRebalanceEventVersion();
}
+
+ Map<Integer, Map<Integer, List<Long>>> diff = initAffinityOnNodeLeft0(evts.topologyVersion(),
+ fut,
+ NODE_TO_ORDER,
+ true);
+
+ return CacheGroupAffinityMessage.createAffinityDiffMessages(diff);
}
/**
@@ -1686,7 +1805,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
return null;
}
else {
- final WaitRebalanceInfo waitRebalanceInfo = new WaitRebalanceInfo(evts.topologyVersion());
+ final WaitRebalanceInfo waitRebalanceInfo = new WaitRebalanceInfo(evts.waitRebalanceEventVersion());
forAllRegisteredCacheGroups(new IgniteInClosureX<CacheGroupDescriptor>() {
@Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException {
@@ -1847,7 +1966,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
initFut.listen(new IgniteInClosure<IgniteInternalFuture<?>>() {
@Override public void apply(IgniteInternalFuture<?> initFut) {
try {
- resFut.onDone(initAffinityOnNodeLeft0(fut.topologyVersion(), fut));
+ resFut.onDone(initAffinityOnNodeLeft0(fut.topologyVersion(), fut, NODE_TO_ID, false));
}
catch (IgniteCheckedException e) {
resFut.onDone(e);
@@ -1858,7 +1977,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
return resFut;
}
else
- return new GridFinishedFuture<>(initAffinityOnNodeLeft0(fut.topologyVersion(), fut));
+ return new GridFinishedFuture<>(initAffinityOnNodeLeft0(fut.topologyVersion(), fut, NODE_TO_ID, false));
}
/**
@@ -1866,14 +1985,16 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
* @return Affinity assignment.
* @throws IgniteCheckedException If failed.
*/
- private Map<Integer, Map<Integer, List<UUID>>> initAffinityOnNodeLeft0(final AffinityTopologyVersion topVer,
- final GridDhtPartitionsExchangeFuture fut)
+ private <T> Map<Integer, Map<Integer, List<T>>> initAffinityOnNodeLeft0(final AffinityTopologyVersion topVer,
+ final GridDhtPartitionsExchangeFuture fut,
+ final IgniteClosure<ClusterNode, T> c,
+ final boolean initAff)
throws IgniteCheckedException {
- final WaitRebalanceInfo waitRebalanceInfo = new WaitRebalanceInfo(topVer);
+ final WaitRebalanceInfo waitRebalanceInfo = new WaitRebalanceInfo(fut.context().events().waitRebalanceEventVersion());
final Collection<ClusterNode> aliveNodes = cctx.discovery().nodes(topVer);
- final Map<Integer, Map<Integer, List<UUID>>> assignment = new HashMap<>();
+ final Map<Integer, Map<Integer, List<T>>> assignment = new HashMap<>();
forAllRegisteredCacheGroups(new IgniteInClosureX<CacheGroupDescriptor>() {
@Override public void applyx(CacheGroupDescriptor desc) throws IgniteCheckedException {
@@ -1892,9 +2013,11 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
assert newAssignment != null;
+ List<List<ClusterNode>> newAssignment0 = initAff ? new ArrayList<>(newAssignment) : null;
+
GridDhtPartitionTopology top = grpHolder.topology(fut);
- Map<Integer, List<UUID>> cacheAssignment = null;
+ Map<Integer, List<T>> cacheAssignment = null;
for (int p = 0; p < newAssignment.size(); p++) {
List<ClusterNode> newNodes = newAssignment.get(p);
@@ -1960,15 +2083,26 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
}
if (newNodes0 != null) {
+ if (newAssignment0 != null)
+ newAssignment0.set(p, newNodes0);
+
if (cacheAssignment == null)
cacheAssignment = new HashMap<>();
- cacheAssignment.put(p, toIds0(newNodes0));
+ List<T> n = new ArrayList<>(newNodes0.size());
+
+ for (int i = 0; i < newNodes0.size(); i++)
+ n.add(c.apply(newNodes0.get(i)));
+
+ cacheAssignment.put(p, n);
}
}
if (cacheAssignment != null)
assignment.put(grpHolder.groupId(), cacheAssignment);
+
+ if (initAff)
+ grpHolder.affinity().initialize(topVer, newAssignment0);
}
});
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
index ad0dcc9..cfbfa6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CachePartitionExchangeWorkerTask.java
@@ -21,5 +21,5 @@ package org.apache.ignite.internal.processors.cache;
* Cache partition exchange worker task marker interface.
*/
public interface CachePartitionExchangeWorkerTask {
- // No-op.
+ boolean skipForExchangeMerge();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheChangeDummyDiscoveryMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheChangeDummyDiscoveryMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheChangeDummyDiscoveryMessage.java
index 68bca27..44f6002 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheChangeDummyDiscoveryMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheChangeDummyDiscoveryMessage.java
@@ -60,6 +60,11 @@ public class ClientCacheChangeDummyDiscoveryMessage implements DiscoveryCustomMe
this.cachesToClose = cachesToClose;
}
+ /** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return true;
+ }
+
/**
* @return Start request ID.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheUpdateTimeout.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheUpdateTimeout.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheUpdateTimeout.java
index aab3a3e..73cc69a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheUpdateTimeout.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClientCacheUpdateTimeout.java
@@ -37,6 +37,11 @@ class ClientCacheUpdateTimeout extends GridTimeoutObjectAdapter implements Cache
}
/** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
@Override public void onTimeout() {
if (!cctx.kernalContext().isStopping())
cctx.exchange().addCustomTask(this);
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeContext.java
index 1d7b73a..1f5d3ba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeContext.java
@@ -23,6 +23,8 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.Gri
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
import org.jetbrains.annotations.Nullable;
+import static org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT;
+
/**
*
*/
@@ -40,17 +42,22 @@ public class ExchangeContext {
private final ExchangeDiscoveryEvents evts;
/**
- * @param protocolVer Protocol version.
* @param fut Exchange future.
*/
- public ExchangeContext(int protocolVer, GridDhtPartitionsExchangeFuture fut) {
+ public ExchangeContext(GridDhtPartitionsExchangeFuture fut) {
+ int protocolVer = GridCachePartitionExchangeManager.exchangeProtocolVersion(
+ fut.discoCache().minimumNodeVersion());
+
fetchAffOnJoin = protocolVer == 1;
- merge = protocolVer > 1;
+ merge = protocolVer > 1 && fut.discoveryEvent().type() != EVT_DISCOVERY_CUSTOM_EVT;
evts = new ExchangeDiscoveryEvents(fut);
}
+ /**
+ * @return Discovery events.
+ */
public ExchangeDiscoveryEvents events() {
return evts;
}
@@ -80,7 +87,7 @@ public class ExchangeContext {
return requestGrpsAffOnJoin;
}
- public boolean canMergeExchanges() {
+ public boolean mergeExchanges() {
return merge;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeDiscoveryEvents.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeDiscoveryEvents.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeDiscoveryEvents.java
index f1c4bea..db9173f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeDiscoveryEvents.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ExchangeDiscoveryEvents.java
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT;
/**
*
@@ -40,12 +41,18 @@ public class ExchangeDiscoveryEvents {
private AffinityTopologyVersion topVer;
/** */
+ private AffinityTopologyVersion srvEvtTopVer;
+
+ /** */
private DiscoCache discoCache;
/** */
private DiscoveryEvent lastEvt;
/** */
+ private DiscoveryEvent lastSrvEvt;
+
+ /** */
private List<DiscoveryEvent> evts = new ArrayList<>();
/** */
@@ -70,6 +77,10 @@ public class ExchangeDiscoveryEvents {
return false;
}
+ public AffinityTopologyVersion waitRebalanceEventVersion() {
+ return srvEvtTopVer != null ? srvEvtTopVer : topVer;
+ }
+
void addEvent(AffinityTopologyVersion topVer, DiscoveryEvent evt, DiscoCache cache) {
evts.add(evt);
@@ -77,15 +88,21 @@ public class ExchangeDiscoveryEvents {
this.lastEvt = evt;
this.discoCache = cache;
- ClusterNode node = evt.eventNode();
+ if (evt.type() != EVT_DISCOVERY_CUSTOM_EVT) {
+ ClusterNode node = evt.eventNode();
+
+ if (!CU.clientNode(node)) {
+ lastSrvEvt = evt;
+
+ srvEvtTopVer = new AffinityTopologyVersion(evt.topologyVersion(), 0);
- if (!CU.clientNode(node)) {
- if (evt.type()== EVT_NODE_JOINED)
- srvJoin = true;
- else {
- assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
+ if (evt.type()== EVT_NODE_JOINED)
+ srvJoin = true;
+ else {
+ assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED : evt;
- srvLeft = !CU.clientNode(node);
+ srvLeft = !CU.clientNode(node);
+ }
}
}
}
@@ -99,7 +116,7 @@ public class ExchangeDiscoveryEvents {
}
public DiscoveryEvent lastEvent() {
- return lastEvt;
+ return lastSrvEvt != null ? lastSrvEvt : lastEvt;
}
public AffinityTopologyVersion topologyVersion() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 9213be3..fabc7ab 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
@@ -5068,7 +5068,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
return op(tx, (AffinityTopologyVersion)null);
// Tx needs affinity for entry creation, wait when affinity is ready to avoid blocking inside async operation.
- final AffinityTopologyVersion topVer = ctx.shared().exchange().topologyVersion();
+ final AffinityTopologyVersion topVer = ctx.shared().exchange().readyAffinityVersion();
IgniteInternalFuture<?> topFut = ctx.shared().exchange().affinityReadyFuture(topVer);
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 1db4b09..d592cd4 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
@@ -598,7 +598,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
* @param ver Node version.
* @return Supported exchange protocol version.
*/
- public int exchangeProtocolVersion(IgniteProductVersion ver) {
+ static int exchangeProtocolVersion(IgniteProductVersion ver) {
if (ver.compareToIgnoreTimestamp(EXCHANGE_PROTOCOL_2_SINCE) >= 0)
return 2;
@@ -1240,7 +1240,10 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
* @param topVer Topology version.
* @param err Error.
*/
- public void onExchangeDone(AffinityTopologyVersion topVer, @Nullable Throwable err) {
+ public void onExchangeDone(AffinityTopologyVersion topVer, AffinityTopologyVersion initTopVer, @Nullable Throwable err) {
+ assert topVer != null || err != null;
+ assert initTopVer != null;
+
if (log.isDebugEnabled())
log.debug("Exchange done [topVer=" + topVer + ", err=" + err + ']');
@@ -1267,10 +1270,10 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
}
else {
for (Map.Entry<AffinityTopologyVersion, AffinityReadyFuture> entry : readyFuts.entrySet()) {
- if (entry.getKey().compareTo(topVer) <= 0) {
+ if (entry.getKey().compareTo(initTopVer) <= 0) {
if (log.isDebugEnabled())
log.debug("Completing created topology ready future with error " +
- "[ver=" + topVer + ", fut=" + entry.getValue() + ']');
+ "[ver=" + entry.getKey() + ", fut=" + entry.getValue() + ']');
entry.getValue().onDone(err);
}
@@ -1283,7 +1286,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
int skipped = 0;
for (GridDhtPartitionsExchangeFuture fut : exchFuts0.values()) {
- if (topVer.compareTo(fut.exchangeId().topologyVersion()) < 0)
+ if (initTopVer.compareTo(fut.exchangeId().topologyVersion()) < 0)
continue;
skipped++;
@@ -1356,7 +1359,7 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
cctx.database().releaseHistoryForPreloading();
}
else
- exchangeFuture(msg.exchangeId(), null, null, null, null).onReceive(node, msg);
+ exchangeFuture(msg.exchangeId(), null, null, null, null).onReceiveFullMessage(node, msg);
}
finally {
leaveBusy();
@@ -1405,24 +1408,8 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
if (updated)
scheduleResendPartitions();
}
- else {
- if (msg.client()) {
- final GridDhtPartitionsExchangeFuture exchFut = exchangeFuture(msg.exchangeId(),
- null,
- null,
- null,
- null);
-
- exchFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
- @Override public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
- // Finished future should reply only to sender client node.
- exchFut.onReceive(node, msg);
- }
- });
- }
- else
- exchangeFuture(msg.exchangeId(), null, null, null, null).onReceive(node, msg);
- }
+ else
+ exchangeFuture(msg.exchangeId(), null, null, null, null).onReceiveSingleMessage(node, msg);
}
finally {
leaveBusy();
@@ -1762,8 +1749,13 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
if (task instanceof GridDhtPartitionsExchangeFuture) {
GridDhtPartitionsExchangeFuture fut = (GridDhtPartitionsExchangeFuture) task;
- if (fut.topologyVersion().compareTo(resVer) > 0)
+ if (fut.topologyVersion().compareTo(resVer) > 0) {
+ log.info("Merge exchange future on finish stop [curFut=" + curFut.topologyVersion() +
+ ", resVer=" + resVer +
+ ", nextFutVer=" + fut.topologyVersion() + ']');
+
break;
+ }
log.info("Merge exchange future on finish [curFut=" + curFut.topologyVersion() +
", mergedFut=" + fut.topologyVersion() + ']');
@@ -1823,6 +1815,8 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
}
}
}
+
+ this.exchMergeTestWaitVer = null;
}
synchronized (curFut) {
@@ -1834,10 +1828,19 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
DiscoveryEvent evt = fut.discoveryEvent();
+ if (evt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
+ log.info("Stop merge, custom event found: " + evt);
+
+ break;
+ }
+
ClusterNode node = evt.eventNode();
- if (!supportsMergeExchanges(node))
+ if (!supportsMergeExchanges(node)) {
+ log.info("Stop merge, node does not support merge: " + node);
+
break;
+ }
log.info("Merge exchange future [curFut=" + curFut.topologyVersion() +
", mergedFut=" + fut.topologyVersion() + ']');
@@ -1846,15 +1849,20 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
fut.discoveryEvent(),
fut.discoCache());
- if (evt.type() == EVT_NODE_JOINED && !CU.clientNode(node)) {
- if (fut.mergeServerJoinExchange(curFut))
+ if (evt.type() == EVT_NODE_JOINED) {
+ if (fut.mergeJoinExchange(curFut))
awaited++;
}
exchWorker.futQ.remove(fut);
}
- else
- break;
+ else {
+ if (!task.skipForExchangeMerge()) {
+ log.info("Stop merge, custom task found: " + task);
+
+ break;
+ }
+ }
}
return awaited == 0;
@@ -1939,6 +1947,8 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
if (resVer.compareTo(fut0.topologyVersion()) >= 0)
futQ.remove(fut0);
+ else
+ break;
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 5b709b3..88fa9f1 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
@@ -2103,11 +2103,11 @@ public class GridCacheProcessor extends GridProcessorAdapter {
*/
@SuppressWarnings("unchecked")
public void onExchangeDone(
- AffinityTopologyVersion topVer,
+ AffinityTopologyVersion cacheStartVer,
@Nullable ExchangeActions exchActions,
@Nullable Throwable err
) {
- initCacheProxies(topVer, err);
+ initCacheProxies(cacheStartVer, err);
if (exchActions == null)
return;
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/ClientCacheDhtTopologyFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/ClientCacheDhtTopologyFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/ClientCacheDhtTopologyFuture.java
index 3166159..d0b2c72 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/ClientCacheDhtTopologyFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/ClientCacheDhtTopologyFuture.java
@@ -56,6 +56,10 @@ public class ClientCacheDhtTopologyFuture extends GridDhtTopologyFutureAdapter
onDone(e);
}
+ @Override public AffinityTopologyVersion resultTopologyVersion() {
+ return topologyVersion();
+ }
+
/**
* @param grp Cache group.
* @param topNodes Topology nodes.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 e477a82..74156d9 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
@@ -286,6 +286,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
long updateSeq = this.updateSeq.incrementAndGet();
+ topVer = exchFut.context().events().topologyVersion();
+
initPartitions0(exchFut, updateSeq);
consistencyCheck();
@@ -493,15 +495,17 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
}
}
- if (grpStarted ||
- exchFut.discoveryEvent().type() == EVT_DISCOVERY_CUSTOM_EVT ||
- exchFut.serverNodeDiscoveryEvent()) {
- if (affReady)
- initPartitions0(exchFut, updateSeq);
- else {
- List<List<ClusterNode>> aff = grp.affinity().idealAssignment();
+ if (grp.affinityNode()) {
+ if (grpStarted ||
+ exchFut.discoveryEvent().type() == EVT_DISCOVERY_CUSTOM_EVT ||
+ exchFut.serverNodeDiscoveryEvent()) {
+ if (affReady)
+ initPartitions0(exchFut, updateSeq);
+ else {
+ List<List<ClusterNode>> aff = grp.affinity().idealAssignment();
- createPartitions(aff, updateSeq);
+ createPartitions(aff, updateSeq);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFuture.java
index aefc7c9..4b5e189 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFuture.java
@@ -39,6 +39,8 @@ public interface GridDhtTopologyFuture extends IgniteInternalFuture<AffinityTopo
*/
public AffinityTopologyVersion topologyVersion();
+ public AffinityTopologyVersion resultTopologyVersion();
+
/**
* Returns error is cache topology is not valid.
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
index f5d89c4..db98052 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
@@ -420,7 +420,7 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
return;
}
- topVer = fut.topologyVersion();
+ topVer = fut.resultTopologyVersion();
}
else {
assert !topLocked : this;
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index 138645d..f715486 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -640,7 +640,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
return;
}
- topVer = fut.topologyVersion();
+ topVer = fut.resultTopologyVersion();
}
else {
assert !topLocked : this;
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/CacheGroupAffinityMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/CacheGroupAffinityMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/CacheGroupAffinityMessage.java
index 5cd5d26..69a507c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/CacheGroupAffinityMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/CacheGroupAffinityMessage.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.GridDirectCollection;
+import org.apache.ignite.internal.GridDirectMap;
import org.apache.ignite.internal.managers.discovery.DiscoCache;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
@@ -45,12 +46,13 @@ public class CacheGroupAffinityMessage implements Message {
private static final long serialVersionUID = 0L;
/** */
- private int grpId;
-
- /** */
@GridDirectCollection(GridLongList.class)
private List<GridLongList> assigns;
+ /** */
+ @GridDirectMap(keyType = Integer.class, valueType = GridLongList.class)
+ private Map<Integer, GridLongList> assignsDiff;
+
/**
*
*/
@@ -59,31 +61,50 @@ public class CacheGroupAffinityMessage implements Message {
}
/**
- * @param grpId Group ID.
* @param assign0 Assignment.
*/
- private CacheGroupAffinityMessage(int grpId, List<List<ClusterNode>> assign0) {
- this.grpId = grpId;
+ private CacheGroupAffinityMessage(List<List<ClusterNode>> assign0, Map<Integer, List<Long>> assignDiff0) {
+ if (assign0 != null) {
+ assigns = new ArrayList<>(assign0.size());
+
+ for (int i = 0; i < assign0.size(); i++) {
+ List<ClusterNode> nodes = assign0.get(i);
+
+ GridLongList l = new GridLongList(nodes.size());
+
+ for (int n = 0; n < nodes.size(); n++)
+ l.add(nodes.get(n).order());
+
+ assigns.add(l);
+ }
+ }
- assigns = new ArrayList<>(assign0.size());
+ if (assignDiff0 != null) {
+ assignsDiff = U.newHashMap(assignDiff0.size());
- for (int i = 0; i < assign0.size(); i++) {
- List<ClusterNode> nodes = assign0.get(i);
+ for (Map.Entry<Integer, List<Long>> e : assignDiff0.entrySet()) {
+ List<Long> orders = e.getValue();
- GridLongList l = new GridLongList(nodes.size());
+ GridLongList l = new GridLongList(orders.size());
- for (int n = 0; n < nodes.size(); n++)
- l.add(nodes.get(n).order());
+ for (int n = 0; n < orders.size(); n++)
+ l.add(orders.get(n));
- assigns.add(l);
+ assignsDiff.put(e.getKey(), l);
+ }
}
}
- /**
- * @return Cache group ID.
- */
- int groupId() {
- return grpId;
+ public static Map<Integer, CacheGroupAffinityMessage> createAffinityDiffMessages(Map<Integer, Map<Integer, List<Long>>> affDiff) {
+ if (F.isEmpty(affDiff))
+ return null;
+
+ Map<Integer, CacheGroupAffinityMessage> map = U.newHashMap(affDiff.size());
+
+ for (Map.Entry<Integer, Map<Integer, List<Long>>> e : affDiff.entrySet())
+ map.put(e.getKey(), new CacheGroupAffinityMessage(null, e.getValue()));
+
+ return map;
}
/**
@@ -98,7 +119,7 @@ public class CacheGroupAffinityMessage implements Message {
AffinityTopologyVersion topVer,
Collection<Integer> affReq,
@Nullable Map<Integer, CacheGroupAffinityMessage> cachesAff) {
- assert !F.isEmpty(affReq);
+ assert !F.isEmpty(affReq) : affReq;
if (cachesAff == null)
cachesAff = U.newHashMap(affReq.size());
@@ -107,47 +128,55 @@ public class CacheGroupAffinityMessage implements Message {
if (!cachesAff.containsKey(grpId)) {
List<List<ClusterNode>> assign = cctx.affinity().affinity(grpId).assignments(topVer);
- cachesAff.put(grpId, new CacheGroupAffinityMessage(grpId, assign));
+ cachesAff.put(grpId, new CacheGroupAffinityMessage(assign, null));
}
}
return cachesAff;
}
+ public static List<ClusterNode> toNodes(GridLongList assign, Map<Long, ClusterNode> nodesByOrder, DiscoCache discoCache) {
+ List<ClusterNode> assign0 = new ArrayList<>(assign.size());
+
+ for (int n = 0; n < assign.size(); n++) {
+ long order = assign.get(n);
+
+ ClusterNode affNode = nodesByOrder.get(order);
+
+ if (affNode == null) {
+ affNode = discoCache.serverNodeByOrder(order);
+
+ assert affNode != null : order;
+
+ nodesByOrder.put(order, affNode);
+ }
+
+ assign0.add(affNode);
+ }
+
+ return assign0;
+ }
+
/**
* @param nodesByOrder Nodes by order cache.
* @param discoCache Discovery data cache.
* @return Assignments.
*/
- List<List<ClusterNode>> createAssignments(Map<Long, ClusterNode> nodesByOrder, DiscoCache discoCache) {
+ public List<List<ClusterNode>> createAssignments(Map<Long, ClusterNode> nodesByOrder, DiscoCache discoCache) {
List<List<ClusterNode>> assignments0 = new ArrayList<>(assigns.size());
for (int p = 0; p < assigns.size(); p++) {
GridLongList assign = assigns.get(p);
- List<ClusterNode> assign0 = new ArrayList<>(assign.size());
- for (int n = 0; n < assign.size(); n++) {
- long order = assign.get(n);
-
- ClusterNode affNode = nodesByOrder.get(order);
-
- if (affNode == null) {
- affNode = discoCache.serverNodeByOrder(order);
-
- assert affNode != null : order;
-
- nodesByOrder.put(order, affNode);
- }
-
- assign0.add(affNode);
- }
-
- assignments0.add(assign0);
+ assignments0.add(toNodes(assign, nodesByOrder, discoCache));
}
return assignments0;
}
+ public Map<Integer, GridLongList> assignmentsDiff() {
+ return assignsDiff;
+ }
/** {@inheritDoc} */
@Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
@@ -168,7 +197,7 @@ public class CacheGroupAffinityMessage implements Message {
writer.incrementState();
case 1:
- if (!writer.writeInt("grpId", grpId))
+ if (!writer.writeMap("assignsDiff", assignsDiff, MessageCollectionItemType.INT, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
@@ -195,7 +224,7 @@ public class CacheGroupAffinityMessage implements Message {
reader.incrementState();
case 1:
- grpId = reader.readInt("grpId");
+ assignsDiff = reader.readMap("assignsDiff", MessageCollectionItemType.INT, MessageCollectionItemType.MSG, false);
if (!reader.isLastRead())
return false;
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/ForceRebalanceExchangeTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/ForceRebalanceExchangeTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/ForceRebalanceExchangeTask.java
index c820175..dfa0e1e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/ForceRebalanceExchangeTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/ForceRebalanceExchangeTask.java
@@ -42,6 +42,11 @@ public class ForceRebalanceExchangeTask implements CachePartitionExchangeWorkerT
this.forcedRebFut = forcedRebFut;
}
+ /** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return true;
+ }
+
/**
* @return Exchange ID.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 190a417..3dca230 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
@@ -36,7 +36,6 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReadWriteLock;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.cache.affinity.Affinity;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.events.CacheEvent;
@@ -64,7 +63,6 @@ import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch;
import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
import org.apache.ignite.internal.processors.cache.ExchangeActions;
import org.apache.ignite.internal.processors.cache.ExchangeContext;
-import org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
@@ -272,6 +270,11 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
log.debug("Creating exchange future [localNode=" + cctx.localNodeId() + ", fut=" + this + ']');
}
+ /** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return false;
+ }
+
/**
* @return Exchange context.
*/
@@ -298,7 +301,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
this.affChangeMsg = affChangeMsg;
}
- private AffinityTopologyVersion initTopologyVersion() {
+ private AffinityTopologyVersion initialVersion() {
return exchId.topologyVersion();
}
@@ -307,6 +310,10 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
return exchId.topologyVersion();
}
+ @Override public AffinityTopologyVersion resultTopologyVersion() {
+ return exchCtx.events().topologyVersion();
+ }
+
/**
* @param grpId Cache group ID.
* @param partId Partition ID.
@@ -455,8 +462,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
assert discoEvt != null : this;
assert exchId.nodeId().equals(discoEvt.eventNode().id()) : this;
- exchCtx = new ExchangeContext(cctx.exchange().exchangeProtocolVersion(discoCache.minimumNodeVersion()),
- this);
+ exchCtx = new ExchangeContext(this);
try {
discoCache.updateAlives(cctx.discovery());
@@ -482,7 +488,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
", customEvt=" + (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT ? ((DiscoveryCustomEvent)discoEvt).customMessage() : null) +
']');
- ExchangeType exchange = null;
+ ExchangeType exchange;
if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
DiscoveryCustomMessage msg = ((DiscoveryCustomEvent)discoEvt).customMessage();
@@ -521,14 +527,25 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
initCachesOnLocalJoin();
}
- if (exchCtx.canMergeExchanges()) {
- if (cctx.kernalContext().clientNode() || CU.clientNode(discoEvt.eventNode()))
- exchange = onClientNodeEvent(crdNode);
- else {
- if (localJoinExchange())
+ // TODO IGNITE-5578: caches from joining nodes for merged exchanges.
+
+ if (exchCtx.mergeExchanges()) {
+ if (localJoinExchange()) {
+ if (cctx.kernalContext().clientNode()) {
+ onClientNodeEvent(crdNode);
+
+ exchange = ExchangeType.CLIENT;
+ } else {
onServerNodeEvent(crdNode);
- exchange = ExchangeType.ALL_2;
+ exchange = ExchangeType.ALL_2;
+ }
+ }
+ else {
+ if (CU.clientNode(discoEvt.eventNode()))
+ exchange = onClientNodeEvent(crdNode);
+ else
+ exchange = cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL_2;
}
}
else {
@@ -554,7 +571,8 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
}
case CLIENT: {
- initTopologies();
+ if (!exchCtx.mergeExchanges())
+ initTopologies();
clientOnlyExchange();
@@ -1234,19 +1252,25 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
/**
* @param nodes Nodes.
- * @param cachesAff Affinity if was requested by some nodes.
* @throws IgniteCheckedException If failed.
*/
- private void sendAllPartitions(Collection<ClusterNode> nodes, Collection<CacheGroupAffinityMessage> cachesAff)
+ private void sendAllPartitions(Collection<ClusterNode> nodes,
+ Map<Integer, CacheGroupAffinityMessage> joinedNodeAff,
+ Map<Integer, CacheGroupAffinityMessage> idealAffDiff,
+ @Nullable GridDhtPartitionExchangeId msgExchId)
throws IgniteCheckedException {
boolean singleNode = nodes.size() == 1;
GridDhtPartitionsFullMessage msg = createPartitionsMessage(true);
- if (exchCtx.canMergeExchanges())
+ if (exchCtx.mergeExchanges()) {
msg.resultTopologyVersion(exchCtx.events().topologyVersion());
- GridDhtPartitionsFullMessage msgWithAff = null;
+ if (exchCtx.events().serverLeft())
+ msg.idealAffinityDiff(idealAffDiff);
+ }
+
+ GridDhtPartitionsFullMessage joinedNodeMsg = null;
assert !nodes.contains(cctx.localNode());
@@ -1260,31 +1284,38 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
for (ClusterNode node : nodes) {
GridDhtPartitionsFullMessage sndMsg = msg;
- if (cachesAff != null) {
+ if (joinedNodeAff != null) {
if (singleNode)
- msg.cachesAffinity(cachesAff);
+ msg.joinedNodeAffinity(joinedNodeAff);
else {
GridDhtPartitionsSingleMessage singleMsg = msgs.get(node.id());
if (singleMsg != null && singleMsg.cacheGroupsAffinityRequest() != null) {
- if (msgWithAff == null) {
- msgWithAff = msg.copy();
+ if (joinedNodeMsg == null) {
+ joinedNodeMsg = msg.copy();
- msgWithAff.cachesAffinity(cachesAff);
+ joinedNodeMsg.joinedNodeAffinity(joinedNodeAff);
}
- sndMsg = msgWithAff;
+ sndMsg = joinedNodeMsg;
}
}
}
try {
- GridDhtPartitionsSingleMessage mergedMsg = mergedJoinExchMsgs.get(node.id());
+ GridDhtPartitionExchangeId sndExchId = msgExchId;
+
+ if (sndExchId == null && mergedJoinExchMsgs != null) {
+ GridDhtPartitionsSingleMessage mergedMsg = mergedJoinExchMsgs.get(node.id());
+
+ if (mergedMsg != null)
+ sndExchId = mergedMsg.exchangeId();
+ }
- if (mergedMsg != null) {
+ if (sndExchId != null && !sndExchId.equals(exchangeId())) {
sndMsg = sndMsg.copy();
- sndMsg.exchangeId(mergedMsg.exchangeId());
+ sndMsg.exchangeId(sndExchId);
}
cctx.io().send(node, sndMsg, SYSTEM_POOL);
@@ -1391,9 +1422,9 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
tryToPerformLocalSnapshotOperation();
- cctx.cache().onExchangeDone(res, exchActions, err);
+ cctx.cache().onExchangeDone(initialVersion(), exchActions, err);
- cctx.exchange().onExchangeDone(res, err);
+ cctx.exchange().onExchangeDone(res, initialVersion(), err);
if (exchActions != null && err == null)
exchActions.completeRequestFutures(cctx);
@@ -1485,10 +1516,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
private GridDhtPartitionsExchangeFuture mergedWith;
/** */
- private GridDhtPartitionsSingleMessage pendingSrvJoinMsg;
-
- /** */
- private Map<ClusterNode, GridDhtPartitionsSingleMessage> pendingClientMsgs;
+ private GridDhtPartitionsSingleMessage pendingJoinMsg;
private boolean addMergedJoinExchange(UUID nodeId, GridDhtPartitionsSingleMessage msg) {
if (mergedJoinExchMsgs == null)
@@ -1524,22 +1552,32 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
/**
* @param fut Current exchange to merge with.
+ * @return {@code True} if need wait for message from joined server node.
*/
- @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
- public boolean mergeServerJoinExchange(final GridDhtPartitionsExchangeFuture fut) {
+ public boolean mergeJoinExchange(final GridDhtPartitionsExchangeFuture fut) {
boolean wait;
synchronized (this) {
assert !isDone();
assert !initFut.isDone();
assert mergedWith == null;
- assert !CU.clientNode(discoEvt.eventNode()) : discoEvt;
mergedWith = fut;
- wait = fut.addMergedJoinExchange(discoEvt.eventNode().id(), pendingSrvJoinMsg);
+ ClusterNode joinedNode = discoEvt.eventNode();
+
+ if (CU.clientNode(joinedNode)) {
+ if (pendingJoinMsg != null) {
+ if (mergedJoinExchMsgs == null)
+ mergedJoinExchMsgs = new LinkedHashMap<>();
+
+ mergedJoinExchMsgs.put(joinedNode.id(), pendingJoinMsg);
+ }
- // TODO 5578 client messages.
+ wait = false;
+ }
+ else
+ wait = fut.addMergedJoinExchange(joinedNode.id(), pendingJoinMsg);
}
return wait;
@@ -1550,6 +1588,16 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
* @param msg
*/
void onReceiveMerged(final ClusterNode node, final GridDhtPartitionsSingleMessage msg) {
+ if (msg.client()) {
+ listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
+ @Override public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
+ sendAllPartitions(msg, node.id(), 0);
+ }
+ });
+
+ return;
+ }
+
boolean done = false;
synchronized (this) {
@@ -1580,7 +1628,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
* @param node Sender node.
* @param msg Single partition info.
*/
- public void onReceive(final ClusterNode node, final GridDhtPartitionsSingleMessage msg) {
+ public void onReceiveSingleMessage(final ClusterNode node, final GridDhtPartitionsSingleMessage msg) {
assert msg != null;
assert exchId.equals(msg.exchangeId()) : msg;
@@ -1593,10 +1641,11 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
sendAllPartitions(msg, node.id(), cctx.gridConfig().getNetworkSendRetryCount());
}
else {
- assert !msg.client() : msg;
- assert msg.lastVersion() != null : msg;
+ if (!msg.client()) {
+ assert msg.lastVersion() != null : msg;
- updateLastVersion(msg.lastVersion());
+ updateLastVersion(msg.lastVersion());
+ }
GridDhtPartitionsExchangeFuture mergedWith0 = null;
@@ -1604,16 +1653,8 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
if (mergedWith != null)
mergedWith0 = mergedWith;
else {
- if (msg.client()) {
- assert false;
-
- // TODO IGNITE-5578
- }
- else if (exchangeId().isJoined() && node.id().equals(exchId.nodeId())) {
- assert !CU.clientNode(node) : node;
-
- pendingSrvJoinMsg = msg;
- }
+ if (exchangeId().isJoined() && node.id().equals(exchId.nodeId()))
+ pendingJoinMsg = msg;
}
}
@@ -1623,6 +1664,17 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
return;
}
+ if (msg.client()) {
+ listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
+ @Override public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
+ if (!centralizedAff)
+ sendAllPartitions(msg, node.id(), cctx.gridConfig().getNetworkSendRetryCount());
+ }
+ });
+
+ return;
+ }
+
initFut.listen(new CI1<IgniteInternalFuture<Boolean>>() {
@Override public void apply(IgniteInternalFuture<Boolean> f) {
try {
@@ -1930,7 +1982,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
}
}
- if (exchCtx.canMergeExchanges()) {
+ if (exchCtx.mergeExchanges()) {
boolean finish = cctx.exchange().mergeExchangesOnCoordinator(this);
if (!finish)
@@ -1954,8 +2006,17 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
try {
log.info("finishExchangeOnCoordinator [topVer=" + topologyVersion() + ", resVer=" + exchCtx.events().topologyVersion() + ']');
- if (exchCtx.canMergeExchanges()) {
- cctx.affinity().onTopologyChange(this, true);
+ AffinityTopologyVersion resTopVer = exchCtx.events().topologyVersion();
+
+ Map<Integer, CacheGroupAffinityMessage> idealAffDiff = null;
+
+ if (exchCtx.mergeExchanges()) {
+ assert exchCtx.events().serverJoin() || exchCtx.events().serverLeft();
+
+ if (exchCtx.events().serverLeft())
+ idealAffDiff = cctx.affinity().mergeExchangesInitAffinityOnServerLeft(this);
+ else
+ cctx.affinity().mergeExchangesOnServerJoin(this, true);
for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
if (grp.isLocal() || cacheGroupStopping(grp.groupId()))
@@ -1974,9 +2035,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
}
}
- AffinityTopologyVersion resTopVer = exchCtx.events().topologyVersion();
-
- Map<Integer, CacheGroupAffinityMessage> cachesAff = null;
+ Map<Integer, CacheGroupAffinityMessage> joinedNodeAff = null;
for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : msgs.entrySet()) {
GridDhtPartitionsSingleMessage msg = e.getValue();
@@ -1999,10 +2058,10 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
Collection<Integer> affReq = msg.cacheGroupsAffinityRequest();
if (affReq != null) {
- cachesAff = CacheGroupAffinityMessage.createAffinityMessages(cctx,
+ joinedNodeAff = CacheGroupAffinityMessage.createAffinityMessages(cctx,
resTopVer,
affReq,
- cachesAff);
+ joinedNodeAff);
UUID nodeId = e.getKey();
@@ -2038,6 +2097,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
}
}
+ // TODO IGNITE-5578: process all merged events.
if (discoEvt.type() == EVT_NODE_JOINED)
assignPartitionsStates();
else if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
@@ -2063,6 +2123,8 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
cctx.versions().onExchange(lastVer.get().order());
if (centralizedAff) {
+ assert !exchCtx.mergeExchanges();
+
IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut = cctx.affinity().initAffinityOnNodeLeft(this);
if (!fut.isDone()) {
@@ -2120,7 +2182,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
}
if (!nodes.isEmpty())
- sendAllPartitions(nodes, cachesAff != null ? cachesAff.values() : null);
+ sendAllPartitions(nodes, joinedNodeAff, idealAffDiff, null);
onDone(exchCtx.events().topologyVersion(), err);
}
@@ -2159,19 +2221,18 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
if (n != null) {
Collection<Integer> affReq = msg.cacheGroupsAffinityRequest();
- Collection<CacheGroupAffinityMessage> cachesAff = null;
+ Map<Integer, CacheGroupAffinityMessage> joinedNodeAff = null;
if (affReq != null) {
- Map<Integer, CacheGroupAffinityMessage> affMap = CacheGroupAffinityMessage.createAffinityMessages(
+ joinedNodeAff = CacheGroupAffinityMessage.createAffinityMessages(
cctx,
msg.exchangeId().topologyVersion(),
affReq,
null);
-
- cachesAff = affMap.values();
}
- sendAllPartitions(F.asList(n), cachesAff);
+ // TODO IGNITE-5578.
+ sendAllPartitions(F.asList(n), joinedNodeAff, null, msg.exchangeId());
}
}
catch (IgniteCheckedException e) {
@@ -2210,7 +2271,7 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
* @param node Sender node.
* @param msg Full partition info.
*/
- public void onReceive(final ClusterNode node, final GridDhtPartitionsFullMessage msg) {
+ public void onReceiveFullMessage(final ClusterNode node, final GridDhtPartitionsFullMessage msg) {
assert msg != null;
final UUID nodeId = node.id();
@@ -2294,53 +2355,21 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
finishState = new FinishState(crd.id(), msg.resultTopologyVersion());
}
- if (exchCtx.canMergeExchanges()) {
- if (msg.resultTopologyVersion() != null && !initTopologyVersion().equals(msg.resultTopologyVersion())) {
+ if (exchCtx.mergeExchanges()) {
+ if (msg.resultTopologyVersion() != null && !initialVersion().equals(msg.resultTopologyVersion())) {
log.info("Received full message, need merge [curFut=" + topologyVersion() +
", resVer=" + msg.resultTopologyVersion() + ']');
cctx.exchange().mergeExchanges(this, msg.resultTopologyVersion());
}
- if (localJoinExchange()) {
- Set<Integer> affReq = exchCtx.groupsAffinityRequestOnJoin();
-
- ExchangeDiscoveryEvents evts = exchCtx.events();
-
- Map<Long, ClusterNode> nodesByOrder = new HashMap<>();
-
- Collection<CacheGroupAffinityMessage> cachesAff = msg.cachesAffinity();
-
- assert !F.isEmpty(cachesAff) : msg;
- assert cachesAff.size() >= affReq.size();
-
- int cnt = 0;
-
- for (CacheGroupAffinityMessage aff : cachesAff) {
- if (affReq.contains(aff.groupId())) {
- CacheGroupContext grp = cctx.cache().cacheGroup(aff.groupId());
-
- assert grp != null : aff.groupId();
- assert AffinityTopologyVersion.NONE.equals(grp.affinity().lastVersion());
-
- List<List<ClusterNode>> assignments = aff.createAssignments(nodesByOrder, evts.discoveryCache());
-
- // Calculate ideal assignments.
- if (!grp.affinity().centralizedAffinityFunction())
- grp.affinity().calculate(evts.topologyVersion(), evts.lastEvent(), evts.discoveryCache());
-
- grp.affinity().initialize(evts.topologyVersion(), assignments);
-
- grp.topology().initPartitions(this);
-
- cnt++;
- }
- }
-
- assert affReq.size() == cnt : cnt;
- }
+ if (localJoinExchange())
+ cctx.affinity().onJoin(this, msg);
else {
- cctx.affinity().onTopologyChange(this, false);
+ if (exchCtx.events().serverLeft())
+ cctx.affinity().mergeExchangesOnServerLeft(this, msg);
+ else
+ cctx.affinity().mergeExchangesOnServerJoin(this, false);
for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
if (grp.isLocal() || cacheGroupStopping(grp.groupId()))
@@ -2701,6 +2730,9 @@ public class GridDhtPartitionsExchangeFuture extends GridDhtTopologyFutureAdapte
if (this == o)
return true;
+ if (o == null || o.getClass() != getClass())
+ return false;
+
GridDhtPartitionsExchangeFuture fut = (GridDhtPartitionsExchangeFuture)o;
return exchId.equals(fut.exchId);
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 8c11ff2..cce299b 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
@@ -106,8 +106,12 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
private AffinityTopologyVersion resTopVer;
/** */
- @GridDirectCollection(CacheGroupAffinityMessage.class)
- private Collection<CacheGroupAffinityMessage> cachesAff;
+ @GridDirectMap(keyType = Integer.class, valueType = CacheGroupAffinityMessage.class)
+ private Map<Integer, CacheGroupAffinityMessage> joinedNodeAff;
+
+ /** */
+ @GridDirectMap(keyType = Integer.class, valueType = CacheGroupAffinityMessage.class)
+ private Map<Integer, CacheGroupAffinityMessage> idealAffDiff;
/**
* Required by {@link Externalizable}.
@@ -151,7 +155,8 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
cp.partsToReload = partsToReload;
cp.partsToReloadBytes = partsToReloadBytes;
cp.topVer = topVer;
- cp.cachesAff = cachesAff;
+ cp.joinedNodeAff = joinedNodeAff;
+ cp.idealAffDiff = idealAffDiff;
cp.resTopVer = resTopVer;
}
@@ -175,17 +180,31 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
}
/**
- * @return Affinity.
+ * @return
+ */
+ @Nullable public Map<Integer, CacheGroupAffinityMessage> joinedNodeAffinity() {
+ return joinedNodeAff;
+ }
+
+ /**
+ * @param joinedNodeAff
*/
- @Nullable Collection<CacheGroupAffinityMessage> cachesAffinity() {
- return cachesAff;
+ void joinedNodeAffinity(Map<Integer, CacheGroupAffinityMessage> joinedNodeAff) {
+ this.joinedNodeAff = joinedNodeAff;
}
/**
- * @param cachesAff Affinity.
+ * @return
*/
- void cachesAffinity(Collection<CacheGroupAffinityMessage> cachesAff) {
- this.cachesAff = cachesAff;
+ @Nullable public Map<Integer, CacheGroupAffinityMessage> idealAffinityDiff() {
+ return idealAffDiff;
+ }
+
+ /**
+ * @param idealAffDiff
+ */
+ void idealAffinityDiff(Map<Integer, CacheGroupAffinityMessage> idealAffDiff) {
+ this.idealAffDiff = idealAffDiff;
}
/** {@inheritDoc} */
@@ -469,54 +488,60 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
switch (writer.state()) {
case 5:
- if (!writer.writeCollection("cachesAff", cachesAff, MessageCollectionItemType.MSG))
+ if (!writer.writeMap("dupPartsData", dupPartsData, MessageCollectionItemType.INT, MessageCollectionItemType.INT))
return false;
writer.incrementState();
case 6:
- if (!writer.writeMap("dupPartsData", dupPartsData, MessageCollectionItemType.INT, MessageCollectionItemType.INT))
+ if (!writer.writeByteArray("errsBytes", errsBytes))
return false;
writer.incrementState();
case 7:
- if (!writer.writeByteArray("errsBytes", errsBytes))
+ if (!writer.writeMap("idealAffDiff", idealAffDiff, MessageCollectionItemType.INT, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
case 8:
- if (!writer.writeByteArray("partCntrsBytes", partCntrsBytes))
+ if (!writer.writeMap("joinedNodeAff", joinedNodeAff, MessageCollectionItemType.INT, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
case 9:
- if (!writer.writeByteArray("partHistSuppliersBytes", partHistSuppliersBytes))
+ if (!writer.writeByteArray("partCntrsBytes", partCntrsBytes))
return false;
writer.incrementState();
case 10:
- if (!writer.writeByteArray("partsBytes", partsBytes))
+ if (!writer.writeByteArray("partHistSuppliersBytes", partHistSuppliersBytes))
return false;
writer.incrementState();
case 11:
- if (!writer.writeByteArray("partsToReloadBytes", partsToReloadBytes))
+ if (!writer.writeByteArray("partsBytes", partsBytes))
return false;
writer.incrementState();
case 12:
- if (!writer.writeMessage("resTopVer", resTopVer))
+ if (!writer.writeByteArray("partsToReloadBytes", partsToReloadBytes))
return false;
writer.incrementState();
case 13:
+ if (!writer.writeMessage("resTopVer", resTopVer))
+ return false;
+
+ writer.incrementState();
+
+ case 14:
if (!writer.writeMessage("topVer", topVer))
return false;
@@ -539,7 +564,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
switch (reader.state()) {
case 5:
- cachesAff = reader.readCollection("cachesAff", MessageCollectionItemType.MSG);
+ dupPartsData = reader.readMap("dupPartsData", MessageCollectionItemType.INT, MessageCollectionItemType.INT, false);
if (!reader.isLastRead())
return false;
@@ -547,7 +572,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 6:
- dupPartsData = reader.readMap("dupPartsData", MessageCollectionItemType.INT, MessageCollectionItemType.INT, false);
+ errsBytes = reader.readByteArray("errsBytes");
if (!reader.isLastRead())
return false;
@@ -555,7 +580,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 7:
- errsBytes = reader.readByteArray("errsBytes");
+ idealAffDiff = reader.readMap("idealAffDiff", MessageCollectionItemType.INT, MessageCollectionItemType.MSG, false);
if (!reader.isLastRead())
return false;
@@ -563,7 +588,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 8:
- partCntrsBytes = reader.readByteArray("partCntrsBytes");
+ joinedNodeAff = reader.readMap("joinedNodeAff", MessageCollectionItemType.INT, MessageCollectionItemType.MSG, false);
if (!reader.isLastRead())
return false;
@@ -571,7 +596,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 9:
- partHistSuppliersBytes = reader.readByteArray("partHistSuppliersBytes");
+ partCntrsBytes = reader.readByteArray("partCntrsBytes");
if (!reader.isLastRead())
return false;
@@ -579,7 +604,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 10:
- partsBytes = reader.readByteArray("partsBytes");
+ partHistSuppliersBytes = reader.readByteArray("partHistSuppliersBytes");
if (!reader.isLastRead())
return false;
@@ -587,7 +612,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 11:
- partsToReloadBytes = reader.readByteArray("partsToReloadBytes");
+ partsBytes = reader.readByteArray("partsBytes");
if (!reader.isLastRead())
return false;
@@ -595,7 +620,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 12:
- resTopVer = reader.readMessage("resTopVer");
+ partsToReloadBytes = reader.readByteArray("partsToReloadBytes");
if (!reader.isLastRead())
return false;
@@ -603,6 +628,14 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
reader.incrementState();
case 13:
+ resTopVer = reader.readMessage("resTopVer");
+
+ if (!reader.isLastRead())
+ return false;
+
+ reader.incrementState();
+
+ case 14:
topVer = reader.readMessage("topVer");
if (!reader.isLastRead())
@@ -622,7 +655,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
/** {@inheritDoc} */
@Override public byte fieldsCount() {
- return 14;
+ return 15;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/RebalanceReassignExchangeTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/RebalanceReassignExchangeTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/RebalanceReassignExchangeTask.java
index 9a76a8e..7e473be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/RebalanceReassignExchangeTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/RebalanceReassignExchangeTask.java
@@ -35,6 +35,11 @@ public class RebalanceReassignExchangeTask implements CachePartitionExchangeWork
this.exchId = exchId;
}
+ /** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return true;
+ }
+
/**
* @return Exchange ID.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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..6428df7 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
@@ -107,7 +107,7 @@ public abstract class GridNearOptimisticTxPrepareFutureAdapter extends GridNearT
}
if (topFut.isDone()) {
- topVer = topFut.topologyVersion();
+ topVer = topFut.resultTopologyVersion();
if (remap)
tx.onRemap(topVer);
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/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 880d9b9..81c06dd 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
@@ -474,7 +474,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter implement
return topVer;
}
- return cctx.exchange().topologyVersion();
+ return cctx.exchange().readyAffinityVersion();
}
return res;
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
index f97f931..c16a7ba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaExchangeWorkerTask.java
@@ -39,6 +39,11 @@ public class SchemaExchangeWorkerTask implements CachePartitionExchangeWorkerTas
this.msg = msg;
}
+ /** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return false;
+ }
+
/**
* @return Message.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/ef038c4c/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
index 79fbfcd..668a2c6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaNodeLeaveExchangeWorkerTask.java
@@ -39,6 +39,11 @@ public class SchemaNodeLeaveExchangeWorkerTask implements CachePartitionExchange
this.node = node;
}
+ /** {@inheritDoc} */
+ @Override public boolean skipForExchangeMerge() {
+ return true;
+ }
+
/**
* @return Node.
*/