Skip to content

Commit

Permalink
IGNITE-8911 Fixed while cache is restarting it's possible to start ne…
Browse files Browse the repository at this point in the history
…w cache with this name - Fixes #5717.

Signed-off-by: Dmitriy Govorukhin <dmitriy.govorukhin@gmail.com>
  • Loading branch information
EdShangGG authored and dgovorukhin committed Dec 29, 2018
1 parent 6ffaba5 commit 3197f9b
Show file tree
Hide file tree
Showing 30 changed files with 1,171 additions and 418 deletions.
Expand Up @@ -131,7 +131,7 @@ protected String getCfgUrl() {

/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
((IgniteEx)ignite(0)).context().cache().dynamicDestroyCache(DEFAULT_CACHE_NAME, true, true, false);
((IgniteEx)ignite(0)).context().cache().dynamicDestroyCache(DEFAULT_CACHE_NAME, true, true, false, null);

if (conn != null) {
conn.close();
Expand Down
Expand Up @@ -18,6 +18,7 @@

package org.apache.ignite;

import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.lang.IgniteFuture;
import org.jetbrains.annotations.Nullable;

Expand All @@ -29,26 +30,34 @@ public class IgniteCacheRestartingException extends IgniteException {
private static final long serialVersionUID = 0L;

/** */
private final IgniteFuture<?> restartFut;
private final transient IgniteFuture<?> restartFut;

/**
* @param cacheName Error message.
*/
public IgniteCacheRestartingException(String cacheName) {
this(null, cacheName, null);
}

/**
* @param restartFut Restart future.
* @param msg Error message.
* @param cacheName Error message.
*/
public IgniteCacheRestartingException(IgniteFuture<?> restartFut, String msg) {
this(restartFut, msg, null);
public IgniteCacheRestartingException(IgniteFuture<?> restartFut, String cacheName) {
this(restartFut, cacheName, null);
}

/**
* @param restartFut Restart future.
* @param msg Error message.
* @param cacheName Cache name what is restarting.
* @param cause Optional nested exception (can be {@code null}).
*/
public IgniteCacheRestartingException(
IgniteFuture<?> restartFut,
String msg,
@Nullable Throwable cause) {
super(msg, cause);
String cacheName,
@Nullable Throwable cause
) {
super("Cache is restarting:" + cacheName + ", you could wait restart completion with restartFuture", cause);

this.restartFut = restartFut;
}
Expand Down
Expand Up @@ -3039,7 +3039,9 @@ public <K, V> IgniteInternalCache<K, V> getCache(String name) {

Boolean res = false;

if (ctx.cache().cache(cacheName) == null) {
IgniteCacheProxy<K, V> cache = ctx.cache().publicJCache(cacheName, false, true);

if (cache == null) {
res =
sql ? ctx.cache().dynamicStartSqlCache(cacheCfg).get() :
ctx.cache().dynamicStartCache(cacheCfg,
Expand All @@ -3048,9 +3050,11 @@ public <K, V> IgniteInternalCache<K, V> getCache(String name) {
false,
true,
true).get();
}

return new IgniteBiTuple<>(ctx.cache().publicJCache(cacheName), res);
return new IgniteBiTuple<>(ctx.cache().publicJCache(cacheName), res);
}
else
return new IgniteBiTuple<>(cache, res);
}
catch (IgniteCheckedException e) {
throw CU.convertToCacheException(e);
Expand Down Expand Up @@ -3298,7 +3302,7 @@ public IgniteInternalFuture<Boolean> destroyCacheAsync(String cacheName, boolean
try {
checkClusterState();

return ctx.cache().dynamicDestroyCache(cacheName, sql, checkThreadTx, false);
return ctx.cache().dynamicDestroyCache(cacheName, sql, checkThreadTx, false, null);
}
finally {
unguard();
Expand All @@ -3318,7 +3322,7 @@ public IgniteInternalFuture<?> destroyCachesAsync(Collection<String> cacheNames,
try {
checkClusterState();

return ctx.cache().dynamicDestroyCaches(cacheNames, checkThreadTx, false);
return ctx.cache().dynamicDestroyCaches(cacheNames, checkThreadTx);
}
finally {
unguard();
Expand All @@ -3334,10 +3338,15 @@ public IgniteInternalFuture<?> destroyCachesAsync(Collection<String> cacheNames,
try {
checkClusterState();

if (ctx.cache().cache(cacheName) == null)
IgniteCacheProxy<K, V> cache = ctx.cache().publicJCache(cacheName, false, true);

if (cache == null) {
ctx.cache().getOrCreateFromTemplate(cacheName, true).get();

return ctx.cache().publicJCache(cacheName);
return ctx.cache().publicJCache(cacheName);
}

return cache;
}
catch (IgniteCheckedException e) {
throw CU.convertToCacheException(e);
Expand Down

0 comments on commit 3197f9b

Please sign in to comment.