Skip to content

Commit

Permalink
IGNITE-5789 Fix for case server was restarted, client doesn't create …
Browse files Browse the repository at this point in the history
…caches defined in client's configuration. - Fixes #3905.

Signed-off-by: dpavlov <dpavlov@apache.org>
  • Loading branch information
vkuragin authored and dspavlov committed May 23, 2018
1 parent a3a619b commit d821d09
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.ignite.cache.CacheRebalanceMode;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException;
Expand Down Expand Up @@ -72,6 +73,7 @@
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.GridCacheProcessor;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.processors.cache.LocalJoinCachesContext;
import org.apache.ignite.internal.processors.cache.StateChangeRequest;
Expand Down Expand Up @@ -797,6 +799,27 @@ private void initCachesOnLocalJoin() throws IgniteCheckedException {
}

cctx.cache().startCachesOnLocalJoin(locJoinCtx, initialVersion());

ensureClientCachesStarted();
}

/**
* Start client caches if absent.
*/
private void ensureClientCachesStarted() {
GridCacheProcessor cacheProcessor = cctx.cache();

Set<String> cacheNames = new HashSet<>(cacheProcessor.cacheNames());

List<CacheConfiguration> notStartedCacheConfigs = new ArrayList<>();

for (CacheConfiguration cCfg : cctx.gridConfig().getCacheConfiguration()) {
if (!cacheNames.contains(cCfg.getName()))
notStartedCacheConfigs.add(cCfg);
}

if (!notStartedCacheConfigs.isEmpty())
cacheProcessor.dynamicStartCaches(notStartedCacheConfigs, false, false, false);
}

/**
Expand Down Expand Up @@ -3854,6 +3877,7 @@ enum ExchangeType {
/** */
NONE
}

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
package org.apache.ignite.internal.processors.cache;

import javax.cache.CacheException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteClientDisconnectedException;
Expand All @@ -33,23 +36,21 @@
import org.apache.ignite.events.Event;
import org.apache.ignite.events.EventType;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
*/
public class ClientReconnectAfterClusterRestartTest extends GridCommonAbstractTest {
/** Server id. */
private static final int SERVER_ID = 0;

/** Client id. */
public static final int CLIENT_ID = 1;
private static final int CLIENT_ID = 1;

/** Cache params. */
public static final String CACHE_PARAMS = "PPRB_PARAMS";
private static final String CACHE_PARAMS = "PPRB_PARAMS";

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
Expand All @@ -58,9 +59,9 @@ public class ClientReconnectAfterClusterRestartTest extends GridCommonAbstractTe
cfg.setMarshaller(new BinaryMarshaller());
cfg.setIncludeEventTypes(EventType.EVTS_CACHE);

if (getTestIgniteInstanceName(CLIENT_ID).equals(igniteInstanceName))
if (getTestIgniteInstanceName(CLIENT_ID).equals(igniteInstanceName)) {
cfg.setClientMode(true);
else {

CacheConfiguration ccfg = getCacheConfiguration();

cfg.setCacheConfiguration(ccfg);
Expand Down Expand Up @@ -88,7 +89,7 @@ public class ClientReconnectAfterClusterRestartTest extends GridCommonAbstractTe

LinkedHashMap<String, String> fields = new LinkedHashMap<>();

fields.put("ID", "java.lang.Long" );
fields.put("ID", "java.lang.Long");
fields.put("PARTITIONID", "java.lang.Long");
fields.put("CLIENTID", "java.lang.Long");
fields.put("PARAMETRCODE", "java.lang.Long");
Expand All @@ -114,9 +115,9 @@ public class ClientReconnectAfterClusterRestartTest extends GridCommonAbstractTe
/** */
public void testReconnectClient() throws Exception {
try {
startGrid(0);
startGrid(SERVER_ID);

Ignite client = startGrid(1);
Ignite client = startGrid(CLIENT_ID);

checkTopology(2);

Expand Down Expand Up @@ -162,7 +163,7 @@ public void testReconnectClient() throws Exception {

Thread.sleep(2_000);

startGrid(0);
startGrid(SERVER_ID);

try {
assertNull(cache.get(1L));
Expand Down

0 comments on commit d821d09

Please sign in to comment.